Skip to content

Commit

Permalink
Fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
enricovianello committed Oct 3, 2024
1 parent 90ac420 commit 51b94e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public class WlcgStructuredPathAuthorizationPdp
public static final String STORAGE_READ = "storage.read";
public static final String STORAGE_MODIFY = "storage.modify";
public static final String STORAGE_CREATE = "storage.create";
public static final Set<String> ALL_STORAGE_SCOPES =
Sets.newHashSet(STORAGE_READ, STORAGE_MODIFY, STORAGE_CREATE, STORAGE_STAGE);

protected static final Set<String> ALL_STORAGE_SCOPES =
Sets.newHashSet(STORAGE_READ, STORAGE_MODIFY, STORAGE_CREATE, STORAGE_STAGE);

public static final String ERROR_INVALID_AUTHENTICATION =
"Invalid authentication: expected a JwtAuthenticationToken object";
Expand All @@ -72,13 +72,10 @@ public class WlcgStructuredPathAuthorizationPdp

public static final String ERROR_UNKNOWN_TOKEN_ISSUER = "Unknown token issuer: %s";

public static final Set<String> READONLY_METHODS = Sets.newHashSet("GET", "PROPFIND");

public static final Set<String> REPLACE_METHODS = Sets.newHashSet("PUT", "MKCOL");

public static final Set<String> MODIFY_METHODS = Sets.newHashSet("PATCH", "DELETE");

public static final Set<String> CATCHALL_METHODS = Sets.newHashSet("HEAD", "OPTIONS");
protected static final Set<String> READONLY_METHODS = Sets.newHashSet("GET", "PROPFIND");
protected static final Set<String> REPLACE_METHODS = Sets.newHashSet("PUT", "MKCOL");
protected static final Set<String> MODIFY_METHODS = Sets.newHashSet("PATCH", "DELETE");
protected static final Set<String> CATCHALL_METHODS = Sets.newHashSet("HEAD", "OPTIONS");

public static final String COPY_METHOD = "COPY";
public static final String MOVE_METHOD = "MOVE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void setup() throws MalformedURLException {
}

