Search in sources :

Example 41 with Owner

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));
}
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 42 with 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));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 43 with Owner

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");
}
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 44 with Owner

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);
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 45 with Owner

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");
}
Also used : Owner(org.candlepin.model.Owner) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Owner (org.candlepin.model.Owner)405 Test (org.junit.Test)254 Product (org.candlepin.model.Product)153 Consumer (org.candlepin.model.Consumer)127 Pool (org.candlepin.model.Pool)79 Date (java.util.Date)72 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)71 ArrayList (java.util.ArrayList)58 Produces (javax.ws.rs.Produces)52 ConsumerType (org.candlepin.model.ConsumerType)52 ApiOperation (io.swagger.annotations.ApiOperation)50 HashSet (java.util.HashSet)44 Entitlement (org.candlepin.model.Entitlement)44 Path (javax.ws.rs.Path)42 HashMap (java.util.HashMap)41 ApiResponses (io.swagger.annotations.ApiResponses)40 Content (org.candlepin.model.Content)39 BadRequestException (org.candlepin.common.exceptions.BadRequestException)37 Subscription (org.candlepin.model.dto.Subscription)32 List (java.util.List)29