-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* skipverification ignored fix * test for PR 2273 * another test for check of expected instance to be retrieved * coverage --------- Co-authored-by: cache-sk <cache.sk@gmail.com>
- Loading branch information
Showing
2 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...er/src/test/java/org/cloudfoundry/identity/uaa/security/SkipSslLdapSocketFactoryTest.java
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.cloudfoundry.identity.uaa.security; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class SkipSslLdapSocketFactoryTest { | ||
|
||
@Test | ||
void testDefaultInstanceIsSkipSslLdapSocketFactory() { | ||
Object ldapFactory = SkipSslLdapSocketFactory.getDefault(); | ||
assertNotNull(ldapFactory); | ||
assertTrue(ldapFactory instanceof SkipSslLdapSocketFactory); | ||
assertTrue(SkipSslLdapSocketFactory.getDefault() instanceof SkipSslLdapSocketFactory); | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
...rc/test/java/org/cloudfoundry/identity/uaa/mock/ldap/LdapSkipCertificateMockMvcTests.java
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package org.cloudfoundry.identity.uaa.mock.ldap; | ||
|
||
import org.cloudfoundry.identity.uaa.DefaultTestContext; | ||
import org.cloudfoundry.identity.uaa.constants.OriginKeys; | ||
import org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils; | ||
import org.cloudfoundry.identity.uaa.provider.LdapIdentityProviderDefinition; | ||
import org.cloudfoundry.identity.uaa.test.InMemoryLdapServer; | ||
import org.cloudfoundry.identity.uaa.util.SetServerNameRequestPostProcessor; | ||
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.oauth2.common.util.RandomValueStringGenerator; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.util.FileSystemUtils; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import java.io.File; | ||
|
||
import static org.cloudfoundry.identity.uaa.constants.OriginKeys.LDAP; | ||
import static org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.CookieCsrfPostProcessor.cookieCsrf; | ||
import static org.cloudfoundry.identity.uaa.provider.LdapIdentityProviderDefinition.LDAP_TLS_NONE; | ||
import static org.springframework.http.MediaType.TEXT_HTML_VALUE; | ||
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@DefaultTestContext | ||
@ExtendWith(InMemoryLdapServer.LdapTrustStoreExtension.class) | ||
class LdapSkipCertificateMockMvcTests { | ||
private static final int LDAP_VALID_LDAP_PORT = 33390; | ||
private static final int LDAP_EXPIRED_LDAP_PORT = LDAP_VALID_LDAP_PORT + 1; | ||
private static final int LDAP_VALID_LDAPS_PORT = 33637; | ||
private static final int LDAP_EXPIRED_LDAPS_PORT = LDAP_VALID_LDAPS_PORT + 1; | ||
|
||
private static File LDAP_ROOT_DIRECTORY_EXPIRED; | ||
private static InMemoryLdapServer expiredLdapCertServer; | ||
private MockMvcUtils.IdentityZoneCreationResult trustedCertZone; | ||
private MockMvcUtils.IdentityZoneCreationResult trustedButExpiredCertZone; | ||
|
||
private RandomValueStringGenerator gen = new RandomValueStringGenerator(8); | ||
|
||
private MockMvc mockMvc; | ||
|
||
@BeforeAll | ||
static void startLdapsServers() { | ||
ClassLoader classLoader = LdapSkipCertificateMockMvcTests.class.getClassLoader(); | ||
|
||
File expiredKeystore = new File(classLoader.getResource("certs/expired-self-signed-ldap-cert.jks").getFile()); | ||
RandomValueStringGenerator generator = new RandomValueStringGenerator(); | ||
LDAP_ROOT_DIRECTORY_EXPIRED = new File(System.getProperty("java.io.tmpdir"), generator.generate()); | ||
|
||
expiredLdapCertServer = InMemoryLdapServer.startLdapWithTls(LDAP_EXPIRED_LDAP_PORT, LDAP_EXPIRED_LDAPS_PORT, expiredKeystore); | ||
} | ||
|
||
@AfterAll | ||
static void stopLdapsServers() { | ||
expiredLdapCertServer.stop(); | ||
FileSystemUtils.deleteRecursively(LDAP_ROOT_DIRECTORY_EXPIRED); | ||
} | ||
|
||
@BeforeEach | ||
void setUp(@Autowired WebApplicationContext webApplicationContext, @Autowired MockMvc mockMvc) throws Exception { | ||
this.mockMvc = mockMvc; | ||
|
||
trustedCertZone = MockMvcUtils.createOtherIdentityZoneAndReturnResult( | ||
gen.generate(), | ||
mockMvc, | ||
webApplicationContext, | ||
null, IdentityZoneHolder.getCurrentZoneId()); | ||
|
||
LdapIdentityProviderDefinition definition = LdapIdentityProviderDefinition.searchAndBindMapGroupToScopes( | ||
expiredLdapCertServer.getLdapSBaseUrl(), | ||
"cn=admin,ou=Users,dc=test,dc=com", | ||
"adminsecret", | ||
"dc=test,dc=com", | ||
"cn={0}", | ||
"ou=scopes,dc=test,dc=com", | ||
"member={0}", | ||
"mail", | ||
null, | ||
false, | ||
true, | ||
true, | ||
10, | ||
true | ||
); | ||
definition.setTlsConfiguration(LDAP_TLS_NONE); | ||
|
||
MockMvcUtils.createIdentityProvider(mockMvc, trustedCertZone, OriginKeys.LDAP, definition); | ||
trustedButExpiredCertZone = MockMvcUtils.createOtherIdentityZoneAndReturnResult( | ||
gen.generate(), | ||
mockMvc, | ||
webApplicationContext, | ||
null, IdentityZoneHolder.getCurrentZoneId()); | ||
definition.setBaseUrl(expiredLdapCertServer.getLdapSBaseUrl()); | ||
MockMvcUtils.createIdentityProvider(mockMvc, trustedButExpiredCertZone, OriginKeys.LDAP, definition); | ||
} | ||
|
||
@Test | ||
void testIgnoreServerCertificate() throws Exception { | ||
mockMvc.perform(post("/login.do").accept(TEXT_HTML_VALUE) | ||
.with(cookieCsrf()) | ||
.with(new SetServerNameRequestPostProcessor(trustedCertZone.getIdentityZone().getSubdomain() + ".localhost")) | ||
.param("username", "marissa2") | ||
.param("password", LDAP)) | ||
.andExpect(status().isFound()) | ||
.andExpect(redirectedUrl("/")) | ||
.andExpect(authenticated()); | ||
} | ||
|
||
@Test | ||
void testIgnoreExpiredServerCertificate() throws Exception { | ||
mockMvc.perform(post("/login.do").accept(TEXT_HTML_VALUE) | ||
.with(cookieCsrf()) | ||
.with(new SetServerNameRequestPostProcessor(trustedButExpiredCertZone.getIdentityZone().getSubdomain() + ".localhost")) | ||
.param("username", "marissa2") | ||
.param("password", LDAP)) | ||
.andExpect(status().isFound()) | ||
.andExpect(redirectedUrl("/")) | ||
.andExpect(authenticated()); | ||
} | ||
} |