use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithMismatchedUuidShouldNotThrowExceptionIfForced.
@Test
public void importConsumerWithMismatchedUuidShouldNotThrowExceptionIfForced() throws ImporterException {
Owner owner = mock(Owner.class);
OwnerDTO ownerDTO = mock(OwnerDTO.class);
ConsumerDTO consumer = mock(ConsumerDTO.class);
ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
when(owner.getUpstreamUuid()).thenReturn("another-test-uuid");
when(consumer.getUuid()).thenReturn("test-uuid");
when(consumer.getOwner()).thenReturn(ownerDTO);
when(consumer.getType()).thenReturn(type);
IdentityCertificate idCert = new IdentityCertificate();
idCert.setSerial(new CertificateSerial());
importer.store(owner, consumer, new ConflictOverrides(Importer.Conflict.DISTRIBUTOR_CONFLICT), idCert);
// now verify that the owner has the upstream consumer set
ArgumentCaptor<UpstreamConsumer> arg = ArgumentCaptor.forClass(UpstreamConsumer.class);
verify(owner).setUpstreamConsumer(arg.capture());
assertEquals("test-uuid", arg.getValue().getUuid());
verify(curator).merge(owner);
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class ExporterTest method exportConsumer.
@Test
public void exportConsumer() throws ExportCreationException, IOException {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
Rules mrules = mock(Rules.class);
Consumer consumer = mock(Consumer.class);
Principal principal = mock(Principal.class);
when(mrules.getRules()).thenReturn("foobar");
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(rc.getRules()).thenReturn(mrules);
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
// specific to this test
IdentityCertificate idcert = new IdentityCertificate();
idcert.setSerial(new CertificateSerial(10L, new Date()));
idcert.setKey("euh0876puhapodifbvj094");
idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
idcert.setCreated(new Date());
idcert.setUpdated(new Date());
when(consumer.getIdCert()).thenReturn(idcert);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
ctype.setId("test-ctype");
KeyPair keyPair = createKeyPair();
when(consumer.getKeyPair()).thenReturn(keyPair);
when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
when(consumer.getUuid()).thenReturn("8auuid");
when(consumer.getName()).thenReturn("consumer_name");
when(consumer.getContentAccessMode()).thenReturn("access_mode");
when(consumer.getTypeId()).thenReturn(ctype.getId());
when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
when(ctc.listAll()).thenReturn(cqmock);
CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
when(cdnc.listAll()).thenReturn(emptyIteratorMock);
// FINALLY test this badboy
Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
File export = e.getFullExport(consumer);
verifyContent(export, "export/consumer.json", new VerifyConsumer("consumer.json"));
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class ExporterTest method doNotExportDirtyEntitlements.
@Test(expected = ExportCreationException.class)
public void doNotExportDirtyEntitlements() throws Exception {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
Consumer consumer = mock(Consumer.class);
Entitlement ent = mock(Entitlement.class);
Principal principal = mock(Principal.class);
IdentityCertificate idcert = new IdentityCertificate();
List<Entitlement> entitlements = new ArrayList<>();
entitlements.add(ent);
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
when(ec.listByConsumer(consumer)).thenReturn(entitlements);
when(ent.isDirty()).thenReturn(true);
idcert.setSerial(new CertificateSerial(10L, new Date()));
idcert.setKey("euh0876puhapodifbvj094");
idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
idcert.setCreated(new Date());
idcert.setUpdated(new Date());
when(consumer.getIdCert()).thenReturn(idcert);
KeyPair keyPair = createKeyPair();
when(consumer.getKeyPair()).thenReturn(keyPair);
when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
when(ctc.listAll()).thenReturn(cqmock);
Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
e.getFullExport(consumer);
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class ExporterTest method exportDistributorVersions.
@Test
public void exportDistributorVersions() throws ExportCreationException, IOException {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
Rules mrules = mock(Rules.class);
Consumer consumer = mock(Consumer.class);
Principal principal = mock(Principal.class);
when(mrules.getRules()).thenReturn("foobar");
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(rc.getRules()).thenReturn(mrules);
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
IdentityCertificate idcert = new IdentityCertificate();
idcert.setSerial(new CertificateSerial(10L, new Date()));
idcert.setKey("euh0876puhapodifbvj094");
idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
idcert.setCreated(new Date());
idcert.setUpdated(new Date());
when(consumer.getIdCert()).thenReturn(idcert);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
ctype.setId("test-ctype");
KeyPair keyPair = createKeyPair();
when(consumer.getKeyPair()).thenReturn(keyPair);
when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
when(consumer.getUuid()).thenReturn("8auuid");
when(consumer.getName()).thenReturn("consumer_name");
when(consumer.getTypeId()).thenReturn(ctype.getId());
when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
DistributorVersion dv = new DistributorVersion("test-dist-ver");
Set<DistributorVersionCapability> dvcSet = new HashSet<>();
dvcSet.add(new DistributorVersionCapability(dv, "capability-1"));
dvcSet.add(new DistributorVersionCapability(dv, "capability-2"));
dvcSet.add(new DistributorVersionCapability(dv, "capability-3"));
dv.setCapabilities(dvcSet);
List<DistributorVersion> dvList = new ArrayList<>();
dvList.add(dv);
when(dvc.findAll()).thenReturn(dvList);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
when(ctc.listAll()).thenReturn(cqmock);
CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
when(emptyIteratorMock.iterator()).thenReturn(Arrays.asList().iterator());
when(cdnc.listAll()).thenReturn(emptyIteratorMock);
when(ctc.listAll()).thenReturn(emptyIteratorMock);
// FINALLY test this badboy
Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
File export = e.getFullExport(consumer);
verifyContent(export, "export/distributor_version/test-dist-ver.json", new VerifyDistributorVersion("test-dist-ver.json"));
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class ExporterTest method verifyExportExtension.
@Test
public void verifyExportExtension() throws Exception {
CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
when(emptyIteratorMock.iterator()).thenReturn(Arrays.asList().iterator());
when(cdnc.listAll()).thenReturn(emptyIteratorMock);
when(ctc.listAll()).thenReturn(emptyIteratorMock);
Map<String, String> extensionData = new HashMap<>();
Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
Principal principal = mock(Principal.class);
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
Consumer consumer = mock(Consumer.class);
Rules mrules = mock(Rules.class);
when(mrules.getRules()).thenReturn("foobar");
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(rc.getRules()).thenReturn(mrules);
// specific to this test
IdentityCertificate idcert = new IdentityCertificate();
idcert.setSerial(new CertificateSerial(10L, new Date()));
idcert.setKey("euh0876puhapodifbvj094");
idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
idcert.setCreated(new Date());
idcert.setUpdated(new Date());
when(consumer.getIdCert()).thenReturn(idcert);
e.getFullExport(consumer, "cdn-key", "webapp-prefix", "api-url", extensionData);
// Default implementation of the ExportExtensionAdapter does nothing so
// we only verify that the extension method was invoked.
verify(exportExtensionAdapter).extendManifest(any(File.class), eq(consumer), eq(extensionData));
}
Aggregations