use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class RevokeStaleAccessTokenServiceTest method shouldDoNothingWhenAuthConfigHasNotChangedDuringUpdateAuthConfig.
// on entity update
@Test
void shouldDoNothingWhenAuthConfigHasNotChangedDuringUpdateAuthConfig() {
BasicCruiseConfig config = new BasicCruiseConfig();
config.server().security().securityAuthConfigs().add(authConfig1);
config.server().security().securityAuthConfigs().add(authConfig2);
when(goConfigService.getConfigForEditing()).thenReturn(config);
when(accessTokenService.findAllTokensForAllUsers(AccessTokenFilter.active)).thenReturn(Arrays.asList(authConfig1_token1, authConfig1_token2, authConfig2_token1));
service.initialize();
verify(accessTokenService, never()).revokeAccessTokenByGoCD(anyInt(), anyString());
service.onEntityConfigChange(new SecurityAuthConfig());
verify(accessTokenService, never()).revokeAccessTokenByGoCD(anyInt(), anyString());
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method verifyConnection_shouldFailForAInvalidAuthConfig.
@Test
public void verifyConnection_shouldFailForAInvalidAuthConfig() throws Exception {
SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap", new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue()));
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("password", "Password cannot be blank"));
validationResult.addError(new ValidationError("username", "Username cannot be blank"));
VerifyConnectionResponse validationFailed = new VerifyConnectionResponse("validation-failed", "Connection check passed", validationResult);
when(extension.verifyConnection("cd.go.ldap", ldap.getConfigurationAsMap(true))).thenReturn(validationFailed);
VerifyConnectionResponse response = securityAuthConfigService.verifyConnection(ldap);
assertThat(response, is(validationFailed));
assertThat(ldap.getProperty("username").errors().get("username").get(0), is("Username cannot be blank"));
assertThat(ldap.getProperty("password").errors().get("password").get(0), is("Password cannot be blank"));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method shouldPerformPluginValidationsBeforeAddingSecurityAuthConfig.
@Test
public void shouldPerformPluginValidationsBeforeAddingSecurityAuthConfig() {
SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("ldap", "cd.go.ldap", create("key", false, "value"));
Username username = new Username("username");
securityAuthConfigService.create(username, securityAuthConfig, new HttpLocalizedOperationResult());
verify(extension).validateAuthConfig(securityAuthConfig.getPluginId(), securityAuthConfig.getConfigurationAsMap(true));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method verifyConnection_shouldFailInAbsenceOfPlugin.
@Test
public void verifyConnection_shouldFailInAbsenceOfPlugin() throws Exception {
SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap");
when(extension.verifyConnection("cd.go.ldap", ldap.getConfigurationAsMap(true))).thenThrow(new RecordNotFoundException(""));
VerifyConnectionResponse response = securityAuthConfigService.verifyConnection(ldap);
assertThat(response, is(new VerifyConnectionResponse("failure", "Unable to verify connection, missing plugin: cd.go.ldap", new com.thoughtworks.go.plugin.domain.common.ValidationResult())));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method shouldGetSecurityAuthConfigByGivenId.
@Test
public void shouldGetSecurityAuthConfigByGivenId() throws Exception {
SecurityAuthConfig authConfig = new SecurityAuthConfig("ldap", "cd.go.ldap");
SecurityConfig securityConfig = new SecurityConfig();
securityConfig.securityAuthConfigs().add(authConfig);
when(goConfigService.security()).thenReturn(securityConfig);
assertThat(securityAuthConfigService.findProfile("ldap"), is(authConfig));
}
Aggregations