From f69402c78a3ec1e58458415fcf23474b6b58eef8 Mon Sep 17 00:00:00 2001 From: DylanSerkovich Date: Sun, 25 Aug 2024 19:36:16 -0500 Subject: [PATCH] terminando test --- ...ycloakGrantedAuthoritiesConverterTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) 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