diff options
author | Krzysztof Gajewski <krzysztof.gajewski@nokia.com> | 2021-02-15 14:07:44 +0100 |
---|---|---|
committer | Krzysztof Gajewski <krzysztof.gajewski@nokia.com> | 2021-02-23 21:22:22 +0100 |
commit | 6055339221e6e81d76c33c2b95ecc8798d378996 (patch) | |
tree | 3e8233070b69d6bb84cf352e8e99990bcb0de049 /datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/http/DfcHttpsClientTest.java | |
parent | 103342b5bc72ec32e3c2f074ac251f43840ce443 (diff) |
Add JWT support in HTTP/HTTPS based locations1.5.4
Issue-ID: DCAEGEN2-2536
Signed-off-by: Krzysztof Gajewski <krzysztof.gajewski@nokia.com>
Change-Id: I47a928159853333014b0fd413a085b7c50eeb7a0
Diffstat (limited to 'datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/http/DfcHttpsClientTest.java')
-rw-r--r-- | datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/http/DfcHttpsClientTest.java | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/http/DfcHttpsClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/http/DfcHttpsClientTest.java index 8df91d3a..168bb08c 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/http/DfcHttpsClientTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/http/DfcHttpsClientTest.java @@ -16,6 +16,7 @@ package org.onap.dcaegen2.collectors.datafile.http; +import org.apache.hc.core5.net.URIBuilder; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.conn.ConnectTimeoutException; @@ -25,15 +26,18 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.collectors.datafile.commons.FileServerData; import org.onap.dcaegen2.collectors.datafile.commons.ImmutableFileServerData; import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; import org.onap.dcaegen2.collectors.datafile.exceptions.NonRetryableDatafileTaskException; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.nio.file.Path; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -50,6 +54,8 @@ class DfcHttpsClientTest { private static final String PASSWORD = "123"; private static final String XNF_ADDRESS = "127.0.0.1"; private static final int PORT = 443; + private static final String JWT_PASSWORD = "thisIsThePassword"; + private static String ACCESS_TOKEN = "access_token"; private static String remoteFile = "remoteFile"; @Mock @@ -105,6 +111,29 @@ class DfcHttpsClientTest { } @Test + void dfcHttpsClient_flow_successfulCallWithJWTAndResponseProcessing() throws Exception { + FileServerData serverData = jWTTokenInFileServerData(); + dfcHttpsClientSpy = spy(new DfcHttpsClient(serverData, connectionManager)); + + doReturn(HttpClientResponseHelper.APACHE_RESPONSE_OK).when(dfcHttpsClientSpy) + .executeHttpClient(any(HttpGet.class)); + doReturn((long)3).when(dfcHttpsClientSpy).writeFile(eq(localFile), any(InputStream.class)); + + dfcHttpsClientSpy.open(); + dfcHttpsClientSpy.collectFile(remoteFile, localFile); + dfcHttpsClientSpy.close(); + + verify(dfcHttpsClientSpy, times(1)).makeCall(any(HttpGet.class)); + verify(dfcHttpsClientSpy, times(1)) + .executeHttpClient(any(HttpGet.class)); + verify(dfcHttpsClientSpy, times(1)) + .processResponse(HttpClientResponseHelper.APACHE_RESPONSE_OK, localFile); + verify(dfcHttpsClientSpy, times(1)) + .writeFile(eq(localFile), any(InputStream.class)); + assertFalse(serverData.toString().contains(JWT_PASSWORD)); + } + + @Test void dfcHttpsClient_flow_failedCallUnexpectedResponseCode() throws Exception { doReturn(HttpClientResponseHelper.APACHE_RESPONSE_OK).when(dfcHttpsClientSpy) .executeHttpClient(any(HttpGet.class)); @@ -112,7 +141,7 @@ class DfcHttpsClientTest { dfcHttpsClientSpy.open(); - assertThrows(NonRetryableDatafileTaskException.class, + assertThrows(DatafileTaskException.class, () -> dfcHttpsClientSpy.collectFile(remoteFile, localFile)); } @@ -157,8 +186,19 @@ class DfcHttpsClientTest { private ImmutableFileServerData invalidUserInFileServerData() { return ImmutableFileServerData.builder() .serverAddress(XNF_ADDRESS) - .userId("demo").password("") + .userId(USERNAME).password("") + .port(PORT) + .build(); + } + + private ImmutableFileServerData jWTTokenInFileServerData() throws URISyntaxException { + String query = "?" + ACCESS_TOKEN + "=" + JWT_PASSWORD; + + return ImmutableFileServerData.builder() + .serverAddress(XNF_ADDRESS) + .userId("").password("") .port(PORT) + .queryParameters(new URIBuilder(query).getQueryParams()) .build(); } } |