Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
federicaagostini committed Nov 6, 2024
1 parent 0ff8c85 commit bf90233
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.italiangrid.storm.webdav.oauth.GrantedAuthoritiesMapperSupport.OAUTH_GROUP_CLAIM_NAMES;

import java.net.URI;

Expand Down Expand Up @@ -127,11 +128,8 @@ void issuerChecksAreEnforcedForWlcgScopeBasedAuthz() throws Exception {

@Test
void getAccessAsJwtUserWithoutScopeLeadsToAccessDenied() throws Exception {
Jwt token = Jwt.withTokenValue("test")
.header("kid", "rsa1")
.issuer(WLCG_ISSUER)
.subject("123")
.build();
Jwt token =
Jwt.withTokenValue("test").header("kid", "rsa1").issuer(WLCG_ISSUER).subject("123").build();

mvc.perform(get(SLASH_WLCG_SLASH_FILE).with(jwt().jwt(token)))
.andExpect(status().isForbidden());
Expand Down Expand Up @@ -180,6 +178,25 @@ void getAccessAsJwtWithWriteCapabilityResultsInAccessDenied() throws Exception {

}

@Test
void readWriteAccessAsJwtWithAllowedGroup() throws Exception {

for (String groupClaim : OAUTH_GROUP_CLAIM_NAMES) {
Jwt token = Jwt.withTokenValue("test")
.header("kid", "rsa1")
.issuer(EXAMPLE_ISSUER)
.claim(groupClaim, "/example/admins")
.build();

mvc.perform(get(SLASH_WLCG_SLASH_FILE).with(jwt().jwt(token).authorities(authConverter)))
.andExpect(status().isNotFound());

mvc.perform(put(SLASH_WLCG_SLASH_FILE).with(jwt().jwt(token).authorities(authConverter)))
.andExpect(status().isOk());
}

}

@WithMockVOMSUser(vos = "wlcg", saReadPermissions = {"wlcg"})
@Test
void localVomsCopyRequiresWithReadPermissionsGetsAccessDenied() throws Exception {
Expand Down

0 comments on commit bf90233

Please sign in to comment.