Skip to content

Commit 491cbf3

Browse files
committed
a couple more tests
1 parent 41f3d6a commit 491cbf3

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

sdk/src/main/java/io/opentdf/platform/sdk/Autoconfigure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ List<KeySplitStep> getSplits(List<String> defaultKases, Supplier<String> genSpli
362362

363363
logger.warn("no grants or mapped keys found, generating plan from default KASes. this is deprecated");
364364
// this is a little bit weird because we don't take into account the KIDs here. This is the way
365-
// that it works in
365+
// that it works in the go SDK but it seems a bit odd
366366
return generatePlanFromDefaultKases(defaultKases, genSplitID);
367367
}
368368

sdk/src/main/java/io/opentdf/platform/sdk/Planner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Optional<SimpleKasKey> fetchBaseKey() {
127127
.build());
128128
}
129129

130-
private static Gson gson = new Gson();
130+
private static final Gson gson = new Gson();
131131

132132
private static class BaseKey {
133133
@SerializedName("kas_url")

sdk/src/test/java/io/opentdf/platform/sdk/AutoconfigureTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.junit.jupiter.api.Assertions.assertEquals;
77
import static org.junit.jupiter.api.Assertions.assertNotNull;
88
import static org.mockito.ArgumentMatchers.any;
9+
import static org.mockito.ArgumentMatchers.isA;
910
import static org.mockito.Mockito.mock;
1011
import static org.mockito.Mockito.never;
1112
import static org.mockito.Mockito.verify;
@@ -47,6 +48,7 @@
4748
import java.util.Optional;
4849
import java.util.Set;
4950
import java.util.concurrent.atomic.AtomicInteger;
51+
import java.util.function.Supplier;
5052
import java.util.stream.Collectors;
5153
import java.util.regex.Matcher;
5254
import java.util.regex.Pattern;
@@ -990,4 +992,41 @@ public ResponseMessage<GetAttributeValuesByFqnsResponse> execute() {
990992
assertEquals("public-key-pem-2", storedKASInfo2.PublicKey);
991993
}
992994

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+
}
9931032
}

0 commit comments

Comments
 (0)