Add test case with missing cluster type
@@ -25,19 +25,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class IdentityDocumentSignerTest {
public static final int KEY_VERSION = 0;
+ private static final IdentityType identityType = TENANT;
+ private static final VespaUniqueInstanceId id =
+ new VespaUniqueInstanceId(1, "cluster-id", "instance", "application", "tenant", "region", "environment", identityType);
+ private static final AthenzService providerService = new AthenzService("vespa", "service");
+ private static final KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.RSA);
+ private static final String configserverHostname = "configserverhostname";
+ private static final String instanceHostname = "instancehostname";
+ private static final Instant createdAt = Instant.EPOCH;
+ private static final HashSet<String> ipAddresses = new HashSet<>(Arrays.asList("1.2.3.4", "::1"));
+ private static final ClusterType clusterType = ClusterType.CONTAINER;
+
@Test
void generates_and_validates_signature() {
IdentityDocumentSigner signer = new IdentityDocumentSigner();
- IdentityType identityType = TENANT;
- VespaUniqueInstanceId id =
- new VespaUniqueInstanceId(1, "cluster-id", "instance", "application", "tenant", "region", "environment", identityType);
- AthenzService providerService = new AthenzService("vespa", "service");
- KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.RSA);
- String configserverHostname = "configserverhostname";
- String instanceHostname = "instancehostname";
- Instant createdAt = Instant.EPOCH;
- HashSet<String> ipAddresses = new HashSet<>(Arrays.asList("1.2.3.4", "::1"));
- var clusterType = ClusterType.CONTAINER;
String signature =
signer.generateSignature(id, providerService, configserverHostname, instanceHostname, createdAt,
ipAddresses, identityType, clusterType, keyPair.getPrivate());
@@ -49,4 +50,18 @@ public class IdentityDocumentSignerTest {
assertTrue(signer.hasValidSignature(signedIdentityDocument, keyPair.getPublic()));
}
+ @Test
+ void handles_missing_cluster_type() {
+ IdentityDocumentSigner signer = new IdentityDocumentSigner();
+ String signature =
+ signer.generateSignature(id, providerService, configserverHostname, instanceHostname, createdAt,
+ ipAddresses, identityType, /*clusterType*/null, keyPair.getPrivate());
+
+ SignedIdentityDocument signedIdentityDocument = new SignedIdentityDocument(
+ signature, KEY_VERSION, id, providerService, DEFAULT_DOCUMENT_VERSION, configserverHostname,
+ instanceHostname, createdAt, ipAddresses, identityType, /*clusterType*/null);
+
+ assertTrue(signer.hasValidSignature(signedIdentityDocument, keyPair.getPublic()));
+ }
+
}
\ No newline at end of file
