Skip to content

Commit

Permalink
Upgrade Spring RestDocs to 1.2.0.RC1 to get wild cards
Browse files Browse the repository at this point in the history
[#142082611] https://www.pivotaltracker.com/story/show/142082611

Signed-off-by: Helen Chung <hchung@pivotal.io>
  • Loading branch information
fhanik authored and Helen Chung committed Apr 12, 2017
1 parent d7d8afd commit 57aeb9a
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 105 deletions.
2 changes: 1 addition & 1 deletion uaa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: parent.hamcrestVersion
testCompile group: 'org.mockito', name: 'mockito-core', version: parent.mockitoVersion
testCompile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version:parent.tomcatJdbcPoolVersion
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.1.0.M1'
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.2.0.RC1'
}
ext {
snippetsDir = file('build/generated-snippets')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.JsonFieldType.ARRAY;
import static org.springframework.restdocs.payload.JsonFieldType.BOOLEAN;
import static org.springframework.restdocs.payload.JsonFieldType.STRING;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
Expand Down Expand Up @@ -85,10 +86,10 @@ public void inviteUsers() throws Exception {
fieldWithPath("new_invites[].userId").type(STRING).description("A unique string for the invited user"),
fieldWithPath("new_invites[].origin").type(STRING).description("Unique alias of the provider"),
fieldWithPath("new_invites[].success").type(BOOLEAN).description("Flag to determine whether the invitation was sent successfully"),
fieldWithPath("new_invites[].errorCode").type(STRING).description("Error code in case of failure to send invitation"),
fieldWithPath("new_invites[].errorMessage").type(STRING).description("Error message in case of failure to send invitation"),
fieldWithPath("new_invites[].errorCode").optional().type(STRING).description("Error code in case of failure to send invitation"),
fieldWithPath("new_invites[].errorMessage").optional().type(STRING).description("Error message in case of failure to send invitation"),
fieldWithPath("new_invites[].inviteLink").type(STRING).description("Invitation link to invite users"),
fieldWithPath("failed_invites").type(STRING).description("List of invites having exception in sending the invitation")
fieldWithPath("failed_invites").type(ARRAY).description("List of invites having exception in sending the invitation")
);

getMockMvc().perform(post("/invite_users?" + String.format("%s=%s&%s=%s", CLIENT_ID, clientId, REDIRECT_URI, redirectUri))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void info_endpoint_for_json() throws Exception {
fieldWithPath("app.version").type(STRING).description("The UAA version"),
fieldWithPath("commit_id").type(STRING).description("The GIT sha for the UAA version"),
fieldWithPath("timestamp").type(STRING).description("JSON timestamp for the commit of the UAA version"),
fieldWithPath("idpDefinitions").type(OBJECT).description("A list of alias/url pairs of SAML IDP providers configured. Each url is the starting point to initiate the authentication process for the SAML identity provider."),
fieldWithPath("idpDefinitions").optional().type(OBJECT).description("A list of alias/url pairs of SAML IDP providers configured. Each url is the starting point to initiate the authentication process for the SAML identity provider."),
fieldWithPath("idpDefinitions.*").optional().type(ARRAY).description("A list of alias/url pairs of SAML IDP providers configured. Each url is the starting point to initiate the authentication process for the SAML identity provider."),
fieldWithPath("links").type(OBJECT).description("A list of alias/url pairs of configured action URLs for the UAA"),
fieldWithPath("links.login").type(STRING).description("The link to the login host alias of the UAA"),
fieldWithPath("links.uaa").type(STRING).description("The link to the uaa alias host of the UAA"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,9 @@

import java.net.URI;
import java.util.Arrays;
import java.util.Collections;

import static org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.MockSecurityContext;
import static org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.getClientCredentialsOAuthAccessToken;
import static org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.getUserOAuthAccessToken;
import static org.cloudfoundry.identity.uaa.oauth.token.TokenConstants.GRANT_TYPE_SAML2_BEARER;
import static org.cloudfoundry.identity.uaa.oauth.token.TokenConstants.GRANT_TYPE_USER_TOKEN;
import static org.cloudfoundry.identity.uaa.oauth.token.TokenConstants.OPAQUE;
import static org.cloudfoundry.identity.uaa.oauth.token.TokenConstants.REQUEST_TOKEN_FORMAT;

import static org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.*;
import static org.cloudfoundry.identity.uaa.oauth.token.TokenConstants.*;
import static org.cloudfoundry.identity.uaa.provider.saml.idp.SamlTestUtils.createLocalSamlIdpDefinition;
import static org.cloudfoundry.identity.uaa.test.SnippetUtils.parameterWithName;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -70,16 +64,9 @@
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.security.oauth2.common.util.OAuth2Utils.CLIENT_ID;
import static org.springframework.security.oauth2.common.util.OAuth2Utils.GRANT_TYPE;
import static org.springframework.security.oauth2.common.util.OAuth2Utils.REDIRECT_URI;
import static org.springframework.security.oauth2.common.util.OAuth2Utils.RESPONSE_TYPE;
import static org.springframework.security.oauth2.common.util.OAuth2Utils.SCOPE;
import static org.springframework.security.oauth2.common.util.OAuth2Utils.STATE;
import static org.springframework.security.oauth2.common.util.OAuth2Utils.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

public class TokenEndpointDocs extends AbstractTokenMockMvcTests {

Expand All @@ -96,13 +83,13 @@ public class TokenEndpointDocs extends AbstractTokenMockMvcTests {
fieldWithPath("[].zoneId").type(STRING).description("The zone ID for the token"),
fieldWithPath("[].tokenId").type(STRING).description("The unique ID for the token"),
fieldWithPath("[].clientId").type(STRING).description("Client ID for this token, will always match the client_id claim in the access token used for this call"),
fieldWithPath("[].userId").type(STRING).description("User ID for this token, will always match the user_id claim in the access token used for this call"),
fieldWithPath("[].userId").optional().type(STRING).description("User ID for this token, will always match the user_id claim in the access token used for this call"),
fieldWithPath("[].format").type(STRING).description("What format was requested, OPAQUE or JWT"),
fieldWithPath("[].expiresAt").type(NUMBER).description("Epoch time - token expiration date"),
fieldWithPath("[].issuedAt").type(NUMBER).description("Epoch time - token issue date"),
fieldWithPath("[].scope").type(STRING).description("Comma separated list of scopes this token holds, up to 1000 characters"),
fieldWithPath("[].responseType").type(STRING).description("response type requested during the token request, possible values ID_TOKEN, ACCESS_TOKEN, REFRESH_TOKEN"),
fieldWithPath("[].value").type(STRING).description("Access token value will always be null")
fieldWithPath("[].value").optional().type(STRING).description("Access token value will always be null")
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.JsonFieldType.ARRAY;
import static org.springframework.restdocs.payload.JsonFieldType.BOOLEAN;
import static org.springframework.restdocs.payload.JsonFieldType.NUMBER;
import static org.springframework.restdocs.payload.JsonFieldType.STRING;
import static org.springframework.restdocs.payload.JsonFieldType.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
Expand All @@ -58,6 +55,7 @@ public class ClientAdminEndpointsDocs extends AdminClientCreator {
private String clientAdminToken;

private static final FieldDescriptor clientSecretField = fieldWithPath("client_secret").constrained("Required if the client allows `authorization_code` or `client_credentials` grant type").type(STRING).description("A secret string used for authenticating as this client. To support secret rotation this can be space delimited string of two secrets.");
private static final FieldDescriptor actionField = fieldWithPath("action").constrained("Always required.").description("Set to `secret` to change client secret, `delete` to delete the client or `add` to add the client");
private static final HeaderDescriptor authorizationHeader = headerWithName("Authorization").description("Bearer token containing `clients.write`, `clients.admin` or `zones.{zone.id}.admin`");
private static final HeaderDescriptor IDENTITY_ZONE_ID_HEADER = headerWithName(IdentityZoneSwitchingFilter.HEADER).optional().description("If using a `zones.<zoneId>.admin scope/token, indicates what zone this request goes to by supplying a zone_id.");
private static final HeaderDescriptor IDENTITY_ZONE_SUBDOMAIN_HEADER = headerWithName(IdentityZoneSwitchingFilter.SUBDOMAIN_HEADER).optional().description("If using a `zones.<zoneId>.admin scope/token, indicates what zone this request goes to by supplying a subdomain.");
Expand All @@ -72,7 +70,7 @@ public class ClientAdminEndpointsDocs extends AdminClientCreator {
fieldWithPath("scope").optional("uaa.none").type(ARRAY).description("Scopes allowed for the client"),
fieldWithPath("resource_ids").optional(Collections.emptySet()).type(ARRAY).description("Resources the client is allowed access to"),
fieldWithPath("authorities").optional("uaa.none").type(ARRAY).description("Scopes which the client is able to grant when creating a client"),
fieldWithPath("autoapprove").optional(Collections.emptySet()).type(ARRAY).description("Scopes that do not require user approval"),
fieldWithPath("autoapprove").optional(Collections.emptySet()).type(Arrays.asList(BOOLEAN, ARRAY)).description("Scopes that do not require user approval"),
fieldWithPath("access_token_validity").optional(null).type(NUMBER).description("time in seconds to access token expiration after it is issued"),
fieldWithPath("refresh_token_validity").optional(null).type(NUMBER).description("time in seconds to refresh token expiration after it is issued"),
fieldWithPath(ClientConstants.ALLOWED_PROVIDERS).optional(null).type(ARRAY).description("A list of origin keys (alias) for identity providers the client is limited to. Null implies any identity provider is allowed."),
Expand Down Expand Up @@ -312,10 +310,19 @@ public void clientTx() throws Exception {
fieldsNoSecret,
subFields("[]", clientSecretField)
);
FieldDescriptor[] fieldsWithSecretAndAction = (FieldDescriptor[]) ArrayUtils.addAll(
fieldsWithSecret,
subFields("[]", actionField)
);

Snippet responseFields = responseFields((FieldDescriptor[]) ArrayUtils.addAll(
fieldsNoSecret,
subFields("[]", lastModifiedField)
));
Snippet responseFieldsWithAction = responseFields((FieldDescriptor[]) ArrayUtils.addAll(
fieldsNoSecret,
subFields("[]", lastModifiedField, actionField)
));
createResultActions
.andExpect(status().isCreated())
.andDo(document("{ClassName}/createClientTx", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
Expand Down Expand Up @@ -417,23 +424,17 @@ public void clientTx() throws Exception {
modifyResultActions
.andExpect(status().isOk())
.andDo(document("{ClassName}/modifyClientTx", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestHeaders(authorizationHeader, IDENTITY_ZONE_ID_HEADER, IDENTITY_ZONE_SUBDOMAIN_HEADER),
requestFields(
fieldWithPath("[]").required().description("Modification objects which will each be processed."),
fieldWithPath("[].client_id").required().description(clientIdDescription),
fieldWithPath("[].action").required().description("Can be any of `add` to create a client, `delete` to delete a client, `update` to alter non-secret client information, `secret` to change the client secret, `update_secret` to alter all client information including the client_secret. For the fields needed to perform any of these actions, see the appropriate endpoint documentation.")
),
responseFields((FieldDescriptor[]) ArrayUtils.addAll(
fieldsNoSecret,
subFields("[]",
lastModifiedField,
fieldWithPath("approvals_deleted").description("Indicates whether the approvals associated with the client were deleted as a result of this action"),
fieldWithPath("action").description("The action that was specified and taken on the client")
)
))
requestHeaders(
authorizationHeader,
IDENTITY_ZONE_ID_HEADER,
IDENTITY_ZONE_SUBDOMAIN_HEADER
),
requestFields(fieldsWithSecretAndAction),
responseFieldsWithAction
)
);


//DELETE

ResultActions deleteResultActions = getMockMvc().perform(post("/oauth/clients/tx/delete")
Expand Down

0 comments on commit 57aeb9a

Please sign in to comment.