From bff8c0a35cfe4de813ae44012c6d2a2331cdaec6 Mon Sep 17 00:00:00 2001 From: dencoded <33698537+dencoded@users.noreply.github.com> Date: Tue, 12 Feb 2019 00:01:41 -0500 Subject: [PATCH] create oauth client test fixed --- api_test.go | 31 ++++++++++++++++++++++++++++++- helpers_test.go | 4 ++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/api_test.go b/api_test.go index 96f5a48954b..85e8cefb113 100644 --- a/api_test.go +++ b/api_test.go @@ -741,6 +741,14 @@ func TestGetOAuthClients(t *testing.T) { spec.UseOauth2 = true }) + createPolicy(func(p *user.Policy) { + p.ID = "test" + p.AccessRights = map[string]user.AccessDefinition{ + "test": { + APIID: "test", + }, + } + }) oauthRequest := NewClientRequest{ ClientID: "test", ClientRedirectURI: "http://localhost", @@ -750,13 +758,34 @@ func TestGetOAuthClients(t *testing.T) { } validOauthRequest, _ := json.Marshal(oauthRequest) + createPolicy(func(p *user.Policy) { + p.ID = "test2" + p.AccessRights = map[string]user.AccessDefinition{ + "test": { + APIID: "test", + }, + "abc": { + APIID: "abc", + }, + } + }) + oauthRequestWrongACL := NewClientRequest{ + ClientID: "test2", + ClientRedirectURI: "http://localhost", + APIID: "test", + PolicyID: "test2", + ClientSecret: "secret", + } + wrongAPIOauthRequest2, _ := json.Marshal(oauthRequestWrongACL) + oauthRequest.APIID = "unknown" wrongAPIOauthRequest, _ := json.Marshal(oauthRequest) ts.Run(t, []test.TestCase{ {Path: "/tyk/oauth/clients/unknown", AdminAuth: true, Code: 404}, {Path: "/tyk/oauth/clients/test", AdminAuth: true, Code: 200, BodyMatch: `[]`}, - {Method: "POST", Path: "/tyk/oauth/clients/create", AdminAuth: true, Data: string(wrongAPIOauthRequest), Code: 500, BodyMatch: `API doesn't exist`}, + {Method: "POST", Path: "/tyk/oauth/clients/create", AdminAuth: true, Data: string(wrongAPIOauthRequest), Code: 400, BodyMatch: `API doesn't exist`}, + {Method: "POST", Path: "/tyk/oauth/clients/create", AdminAuth: true, Data: string(wrongAPIOauthRequest2), Code: 400, BodyMatch: `should contain only one API`}, {Method: "POST", Path: "/tyk/oauth/clients/create", AdminAuth: true, Data: string(validOauthRequest), Code: 200}, {Path: "/tyk/oauth/clients/test", AdminAuth: true, Code: 200, BodyMatch: `[{"client_id":"test"`}, }...) diff --git a/helpers_test.go b/helpers_test.go index ae5a88db5f4..25f08f80539 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -226,10 +226,10 @@ func createPolicy(pGen ...func(p *user.Policy)) string { } policiesMu.Lock() - policiesByID[pID] = *pol + policiesByID[pol.ID] = *pol policiesMu.Unlock() - return pID + return pol.ID } func createJWKToken(jGen ...func(*jwt.Token)) string {