Skip to content

Commit

Permalink
create oauth client test fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded committed Feb 12, 2019
1 parent a14d309 commit bff8c0a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"`},
}...)
Expand Down
4 changes: 2 additions & 2 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bff8c0a

Please sign in to comment.