/* * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.cloudfoundry.reactor.uaa.identityzones; import org.cloudfoundry.reactor.InteractionContext; import org.cloudfoundry.reactor.TestRequest; import org.cloudfoundry.reactor.TestResponse; import org.cloudfoundry.reactor.uaa.AbstractUaaApiTest; import org.cloudfoundry.uaa.identityzones.Branding; import org.cloudfoundry.uaa.identityzones.ClientLockoutPolicy; import org.cloudfoundry.uaa.identityzones.CorsConfiguration; import org.cloudfoundry.uaa.identityzones.CorsPolicy; import org.cloudfoundry.uaa.identityzones.CreateIdentityZoneRequest; import org.cloudfoundry.uaa.identityzones.CreateIdentityZoneResponse; import org.cloudfoundry.uaa.identityzones.DeleteIdentityZoneRequest; import org.cloudfoundry.uaa.identityzones.DeleteIdentityZoneResponse; import org.cloudfoundry.uaa.identityzones.GetIdentityZoneRequest; import org.cloudfoundry.uaa.identityzones.GetIdentityZoneResponse; import org.cloudfoundry.uaa.identityzones.IdentityZone; import org.cloudfoundry.uaa.identityzones.IdentityZoneConfiguration; import org.cloudfoundry.uaa.identityzones.Links; import org.cloudfoundry.uaa.identityzones.ListIdentityZonesRequest; import org.cloudfoundry.uaa.identityzones.ListIdentityZonesResponse; import org.cloudfoundry.uaa.identityzones.LogoutLink; import org.cloudfoundry.uaa.identityzones.Prompt; import org.cloudfoundry.uaa.identityzones.SamlConfiguration; import org.cloudfoundry.uaa.identityzones.SelfServiceLink; import org.cloudfoundry.uaa.identityzones.TokenPolicy; import org.cloudfoundry.uaa.identityzones.UpdateIdentityZoneRequest; import org.cloudfoundry.uaa.identityzones.UpdateIdentityZoneResponse; import org.junit.Test; import reactor.test.StepVerifier; import java.time.Duration; import java.util.Collections; import static io.netty.handler.codec.http.HttpMethod.DELETE; import static io.netty.handler.codec.http.HttpMethod.GET; import static io.netty.handler.codec.http.HttpMethod.POST; import static io.netty.handler.codec.http.HttpMethod.PUT; import static io.netty.handler.codec.http.HttpResponseStatus.CREATED; import static io.netty.handler.codec.http.HttpResponseStatus.OK; public final class ReactorIdentityZonesTest extends AbstractUaaApiTest { private final ReactorIdentityZones identityZones = new ReactorIdentityZones(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER); @Test public void create() { mockRequest(InteractionContext.builder() .request(TestRequest.builder() .method(POST).path("/identity-zones") .payload("fixtures/uaa/identity-zones/POST_request.json") .build()) .response(TestResponse.builder() .status(CREATED) .payload("fixtures/uaa/identity-zones/POST_response.json") .build()) .build()); this.identityZones .create(CreateIdentityZoneRequest.builder() .identityZoneId("twiglet-create") .subdomain("twiglet-create") .configuration(IdentityZoneConfiguration.builder() .clientLockoutPolicy(ClientLockoutPolicy.builder() .lockoutPeriodSeconds(300) .lockoutAfterFailures(5) .countFailuresWithin(3600) .build()) .tokenPolicy(TokenPolicy.builder() .accessTokenValidity(-1) .refreshTokenValidity(-1) .jwtRevocable(false) .key("exampleKeyId", Collections.singletonMap("signingKey", "s1gNiNg.K3y/t3XT")) .build()) .samlConfiguration(SamlConfiguration.builder() .assertionSigned(true) .requestSigned(true) .wantAssertionSigned(true) .wantPartnerAuthenticationRequestSigned(false) .assertionTimeToLive(600) .build()) .corsPolicy(CorsPolicy.builder() .xhrConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .defaultConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .build()) .links(Links.builder() .logout(LogoutLink.builder() .redirectUrl("/login") .redirectParameterName("redirect") .disableRedirectParameter(true) .build()) .homeRedirect("http://my.hosted.homepage.com/") .selfService(SelfServiceLink.builder() .selfServiceLinksEnabled(true) .signupLink("/create_account") .resetPasswordLink("/forgot_password") .build()) .build()) .prompt(Prompt.builder() .fieldName("username") .fieldType("text") .text("Email") .build()) .prompt(Prompt.builder() .fieldName("password") .fieldType("password") .text("Password") .build()) .prompt(Prompt.builder() .fieldName("passcode") .fieldType("password") .text("One Time Code (Get on at /passcode)") .build()) .ldapDiscoveryEnabled(false) .branding(Branding.builder() .companyName("Test Company") .productLogo("VGVzdFByb2R1Y3RMb2dv") .squareLogo("VGVzdFNxdWFyZUxvZ28=") .footerLegalText("Test footer legal text") .footerLink("Support", "http://support.example.com") .build()) .accountChooserEnabled(false) .build()) .name("The Twiglet Zone") .version(0) .description("Like the Twilight Zone but tastier.") .createdAt(1481728057524L) .lastModified(1481728057524L) .build()) .as(StepVerifier::create) .expectNext(CreateIdentityZoneResponse.builder() .id("twiglet-create") .subdomain("twiglet-create") .configuration(IdentityZoneConfiguration.builder() .clientLockoutPolicy(ClientLockoutPolicy.builder() .lockoutPeriodSeconds(300) .lockoutAfterFailures(5) .countFailuresWithin(3600) .build()) .tokenPolicy(TokenPolicy.builder() .accessTokenValidity(-1) .refreshTokenValidity(-1) .jwtRevocable(false) .key("exampleKeyId", Collections.singletonMap("signingKey", "s1gNiNg.K3y/t3XT")) .build()) .samlConfiguration(SamlConfiguration.builder() .assertionSigned(true) .requestSigned(true) .wantAssertionSigned(true) .wantPartnerAuthenticationRequestSigned(false) .assertionTimeToLive(600) .build()) .corsPolicy(CorsPolicy.builder() .xhrConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .defaultConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .build()) .links(Links.builder() .logout(LogoutLink.builder() .redirectUrl("/login") .redirectParameterName("redirect") .disableRedirectParameter(true) .build()) .homeRedirect("http://my.hosted.homepage.com/") .selfService(SelfServiceLink.builder() .selfServiceLinksEnabled(true) .signupLink("/create_account") .resetPasswordLink("/forgot_password") .build()) .build()) .prompt(Prompt.builder() .fieldName("username") .fieldType("text") .text("Email") .build()) .prompt(Prompt.builder() .fieldName("password") .fieldType("password") .text("Password") .build()) .prompt(Prompt.builder() .fieldName("passcode") .fieldType("password") .text("One Time Code (Get on at /passcode)") .build()) .ldapDiscoveryEnabled(false) .branding(Branding.builder() .companyName("Test Company") .productLogo("VGVzdFByb2R1Y3RMb2dv") .squareLogo("VGVzdFNxdWFyZUxvZ28=") .footerLegalText("Test footer legal text") .footerLink("Support", "http://support.example.com") .build()) .accountChooserEnabled(false) .build()) .name("The Twiglet Zone") .version(0) .description("Like the Twilight Zone but tastier.") .createdAt(1481728057533L) .lastModified(1481728057533L) .build()) .expectComplete() .verify(Duration.ofSeconds(5)); } @Test public void delete() { mockRequest(InteractionContext.builder() .request(TestRequest.builder() .method(DELETE).path("/identity-zones/twiglet-delete") .build()) .response(TestResponse.builder() .status(OK) .payload("fixtures/uaa/identity-zones/DELETE_{id}_response.json") .build()) .build()); this.identityZones .delete(DeleteIdentityZoneRequest.builder() .identityZoneId("twiglet-delete") .build()) .as(StepVerifier::create) .expectNext(DeleteIdentityZoneResponse.builder() .id("twiglet-delete") .subdomain("twiglet-delete") .configuration(IdentityZoneConfiguration.builder() .clientLockoutPolicy(ClientLockoutPolicy.builder() .lockoutPeriodSeconds(-1) .lockoutAfterFailures(-1) .countFailuresWithin(-1) .build()) .tokenPolicy(TokenPolicy.builder() .accessTokenValidity(-1) .refreshTokenValidity(-1) .jwtRevocable(false) .keys(Collections.emptyMap()) .build()) .samlConfiguration(SamlConfiguration.builder() .assertionSigned(true) .requestSigned(true) .wantAssertionSigned(true) .wantPartnerAuthenticationRequestSigned(false) .assertionTimeToLive(600) .build()) .corsPolicy(CorsPolicy.builder() .xhrConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .defaultConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .build()) .links(Links.builder() .logout(LogoutLink.builder() .redirectUrl("/login") .redirectParameterName("redirect") .disableRedirectParameter(true) .build()) .homeRedirect("http://my.hosted.homepage.com/") .selfService(SelfServiceLink.builder() .selfServiceLinksEnabled(true) .signupLink("/create_account") .resetPasswordLink("/forgot_password") .build()) .build()) .prompt(Prompt.builder() .fieldName("username") .fieldType("text") .text("Email") .build()) .prompt(Prompt.builder() .fieldName("password") .fieldType("password") .text("Password") .build()) .prompt(Prompt.builder() .fieldName("passcode") .fieldType("password") .text("One Time Code (Get on at /passcode)") .build()) .ldapDiscoveryEnabled(false) .branding(Branding.builder() .companyName("Test Company") .productLogo("VGVzdFByb2R1Y3RMb2dv") .squareLogo("VGVzdFNxdWFyZUxvZ28=") .footerLegalText("Test footer legal text") .footerLink("Support", "http://support.example.com") .build()) .accountChooserEnabled(false) .build()) .name("The Twiglet Zone") .version(0) .createdAt(1481728057024L) .lastModified(1481728057024L) .build()) .expectComplete() .verify(Duration.ofSeconds(5)); } @Test public void get() { mockRequest(InteractionContext.builder() .request(TestRequest.builder() .method(GET).path("/identity-zones/twiglet-get") .build()) .response(TestResponse.builder() .status(OK) .payload("fixtures/uaa/identity-zones/GET_{id}_response.json") .build()) .build()); this.identityZones .get(GetIdentityZoneRequest.builder() .identityZoneId("twiglet-get") .build()) .as(StepVerifier::create) .expectNext(GetIdentityZoneResponse.builder() .id("twiglet-get") .subdomain("twiglet-get") .configuration(IdentityZoneConfiguration.builder() .clientLockoutPolicy(ClientLockoutPolicy.builder() .lockoutPeriodSeconds(-1) .lockoutAfterFailures(-1) .countFailuresWithin(-1) .build()) .tokenPolicy(TokenPolicy.builder() .accessTokenValidity(-1) .refreshTokenValidity(-1) .jwtRevocable(false) .keys(Collections.emptyMap()) .build()) .samlConfiguration(SamlConfiguration.builder() .assertionSigned(true) .requestSigned(true) .wantAssertionSigned(true) .wantPartnerAuthenticationRequestSigned(false) .assertionTimeToLive(600) .build()) .corsPolicy(CorsPolicy.builder() .xhrConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .defaultConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .build()) .links(Links.builder() .logout(LogoutLink.builder() .redirectUrl("/login") .redirectParameterName("redirect") .disableRedirectParameter(true) .build()) .homeRedirect("http://my.hosted.homepage.com/") .selfService(SelfServiceLink.builder() .selfServiceLinksEnabled(true) .signupLink("/create_account") .resetPasswordLink("/forgot_password") .build()) .build()) .prompt(Prompt.builder() .fieldName("username") .fieldType("text") .text("Email") .build()) .prompt(Prompt.builder() .fieldName("password") .fieldType("password") .text("Password") .build()) .prompt(Prompt.builder() .fieldName("passcode") .fieldType("password") .text("One Time Code (Get on at /passcode)") .build()) .ldapDiscoveryEnabled(false) .branding(Branding.builder() .companyName("Test Company") .productLogo("VGVzdFByb2R1Y3RMb2dv") .squareLogo("VGVzdFNxdWFyZUxvZ28=") .footerLegalText("Test footer legal text") .footerLink("Support", "http://support.example.com") .build()) .accountChooserEnabled(false) .build()) .name("The Twiglet Zone") .version(0) .createdAt(1481728057382L) .lastModified(1481728057382L) .build()) .expectComplete() .verify(Duration.ofSeconds(5)); } @Test public void list() { mockRequest(InteractionContext.builder() .request(TestRequest.builder() .method(GET).path("/identity-zones") .build()) .response(TestResponse.builder() .status(OK) .payload("fixtures/uaa/identity-zones/GET_response.json") .build()) .build()); this.identityZones .list(ListIdentityZonesRequest.builder() .build()) .as(StepVerifier::create) .expectNext(ListIdentityZonesResponse.builder() .identityZone(IdentityZone.builder() .id("15wtczzd") .subdomain("15wtczzd") .configuration(IdentityZoneConfiguration.builder() .clientLockoutPolicy(ClientLockoutPolicy.builder() .lockoutPeriodSeconds(-1) .lockoutAfterFailures(-1) .countFailuresWithin(-1) .build()) .tokenPolicy(TokenPolicy.builder() .accessTokenValidity(-1) .refreshTokenValidity(-1) .jwtRevocable(false) .keys(Collections.emptyMap()) .build()) .samlConfiguration(SamlConfiguration.builder() .assertionSigned(true) .requestSigned(true) .wantAssertionSigned(true) .wantPartnerAuthenticationRequestSigned(false) .assertionTimeToLive(600) .build()) .corsPolicy(CorsPolicy.builder() .xhrConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .defaultConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .build()) .links(Links.builder() .logout(LogoutLink.builder() .redirectUrl("/login") .redirectParameterName("redirect") .disableRedirectParameter(true) .build()) .selfService(SelfServiceLink.builder() .selfServiceLinksEnabled(true) .signupLink("/create_account") .resetPasswordLink("/forgot_password") .build()) .build()) .prompt(Prompt.builder() .fieldName("username") .fieldType("text") .text("Email") .build()) .prompt(Prompt.builder() .fieldName("password") .fieldType("password") .text("Password") .build()) .prompt(Prompt.builder() .fieldName("passcode") .fieldType("password") .text("One Time Code (Get on at /passcode)") .build()) .ldapDiscoveryEnabled(false) .accountChooserEnabled(false) .build()) .name("The Twiglet Zone") .version(0) .description("Like the Twilight Zone but tastier.") .createdAt(1481728053399L) .lastModified(1481728053399L) .build()) .build()) .expectComplete() .verify(Duration.ofSeconds(5)); } @Test public void update() { mockRequest(InteractionContext.builder() .request(TestRequest.builder() .method(PUT).path("/identity-zones/twiglet-update") .payload("fixtures/uaa/identity-zones/PUT_{id}_request.json") .build()) .response(TestResponse.builder() .status(OK) .payload("fixtures/uaa/identity-zones/PUT_{id}_response.json") .build()) .build()); this.identityZones .update(UpdateIdentityZoneRequest.builder() .identityZoneId("twiglet-update") .subdomain("twiglet-update") .configuration(IdentityZoneConfiguration.builder() .clientLockoutPolicy(ClientLockoutPolicy.builder() .lockoutPeriodSeconds(-1) .lockoutAfterFailures(-1) .countFailuresWithin(-1) .build()) .tokenPolicy(TokenPolicy.builder() .accessTokenValidity(-1) .refreshTokenValidity(-1) .jwtRevocable(false) .key("updatedKeyId", Collections.singletonMap("signingKey", "upD4t3d.s1gNiNg.K3y/t3XT")) .build()) .samlConfiguration(SamlConfiguration.builder() .assertionSigned(true) .requestSigned(true) .wantAssertionSigned(true) .wantPartnerAuthenticationRequestSigned(false) .assertionTimeToLive(600) .build()) .corsPolicy(CorsPolicy.builder() .xhrConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .defaultConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .build()) .links(Links.builder() .logout(LogoutLink.builder() .redirectUrl("/login") .redirectParameterName("redirect") .disableRedirectParameter(true) .build()) .homeRedirect("http://my.hosted.homepage.com/") .selfService(SelfServiceLink.builder() .selfServiceLinksEnabled(true) .signupLink("/create_account") .resetPasswordLink("/forgot_password") .build()) .build()) .prompt(Prompt.builder() .fieldName("username") .fieldType("text") .text("Email") .build()) .prompt(Prompt.builder() .fieldName("password") .fieldType("password") .text("Password") .build()) .prompt(Prompt.builder() .fieldName("passcode") .fieldType("password") .text("One Time Code (Get on at /passcode)") .build()) .ldapDiscoveryEnabled(false) .branding(Branding.builder() .companyName("Test Company") .productLogo("VGVzdFByb2R1Y3RMb2dv") .squareLogo("VGVzdFNxdWFyZUxvZ28=") .footerLegalText("Test footer legal text") .footerLink("Support", "http://support.example.com") .build()) .accountChooserEnabled(false) .build()) .name("The Updated Twiglet Zone") .version(0) .description("Like the Twilight Zone but not tastier.") .createdAt(1481728057246L) .lastModified(1481728057246L) .build()) .as(StepVerifier::create) .expectNext(UpdateIdentityZoneResponse.builder() .id("twiglet-update") .subdomain("twiglet-update") .configuration(IdentityZoneConfiguration.builder() .clientLockoutPolicy(ClientLockoutPolicy.builder() .lockoutPeriodSeconds(-1) .lockoutAfterFailures(-1) .countFailuresWithin(-1) .build()) .tokenPolicy(TokenPolicy.builder() .accessTokenValidity(-1) .refreshTokenValidity(-1) .jwtRevocable(false) .key("updatedKeyId", Collections.singletonMap("signingKey", "upD4t3d.s1gNiNg.K3y/t3XT")) .build()) .samlConfiguration(SamlConfiguration.builder() .assertionSigned(true) .requestSigned(true) .wantAssertionSigned(true) .wantPartnerAuthenticationRequestSigned(false) .assertionTimeToLive(600) .build()) .corsPolicy(CorsPolicy.builder() .xhrConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .defaultConfiguration(CorsConfiguration.builder() .allowedOrigin(".*") .allowedUri(".*") .allowedHeader("Accept") .allowedHeader("Authorization") .allowedHeader("Content-Type") .allowedMethod("GET") .allowedCredentials(false) .maxAge(1728000L) .build()) .build()) .links(Links.builder() .logout(LogoutLink.builder() .redirectUrl("/login") .redirectParameterName("redirect") .disableRedirectParameter(true) .build()) .homeRedirect("http://my.hosted.homepage.com/") .selfService(SelfServiceLink.builder() .selfServiceLinksEnabled(true) .signupLink("/create_account") .resetPasswordLink("/forgot_password") .build()) .build()) .prompt(Prompt.builder() .fieldName("username") .fieldType("text") .text("Email") .build()) .prompt(Prompt.builder() .fieldName("password") .fieldType("password") .text("Password") .build()) .prompt(Prompt.builder() .fieldName("passcode") .fieldType("password") .text("One Time Code (Get on at /passcode)") .build()) .ldapDiscoveryEnabled(false) .branding(Branding.builder() .companyName("Test Company") .productLogo("VGVzdFByb2R1Y3RMb2dv") .squareLogo("VGVzdFNxdWFyZUxvZ28=") .footerLegalText("Test footer legal text") .footerLink("Support", "http://support.example.com") .build()) .accountChooserEnabled(false) .build()) .name("The Updated Twiglet Zone") .version(1) .description("Like the Twilight Zone but not tastier.") .createdAt(1481728057213L) .lastModified(1481728057259L) .build()) .expectComplete() .verify(Duration.ofSeconds(5)); } }