DFC shall provide a bearer authorization token in HTTP
[nonrtric/plt/ranpm.git] / datafilecollector / src / test / java / org / oran / datafile / http / DfcHttpClientTest.java
index 0e9a8d0..4d605af 100644 (file)
@@ -29,18 +29,16 @@ import static org.mockito.Mockito.when;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-import java.net.URISyntaxException;
 import java.nio.file.Path;
 
-import org.apache.hc.core5.net.URIBuilder;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.oran.datafile.exceptions.DatafileTaskException;
 import org.oran.datafile.model.FileServerData;
+import org.oran.datafile.oauth2.SecurityContext;
 
 import reactor.core.publisher.Flux;
 import reactor.netty.http.client.HttpClientConfig;
@@ -52,8 +50,6 @@ class DfcHttpClientTest {
     private static final String PASSWORD = "123";
     private static final String XNF_ADDRESS = "127.0.0.1";
     private static final int PORT = 80;
-    private static final String JWT_PASSWORD = "thisIsThePassword";
-    private static String ACCESS_TOKEN = "access_token";
 
     @Mock
     private Path pathMock;
@@ -62,7 +58,8 @@ class DfcHttpClientTest {
 
     @BeforeEach
     public void setup() {
-        dfcHttpClientSpy = spy(new DfcHttpClient(createFileServerData()));
+        SecurityContext ctx = new SecurityContext("");
+        dfcHttpClientSpy = spy(new DfcHttpClient(ctx, createFileServerData()));
     }
 
     @Test
@@ -72,17 +69,6 @@ class DfcHttpClientTest {
         assertEquals(HttpUtils.basicAuthContent(USERNAME, PASSWORD), config.headers().get("Authorization"));
     }
 
-    @Test
-    void openConnection_failedBasicAuthSetupThrowException() {
-        FileServerData serverData =
-            FileServerData.builder().serverAddress(XNF_ADDRESS).userId(USERNAME).password("").port(PORT).build();
-
-        DfcHttpClient dfcHttpClientSpy = spy(new DfcHttpClient(serverData));
-
-        assertThatThrownBy(() -> dfcHttpClientSpy.open())
-            .hasMessageContaining("Not sufficient basic auth data for file.");
-    }
-
     @Test
     void collectFile_AllOk() throws Exception {
         String REMOTE_FILE = "any";
@@ -101,27 +87,6 @@ class DfcHttpClientTest {
         verify(dfcHttpClientSpy, times(1)).isDownloadFailed(any());
     }
 
-    @Test
-    void collectFile_AllOkWithJWTToken() throws Exception {
-        dfcHttpClientSpy = spy(new DfcHttpClient(fileServerDataWithJWTToken()));
-        String REMOTE_FILE = "any";
-        Flux<InputStream> fis = Flux.just(new ByteArrayInputStream("ReturnedString".getBytes()));
-
-        dfcHttpClientSpy.open();
-        HttpClientConfig config = dfcHttpClientSpy.client.configuration();
-        assertEquals(HttpUtils.jwtAuthContent(JWT_PASSWORD), config.headers().get("Authorization"));
-
-        when(dfcHttpClientSpy.getServerResponse(any())).thenReturn(fis);
-        doReturn(false).when(dfcHttpClientSpy).isDownloadFailed(any());
-
-        dfcHttpClientSpy.collectFile(REMOTE_FILE, pathMock);
-        dfcHttpClientSpy.close();
-
-        verify(dfcHttpClientSpy, times(1)).getServerResponse(ArgumentMatchers.eq(REMOTE_FILE));
-        verify(dfcHttpClientSpy, times(1)).processDataFromServer(any(), any(), any());
-        verify(dfcHttpClientSpy, times(1)).isDownloadFailed(any());
-    }
-
     @Test
     void collectFile_No200ResponseWriteToErrorMessage() throws DatafileTaskException {
         String ERROR_RESPONSE = "This is unexpected message";
@@ -149,11 +114,4 @@ class DfcHttpClientTest {
         return FileServerData.builder().serverAddress(XNF_ADDRESS).userId(USERNAME).password(PASSWORD).port(PORT)
             .build();
     }
-
-    private FileServerData fileServerDataWithJWTToken() throws URISyntaxException {
-        String query = "?" + ACCESS_TOKEN + "=" + JWT_PASSWORD;
-
-        return FileServerData.builder().serverAddress(XNF_ADDRESS).userId("").password("").port(PORT)
-            .queryParameters(new URIBuilder(query).getQueryParams()).build();
-    }
 }