use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_AuthenticateUser.
@Test
void shouldTalkToPlugin_To_AuthenticateUser() {
String requestBody = "{\n" + " \"credentials\": {\n" + " \"username\": \"bob\",\n" + " \"password\": \"secret\"\n" + " },\n" + " \"auth_configs\": [\n" + " {\n" + " \"id\": \"ldap\",\n" + " \"configuration\": {\n" + " \"url\": \"some-url\"\n" + " }\n" + " }\n" + " ],\n" + " \"role_configs\": [\n" + " {\n" + " \"name\": \"foo\",\n" + " \"auth_config_id\": \"ldap\",\n" + " \"configuration\": {\n" + " \"memberOf\": \"ou=some-value\"\n" + " }\n" + " }\n" + " ]\n" + "}";
String responseBody = "{\"user\":{\"username\":\"bob\",\"display_name\":\"Bob\",\"email\":\"bob@example.com\"},\"roles\":[\"blackbird\"]}";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
final PluginRoleConfig roleConfig = new PluginRoleConfig("foo", "ldap", create("memberOf", false, "ou=some-value"));
final List<PluginRoleConfig> pluginRoleConfigs = Collections.singletonList(roleConfig);
final SecurityAuthConfigs authConfigs = new SecurityAuthConfigs();
authConfigs.add(new SecurityAuthConfig("ldap", "cd.go.ldap", create("url", false, "some-url")));
AuthenticationResponse authenticationResponse = authorizationExtension.authenticateUser(PLUGIN_ID, "bob", "secret", authConfigs, pluginRoleConfigs);
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_AUTHENTICATE_USER, requestBody);
assertThat(authenticationResponse.getUser()).isEqualTo(new User("bob", "Bob", "bob@example.com"));
assertThat(authenticationResponse.getRoles().get(0)).isEqualTo("blackbird");
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_GetAuthorizationServerUrl.
@Test
void shouldTalkToPlugin_To_GetAuthorizationServerUrl() {
String requestBody = "{\n" + " \"auth_configs\": [\n" + " {\n" + " \"id\": \"github\",\n" + " \"configuration\": {\n" + " \"url\": \"some-url\"\n" + " }\n" + " }\n" + " ],\n" + " \"authorization_server_callback_url\": \"http://go.site.url/go/plugin/plugin-id/authenticate\"\n" + "}";
String responseBody = "{\"authorization_server_url\":\"url_to_authorization_server\"}";
SecurityAuthConfig authConfig = new SecurityAuthConfig("github", "cd.go.github", create("url", false, "some-url"));
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
String authorizationServerRedirectUrl = authorizationExtension.getAuthorizationServerUrl(PLUGIN_ID, Collections.singletonList(authConfig), "http://go.site.url");
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_AUTHORIZATION_SERVER_URL, requestBody);
assertThat(authorizationServerRedirectUrl).isEqualTo("url_to_authorization_server");
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class AuthorizationExtensionTest method shouldReturnFalseForSupportsValidatingUserExistenceForAuthorizationExtensionV1.
@Test
void shouldReturnFalseForSupportsValidatingUserExistenceForAuthorizationExtensionV1() throws Exception {
String pluginId = "cd.go.ldap";
when(pluginManager.resolveExtensionVersion(pluginId, AUTHORIZATION_EXTENSION, SUPPORTED_VERSIONS)).thenReturn(AuthorizationMessageConverterV1.VERSION);
SecurityAuthConfig authConfig = new SecurityAuthConfig("ldap", pluginId, create("url", false, "some-url"));
boolean expected = authorizationExtension.supportsPluginAPICallsRequiredForAccessToken(authConfig);
assertThat(expected).isFalse();
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_AuthenticateUserWithEmptyListIfRoleConfigsAreNotProvided.
@Test
void shouldTalkToPlugin_To_AuthenticateUserWithEmptyListIfRoleConfigsAreNotProvided() {
String requestBody = "{\n" + " \"credentials\": {\n" + " \"username\": \"bob\",\n" + " \"password\": \"secret\"\n" + " },\n" + " \"auth_configs\": [\n" + " {\n" + " \"id\": \"ldap\",\n" + " \"configuration\": {\n" + " \"url\": \"some-url\"\n" + " }\n" + " }\n" + " ],\n" + " \"role_configs\": []\n" + "}";
String responseBody = "{\"user\":{\"username\":\"bob\",\"display_name\":\"Bob\",\"email\":\"bob@example.com\"},\"roles\":[\"blackbird\"]}";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
final SecurityAuthConfigs authConfigs = new SecurityAuthConfigs();
authConfigs.add(new SecurityAuthConfig("ldap", "cd.go.ldap", create("url", false, "some-url")));
AuthenticationResponse authenticationResponse = authorizationExtension.authenticateUser(PLUGIN_ID, "bob", "secret", authConfigs, null);
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_AUTHENTICATE_USER, requestBody);
assertThat(authenticationResponse.getUser()).isEqualTo(new User("bob", "Bob", "bob@example.com"));
assertThat(authenticationResponse.getRoles().get(0)).isEqualTo("blackbird");
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class AuthorizationMessageConverterV2Test method shouldReturnRequestBodyForDoesUserExistsRequest.
@Test
void shouldReturnRequestBodyForDoesUserExistsRequest() {
SecurityAuthConfig authConfig = new SecurityAuthConfig("p1", "ldap", ConfigurationPropertyMother.create("key1", false, "value2"));
String requestBody = converter.isValidUserRequestBody("foo", authConfig);
assertThatJson(requestBody).isEqualTo("{\n" + " \"auth_config\": {\n" + " \"configuration\": {\n" + " \"key1\": \"value2\"\n" + " },\n" + " \"id\": \"p1\"\n" + " },\n" + " \"username\": \"foo\"\n" + "}");
}
Aggregations