This repository was archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 155
DefaultTokenResponse.toJson did not include id_token in the JSON #1239 #1240
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
104 changes: 104 additions & 0 deletions
104
.../oauth/src/test/groovy/com/stormpath/sdk/impl/oauth/authz/DefaultTokenResponseTest.groovy
This file contains hidden or 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,104 @@ | ||
| package com.stormpath.sdk.impl.oauth.authz | ||
|
|
||
| import com.stormpath.sdk.oauth.TokenResponse | ||
| import org.apache.oltu.oauth2.common.message.types.TokenType | ||
| import org.hamcrest.Matchers | ||
| import org.json.JSONObject | ||
| import org.testng.annotations.Test | ||
|
|
||
| import static Matchers.is | ||
| import static org.hamcrest.MatcherAssert.assertThat | ||
|
|
||
| class DefaultTokenResponseTest { | ||
|
|
||
| public static final String APP_HREF = "http://test.app.href.com" | ||
| public static final String ACCESS_TOKEN = "testAccessToken" | ||
| public static final String REFRESH_TOKEN = "testRefreshToken" | ||
| public static final String ID_TOKEN = "testIdToken" | ||
| public static final String SCOPE = "test scope" | ||
| public static final String EXPIRES_IN = "3600" | ||
| public static final String TOKEN_TYPE = "Bearer" | ||
|
|
||
| @Test | ||
| void testBuildCompleteResponse() { | ||
| TokenResponse tokenResponse = DefaultTokenResponse.tokenType(TokenType.BEARER) | ||
| .accessToken(ACCESS_TOKEN) | ||
| .refreshToken(REFRESH_TOKEN) | ||
| .idToken(ID_TOKEN) | ||
| .scope(SCOPE) | ||
| .expiresIn(EXPIRES_IN) | ||
| .applicationHref(APP_HREF) | ||
| .build() | ||
| assertThat(tokenResponse.tokenType, is(TOKEN_TYPE)) | ||
| assertThat(tokenResponse.accessToken, is(ACCESS_TOKEN)) | ||
| assertThat(tokenResponse.refreshToken, is(REFRESH_TOKEN)) | ||
| assertThat(tokenResponse.idToken, is(ID_TOKEN)) | ||
| assertThat(tokenResponse.scope, is(SCOPE)) | ||
| assertThat(tokenResponse.expiresIn, is(EXPIRES_IN)) | ||
| assertThat(tokenResponse.applicationHref, is(APP_HREF)) | ||
| } | ||
|
|
||
| @Test | ||
| void testJsonWithOnlyAccessToken() { | ||
| TokenResponse tokenResponse = DefaultTokenResponse.tokenType(TokenType.BEARER) | ||
| .accessToken(ACCESS_TOKEN) | ||
| .expiresIn(EXPIRES_IN) | ||
| .scope(SCOPE) | ||
| .applicationHref(APP_HREF) | ||
| .build() | ||
|
|
||
| String json = tokenResponse.toJson() | ||
| JSONObject actual = new JSONObject(json) | ||
| assertField(actual, "token_type", TOKEN_TYPE) | ||
| assertField(actual, "access_token", ACCESS_TOKEN) | ||
| assertField(actual, "expires_in", EXPIRES_IN) | ||
| assertField(actual, "scope", SCOPE) | ||
| assertNoField(actual, "refresh_token") | ||
| assertNoField(actual, "id_token") | ||
| } | ||
|
|
||
| @Test | ||
| void testJsonWithAccessAndRefreshTokens() { | ||
| TokenResponse tokenResponse = DefaultTokenResponse.tokenType(TokenType.BEARER) | ||
| .accessToken(ACCESS_TOKEN) | ||
| .refreshToken(REFRESH_TOKEN) | ||
| .expiresIn(EXPIRES_IN) | ||
| .applicationHref(APP_HREF) | ||
| .build() | ||
|
|
||
| String json = tokenResponse.toJson() | ||
| JSONObject actual = new JSONObject(json) | ||
| assertField(actual, "token_type", TOKEN_TYPE) | ||
| assertField(actual, "access_token", ACCESS_TOKEN) | ||
| assertField(actual, "refresh_token", REFRESH_TOKEN) | ||
| assertField(actual, "expires_in", EXPIRES_IN) | ||
| assertNoField(actual, "id_token") | ||
| } | ||
|
|
||
| @Test | ||
| void testJsonWithAccessAndRefreshAndIdTokens() { | ||
| TokenResponse tokenResponse = DefaultTokenResponse.tokenType(TokenType.BEARER) | ||
| .accessToken(ACCESS_TOKEN) | ||
| .refreshToken(REFRESH_TOKEN) | ||
| .idToken(ID_TOKEN) | ||
| .expiresIn(EXPIRES_IN) | ||
| .applicationHref(APP_HREF) | ||
| .build() | ||
|
|
||
| String json = tokenResponse.toJson() | ||
| JSONObject actual = new JSONObject(json) | ||
| assertField(actual, "token_type", TOKEN_TYPE) | ||
| assertField(actual, "access_token", ACCESS_TOKEN) | ||
| assertField(actual, "refresh_token", REFRESH_TOKEN) | ||
| assertField(actual, "id_token", ID_TOKEN) | ||
| assertField(actual, "expires_in", EXPIRES_IN) | ||
| } | ||
|
|
||
| private static void assertField(JSONObject actual, String field, String expected) { | ||
| assertThat("${field} in ${actual.toString(2)}", actual.optString(field), is(expected)) | ||
| } | ||
|
|
||
| private static void assertNoField(JSONObject actual, String field) { | ||
| assertThat("${field} present in ${actual.toString(2)}", actual.has(field), is(false)) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just for testing? If so, would you please add test scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is. Thanks for the change.