|
6 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; |
7 | 7 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
8 | 8 | import static org.mockito.ArgumentMatchers.any; |
| 9 | +import static org.mockito.ArgumentMatchers.isA; |
9 | 10 | import static org.mockito.Mockito.mock; |
10 | 11 | import static org.mockito.Mockito.never; |
11 | 12 | import static org.mockito.Mockito.verify; |
|
47 | 48 | import java.util.Optional; |
48 | 49 | import java.util.Set; |
49 | 50 | import java.util.concurrent.atomic.AtomicInteger; |
| 51 | +import java.util.function.Supplier; |
50 | 52 | import java.util.stream.Collectors; |
51 | 53 | import java.util.regex.Matcher; |
52 | 54 | import java.util.regex.Pattern; |
@@ -990,4 +992,41 @@ public ResponseMessage<GetAttributeValuesByFqnsResponse> execute() { |
990 | 992 | assertEquals("public-key-pem-2", storedKASInfo2.PublicKey); |
991 | 993 | } |
992 | 994 |
|
| 995 | + @Test |
| 996 | + void testUsingBaseKeyWhenNoMappedKeysOrGrants() { |
| 997 | + Autoconfigure.Granter granter = Autoconfigure.newGranterFromAttributes(null); |
| 998 | + SimpleKasKey key = SimpleKasKey.newBuilder() |
| 999 | + .setKasUri("https://example.com/kas") |
| 1000 | + .setPublicKey( |
| 1001 | + SimpleKasPublicKey.newBuilder() |
| 1002 | + .setKid("thenewkid") |
| 1003 | + .setPem("anotherpem") |
| 1004 | + .setAlgorithm(Algorithm.ALGORITHM_EC_P521) |
| 1005 | + ).build(); |
| 1006 | + |
| 1007 | + var splits = granter.getSplits( |
| 1008 | + List.of("https://example.org/kas2"), |
| 1009 | + () -> { throw new IllegalStateException("the plan should have a single element"); }, |
| 1010 | + () -> Optional.of(key)); |
| 1011 | + assertThat(splits).hasSize(1); |
| 1012 | + assertThat(splits.get(0)).isEqualTo(new KeySplitStep("https://example.com/kas", "", "thenewkid")); |
| 1013 | + } |
| 1014 | + |
| 1015 | + @Test |
| 1016 | + void testUsingDefaultKasesWhenNothingElseProvided() { |
| 1017 | + Autoconfigure.Granter granter = Autoconfigure.newGranterFromAttributes(null); |
| 1018 | + var counter = new AtomicInteger(); |
| 1019 | + Supplier<String> splitGen = () -> String.valueOf(counter.getAndIncrement()); |
| 1020 | + var splits = granter.getSplits( |
| 1021 | + List.of("https://example.org/kas1", "https://example.org/kas2"), |
| 1022 | + splitGen, |
| 1023 | + Optional::empty); |
| 1024 | + |
| 1025 | + assertThat(splits).hasSize(2); |
| 1026 | + assertThat(splits).asList() |
| 1027 | + .containsExactly( |
| 1028 | + new KeySplitStep("https://example.org/kas1", "0", null), |
| 1029 | + new KeySplitStep("https://example.org/kas2", "1", null) |
| 1030 | + ); |
| 1031 | + } |
993 | 1032 | } |
0 commit comments