-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from SmartThingsOSS/guice
Add Guice bindings for RequireAuthHandler and BearerTokenAuthHandler
- Loading branch information
Showing
2 changed files
with
27 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ package st.ratpack.auth.handler | |
|
||
import io.netty.handler.codec.http.HttpHeaderNames | ||
import ratpack.exec.Promise | ||
import ratpack.handling.UserId | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
import st.ratpack.auth.DefaultValidateTokenResult | ||
import st.ratpack.auth.User | ||
import st.ratpack.auth.ValidateTokenResult | ||
import st.ratpack.auth.internal.DefaultOAuthToken | ||
import st.ratpack.auth.OAuthToken | ||
|
@@ -17,7 +19,10 @@ class BearerTokenAuthHandlerSpec extends Specification { | |
def "Should set OAuthToken on valid token"() { | ||
given: | ||
def tokenValidator = Mock(TokenValidator) | ||
def oAuthToken = new DefaultOAuthToken.Builder().build() | ||
def oAuthToken = new DefaultOAuthToken.Builder().setAdditionalInformation([ | ||
"user_name": "[email protected]", | ||
"uuid" : UUID.randomUUID().toString() | ||
]) build() | ||
|
||
when: | ||
def result = handle(new BearerTokenAuthHandler(tokenValidator)) { | ||
|
@@ -28,6 +33,8 @@ class BearerTokenAuthHandlerSpec extends Specification { | |
1 * tokenValidator.validate("Token") >> Promise.value(ValidateTokenResult.valid(oAuthToken)) | ||
result.getRegistry().maybeGet(OAuthToken).present | ||
result.getRegistry().maybeGet(ValidateTokenResult).present | ||
result.getRegistry().maybeGet(User).present | ||
result.getRegistry().maybeGet(UserId).present | ||
result.calledNext | ||
} | ||
|
||
|
@@ -45,9 +52,9 @@ class BearerTokenAuthHandlerSpec extends Specification { | |
|
||
where: | ||
authHeader << [ | ||
"", | ||
"Basic BLAH", | ||
"Bearer Token Something" | ||
"", | ||
"Basic BLAH", | ||
"Bearer Token Something" | ||
] | ||
} | ||
|
||
|