use of org.candlepin.model.Content in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method tooManyContentSetsAcrossMultipleProducts.
@Test(expected = CertificateSizeException.class)
public void tooManyContentSetsAcrossMultipleProducts() throws Exception {
Set<Product> providedProducts = new HashSet<>();
Product pp1 = new Product("12346", "Provided 1", "variant", "version", ARCH_LABEL, "SVC");
for (Content content : generateContent(100, "PP1")) {
pp1.addContent(content, false);
}
providedProducts.add(pp1);
Product pp2 = new Product("12347", "Provided 2", "variant", "version", ARCH_LABEL, "SVC");
for (Content content : generateContent(100, "PP2")) {
pp2.addContent(content, false);
}
providedProducts.add(pp2);
// TODO: Is this even needed anymore?
// subscription.setProvidedProducts(providedProducts);
certServiceAdapter.createX509Certificate(consumer, owner, pool, entitlement, product, providedProducts, getProductModels(product, providedProducts, "prefix", entitlement), new BigInteger("1234"), keyPair, true);
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsNoCompatibleArch.
@Test
public void testPrepareV1ExtensionsNoCompatibleArch() throws IOException, GeneralSecurityException {
Set<Product> products = new HashSet<>();
// product with no compatible content, but marked as 'ALL' arch
Product wrongArchProduct = TestUtil.createProduct("12345", "a product");
wrongArchProduct.setAttribute(Product.Attributes.VERSION, "version");
wrongArchProduct.setAttribute(Product.Attributes.VARIANT, "variant");
wrongArchProduct.setAttribute(Product.Attributes.TYPE, "SVC");
wrongArchProduct.setAttribute(Product.Attributes.ARCHITECTURE, "ALL");
// no x86_64, ie ARCH_LABEL
String wrongArches = "s390x,s390,ppc64,ia64";
Content wrongArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, wrongArches);
wrongArchProduct.addContent(wrongArchContent, false);
products.add(wrongArchProduct);
setupEntitlements(ARCH_LABEL, "1.0");
Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null);
Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions);
Map<String, String> extMap = getEncodedContentMap(extensions);
assertFalse(isEncodedContentValid(map));
assertFalse(map.containsKey(CONTENT_URL));
// make sure we don't set content type to "null"
assertFalse(extMapHasContentType(kickstartContent, extMap, "null"));
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testContentExtension.
@Test
public void testContentExtension() throws IOException {
Set<Product> products = new HashSet<>();
products.add(product);
product.setProductContent(null);
for (Content content : superContent) {
product.addContent(content, false);
}
consumer.setFact("system.certificate_version", "3.3");
consumer.setFact("uname.machine", "x86_64");
Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions(product, getProductModels(product, products, "prefix", entitlement), "prefix", null);
Map<String, X509ByteExtensionWrapper> byteMap = new HashMap<>();
for (X509ByteExtensionWrapper ext : byteExtensions) {
byteMap.put(ext.getOid(), ext);
}
assertTrue(byteMap.containsKey("1.3.6.1.4.1.2312.9.7"));
List<String> contentSetList = new ArrayList<>();
try {
contentSetList = v3extensionUtil.hydrateContentPackage(byteMap.get("1.3.6.1.4.1.2312.9.7").getValue());
} catch (Exception e) {
throw new RuntimeException(e);
}
assertEquals(7, contentSetList.size());
for (String url : testUrls) {
assertTrue(contentSetList.contains("/prefix" + url));
}
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testFilterProductContent.
@Test
public void testFilterProductContent() {
Product modProduct = new Product("12345", "a product", "variant", "version", ARCH_LABEL, "SVC");
// Use this set for successful providing queries:
Set<Entitlement> successResult = new HashSet<>();
// just need something in there
successResult.add(new Entitlement());
Content normalContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
// Change label to prevent an equals match:
Content modContent = createContent(CONTENT_NAME, CONTENT_ID + "_2", "differentlabel", CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
modContent.setLabel("mod content");
Set<String> modifiedProductIds = new HashSet<>(Arrays.asList(new String[] { "product1", "product2" }));
modContent.setModifiedProductIds(modifiedProductIds);
modProduct.addContent(normalContent, false);
modProduct.addContent(modContent, false);
// First check that if we have no entitlements providing the modified
// products,
// the content set is filtered out:
// Mod content should get filtered out because we have no ents providing
// the product it modifies:
assertEquals(1, extensionUtil.filterProductContent(modProduct, consumer, new HashMap<>(), false, new HashSet<>()).size());
// Now mock that we have an entitlement providing one of the modified
// products,
// and we should see both content sets included in the cert:
Set<String> entitledProdIds = new HashSet<>();
entitledProdIds.add("product2");
assertEquals(2, extensionUtil.filterProductContent(modProduct, consumer, new HashMap<>(), false, entitledProdIds).size());
// Make sure that we filter by environment when asked.
Environment environment = this.mockEnvironment(new Environment());
consumer.setEnvironment(environment);
Map<String, EnvironmentContent> promotedContent = new HashMap<>();
promotedContent.put(normalContent.getId(), new EnvironmentContent(environment, normalContent, true));
assertEquals(1, extensionUtil.filterProductContent(modProduct, consumer, promotedContent, true, entitledProdIds).size());
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method tooManyContentSets.
@Test(expected = CertificateSizeException.class)
public void tooManyContentSets() throws Exception {
Set<Content> productContent = generateContent(X509ExtensionUtil.V1_CONTENT_LIMIT + 1, "TestContent");
product.setProductContent(null);
for (Content content : productContent) {
product.addContent(content, false);
}
certServiceAdapter.createX509Certificate(consumer, owner, pool, entitlement, product, new HashSet<>(), getProductModels(product, new HashSet<>(), "prefix", entitlement), new BigInteger("1234"), keyPair, true);
}
Aggregations