Skip to content

Commit

Permalink
Update and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kalletlak committed Aug 11, 2023
1 parent bb9a48f commit 5f8caf7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ public static String parseUrl(String url)
public void setDownloadGroup(String property) { downloadGroup = property; }

public static final String DEFAULT_DAT_METHOD = "none";

private static String dataAccessTokenMethod;
@Value("${dat.method:none}") // default is empty string
public void setDataAccessTokenMethod(String property) { dataAccessTokenMethod = property; }

private static String tokenAccessUserRole;
@Value("${dat.filter_user_role:}") // default is empty string
Expand Down Expand Up @@ -1305,7 +1309,6 @@ public static String getDownloadControl() {

public static String getDataAccessTokenMethod() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String dataAccessTokenMethod = getProperty("dat.method");

if (authentication != null &&
StringUtils.isNotEmpty(tokenAccessUserRole)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,15 @@ public Void answer(InvocationOnMock getAllTokensInvocation) {
Assert.fail("Unexpected argument passed to service class. Expected argument: " + MOCK_USER + " Received argument: " + receivedArgument);
}
}

@Test
public void createTokenNotLoggedIn() throws Exception {
ReflectionTestUtils.setField(DataAccessTokenController.class, "userRoleToAccessToken", "TEST");
Mockito.when(tokenService.createDataAccessToken(ArgumentMatchers.anyString())).thenReturn(MOCK_TOKEN_INFO);
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post("/data-access-tokens")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isUnauthorized())
.andReturn();
}
}

0 comments on commit 5f8caf7

Please sign in to comment.