Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Revert "Feat: no basic auth (#183)" #185

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public Response createQueryOptions(String queryString, @Context HttpServletReque
public Response createQuery(String queryString, @Context HttpServletRequest request) {
String apiCallId = UUID.randomUUID().toString();
logger.info(apiCallId + " API call via create_query API.");
checkAuthentication(request);

try(Config config = getConfigFromDactory()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ void tearDown() {
@Test
@DisplayName("Create new Request with no Token")
void testCreateQuery_withNoToken() throws SQLException {
// Mock config classes
Mockito.when(negotiatorConfig.getMolgenisUsername()).thenReturn("username");
Mockito.when(negotiatorConfig.getMolgenisPassword()).thenReturn("password");
Mockito.when(request.getHeader("Authorization")).thenReturn("Basic dXNlcm5hbWU6cGFzc3dvcmQ=");

// Mock object under test
Directory directorySpy = Mockito.spy(directory);
Mockito.doReturn(config).when(directorySpy).getConfigFromDactory();
Mockito.doReturn(negotiatorConfig).when(directorySpy).getNegotiatorConfig();

JsonQueryRecord jsonQueryRecord = new JsonQueryRecord();
jsonQueryRecord.setJsonText(queryJsonNoNToken);
Expand All @@ -60,16 +67,23 @@ void testCreateQuery_withNoToken() throws SQLException {
@Test
@DisplayName("Create new Request with Token")
void testCreateQuery_withToken() throws SQLException {
Mockito.when(queryRecord.getJsonText()).thenReturn(recordJsonWithMultipleQueries);
// Mock classes
Mockito.when(negotiatorConfig.getMolgenisUsername()).thenReturn("username");
Mockito.when(negotiatorConfig.getMolgenisPassword()).thenReturn("password");
Mockito.when(request.getHeader("Authorization")).thenReturn("Basic dXNlcm5hbWU6cGFzc3dvcmQ=");
Mockito.when(queryRecord.getJsonText()).thenReturn(recordJsonWithMultipleQueries);

// Mock object under test
Directory directorySpy = Mockito.spy(directory);
Mockito.doReturn(config).when(directorySpy).getConfigFromDactory();
Mockito.doReturn(negotiatorConfig).when(directorySpy).getNegotiatorConfig();
Mockito.doReturn(queryRecord).when(directorySpy).getQueryForNToken(Mockito.any(), Mockito.any());
Mockito.doNothing().when(directorySpy).updateRecord(queryRecord);

JsonQueryRecord jsonQueryRecord = new JsonQueryRecord();
jsonQueryRecord.setJsonText(queryJsonNToken);
jsonQueryRecord.setId(1);
//Mockito.doReturn(jsonQueryRecord).when(directorySpy).saveJsonQueryRecord(queryJsonNToken, config);

// Test call
Response response = directorySpy.createQuery(queryJsonNToken, request);
Expand Down