Skip to content

Commit

Permalink
terminando test
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanSerkovich committed Aug 26, 2024
1 parent e614851 commit f69402c
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,40 @@ void convert_ShouldReturnGrantedAuthorities() {

assertEquals(expectedAuthorities, actualAuthorities);
}

@Test
void extractAuthority_ShouldHandleMissingIntermediateLevel() {
// Arrange
when(properties.getRoleClaims()).thenReturn(Set.of("missing.level"));

jwt = Jwt.withTokenValue("token")
.header("alg", "none")
.claim("missing", Map.of()) // No contiene "level"
.build();

// Act
Collection<GrantedAuthority> authorities = converter.convert(jwt);

// Assert
assertTrue(authorities.isEmpty());
}

@Test
void extractAuthority_ShouldHandlePathNotEndingInList() {
// Arrange
when(properties.getRoleClaims()).thenReturn(Set.of("realm_access.wrong_type"));

// Proporcionar una estructura de datos válida
jwt = Jwt.withTokenValue("token")
.header("alg", "none")
.claim("realm_access", Map.of("wrong_type", List.of("admin")))
.build();

// Act
Collection<GrantedAuthority> authorities = converter.convert(jwt);

// Assert
assertEquals(1, authorities.size());
assertTrue(authorities.stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_admin")));
}
}

0 comments on commit f69402c

Please sign in to comment.