use of com.emc.vipr.model.keystore.TrustedCertificateChanges in project coprhd-controller by CoprHD.
the class TrustStoreTest method generalTruststoreTest.
/**
*/
public void generalTruststoreTest() {
ClientResponse response;
// test GET with a non-privileged user -should fail
response = rRootUser2.path("/vdc/truststore").get(ClientResponse.class);
Assert.assertEquals(403, response.getStatus());
// test GET with a security admin user -should succeed
response = rSys.path("/vdc/truststore").get(ClientResponse.class);
Assert.assertEquals(200, response.getStatus());
TrustedCertificates certs = response.getEntity(TrustedCertificates.class);
nExistedCert = certs.getTrustedCertificates().size();
// should have ca certificates by default
Assert.assertTrue(!certs.getTrustedCertificates().isEmpty());
TrustedCertificateChanges changes = new TrustedCertificateChanges();
List<String> add = new ArrayList<String>();
List<String> remove = new ArrayList<String>();
changes.setAdd(add);
// test PUT with a non-privileged user -should fail
response = rRootUser2.path("/vdc/truststore").put(ClientResponse.class, changes);
Assert.assertEquals(403, response.getStatus());
// test PUT with no changes - should succeed, and not cause a reboot
response = rSys.path("/vdc/truststore").put(ClientResponse.class, changes);
Assert.assertEquals(200, response.getStatus());
// test PUT with a bad format certificate in both sections, and a good certificate
// that doesn't exist in the keystore - should fail
String certStr = "this is a bad certificate";
String anotherCertStr = "this is another bad cert";
changes = new TrustedCertificateChanges();
changes.setAdd(add);
add.add(certStr);
remove.add(anotherCertStr);
remove.add(TRUSTED_CERTIFICATE);
changes.setRemove(remove);
String expectedMessage = "Truststore update had some failures. The following certificates could not be parsed: [" + certStr + ", " + anotherCertStr + "], the following certificates in the remove section were not in the truststore: [" + TRUSTED_CERTIFICATE + "]";
response = rSys.path("/vdc/truststore").put(ClientResponse.class, changes);
assertExpectedError(response, 400, ServiceCode.API_PARAMETER_INVALID, expectedMessage);
waitForClusterToBeStable();
// test PUT with adding a good cert - should succeed
changes = new TrustedCertificateChanges();
add = new ArrayList<String>();
add.add(CERTIFICATE);
changes.setAdd(add);
response = rSys.path("/vdc/truststore").put(ClientResponse.class, changes);
Assert.assertEquals(200, response.getStatus());
certs = response.getEntity(TrustedCertificates.class);
Assert.assertEquals(nExistedCert + 1, certs.getTrustedCertificates().size());
Assert.assertEquals(removeNewLines(CERTIFICATE), removeNewLines(certs.getTrustedCertificates().get(0).getCertString()));
waitForClusterToBeStable();
// test adding the same certificate, should be successful and the trusted
// certificates should be the same as before
response = rSys.path("/vdc/truststore").put(ClientResponse.class, changes);
Assert.assertEquals(200, response.getStatus());
certs = response.getEntity(TrustedCertificates.class);
Assert.assertEquals(nExistedCert + 1, certs.getTrustedCertificates().size());
Assert.assertEquals(removeNewLines(CERTIFICATE), removeNewLines(certs.getTrustedCertificates().get(0).getCertString()));
waitForClusterToBeStable();
add = new ArrayList<String>();
add.add(TRUSTED_CERTIFICATE);
changes.setAdd(add);
remove = new ArrayList<String>();
remove.add(CERTIFICATE);
changes.setRemove(remove);
// test adding and removing in the same operation should succeed, and response
// should have only newly added cert
response = rSys.path("/vdc/truststore").put(ClientResponse.class, changes);
Assert.assertEquals(200, response.getStatus());
certs = response.getEntity(TrustedCertificates.class);
Assert.assertEquals(nExistedCert + 1, certs.getTrustedCertificates().size());
// Assert.assertEquals(removeNewLines(TRUSTED_CERTIFICATE), removeNewLines(certs
// .getTrustedCertificates().get(0).getCertString()));
// test just remove- should succeed
remove = new ArrayList<String>();
remove.add(TRUSTED_CERTIFICATE);
changes.setRemove(remove);
changes.setAdd(new ArrayList<String>());
waitForClusterToBeStable();
response = rSys.path("/vdc/truststore").put(ClientResponse.class, changes);
Assert.assertEquals(200, response.getStatus());
certs = response.getEntity(TrustedCertificates.class);
Assert.assertEquals(nExistedCert, certs.getTrustedCertificates().size());
waitForClusterToBeStable();
}
use of com.emc.vipr.model.keystore.TrustedCertificateChanges in project coprhd-controller by CoprHD.
the class Certificates method delete.
@FlashException(value = "list")
public static void delete(@As(",") List<String> ids) {
TrustedCertificateChanges changes = new TrustedCertificateChanges();
changes.setRemove(ids);
api().updateTrustedCertificate(changes);
flash.success(MessagesUtils.get("certificateChanges.submittedReconfigure"));
list();
}
use of com.emc.vipr.model.keystore.TrustedCertificateChanges in project coprhd-controller by CoprHD.
the class TrustStoreTest method addResourcesCertificates.
/**
*/
private void addResourcesCertificates() {
TrustedCertificateChanges changes = new TrustedCertificateChanges();
changes.setAdd(getResourcesCertList());
ClientResponse response = rSys.path("/vdc/truststore").put(ClientResponse.class, changes);
Assert.assertEquals(200, response.getStatus());
TrustedCertificates certs = response.getEntity(TrustedCertificates.class);
// Assert.assertEquals(changes.getAdd().size(), certs.getTrustedCertificates()
// .size());
waitForClusterToBeStable();
}
use of com.emc.vipr.model.keystore.TrustedCertificateChanges in project coprhd-controller by CoprHD.
the class TrustStoreTest method removeResourcesCertificate.
/**
*/
private void removeResourcesCertificate() {
TrustedCertificateChanges changes = new TrustedCertificateChanges();
changes.setRemove(getResourcesCertList());
ClientResponse response = rSys.path("/vdc/truststore").put(ClientResponse.class, changes);
Assert.assertEquals(200, response.getStatus());
TrustedCertificates certs = response.getEntity(TrustedCertificates.class);
Assert.assertEquals(nExistedCert, certs.getTrustedCertificates().size());
waitForClusterToBeStable();
}
use of com.emc.vipr.model.keystore.TrustedCertificateChanges in project coprhd-controller by CoprHD.
the class Certificates method addCertificates.
@FlashException(value = "list")
public static void addCertificates(CertificateChangesForm certificateChanges) {
if (certificateChanges.validateAndExtractAdds("certificateChanges")) {
if (certificateChanges.hasChanges()) {
TrustedCertificateChanges changes = new TrustedCertificateChanges();
changes.setAdd(certificateChanges.adds);
api().updateTrustedCertificate(changes);
flash.success(MessagesUtils.get("certificateChanges.submittedReconfigure"));
list();
} else {
// shouldn't actually be possible.
// The save button is disabled when there are no changes.
flash.error(MessagesUtils.get("certificates.nothing"));
}
} else {
params.flash();
Validation.keep();
}
create();
}
Aggregations