-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration: tests for resource owner password credentials grant
- Loading branch information
aeneasr
committed
Mar 21, 2016
1 parent
c13298c
commit f503615
Showing
6 changed files
with
98 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package integration_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ory-am/fosite/handler/core" | ||
"github.com/stretchr/testify/assert" | ||
"golang.org/x/oauth2" | ||
"github.com/stretchr/testify/require" | ||
"github.com/ory-am/fosite/handler/core/owner" | ||
) | ||
|
||
func TestClientCredentialsFlow(t *testing.T) { | ||
for _, strategy := range []core.AccessTokenStrategy{ | ||
hmacStrategy, | ||
} { | ||
runClientCredentialsFlowTest(t, strategy) | ||
} | ||
} | ||
|
||
func runClientCredentialsFlowTest(t *testing.T, strategy core.AccessTokenStrategy) { | ||
f := newFosite() | ||
ts := mockServer(t, f, nil) | ||
defer ts.Close() | ||
|
||
oauthClient := newOAuth2Client(ts) | ||
var username string | ||
var password string | ||
for k, c := range []struct { | ||
description string | ||
setup func() | ||
err bool | ||
}{ | ||
{ | ||
description: "should fail because handler not registered", | ||
setup: func() {}, | ||
err: true, | ||
}, | ||
{ | ||
description: "should fail because unknown client", | ||
setup: func() { | ||
f.TokenEndpointHandlers.Append(&owner.ResourceOwnerPasswordCredentialsGrantHandler{ | ||
AccessTokenStrategy: strategy, | ||
Store: fositeStore, | ||
AccessTokenLifespan: accessTokenLifespan, | ||
}) | ||
}, | ||
err: true, | ||
}, | ||
{ | ||
description: "should fail because user does not exist", | ||
setup: func() { | ||
username = "not-existent" | ||
password = "wrong" | ||
}, | ||
err: true, | ||
}, | ||
{ | ||
description: "should fail because wrong credentials", | ||
setup: func() { | ||
username = "peter" | ||
password = "wrong" | ||
}, | ||
err: true, | ||
}, | ||
{ | ||
description: "should pass", | ||
setup: func() { | ||
username = "peter" | ||
password = "foobar" | ||
}, | ||
}, | ||
} { | ||
c.setup() | ||
|
||
token, err := oauthClient.PasswordCredentialsToken(oauth2.NoContext, username, password) | ||
require.Equal(t, c.err, err != nil, "(%d) %s\n%s\n%s", k, c.description, c.err, err) | ||
if !c.err { | ||
assert.NotEmpty(t, token.AccessToken, "(%d) %s\n%s", k, c.description, token) | ||
} | ||
t.Logf("Passed test case %d", k) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters