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));
}
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");
}
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");
}
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");
}
Aggregations