Search in sources :

Example 1 with MockNodeFlavors

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));
}
Also used : MockNodeFlavors(com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors) Allocation(com.yahoo.vespa.hosted.provision.node.Allocation) Node(com.yahoo.vespa.hosted.provision.Node) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) AutoGeneratedKeyProvider(com.yahoo.vespa.hosted.athenz.instanceproviderservice.AutoGeneratedKeyProvider) AthenzProviderServiceConfig(com.yahoo.vespa.hosted.athenz.instanceproviderservice.config.AthenzProviderServiceConfig) ApplicationId(com.yahoo.config.provision.ApplicationId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with MockNodeFlavors

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);
    }
}
Also used : MockNodeFlavors(com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors) Set(java.util.Set) HashSet(java.util.HashSet) NodeFlavors(com.yahoo.config.provision.NodeFlavors) MockNodeFlavors(com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors) MockNodeRepository(com.yahoo.vespa.hosted.provision.testutils.MockNodeRepository) ArrayList(java.util.ArrayList) List(java.util.List) Flavor(com.yahoo.config.provision.Flavor) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Before(org.junit.Before)

Aggregations

MockNodeFlavors (com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors)2 HashSet (java.util.HashSet)2 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Flavor (com.yahoo.config.provision.Flavor)1 NodeFlavors (com.yahoo.config.provision.NodeFlavors)1 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)1 AutoGeneratedKeyProvider (com.yahoo.vespa.hosted.athenz.instanceproviderservice.AutoGeneratedKeyProvider)1 AthenzProviderServiceConfig (com.yahoo.vespa.hosted.athenz.instanceproviderservice.config.AthenzProviderServiceConfig)1 Node (com.yahoo.vespa.hosted.provision.Node)1 NodeRepository (com.yahoo.vespa.hosted.provision.NodeRepository)1 Allocation (com.yahoo.vespa.hosted.provision.node.Allocation)1 MockNodeRepository (com.yahoo.vespa.hosted.provision.testutils.MockNodeRepository)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Before (org.junit.Before)1 Test (org.junit.Test)1