diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2017-10-25 15:00:49 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2017-10-25 15:00:49 +0200 |
commit | 5b7371df7a1fb414c87014d2e50e883cdf20705b (patch) | |
tree | 0b6e43152aea50a5ff69378e7ee1a4903fdf3702 /athenz-identity-provider-service/src | |
parent | bbf54c75758d631c8626fd00e000d705c96a5d01 (diff) |
Keep code line length below limit
Diffstat (limited to 'athenz-identity-provider-service/src')
-rw-r--r-- | athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/AthenzInstanceProviderServiceTest.java | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/AthenzInstanceProviderServiceTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/AthenzInstanceProviderServiceTest.java index b93fae6af0f..0fe31e4ff06 100644 --- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/AthenzInstanceProviderServiceTest.java +++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/AthenzInstanceProviderServiceTest.java @@ -10,7 +10,6 @@ import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ApplicationName; import com.yahoo.config.provision.ClusterMembership; import com.yahoo.config.provision.Environment; -import com.yahoo.config.provision.Flavor; import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.NodeType; import com.yahoo.config.provision.RegionName; @@ -134,32 +133,49 @@ public class AthenzInstanceProviderServiceTest { } @Test - public void generates_valid_identity_document() throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + public void generates_valid_identity_document() throws Exception { String hostname = "x.y.com"; - AutoGeneratedKeyProvider keyProvider = new AutoGeneratedKeyProvider(); - AthenzProviderServiceConfig config = getAthenzProviderConfig("domain", "service"); + + ApplicationId appid = ApplicationId.from( + TenantName.from("tenant"), ApplicationName.from("application"), InstanceName.from("default")); + Allocation allocation = new Allocation(appid, + ClusterMembership.from("container/default/0/0", Version.fromString("1.2.3")), + Generation.inital(), + false); + Node n = Node.create("ostkid", + ImmutableSet.of("127.0.0.1"), + new HashSet<>(), + hostname, + Optional.empty(), + new MockNodeFlavors().getFlavorOrThrow("default"), + NodeType.tenant) + .with(allocation); NodeRepository nodeRepository = mock(NodeRepository.class); - MockNodeFlavors nodeFlavors = new MockNodeFlavors(); - ApplicationId appid = ApplicationId.from(TenantName.from("tenant"), ApplicationName.from("application"), InstanceName.from("default")); - Allocation allocation = new Allocation(appid, ClusterMembership.from("container/default/0/0", Version.fromString("1.2.3")), Generation.inital(), false); Flavor flavor = nodeFlavors.getFlavorOrThrow("default"); - Node n = Node.create("ostkid", ImmutableSet.of("127.0.0.1"), new HashSet<>(), hostname, Optional.empty(), flavor, NodeType.tenant).with(allocation); when(nodeRepository.getNode(eq(hostname))).thenReturn(Optional.of(n)); + AutoGeneratedKeyProvider keyProvider = new AutoGeneratedKeyProvider(); - IdentityDocumentGenerator identityDocumentGenerator = new IdentityDocumentGenerator(config, nodeRepository, ZONE, keyProvider); + IdentityDocumentGenerator identityDocumentGenerator = new IdentityDocumentGenerator( + getAthenzProviderConfig("domain", "service"), + nodeRepository, + ZONE, + keyProvider); String rawSignedIdentityDocument = identityDocumentGenerator.generateSignedIdentityDocument(hostname); - SignedIdentityDocument signedIdentityDocument = Utils.getMapper().readValue(rawSignedIdentityDocument, SignedIdentityDocument.class); + SignedIdentityDocument signedIdentityDocument = + Utils.getMapper().readValue(rawSignedIdentityDocument, SignedIdentityDocument.class); // Verify attributes assertEquals(hostname, signedIdentityDocument.identityDocument.instanceHostname); - ProviderUniqueId expectedProviderUniqueId = new ProviderUniqueId("tenant", "application", "dev", "us-north-1", "default", "default", 0); + ProviderUniqueId expectedProviderUniqueId = + new ProviderUniqueId("tenant", "application", "dev", "us-north-1", "default", "default", 0); assertEquals(expectedProviderUniqueId, signedIdentityDocument.identityDocument.providerUniqueId); // Validate signature - assertTrue("Message", InstanceValidator.isSignatureValid(Crypto.loadPublicKey(keyProvider.getPublicKey(0)), signedIdentityDocument.rawIdentityDocument, signedIdentityDocument.signature)); - + assertTrue("Message", InstanceValidator.isSignatureValid(Crypto.loadPublicKey(keyProvider.getPublicKey(0)), + signedIdentityDocument.rawIdentityDocument, + signedIdentityDocument.signature)); } private static AthenzProviderServiceConfig getAthenzProviderConfig(String domain, String service) { @@ -207,9 +223,10 @@ public class AthenzInstanceProviderServiceTest { private static HttpEntity createInstanceConfirmation(PrivateKey privateKey) { IdentityDocument identityDocument = new IdentityDocument( - new ProviderUniqueId( - "tenant", "application", "environment", "region", "instance", "cluster-id", 0), - "hostname", "instance-hostname", Instant.now()); + new ProviderUniqueId("tenant", "application", "environment", "region", "instance", "cluster-id", 0), + "hostname", + "instance-hostname", + Instant.now()); try { ObjectMapper mapper = Utils.getMapper(); String encodedIdentityDocument = @@ -217,11 +234,17 @@ public class AthenzInstanceProviderServiceTest { Signature sigGenerator = Signature.getInstance("SHA512withRSA"); sigGenerator.initSign(privateKey); sigGenerator.update(encodedIdentityDocument.getBytes()); - String signature = Base64.getEncoder().encodeToString(sigGenerator.sign()); InstanceConfirmation instanceConfirmation = new InstanceConfirmation( "provider", "domain", "service", - new SignedIdentityDocument(encodedIdentityDocument, signature, 0, identityDocument.providerUniqueId.asString(), "dnssuffix", "service", "localhost/zts",1)); + new SignedIdentityDocument(encodedIdentityDocument, + Base64.getEncoder().encodeToString(sigGenerator.sign()), + 0, + identityDocument.providerUniqueId.asString(), + "dnssuffix", + "service", + "localhost/zts", + 1)); return new StringEntity(mapper.writeValueAsString(instanceConfirmation)); } catch (JsonProcessingException | NoSuchAlgorithmException |