diff --git a/src/test/java/com/entrevistador/gateway/config/security/KeycloakGrantedAuthoritiesConverterTest.java b/src/test/java/com/entrevistador/gateway/config/security/KeycloakGrantedAuthoritiesConverterTest.java index ed590ee..ded9283 100644 --- a/src/test/java/com/entrevistador/gateway/config/security/KeycloakGrantedAuthoritiesConverterTest.java +++ b/src/test/java/com/entrevistador/gateway/config/security/KeycloakGrantedAuthoritiesConverterTest.java @@ -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 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 authorities = converter.convert(jwt); + + // Assert + assertEquals(1, authorities.size()); + assertTrue(authorities.stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_admin"))); + } } \ No newline at end of file