11package org .cloudfoundry .identity .uaa .mock .codestore ;
22
33import org .cloudfoundry .identity .uaa .DefaultTestContext ;
4+ import org .cloudfoundry .identity .uaa .client .UaaClientDetails ;
45import org .cloudfoundry .identity .uaa .codestore .ExpiringCode ;
56import org .cloudfoundry .identity .uaa .codestore .JdbcExpiringCodeStore ;
7+ import org .cloudfoundry .identity .uaa .mock .util .MockMvcUtils ;
8+ import org .cloudfoundry .identity .uaa .mock .util .MockMvcUtils .ZoneResolutionMode ;
69import org .cloudfoundry .identity .uaa .test .TestClient ;
710import org .cloudfoundry .identity .uaa .util .JsonUtils ;
11+ import org .cloudfoundry .identity .uaa .zone .IdentityZoneHolder ;
812import org .junit .jupiter .api .AfterEach ;
913import org .junit .jupiter .api .BeforeEach ;
1014import org .junit .jupiter .api .Nested ;
1115import org .junit .jupiter .api .Test ;
1216import org .junit .jupiter .params .ParameterizedTest ;
17+ import org .junit .jupiter .params .provider .EnumSource ;
1318import org .junit .jupiter .params .provider .ValueSource ;
1419import org .springframework .beans .factory .annotation .Autowired ;
1520import org .springframework .beans .factory .annotation .Value ;
21+ import org .springframework .http .HttpMethod ;
1622import org .springframework .http .MediaType ;
1723import org .springframework .jdbc .core .JdbcTemplate ;
1824import org .springframework .test .web .servlet .MockMvc ;
1925import org .springframework .test .web .servlet .MvcResult ;
2026import org .springframework .test .web .servlet .request .MockHttpServletRequestBuilder ;
27+ import org .springframework .web .context .WebApplicationContext ;
2128
2229import java .sql .Timestamp ;
2330
@@ -41,6 +48,9 @@ class CodeStoreEndpointsMockMvcTests {
4148 private JdbcTemplate jdbcTemplate ;
4249 private JdbcExpiringCodeStore jdbcExpiringCodeStore ;
4350
51+ @ Autowired
52+ private WebApplicationContext webApplicationContext ;
53+
4454 @ BeforeEach
4555 void setUp (@ Autowired JdbcTemplate jdbcTemplate ,
4656 @ Autowired JdbcExpiringCodeStore jdbcExpiringCodeStore ,
@@ -325,6 +335,30 @@ void verifyExpirationIntervalWorks(String url) throws Exception {
325335 }
326336 }
327337
338+ @ Nested
339+ @ DefaultTestContext
340+ class CodesZonePathSupport {
341+
342+ @ ParameterizedTest
343+ @ EnumSource (ZoneResolutionMode .class )
344+ void codes_endpoint_responds_for_zone_path (ZoneResolutionMode mode ) throws Exception {
345+ String subdomain = "codeszone" + System .nanoTime ();
346+ UaaClientDetails loginClient = new UaaClientDetails ("login" , "" , "oauth.login" , "client_credentials" , "" , "http://redirect" );
347+ loginClient .setClientSecret ("loginsecret" );
348+ MockMvcUtils .createOtherIdentityZoneAndReturnResult (subdomain , mockMvc , webApplicationContext , loginClient , IdentityZoneHolder .getCurrentZoneId ());
349+
350+ Timestamp ts = new Timestamp (System .currentTimeMillis () + 60000 );
351+ ExpiringCode code = new ExpiringCode (null , ts , "{}" , null );
352+ String requestBody = JsonUtils .writeValueAsString (code );
353+
354+ mockMvc .perform (mode .createRequestBuilder (subdomain , HttpMethod .POST , "/Codes" )
355+ .contentType (APPLICATION_JSON )
356+ .accept (MediaType .APPLICATION_JSON )
357+ .content (requestBody ))
358+ .andExpect (status ().isUnauthorized ());
359+ }
360+ }
361+
328362 private void expireAllCodes () {
329363 jdbcExpiringCodeStore .setExpirationInterval (0 );
330364 Timestamp expired = new Timestamp (System .currentTimeMillis () - 5000 );
0 commit comments