use of com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors in project vespa by vespa-engine.
the class IdentityDocumentGeneratorTest method generates_valid_identity_document.
@Test
public void generates_valid_identity_document() throws Exception {
String hostname = "x.y.com";
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);
when(nodeRepository.getNode(eq(hostname))).thenReturn(Optional.of(n));
AutoGeneratedKeyProvider keyProvider = new AutoGeneratedKeyProvider();
String dnsSuffix = "vespa.dns.suffix";
AthenzProviderServiceConfig config = getAthenzProviderConfig("domain", "service", dnsSuffix, ZONE);
IdentityDocumentGenerator identityDocumentGenerator = new IdentityDocumentGenerator(config, nodeRepository, ZONE, keyProvider);
SignedIdentityDocument signedIdentityDocument = identityDocumentGenerator.generateSignedIdentityDocument(hostname);
// Verify attributes
assertEquals(hostname, signedIdentityDocument.identityDocument.instanceHostname);
String environment = "dev";
String region = "us-north-1";
String expectedZoneDnsSuffix = environment + "-" + region + "." + dnsSuffix;
assertEquals(expectedZoneDnsSuffix, signedIdentityDocument.dnsSuffix);
ProviderUniqueId expectedProviderUniqueId = new ProviderUniqueId("tenant", "application", environment, region, "default", "default", 0);
assertEquals(expectedProviderUniqueId, signedIdentityDocument.identityDocument.providerUniqueId);
// Validate signature
assertTrue("Message", InstanceValidator.isSignatureValid(keyProvider.getPublicKey(0), signedIdentityDocument.rawIdentityDocument, signedIdentityDocument.signature));
}
use of com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors in project vespa by vespa-engine.
the class AuthorizerTest method before.
@Before
public void before() {
NodeFlavors flavors = new MockNodeFlavors();
nodeRepository = new MockNodeRepository(new MockCurator(), flavors);
authorizer = new Authorizer(SystemName.main, nodeRepository, () -> "cfg1");
{
// Populate with nodes used in this test. Note that only nodes requiring node repository lookup are added here
Set<String> ipAddresses = new HashSet<>(Arrays.asList("127.0.0.1", "::1"));
Flavor flavor = flavors.getFlavorOrThrow("default");
List<Node> nodes = new ArrayList<>();
nodes.add(nodeRepository.createNode("host1", "host1", ipAddresses, Optional.empty(), flavor, NodeType.host));
nodes.add(nodeRepository.createNode("child1-1", "child1-1", ipAddresses, Optional.of("host1"), flavor, NodeType.tenant));
nodes.add(nodeRepository.createNode("child1-2", "child1-2", ipAddresses, Optional.of("host1"), flavor, NodeType.tenant));
nodes.add(nodeRepository.createNode("host2", "host2", ipAddresses, Optional.empty(), flavor, NodeType.host));
nodes.add(nodeRepository.createNode("child2-1", "child2-1", ipAddresses, Optional.of("host1.tld"), flavor, NodeType.tenant));
nodes.add(nodeRepository.createNode("proxy1", "proxy1", ipAddresses, Optional.empty(), flavor, NodeType.proxy));
nodes.add(nodeRepository.createNode("proxy1-host1", "proxy1-host", ipAddresses, Optional.empty(), flavor, NodeType.proxyhost));
nodeRepository.addNodes(nodes);
}
}
Aggregations