Search in sources :

Example 1 with PKIUtility

use of org.candlepin.pki.PKIUtility 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 PKIUtility

use of org.candlepin.pki.PKIUtility in project candlepin by candlepin.

the class ImporterTest method testImportBadConsumerZip.

@Test
public void testImportBadConsumerZip() throws Exception {
    PKIUtility pki = mock(PKIUtility.class);
    Importer i = new Importer(null, null, null, null, null, null, null, pki, config, null, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    Owner owner = mock(Owner.class);
    ConflictOverrides co = mock(ConflictOverrides.class);
    // Mock a passed signature check:
    when(pki.verifySHA256WithRSAHashAgainstCACerts(any(File.class), any(byte[].class))).thenReturn(true);
    File archive = new File(folder.getRoot(), "file.zip");
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(archive));
    out.putNextEntry(new ZipEntry("signature"));
    out.write("This is the placeholder for the signature file".getBytes());
    File ceArchive = new File(folder.getRoot(), "consumer_export.zip");
    FileOutputStream fos = new FileOutputStream(ceArchive);
    fos.write("This is just a flat file".getBytes());
    fos.close();
    addFileToArchive(out, ceArchive);
    out.close();
    ee.expect(ImportExtractionException.class);
    ee.expectMessage("not a properly compressed file or is empty");
    i.loadExport(owner, archive, co, "original_file.zip");
}
Also used : Owner(org.candlepin.model.Owner) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) PKIUtility(org.candlepin.pki.PKIUtility) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Example 3 with PKIUtility

use of org.candlepin.pki.PKIUtility in project candlepin by candlepin.

the class ImporterTest method testImportBadSignature.

@Test(expected = ImportConflictException.class)
public void testImportBadSignature() throws IOException, ImporterException {
    PKIUtility pki = mock(PKIUtility.class);
    Importer i = new Importer(null, null, null, null, null, null, null, pki, config, null, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    Owner owner = mock(Owner.class);
    ConflictOverrides co = mock(ConflictOverrides.class);
    File archive = new File(folder.getRoot(), "file.zip");
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(archive));
    out.putNextEntry(new ZipEntry("signature"));
    out.write("This is the placeholder for the signature file".getBytes());
    File ceArchive = new File(folder.getRoot(), "consumer_export.zip");
    FileOutputStream fos = new FileOutputStream(ceArchive);
    fos.write("This is just a flat file".getBytes());
    fos.close();
    addFileToArchive(out, ceArchive);
    out.close();
    i.loadExport(owner, archive, co, "original_file.zip");
}
Also used : Owner(org.candlepin.model.Owner) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) PKIUtility(org.candlepin.pki.PKIUtility) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Example 4 with PKIUtility

use of org.candlepin.pki.PKIUtility in project candlepin by candlepin.

the class ImporterTest method testImportZipSigAndEmptyConsumerZip.

@Test
public void testImportZipSigAndEmptyConsumerZip() throws Exception {
    PKIUtility pki = mock(PKIUtility.class);
    Importer i = new Importer(null, null, null, null, null, null, null, pki, config, null, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    Owner owner = mock(Owner.class);
    ConflictOverrides co = mock(ConflictOverrides.class);
    // Mock a passed signature check:
    when(pki.verifySHA256WithRSAHashAgainstCACerts(any(File.class), any(byte[].class))).thenReturn(true);
    File archive = new File(folder.getRoot(), "file.zip");
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(archive));
    out.putNextEntry(new ZipEntry("signature"));
    out.write("This is the placeholder for the signature file".getBytes());
    File ceArchive = new File(folder.getRoot(), "consumer_export.zip");
    ZipOutputStream cezip = new ZipOutputStream(new FileOutputStream(ceArchive));
    cezip.putNextEntry(new ZipEntry("no_content"));
    cezip.close();
    addFileToArchive(out, ceArchive);
    out.close();
    ee.expect(ImportExtractionException.class);
    ee.expectMessage("consumer_export archive has no contents");
    i.loadExport(owner, archive, co, "original_file.zip");
}
Also used : Owner(org.candlepin.model.Owner) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) PKIUtility(org.candlepin.pki.PKIUtility) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)4 Owner (org.candlepin.model.Owner)4 PKIUtility (org.candlepin.pki.PKIUtility)4 BouncyCastlePKIUtility (org.candlepin.pki.impl.BouncyCastlePKIUtility)4 ImportFile (org.candlepin.sync.Importer.ImportFile)4 Test (org.junit.Test)4 FileOutputStream (java.io.FileOutputStream)3 ZipEntry (java.util.zip.ZipEntry)3 ZipOutputStream (java.util.zip.ZipOutputStream)3 Date (java.util.Date)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 CertificateSerialCurator (org.candlepin.model.CertificateSerialCurator)1 ConsumerType (org.candlepin.model.ConsumerType)1 IdentityCertificateCurator (org.candlepin.model.IdentityCertificateCurator)1 OwnerCurator (org.candlepin.model.OwnerCurator)1