use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class DefaultIdentityCertServiceAdapterTest method testRegenerateCallsDeletes.
@Test
public void testRegenerateCallsDeletes() throws GeneralSecurityException, IOException {
Consumer consumer = mock(Consumer.class);
IdentityCertificate mockic = mock(IdentityCertificate.class);
when(consumer.getIdCert()).thenReturn(mockic);
when(mockic.getId()).thenReturn("43");
when(idcur.find(mockic.getId())).thenReturn(mockic);
KeyPair kp = createKeyPair();
when(kpc.getConsumerKeyPair(consumer)).thenReturn(kp);
when(csc.create(any(CertificateSerial.class))).thenAnswer(new Answer<CertificateSerial>() {
public CertificateSerial answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
CertificateSerial cs = (CertificateSerial) args[0];
cs.setId(42L);
return cs;
}
});
when(pki.getPemEncoded(any(X509Certificate.class))).thenReturn("x509cert".getBytes());
when(pki.getPemEncoded(any(PrivateKey.class))).thenReturn("priv".getBytes());
when(idcur.create(any(IdentityCertificate.class))).thenAnswer(new Answer<IdentityCertificate>() {
public IdentityCertificate answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
IdentityCertificate ic = (IdentityCertificate) args[0];
ic.setId("42");
return ic;
}
});
IdentityCertificate ic = dicsa.regenerateIdentityCert(consumer);
verify(consumer).setIdCert(null);
verify(idcur).delete(mockic);
assertNotSame(ic, mockic);
assertEquals("priv", ic.getKey());
assertEquals("x509cert", ic.getCert());
assertNotNull(ic.getCertAsBytes());
assertNotNull(ic.getKeyAsBytes());
verify(consumer).setIdCert(ic);
verify(csc).create(any(CertificateSerial.class));
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class DefaultIdentityCertServiceAdapterTest method testRegenerate.
@Test
public void testRegenerate() throws GeneralSecurityException, IOException {
Consumer consumer = mock(Consumer.class);
when(consumer.getId()).thenReturn("42L");
when(consumer.getUuid()).thenReturn(Util.generateUUID());
when(idcur.find(consumer.getId())).thenReturn(null);
KeyPair kp = createKeyPair();
when(kpc.getConsumerKeyPair(consumer)).thenReturn(kp);
when(csc.create(any(CertificateSerial.class))).thenAnswer(new Answer<CertificateSerial>() {
public CertificateSerial answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
CertificateSerial cs = (CertificateSerial) args[0];
cs.setId(42L);
return cs;
}
});
when(pki.getPemEncoded(any(X509Certificate.class))).thenReturn("x509cert".getBytes());
when(pki.getPemEncoded(any(PrivateKey.class))).thenReturn("priv".getBytes());
when(idcur.create(any(IdentityCertificate.class))).thenAnswer(new Answer<IdentityCertificate>() {
public IdentityCertificate answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
IdentityCertificate ic = (IdentityCertificate) args[0];
ic.setId("42");
return ic;
}
});
IdentityCertificate ic = dicsa.regenerateIdentityCert(consumer);
assertNotNull(ic);
verify(consumer, never()).setIdCert(null);
verify(idcur, never()).delete(any(IdentityCertificate.class));
assertEquals("priv", ic.getKey());
assertEquals("x509cert", ic.getCert());
assertNotNull(ic.getCertAsBytes());
assertNotNull(ic.getKeyAsBytes());
verify(consumer).setIdCert(ic);
verify(csc).create(any(CertificateSerial.class));
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class EntitlementImporterTest method createEntitlementCertificate.
protected EntitlementCertificate createEntitlementCertificate(String key, String cert) {
EntitlementCertificate toReturn = new EntitlementCertificate();
CertificateSerial certSerial = new CertificateSerial(new Date());
certSerial.setCollected(true);
certSerial.setUpdated(new Date());
certSerial.setCreated(new Date());
toReturn.setKeyAsBytes(key.getBytes());
toReturn.setCertAsBytes(cert.getBytes());
toReturn.setSerial(certSerial);
return toReturn;
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class EntitlementImporterTest method fullImport.
@Test
public void fullImport() throws Exception {
Product parentProduct = TestUtil.createProduct();
Product derivedProduct = TestUtil.createProduct();
Product provided1 = TestUtil.createProduct();
Set<Product> providedProducts = new HashSet<>();
providedProducts.add(new Product(provided1));
Product derivedProvided1 = TestUtil.createProduct();
Set<Product> derivedProvidedProducts = new HashSet<>();
derivedProvidedProducts.add(new Product(derivedProvided1));
Pool pool = TestUtil.createPool(owner, parentProduct, new HashSet<>(), derivedProduct, new HashSet<>(), 3);
pool.setProvidedProducts(providedProducts);
pool.setDerivedProvidedProducts(derivedProvidedProducts);
Entitlement ent = TestUtil.createEntitlement(owner, consumer, pool, cert);
ent.setQuantity(3);
EntitlementDTO dtoEnt = this.translator.translate(ent, EntitlementDTO.class);
when(om.readValue(reader, EntitlementDTO.class)).thenReturn(dtoEnt);
// Create our expected products
Map<String, ProductDTO> productsById = buildProductCache(parentProduct, provided1, derivedProduct, derivedProvided1);
Subscription sub = importer.importObject(om, reader, owner, productsById, consumerDTO.getUuid(), meta);
assertEquals(pool.getId(), sub.getUpstreamPoolId());
assertEquals(consumer.getUuid(), sub.getUpstreamConsumerId());
assertEquals(ent.getId(), sub.getUpstreamEntitlementId());
assertEquals(owner, sub.getOwner());
assertEquals(ent.getStartDate(), sub.getStartDate());
assertEquals(ent.getEndDate(), sub.getEndDate());
assertEquals(pool.getAccountNumber(), sub.getAccountNumber());
assertEquals(pool.getContractNumber(), sub.getContractNumber());
assertEquals(pool.getOrderNumber(), sub.getOrderNumber());
assertEquals(ent.getQuantity().intValue(), sub.getQuantity().intValue());
assertEquals(parentProduct.toDTO(), sub.getProduct());
assertEquals(providedProducts.size(), sub.getProvidedProducts().size());
assertEquals(provided1.getId(), sub.getProvidedProducts().iterator().next().getId());
assertEquals(derivedProduct.toDTO(), sub.getDerivedProduct());
assertEquals(1, sub.getDerivedProvidedProducts().size());
assertEquals(derivedProvided1.getId(), sub.getDerivedProvidedProducts().iterator().next().getId());
assertNotNull(sub.getCertificate());
CertificateSerial serial = sub.getCertificate().getSerial();
assertEquals(cert.getSerial().isCollected(), serial.isCollected());
assertEquals(cert.getSerial().getExpiration(), serial.getExpiration());
assertEquals(cert.getSerial().getCreated(), serial.getCreated());
assertEquals(cert.getSerial().getUpdated(), serial.getUpdated());
assertEquals(sub.getCdn().getLabel(), meta.getCdnLabel());
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithSameUuidOnOwnerShouldDoNothing.
@Test
public void importConsumerWithSameUuidOnOwnerShouldDoNothing() throws ImporterException {
Owner owner = mock(Owner.class);
OwnerDTO ownerDTO = mock(OwnerDTO.class);
ConsumerDTO consumer = mock(ConsumerDTO.class);
ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
when(owner.getUpstreamUuid()).thenReturn("test-uuid");
when(consumer.getUuid()).thenReturn("test-uuid");
when(consumer.getOwner()).thenReturn(ownerDTO);
when(consumer.getType()).thenReturn(type);
IdentityCertificate idCert = new IdentityCertificate();
idCert.setSerial(new CertificateSerial());
importer.store(owner, consumer, new ConflictOverrides(), idCert);
// now verify that the owner didn't change
// arg.getValue() returns the Owner being stored
ArgumentCaptor<Owner> arg = ArgumentCaptor.forClass(Owner.class);
verify(curator).merge(arg.capture());
assertEquals("test-uuid", arg.getValue().getUpstreamUuid());
}
Aggregations