use of org.candlepin.model.Owner 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.model.Owner in project candlepin by candlepin.
the class ImporterTest method testRecordImportIgnoresUpstreamConsumerIfNotSetOnOwner.
@Test
public void testRecordImportIgnoresUpstreamConsumerIfNotSetOnOwner() {
String expectedOwnerKey = "TEST_OWNER";
Owner owner = new Owner(expectedOwnerKey);
EventSink eventSinkMock = mock(EventSink.class);
ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
Map<String, Object> data = new HashMap<>();
data.put("meta", meta);
data.put("subscriptions", new ArrayList<Subscription>());
ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
assertNull(record.getUpstreamConsumer());
verify(importRecordCurator).create(eq(record));
}
use of org.candlepin.model.Owner 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.model.Owner in project candlepin by candlepin.
the class ImporterTest method testRecordImportSuccess.
@Test
public void testRecordImportSuccess() {
String expectedOwnerKey = "TEST_OWNER";
Owner owner = new Owner(expectedOwnerKey);
EventSink eventSinkMock = mock(EventSink.class);
ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
List<Subscription> subscriptions = new ArrayList<>();
Subscription subscription = new Subscription();
subscriptions.add(subscription);
Map<String, Object> data = new HashMap<>();
data.put("meta", meta);
data.put("subscriptions", subscriptions);
ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
assertEquals(meta.getPrincipalName(), record.getGeneratedBy());
assertEquals(meta.getCreated(), record.getGeneratedDate());
assertEquals(ImportRecord.Status.SUCCESS, record.getStatus());
assertEquals(owner.getKey() + " file imported successfully.", record.getStatusMessage());
assertEquals("test.zip", record.getFileName());
verify(importRecordCurator).create(eq(record));
verify(eventSinkMock, never()).emitSubscriptionExpired(subscription);
}
use of org.candlepin.model.Owner in project candlepin by candlepin.
the class ImporterTest method testImportZipArchiveNoContent.
@Test
public void testImportZipArchiveNoContent() throws IOException, ImporterException {
Importer i = new Importer(null, null, null, null, null, null, null, null, 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("no_content"));
out.close();
String m = i18n.tr("The archive does not contain the required signature file");
ee.expect(ImportExtractionException.class);
ee.expectMessage(m);
i.loadExport(owner, archive, co, "original_file.zip");
}
Aggregations