@@ -0,0 +1,3592 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.%0Apackage com.yahoo.vespa.model.application.validation;%0A%0Aimport com.yahoo.config.application.api.ApplicationPackage;%0Aimport com.yahoo.config.model.NullConfigModelRegistry;%0Aimport com.yahoo.config.model.api.TlsSecrets;%0Aimport com.yahoo.config.model.deploy.DeployState;%0Aimport com.yahoo.config.model.deploy.TestProperties;%0Aimport com.yahoo.config.model.test.MockApplicationPackage;%0Aimport com.yahoo.config.provision.CertificateNotReadyException;%0Aimport com.yahoo.config.provision.Environment;%0Aimport com.yahoo.config.provision.RegionName;%0Aimport com.yahoo.config.provision.Zone;%0Aimport com.yahoo.vespa.model.VespaModel;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException;%0A%0Aimport java.util.Optional;%0A%0Aimport static com.yahoo.config.model.test.TestUtil.joinLines;%0Aimport static org.junit.Assert.assertTrue;%0A%0A/**%0A * @author andreer%0A */%0Apublic class TlsSecretsValidatorTest %7B%0A    @Rule%0A    public final ExpectedException exceptionRule = ExpectedException.none();%0A%0A    private static String servicesXml() %7B%0A        return joinLines(%22%3Cservices version='1.0'%3E%22,%0A                %22  %3Ccontainer id='default' version='1.0'%3E%22,%0A                %22  %3C/container%3E%22,%0A                %22%3C/services%3E%22);%0A    %7D%0A%0A    private static String deploymentXml() %7B%0A        return joinLines(%22%3Cdeployment version='1.0' %3E%22,%0A                %22  %3Cprod /%3E%22,%0A                %22%3C/deployment%3E%22);%0A    %7D%0A%0A    @Test%0A    public void missing_certificate_fails_validation() throws Exception %7B%0A        DeployState deployState = deployState(servicesXml(), deploymentXml(), Optional.of(TlsSecrets.MISSING));%0A        VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState);%0A%0A        exceptionRule.expect(CertificateNotReadyException.class);%0A        exceptionRule.expectMessage(%22TLS enabled, but could not retrieve certificate yet%22);%0A%0A        new TlsSecretsValidator().validate(model, deployState);%0A    %7D%0A%0A    @Test%0A    public void validation_succeeds_with_certificate() throws Exception %7B%0A        DeployState deployState = deployState(servicesXml(), deploymentXml(), Optional.of(new TlsSecrets(%22cert%22, %22key%22)));%0A        VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState);%0A%0A        new TlsSecretsValidator().validate(model, deployState);%0A    %7D%0A%0A    @Test%0A    public void validation_succeeds_without_certificate() throws Exception %7B%0A        DeployState deployState = deployState(servicesXml(), deploymentXml(), Optional.empty());%0A        VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState);%0A%0A        new TlsSecretsValidator().validate(model, deployState);%0A    %7D%0A%0A    private static DeployState deployState(String servicesXml, String deploymentXml, Optional%3CTlsSecrets%3E tlsSecrets) %7B%0A        ApplicationPackage app = new MockApplicationPackage.Builder()%0A                .withServices(servicesXml)%0A                .withDeploymentSpec(deploymentXml)%0A                .build();%0A        DeployState.Builder builder = new DeployState.Builder()%0A                .applicationPackage(app)%0A                .zone(new Zone(Environment.prod, RegionName.from(%22foo%22)))%0A                .properties(%0A                        new TestProperties()%0A                                .setHostedVespa(true)%0A                                .setTlsSecrets(tlsSecrets));%0A        final DeployState deployState = builder.build();%0A%0A        assertTrue(%22Test must emulate a hosted deployment.%22, deployState.isHosted());%0A        return deployState;%0A    %7D%0A%7D%0A

test TlsSecretsValidator