use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class ExporterTest method exportIdentityCertificate.
@Test
public void exportIdentityCertificate() throws Exception {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
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);
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);
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);
// 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);
// VERIFY
assertNotNull(export);
assertTrue(export.exists());
verifyContent(export, "export/upstream_consumer/10.pem", new VerifyIdentityCert("10.pem"));
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class DatabaseTestFixture method createEntitlementCertificate.
protected EntitlementCertificate createEntitlementCertificate(String key, String cert) {
EntitlementCertificate toReturn = new EntitlementCertificate();
CertificateSerial certSerial = new CertificateSerial(new Date());
certSerialCurator.create(certSerial);
toReturn.setKeyAsBytes(key.getBytes());
toReturn.setCertAsBytes(cert.getBytes());
toReturn.setSerial(certSerial);
return toReturn;
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class PoolTranslatorTest method initSourceObject.
@Override
protected Pool initSourceObject() {
Pool source = new Pool();
source.setId("pool-id");
source.setOwner(this.ownerTranslatorTest.initSourceObject());
source.setProduct(this.productTranslatorTest.initSourceObject());
source.setDerivedProduct(this.productTranslatorTest.initSourceObject());
Set<Branding> brandingSet = new HashSet<>();
brandingSet.add(this.brandingTranslatorTest.initSourceObject());
source.setBranding(brandingSet);
Entitlement entitlement = new Entitlement();
entitlement.setId("ent-id");
source.setSourceEntitlement(entitlement);
SubscriptionsCertificate subCert = new SubscriptionsCertificate();
subCert.setId("cert-id");
subCert.setKey("cert-key");
subCert.setCert("cert-cert");
subCert.setSerial(new CertificateSerial());
source.setCertificate(subCert);
SourceSubscription sourceSubscription = new SourceSubscription();
sourceSubscription.setId("source-sub-id-1");
sourceSubscription.setSubscriptionId("source-sub-subscription-id-1");
sourceSubscription.setSubscriptionSubKey("source-sub-subscription-sub-key-1");
source.setSourceSubscription(sourceSubscription);
source.setActiveSubscription(true);
source.setCreatedByShare(false);
source.setHasSharedAncestor(true);
source.setQuantity(1L);
source.setStartDate(new Date());
source.setEndDate(new Date());
Map<String, String> attributes = new HashMap<>();
attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
source.setAttributes(attributes);
source.setRestrictedToUsername("restricted-to-username-value");
source.setContractNumber("333");
source.setAccountNumber("444");
source.setOrderNumber("555");
source.setConsumed(6L);
source.setExported(7L);
source.setShared(8L);
Map<String, String> calculatedAttributes = new HashMap<>();
calculatedAttributes.put("calc-attribute-key-3", "calc-attribute-value-3");
calculatedAttributes.put("calc-attribute-key-4", "calc-attribute-value-4");
source.setCalculatedAttributes(calculatedAttributes);
source.setUpstreamPoolId("upstream-pool-id-2");
source.setUpstreamEntitlementId("upstream-entitlement-id-2");
source.setUpstreamConsumerId("upstream-consumer-id-2");
source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
Product derivedProduct = new Product();
derivedProduct.setId("derived-product-id-2");
derivedProduct.setName("derived-product-name-2");
derivedProduct.setAttributes(new HashMap<>());
derivedProduct.setAttribute(Product.Attributes.ARCHITECTURE, "POWER");
derivedProduct.setAttribute(Product.Attributes.STACKING_ID, "2221");
source.setDerivedProduct(derivedProduct);
ProvidedProduct providedProd = new ProvidedProduct();
providedProd.setProductId("provided-product-id-1");
providedProd.setProductName("provided-product-name-1");
Set<ProvidedProduct> providedProducts = new HashSet<>();
providedProducts.add(providedProd);
source.setProvidedProductDtos(providedProducts);
ProvidedProduct derivedProvidedProd = new ProvidedProduct();
derivedProvidedProd.setProductId("derived-provided-product-id-1");
derivedProvidedProd.setProductName("derived-provided-product-name-1");
Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
derivedProvidedProducts.add(derivedProvidedProd);
source.setDerivedProvidedProductDtos(derivedProvidedProducts);
Consumer sourceConsumer = new Consumer();
sourceConsumer.setUuid("source-consumer-uuid");
SourceStack sourceStack = new SourceStack();
sourceStack.setSourceStackId("source-stack-source-stack-id-1");
sourceStack.setId("source-stack-id-1");
sourceStack.setSourceConsumer(sourceConsumer);
source.setSourceStack(sourceStack);
return source;
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class CertificateSerialTranslatorTest method initSourceObject.
@Override
protected CertificateSerial initSourceObject() {
CertificateSerial source = new CertificateSerial();
// ID is automatically generated for this object
// ID is also used as the serial here
source.setExpiration(new Date());
source.setCollected(true);
source.setRevoked(true);
return source;
}
use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.
the class PoolTranslatorTest method initSourceObject.
@Override
protected Pool initSourceObject() {
Pool source = new Pool();
source.setId("pool-id");
source.setOwner(this.ownerTranslatorTest.initSourceObject());
source.setProduct(this.productTranslatorTest.initSourceObject());
source.setDerivedProduct(this.productTranslatorTest.initSourceObject());
Set<Branding> brandingSet = new HashSet<>();
brandingSet.add(this.brandingTranslatorTest.initSourceObject());
source.setBranding(brandingSet);
Entitlement entitlement = new Entitlement();
entitlement.setId("ent-id");
source.setSourceEntitlement(entitlement);
SubscriptionsCertificate subCert = new SubscriptionsCertificate();
subCert.setId("cert-id");
subCert.setKey("cert-key");
subCert.setCert("cert-cert");
subCert.setSerial(new CertificateSerial());
source.setCertificate(subCert);
SourceSubscription sourceSubscription = new SourceSubscription();
sourceSubscription.setId("source-sub-id-1");
sourceSubscription.setSubscriptionId("source-sub-subscription-id-1");
sourceSubscription.setSubscriptionSubKey("source-sub-subscription-sub-key-1");
source.setSourceSubscription(sourceSubscription);
source.setActiveSubscription(true);
source.setCreatedByShare(false);
source.setHasSharedAncestor(true);
source.setQuantity(1L);
source.setStartDate(new Date());
source.setEndDate(new Date());
Map<String, String> attributes = new HashMap<>();
attributes.put(Pool.Attributes.SOURCE_POOL_ID, "true");
source.setAttributes(attributes);
source.setRestrictedToUsername("restricted-to-username-value");
source.setContractNumber("333");
source.setAccountNumber("444");
source.setOrderNumber("555");
source.setConsumed(6L);
source.setExported(7L);
source.setShared(8L);
Map<String, String> calculatedAttributes = new HashMap<>();
calculatedAttributes.put("calc-attribute-key-3", "calc-attribute-value-3");
calculatedAttributes.put("calc-attribute-key-4", "calc-attribute-value-4");
source.setCalculatedAttributes(calculatedAttributes);
source.setUpstreamPoolId("upstream-pool-id-2");
source.setUpstreamEntitlementId("upstream-entitlement-id-2");
source.setUpstreamConsumerId("upstream-consumer-id-2");
source.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
ProvidedProduct providedProd = new ProvidedProduct();
providedProd.setProductId("provided-product-id-1");
providedProd.setProductName("provided-product-name-1");
Set<ProvidedProduct> providedProducts = new HashSet<>();
providedProducts.add(providedProd);
source.setProvidedProductDtos(providedProducts);
ProvidedProduct derivedProvidedProd = new ProvidedProduct();
derivedProvidedProd.setProductId("derived-provided-product-id-1");
derivedProvidedProd.setProductName("derived-provided-product-name-1");
Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
derivedProvidedProducts.add(derivedProvidedProd);
source.setDerivedProvidedProductDtos(derivedProvidedProducts);
Consumer sourceConsumer = new Consumer();
sourceConsumer.setUuid("source-consumer-uuid");
SourceStack sourceStack = new SourceStack();
sourceStack.setSourceStackId("source-stack-source-stack-id-1");
sourceStack.setId("source-stack-id-1");
sourceStack.setSourceConsumer(sourceConsumer);
source.setSourceStack(sourceStack);
return source;
}
Aggregations