Search in sources :

Example 1 with BouncyCastlePKIUtility

use of org.candlepin.pki.impl.BouncyCastlePKIUtility in project candlepin by candlepin.

the class ImporterTest method importConsumer.

@Test
public void importConsumer() throws Exception {
    PKIUtility pki = new BouncyCastlePKIUtility(null, null, null);
    OwnerCurator oc = mock(OwnerCurator.class);
    ConsumerType type = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
    type.setId("test-ctype");
    when(consumerTypeCurator.lookupByLabel(eq("candlepin"))).thenReturn(type);
    when(consumerTypeCurator.find(eq(type.getId()))).thenReturn(type);
    Importer i = new Importer(consumerTypeCurator, null, null, oc, mock(IdentityCertificateCurator.class), null, null, pki, null, null, mock(CertificateSerialCurator.class), null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    File[] upstream = createUpstreamFiles();
    Owner owner = new Owner("admin", "Admin Owner");
    ConsumerDTO consumerDTO = new ConsumerDTO();
    consumerDTO.setUuid("eb5e04bf-be27-44cf-abe3-0c0b1edd523e");
    consumerDTO.setName("mymachine");
    ConsumerTypeDTO typeDTO = new ConsumerTypeDTO();
    typeDTO.setLabel("candlepin");
    typeDTO.setManifest(true);
    consumerDTO.setType(typeDTO);
    consumerDTO.setUrlWeb("foo.example.com/subscription");
    consumerDTO.setUrlApi("/candlepin");
    consumerDTO.setContentAccessMode("access_mode");
    OwnerDTO ownerDTO = new OwnerDTO();
    ownerDTO.setKey("admin");
    ownerDTO.setDisplayName("Admin Owner");
    consumerDTO.setOwner(ownerDTO);
    File consumerfile = new File(folder.getRoot(), "consumer.json");
    mapper.writeValue(consumerfile, consumerDTO);
    ConflictOverrides forcedConflicts = mock(ConflictOverrides.class);
    when(forcedConflicts.isForced(any(Importer.Conflict.class))).thenReturn(false);
    Meta meta = new Meta("1.0", new Date(), "admin", "/candlepin/owners", null);
    i.importConsumer(owner, consumerfile, upstream, forcedConflicts, meta);
    verify(oc).merge(eq(owner));
}
Also used : Owner(org.candlepin.model.Owner) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) PKIUtility(org.candlepin.pki.PKIUtility) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) Date(java.util.Date) CertificateSerialCurator(org.candlepin.model.CertificateSerialCurator) OwnerCurator(org.candlepin.model.OwnerCurator) IdentityCertificateCurator(org.candlepin.model.IdentityCertificateCurator) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) ConsumerType(org.candlepin.model.ConsumerType) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Example 2 with BouncyCastlePKIUtility

use of org.candlepin.pki.impl.BouncyCastlePKIUtility in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method testDetachedEntitlementDataNotAddedToCertV1.

@Test
public void testDetachedEntitlementDataNotAddedToCertV1() throws Exception {
    KeyPair keyPair = new BouncyCastlePKIUtility(null, null, null).generateNewKeyPair();
    when(keyPairCurator.getConsumerKeyPair(any(Consumer.class))).thenReturn(keyPair);
    when(mockedPKI.getPemEncoded(any(X509Certificate.class))).thenReturn("".getBytes());
    when(mockedPKI.getPemEncoded(any(Key.class))).thenReturn("".getBytes());
    final CertificateSerial serial = mock(CertificateSerial.class);
    when(serial.getId()).thenReturn(1L);
    pool.setId("poolId");
    doAnswer(new Answer<Map<String, CertificateSerial>>() {

        @Override
        public Map<String, CertificateSerial> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            Map<String, CertificateSerial> map = (Map<String, CertificateSerial>) args[0];
            map.put("poolId", serial);
            return null;
        }
    }).when(serialCurator).saveOrUpdateAll(anyMap());
    EntitlementCertificate cert = certServiceAdapter.generateEntitlementCert(entitlement, product);
    assertTrue(!cert.getCert().contains("ENTITLEMENT DATA"));
}
Also used : KeyPair(java.security.KeyPair) PEMKeyPair(org.bouncycastle.openssl.PEMKeyPair) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Matchers.anyString(org.mockito.Matchers.anyString) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) X509Certificate(java.security.cert.X509Certificate) Consumer(org.candlepin.model.Consumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Key(java.security.Key) Test(org.junit.Test)

Aggregations

BouncyCastlePKIUtility (org.candlepin.pki.impl.BouncyCastlePKIUtility)2 Test (org.junit.Test)2 File (java.io.File)1 Key (java.security.Key)1 KeyPair (java.security.KeyPair)1 X509Certificate (java.security.cert.X509Certificate)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PEMKeyPair (org.bouncycastle.openssl.PEMKeyPair)1 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)1 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)1 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)1 CertificateSerial (org.candlepin.model.CertificateSerial)1 CertificateSerialCurator (org.candlepin.model.CertificateSerialCurator)1 Consumer (org.candlepin.model.Consumer)1 ConsumerType (org.candlepin.model.ConsumerType)1 EntitlementCertificate (org.candlepin.model.EntitlementCertificate)1 IdentityCertificateCurator (org.candlepin.model.IdentityCertificateCurator)1 Owner (org.candlepin.model.Owner)1