@Test
public void invalidAuthentication() {
void invalidAuthentication() {

Authentication auth = mock(Authentication.class);
assertThrows(IllegalArgumentException.class, () -> {
Expand All @@ -110,7 +110,7 @@ public void invalidAuthentication() {
}

@Test
public void noScopeClaimYeldsIndeterminate() throws Exception {
void noScopeClaimYeldsIndeterminate() throws Exception {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn(null);
PathAuthorizationResult result =
pdp.authorizeRequest(newAuthorizationRequest(request, jwtAuth));
Expand All @@ -120,7 +120,7 @@ public void noScopeClaimYeldsIndeterminate() throws Exception {
}

@Test
public void noSaYeldsIndeterminate() throws Exception {
void noSaYeldsIndeterminate() throws Exception {

when(pathResolver.resolveStorageArea("/test/example")).thenReturn(null);
PathAuthorizationResult result =
Expand All @@ -131,7 +131,7 @@ public void noSaYeldsIndeterminate() throws Exception {
}

@Test
public void noStorageScopesYeldsDeny() throws Exception {
void noStorageScopesYeldsDeny() throws Exception {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid profile storage.read");

PathAuthorizationResult result =
Expand All @@ -143,7 +143,7 @@ public void noStorageScopesYeldsDeny() throws Exception {
}

@Test
public void noStorageScopesYeldsDenyForCatchallMethods() throws Exception {
void noStorageScopesYeldsDenyForCatchallMethods() {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid profile");

for (String m : CATCHALL_METHODS) {
Expand All @@ -158,7 +158,7 @@ public void noStorageScopesYeldsDenyForCatchallMethods() throws Exception {
}

@Test
public void catchallMethodsRequestsAtLeastOneStorageScope() throws Exception {
void catchallMethodsRequestsAtLeastOneStorageScope() {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.modify:/");

for (String m : CATCHALL_METHODS) {
Expand Down Expand Up @@ -197,7 +197,7 @@ public void catchallMethodsRequestsAtLeastOneStorageScope() throws Exception {
}

@Test
public void readMethodsRequestsRequireStorageReadOrStage() throws Exception {
void readMethodsRequestsRequireStorageReadOrStage() {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.modify:/");

for (String m : READ_METHODS) {
Expand Down Expand Up @@ -229,7 +229,7 @@ public void readMethodsRequestsRequireStorageReadOrStage() throws Exception {
}

@Test
public void replaceMethodsRequestsRequireStorageModifyOrCreate() throws Exception {
void replaceMethodsRequestsRequireStorageModifyOrCreate() throws Exception {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.read:/");

for (String m : REPLACE_METHODS) {
Expand Down Expand Up @@ -273,7 +273,7 @@ public void replaceMethodsRequestsRequireStorageModifyOrCreate() throws Exceptio
}

@Test
public void modifyMethodsRequestsRequireStorageModifyOrCreate() throws Exception {
void modifyMethodsRequestsRequireStorageModifyOrCreate() throws Exception {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.read:/ storage.create:/");

for (String m : MODIFY_METHODS) {
Expand All @@ -296,7 +296,7 @@ public void modifyMethodsRequestsRequireStorageModifyOrCreate() throws Exception
}

@Test
public void testLocalCopyRequiresStorageCreateOrModify() throws Exception {
void testLocalCopyRequiresStorageCreateOrModify() throws Exception {

when(request.getMethod()).thenReturn(COPY_METHOD);
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.modify:/");
Expand All @@ -313,7 +313,7 @@ public void testLocalCopyRequiresStorageCreateOrModify() throws Exception {
}

@Test
public void testPullTpcRequiresCreateOrModify() throws Exception {
void testPullTpcRequiresCreateOrModify() throws Exception {
when(request.getMethod()).thenReturn(COPY_METHOD);
when(request.getHeader("Source")).thenReturn("https://remote.example/test/example");
when(pathResolver.pathExists("/test/example")).thenReturn(true);
Expand Down Expand Up @@ -341,7 +341,7 @@ public void testPullTpcRequiresCreateOrModify() throws Exception {
}

@Test
public void testPushTpcRequiresRead() throws Exception {
void testPushTpcRequiresRead() throws Exception {
when(request.getMethod()).thenReturn(COPY_METHOD);
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.create:/ storage.modify:/");
PathAuthorizationResult result =
Expand All @@ -357,7 +357,7 @@ public void testPushTpcRequiresRead() throws Exception {
}

@Test
public void testMoveRequiresModify() throws Exception {
void testMoveRequiresModify() throws Exception {
when(request.getMethod()).thenReturn(MOVE_METHOD);
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.read:/ storage.create:/");
PathAuthorizationResult result =
Expand All @@ -373,7 +373,7 @@ public void testMoveRequiresModify() throws Exception {
}

@Test
public void testModifyImpliesCreate() throws Exception {
void testModifyImpliesCreate() throws Exception {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.read:/ storage.modify:/");
when(pathResolver.pathExists("/test/example")).thenReturn(false);

Expand All @@ -386,15 +386,15 @@ public void testModifyImpliesCreate() throws Exception {
}

@Test
public void testUnsupportedMethod() throws Exception {
void testUnsupportedMethod() throws Exception {
when(request.getMethod()).thenReturn("TRACE");
assertThrows(IllegalArgumentException.class, () -> {
pdp.authorizeRequest(newAuthorizationRequest(request, jwtAuth));
});
}

@Test
public void testPathAuthzIsEnforced() throws Exception {
void testPathAuthzIsEnforced() throws Exception {
when(jwt.getClaimAsString(SCOPE_CLAIM)).thenReturn("openid storage.read:/subfolder");
when(request.getMethod()).thenReturn("GET");
PathAuthorizationResult result =
Expand All @@ -410,7 +410,7 @@ public void testPathAuthzIsEnforced() throws Exception {
}

@Test
public void issuerChecksAreEnforced() throws Exception {
void issuerChecksAreEnforced() throws Exception {
when(jwt.getIssuer()).thenReturn(new URL("https://unknown.example"));
when(request.getMethod()).thenReturn("GET");
PathAuthorizationResult result =
Expand Down

0 comments on commit 51b94e6

Please sign in to comment.