Search in sources :

Example 6 with CertificateSerial

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));
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) Consumer(org.candlepin.model.Consumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CertificateSerial(org.candlepin.model.CertificateSerial) X509Certificate(java.security.cert.X509Certificate) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 7 with CertificateSerial

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));
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) Consumer(org.candlepin.model.Consumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CertificateSerial(org.candlepin.model.CertificateSerial) X509Certificate(java.security.cert.X509Certificate) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 8 with CertificateSerial

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;
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Date(java.util.Date)

Example 9 with CertificateSerial

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());
}
Also used : EntitlementDTO(org.candlepin.dto.manifest.v1.EntitlementDTO) Product(org.candlepin.model.Product) CertificateSerial(org.candlepin.model.CertificateSerial) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Subscription(org.candlepin.model.dto.Subscription) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with CertificateSerial

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());
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) CertificateSerial(org.candlepin.model.CertificateSerial) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Aggregations

CertificateSerial (org.candlepin.model.CertificateSerial)46 Date (java.util.Date)23 Test (org.junit.Test)21 Consumer (org.candlepin.model.Consumer)16 IdentityCertificate (org.candlepin.model.IdentityCertificate)16 Entitlement (org.candlepin.model.Entitlement)11 EntitlementCertificate (org.candlepin.model.EntitlementCertificate)11 HashSet (java.util.HashSet)9 CandlepinQuery (org.candlepin.model.CandlepinQuery)9 Owner (org.candlepin.model.Owner)9 File (java.io.File)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 KeyPair (java.security.KeyPair)7 X509Certificate (java.security.cert.X509Certificate)7 ZipInputStream (java.util.zip.ZipInputStream)7 Principal (org.candlepin.auth.Principal)7 ConsumerType (org.candlepin.model.ConsumerType)7 HashMap (java.util.HashMap)6 KeyPair (org.candlepin.model.KeyPair)6