|
7 | 7 | import static org.mockito.Mockito.when; |
8 | 8 | import static org.springframework.security.oauth2.client.registration.ClientRegistration.withRegistrationId; |
9 | 9 |
|
| 10 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 11 | +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; |
| 12 | +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; |
10 | 13 | import io.kafbat.ui.config.auth.OAuthProperties; |
11 | 14 | import io.kafbat.ui.model.rbac.Role; |
12 | 15 | import io.kafbat.ui.service.rbac.AccessControlService; |
|
16 | 19 | import io.kafbat.ui.service.rbac.extractor.OauthAuthorityExtractor; |
17 | 20 | import io.kafbat.ui.service.rbac.extractor.ProviderAuthorityExtractor; |
18 | 21 | import io.kafbat.ui.util.AccessControlServiceMock; |
| 22 | +import java.io.IOException; |
19 | 23 | import java.io.InputStream; |
20 | 24 | import java.time.Instant; |
21 | 25 | import java.time.temporal.ChronoUnit; |
|
32 | 36 | import org.springframework.security.oauth2.core.OAuth2AccessToken; |
33 | 37 | import org.springframework.security.oauth2.core.user.DefaultOAuth2User; |
34 | 38 | import org.springframework.security.oauth2.core.user.OAuth2User; |
35 | | -import org.yaml.snakeyaml.Yaml; |
36 | | -import org.yaml.snakeyaml.introspector.BeanAccess; |
37 | 39 |
|
38 | 40 | public class RegexBasedProviderAuthorityExtractorTest { |
39 | 41 |
|
40 | 42 |
|
41 | 43 | private final AccessControlService accessControlService = new AccessControlServiceMock().getMock(); |
42 | | - Yaml yaml; |
43 | 44 | ProviderAuthorityExtractor extractor; |
44 | 45 |
|
45 | 46 | @BeforeEach |
46 | | - void setUp() { |
47 | | - yaml = new Yaml(); |
48 | | - yaml.setBeanAccess(BeanAccess.FIELD); |
| 47 | + void setUp() throws IOException { |
| 48 | + |
| 49 | + YAMLMapper mapper = new YAMLMapper(); |
49 | 50 |
|
50 | 51 | InputStream rolesFile = this.getClass() |
51 | 52 | .getClassLoader() |
52 | 53 | .getResourceAsStream("roles_definition.yaml"); |
53 | 54 |
|
54 | | - Role[] roleArray = yaml.loadAs(rolesFile, Role[].class); |
55 | | - when(accessControlService.getRoles()).thenReturn(List.of(roleArray)); |
| 55 | + Role[] roles = mapper.readValue(rolesFile, Role[].class); |
| 56 | + |
| 57 | + when(accessControlService.getRoles()).thenReturn(List.of(roles)); |
56 | 58 |
|
57 | 59 | } |
58 | 60 |
|
|
0 commit comments