use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.
the class CommonTestStateFactory method createSslTrustCertificateState.
public static SslTrustCertificateState createSslTrustCertificateState(String pemFileName, String id) {
SslTrustCertificateState sslTrustState = new SslTrustCertificateState();
sslTrustState.documentSelfLink = id;
sslTrustState.certificate = getFileContent(pemFileName);
return sslTrustState;
}
use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.
the class SslTrustCertificateServiceUtils method loadCertificates.
static void loadCertificates(ServiceHost host, Consumer<SslTrustCertificateState> consumer) {
Query.Builder query = Query.Builder.create().addKindFieldClause(SslTrustCertificateState.class);
QueryStrategy<SslTrustCertificateState> queryLocalStates = new QueryUtils.QueryByPages<>(host, query.build(), SslTrustCertificateState.class, null, null).setMaxPageSize(QUERY_RESULT_LIMIT);
queryLocalStates.queryDocuments(c -> {
try {
host.log(Level.FINE, "Processing '%s'.", c);
SslTrustCertificateState sslTrustCert = Utils.fromJson(c, SslTrustCertificateState.class);
host.log(Level.FINE, "Certificate with '%s', issuer '%s' and alias '%s' loaded.", sslTrustCert.commonName, sslTrustCert.issuerName, sslTrustCert.getAlias());
consumer.accept(sslTrustCert);
} catch (Exception e) {
host.log(Level.WARNING, "cannot deserialize " + c);
}
});
}
use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.
the class BaseVSphereAdapterTest method setUp.
@Before
public void setUp() throws Throwable {
this.host = VerificationHost.create(Integer.getInteger(TestProperties.HOST_PREFERRED_PORT, 0));
String bindingAddress = System.getProperty(TestProperties.HOST_BINDING_ADDRESS);
if (!StringUtils.isEmpty(bindingAddress)) {
this.host.setBindAddress(bindingAddress);
}
this.host.start();
this.host.waitForServiceAvailable(ExampleService.FACTORY_LINK);
// TODO: VSYM-992 - improve test/fix arbitrary timeout
// must be at least 15min as default timeout to get an IP is 10min
this.host.setTimeoutSeconds(15 * 60);
try {
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
PhotonModelServices.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
PhotonModelSecurityServices.startServices(this.host);
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelSecurityServices.LINKS);
startAdditionalServices();
ServerX509TrustManager.create(this.host);
} catch (Throwable e) {
this.host.log("Error starting up services for the test %s", e.getMessage());
throw new Exception(e);
}
if (this.vcUrl == null) {
this.vcUrl = "http://not-configured";
} else {
X509TrustManagerResolver resolver = CertificateUtil.resolveCertificate(URI.create(this.vcUrl), 20000);
if (!resolver.isCertsTrusted()) {
SslTrustCertificateState certState = new SslTrustCertificateState();
certState.certificate = CertificateUtil.toPEMformat(resolver.getCertificate());
SslTrustCertificateState.populateCertificateProperties(certState, resolver.getCertificate());
Operation op = Operation.createPost(this.host, SslTrustCertificateService.FACTORY_LINK).setReferer(this.host.getReferer()).setBody(certState);
this.host.waitForResponse(op);
}
}
if (this.dataStoreId != null) {
this.dataStoreId = this.dataStoreId.substring(this.dataStoreId.lastIndexOf("/") + 1, this.dataStoreId.length());
}
doSetup();
}
use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.
the class SslTrustCertificateServiceTest method testIdempotentPOST.
@Test
public void testIdempotentPOST() throws Throwable {
SslTrustCertificateState sslTrustCert1 = new SslTrustCertificateState();
sslTrustCert1.certificate = this.sslTrust1;
sslTrustCert1.subscriptionLink = null;
sslTrustCert1 = doPost(sslTrustCert1, SslTrustCertificateService.FACTORY_LINK);
SslTrustCertificateState sslTrustCert2 = new SslTrustCertificateState();
sslTrustCert2.certificate = this.sslTrust1;
sslTrustCert2.subscriptionLink = "subscription-link";
sslTrustCert2 = doPost(sslTrustCert2, SslTrustCertificateService.FACTORY_LINK);
this.sslTrustCert = getDocument(SslTrustCertificateState.class, sslTrustCert1.documentSelfLink);
/* We POST two different objects without explicitly setting the documentSelfLink, but these
* objects have the same certificate. The factory will build the same documentSelfLink for
* both of these objects and the idempotent option will turn the post to a put, so we expect
* to have the subscriptionLink set after the POST */
assertEquals(sslTrustCert2.subscriptionLink, this.sslTrustCert.subscriptionLink);
validateCertProperties(this.sslTrustCert);
}
use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.
the class SslTrustCertificateServiceTest method testPATCH.
@Test
public void testPATCH() throws Throwable {
this.sslTrustCert = doPost(this.sslTrustCert, SslTrustCertificateService.FACTORY_LINK);
this.sslTrustCert.certificate = this.sslTrust2;
boolean expectedFailure = false;
URI uri = UriUtils.buildUri(this.host, this.sslTrustCert.documentSelfLink);
doOperation(this.sslTrustCert, uri, expectedFailure, Action.PATCH);
SslTrustCertificateState updatedSslTrustCert = getDocument(SslTrustCertificateState.class, this.sslTrustCert.documentSelfLink);
assertEquals(this.sslTrust2, updatedSslTrustCert.certificate);
validateCertProperties(updatedSslTrustCert);
}
Aggregations