diff options
Diffstat (limited to 'src/test/java')
4 files changed, 25 insertions, 51 deletions
diff --git a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java index 0e91bc70..60287aef 100644 --- a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java +++ b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java @@ -215,25 +215,6 @@ public class ApplicationSettingsTest { assertEquals(sanitizePath("etc/keystore"), keystoreFileLocation); } - - @Test - public void shouldReturnKeystoreAlias() throws IOException { - // when - String keystoreAlias = fromTemporaryConfiguration("collector.keystore.alias=alias").keystoreAlias(); - - // then - assertEquals("alias", keystoreAlias); - } - - @Test - public void shouldReturnDefaultKeystoreAlias() throws IOException { - // when - String keystoreAlias = fromTemporaryConfiguration().keystoreAlias(); - - // then - assertEquals("tomcat", keystoreAlias); - } - @Test public void shouldReturnDMAAPConfigFileLocation() throws IOException { // when @@ -363,22 +344,12 @@ public class ApplicationSettingsTest { } @Test - public void shouldReturnIfAuthorizationIsEnabled() throws IOException { - // when - boolean authorizationEnabled = fromTemporaryConfiguration("header.authflag=1") - .authorizationEnabled(); - - // then - assertTrue(authorizationEnabled); - } - - @Test public void shouldAuthorizationBeDisabledByDefault() throws IOException { // when - boolean authorizationEnabled = fromTemporaryConfiguration().authorizationEnabled(); + boolean authorizationEnabled = fromTemporaryConfiguration().authMethod().contains("noAuth"); // then - assertFalse(authorizationEnabled); + assertTrue(authorizationEnabled); } @Test diff --git a/src/test/java/org/onap/dcae/TLSTest.java b/src/test/java/org/onap/dcae/TLSTest.java index c73bb53b..b1f90371 100644 --- a/src/test/java/org/onap/dcae/TLSTest.java +++ b/src/test/java/org/onap/dcae/TLSTest.java @@ -24,6 +24,7 @@ package org.onap.dcae; import io.vavr.collection.HashMap; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.onap.dcae.common.configuration.AuthMethodType; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; @@ -86,8 +87,8 @@ public class TLSTest extends TLSTestBase { class HttpsWithTLSAuthenticationAndBasicAuthTest extends TestClassBase { @Test - public void shouldHttpsRequestWithoutBasicAuthFail() { - assertThrows(Exception.class, this::makeHttpsRequestWithClientCert); + public void shouldHttpsRequestWithoutBasicAuthSucceed() { + assertEquals(HttpStatus.OK, makeHttpsRequestWithClientCert().getStatusCode()); } @Test @@ -100,6 +101,7 @@ public class TLSTest extends TLSTestBase { static class HttpConfiguration extends TLSTestBase.ConfigurationBase { @Override protected void configureSettings(ApplicationSettings settings) { + when(settings.authMethod()).thenReturn(AuthMethodType.NO_AUTH.value()); } } @@ -109,10 +111,9 @@ public class TLSTest extends TLSTestBase { @Override protected void configureSettings(ApplicationSettings settings) { - when(settings.keystoreAlias()).thenReturn(KEYSTORE_ALIAS); when(settings.keystoreFileLocation()).thenReturn(KEYSTORE.toString()); when(settings.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString()); - when(settings.authorizationEnabled()).thenReturn(true); + when(settings.authMethod()).thenReturn(AuthMethodType.BASIC_AUTH.value()); when(settings.validAuthorizationCredentials()).thenReturn(HashMap.of(USERNAME, "$2a$10$51tDgG2VNLde5E173Ay/YO.Fq.aD.LR2Rp8pY3QAKriOSPswvGviy")); } } @@ -121,8 +122,7 @@ public class TLSTest extends TLSTestBase { @Override protected void configureSettings(ApplicationSettings settings) { super.configureSettings(settings); - when(settings.authorizationEnabled()).thenReturn(false); - when(settings.clientTlsAuthenticationEnabled()).thenReturn(true); + when(settings.authMethod()).thenReturn(AuthMethodType.CERT_ONLY.value()); when(settings.truststoreFileLocation()).thenReturn(TRUSTSTORE.toString()); when(settings.truststorePasswordFileLocation()).thenReturn(TRUSTSTORE_PASSWORD_FILE.toString()); } @@ -132,7 +132,7 @@ public class TLSTest extends TLSTestBase { @Override protected void configureSettings(ApplicationSettings settings) { super.configureSettings(settings); - when(settings.authorizationEnabled()).thenReturn(true); + when(settings.authMethod()).thenReturn(AuthMethodType.CERT_BASIC_AUTH.value()); } } -} +}
\ No newline at end of file diff --git a/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java b/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java index b0a984a0..90c8a9c8 100644 --- a/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java +++ b/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java @@ -22,11 +22,11 @@ package org.onap.dcae.controller; import static io.vavr.API.Map; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; import static org.onap.dcae.TestingUtilities.createTemporaryFile; import static org.onap.dcae.TestingUtilities.readFile; import static org.onap.dcae.TestingUtilities.readJSONFromFile; @@ -36,10 +36,15 @@ import java.nio.file.Path; import java.nio.file.Paths; import org.json.JSONObject; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.dcae.ApplicationSettings; import org.onap.dcae.WiremockBasedTest; import org.onap.dcae.common.publishing.DMaaPConfigurationParser; import org.onap.dcae.common.publishing.EventPublisher; +@RunWith(MockitoJUnitRunner.Silent.class) public class ConfigLoaderIntegrationE2ETest extends WiremockBasedTest { @Test @@ -54,11 +59,8 @@ public class ConfigLoaderIntegrationE2ETest extends WiremockBasedTest { EventPublisher eventPublisherMock = mock(EventPublisher.class); ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(dMaaPConfigFile, collectorPropertiesFile); - - // when ConfigLoader configLoader = new ConfigLoader(eventPublisherMock::reconfigure, configFilesFacade, ConfigSource::getAppConfig, () -> wiremockBasedEnvProps()); configLoader.updateConfig(); - // then assertThat(readJSONFromFile(dMaaPConfigSource).toString()).isEqualTo(dMaaPConf.toString()); assertThat(readFile(collectorPropertiesFile).trim()).isEqualTo("collector.port = 8080"); diff --git a/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java b/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java index 569fd969..a295046b 100644 --- a/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java +++ b/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java @@ -28,6 +28,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.dcae.ApplicationSettings; +import org.onap.dcae.common.configuration.AuthMethodType; import org.slf4j.Logger; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -89,7 +90,7 @@ public class ApiAuthInterceptionTest { // given final HttpServletRequest request = createEmptyRequest(); - when(settings.authorizationEnabled()).thenReturn(false); + when(settings.authMethod()).thenReturn(AuthMethodType.NO_AUTH.value()); // when final boolean isAuthorized = sut.preHandle(request, response, obj); @@ -103,7 +104,7 @@ public class ApiAuthInterceptionTest { // given final HttpServletRequest request = createEmptyRequest(); - when(settings.authorizationEnabled()).thenReturn(true); + when(settings.authMethod()).thenReturn(AuthMethodType.BASIC_AUTH.value()); when(response.getWriter()).thenReturn(writer); // when @@ -113,7 +114,7 @@ public class ApiAuthInterceptionTest { // then assertFalse(isAuthorized); - verify(response).setStatus(HttpStatus.BAD_REQUEST.value()); + verify(response).setStatus(HttpStatus.UNAUTHORIZED.value()); verify(writer).write(ApiException.UNAUTHORIZED_USER.toJSON().toString()); } @@ -122,7 +123,7 @@ public class ApiAuthInterceptionTest { // given final HttpServletRequest request = createRequestWithAuthorizationHeader(); - when(settings.authorizationEnabled()).thenReturn(true); + when(settings.authMethod()).thenReturn(AuthMethodType.BASIC_AUTH.value()); when(response.getWriter()).thenReturn(writer); // when @@ -131,7 +132,7 @@ public class ApiAuthInterceptionTest { // then assertFalse(isAuthorized); - verify(response).setStatus(HttpStatus.BAD_REQUEST.value()); + verify(response).setStatus(HttpStatus.UNAUTHORIZED.value()); verify(writer).write(ApiException.UNAUTHORIZED_USER.toJSON().toString()); } @@ -139,7 +140,7 @@ public class ApiAuthInterceptionTest { public void shouldSucceed() throws IOException { // given final HttpServletRequest request = createRequestWithAuthorizationHeader(); - when(settings.authorizationEnabled()).thenReturn(true); + when(settings.authMethod()).thenReturn(AuthMethodType.CERT_ONLY.value()); when(settings.validAuthorizationCredentials()).thenReturn( HashMap.of(USERNAME, "$2a$10$BsZkEynNm/93wbAeeZuxJeu6IHRyQl4XReqDg2BtYOFDhUsz20.3G")); when(response.getWriter()).thenReturn(writer); @@ -160,7 +161,7 @@ public class ApiAuthInterceptionTest { .header(HttpHeaders.AUTHORIZATION, "FooBar") .buildRequest(null); - when(settings.authorizationEnabled()).thenReturn(true); + when(settings.authMethod()).thenReturn(AuthMethodType.BASIC_AUTH.value()); when(settings.validAuthorizationCredentials()).thenReturn(CREDENTIALS); when(response.getWriter()).thenReturn(writer); @@ -170,7 +171,7 @@ public class ApiAuthInterceptionTest { // then assertFalse(isAuthorized); - verify(response).setStatus(HttpStatus.BAD_REQUEST.value()); + verify(response).setStatus(HttpStatus.UNAUTHORIZED.value()); verify(writer).write(ApiException.UNAUTHORIZED_USER.toJSON().toString()); } } |