use of org.candlepin.model.Product 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.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testContentExtensionLargeSet.
@Test
public void testContentExtensionLargeSet() throws IOException {
Set<Product> products = new HashSet<>();
Product extremeProduct = TestUtil.createProduct("12345", "a product");
extremeProduct.setAttribute(Product.Attributes.VERSION, "version");
extremeProduct.setAttribute(Product.Attributes.VARIANT, "variant");
extremeProduct.setAttribute(Product.Attributes.TYPE, "SVC");
extremeProduct.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
products.add(extremeProduct);
for (int i = 0; i < 550; i++) {
String url = "/content/dist" + i + "/jboss/source" + i;
Content content = createContent(CONTENT_NAME + i, CONTENT_ID + i, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL);
extremeProduct.addContent(content, false);
}
consumer.setUuid("test-consumer");
consumer.setFact("system.certificate_version", "3.3");
consumer.setFact("uname.machine", "x86_64");
certServiceAdapter.prepareV3Extensions();
Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions(extremeProduct, getProductModels(extremeProduct, 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(550, contentSetList.size());
for (int i = 0; i < 550; i++) {
String url = "/content/dist" + i + "/jboss/source" + i;
assertTrue(contentSetList.contains("/prefix" + url));
}
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV3EntitlementDataNoCompatibleArch.
@Test
public void testPrepareV3EntitlementDataNoCompatibleArch() 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.clear();
products.add(wrongArchProduct);
setupEntitlements(ARCH_LABEL, "3.3");
Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV3Extensions();
Map<String, X509ExtensionWrapper> map = new HashMap<>();
for (X509ExtensionWrapper ext : extensions) {
map.put(ext.getOid(), ext);
}
assertTrue(map.containsKey("1.3.6.1.4.1.2312.9.6"));
assertEquals(map.get("1.3.6.1.4.1.2312.9.6").getValue(), ("3.3"));
byte[] payload = v3extensionUtil.createEntitlementDataPayload(getProductModels(product, products, "prefix", entitlement), consumer, pool, entitlement.getQuantity());
String stringValue = "";
try {
stringValue = processPayload(payload);
} catch (Exception e) {
throw new RuntimeException(e);
}
Map<String, Object> data = (Map<String, Object>) Util.fromJson(stringValue, Map.class);
List<Map<String, Object>> prods = (List<Map<String, Object>>) data.get("products");
List<Map<String, Object>> contents = null;
for (Map<String, Object> prod : prods) {
String arch = wrongArchProduct.hasAttribute(Product.Attributes.ARCHITECTURE) ? wrongArchProduct.getAttributeValue(Product.Attributes.ARCHITECTURE) : "";
StringTokenizer st = new StringTokenizer(arch, ",");
while (st.hasMoreElements()) {
assertTrue(((List) prod.get("architectures")).contains(st.nextElement()));
}
contents = (List<Map<String, Object>>) prod.get("content");
assertTrue(contents.isEmpty());
}
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV3EntitlementDataForDefaults.
@Test
public void testPrepareV3EntitlementDataForDefaults() throws IOException {
Set<Product> products = new HashSet<>();
products.add(product);
consumer.setFact("system.certificate_version", "3.3");
consumer.setFact("uname.machine", "x86_64");
subscription.getProduct().setAttribute(Product.Attributes.WARNING_PERIOD, "0");
subscription.getProduct().setAttribute(Product.Attributes.MANAGEMENT_ENABLED, "false");
entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "false");
for (ProductContent pc : product.getProductContent()) {
pc.setEnabled(true);
}
Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV3Extensions();
Map<String, X509ExtensionWrapper> map = new HashMap<>();
for (X509ExtensionWrapper ext : extensions) {
map.put(ext.getOid(), ext);
}
assertTrue(map.containsKey("1.3.6.1.4.1.2312.9.6"));
assertEquals(map.get("1.3.6.1.4.1.2312.9.6").getValue(), ("3.3"));
byte[] payload = v3extensionUtil.createEntitlementDataPayload(getProductModels(product, products, "prefix", entitlement), consumer, pool, entitlement.getQuantity());
String stringValue = "";
try {
stringValue = processPayload(payload);
} catch (Exception e) {
throw new RuntimeException(e);
}
Map<String, Object> data = (Map<String, Object>) Util.fromJson(stringValue, Map.class);
assertEquals(data.get("consumer"), "test-consumer");
// each has been set to the default and should not be populated in the cert
Map<String, Object> subs = (Map<String, Object>) data.get("subscription");
assertNull(subs.get("warning"));
assertNull(subs.get("management"));
assertNull(subs.get("virt_only"));
List<Map<String, Object>> prods = (List<Map<String, Object>>) data.get("products");
for (Map<String, Object> prod : prods) {
List<Map<String, Object>> contents = (List<Map<String, Object>>) prod.get("content");
for (Map<String, Object> cont : contents) {
assertNull(cont.get("enabled"));
}
}
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsFileUnknownContentType.
@Test
public void testPrepareV1ExtensionsFileUnknownContentType() throws IOException, GeneralSecurityException {
Set<Product> products = new HashSet<>();
// product with a kickstart content
Product unknownContentTypeProduct = TestUtil.createProduct("12345", "a product");
unknownContentTypeProduct.setAttribute(Product.Attributes.VERSION, "version");
unknownContentTypeProduct.setAttribute(Product.Attributes.VARIANT, "variant");
unknownContentTypeProduct.setAttribute(Product.Attributes.TYPE, "SVC");
unknownContentTypeProduct.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
unknownContentTypeProduct.addContent(unknownTypeContent, false);
products.clear();
products.add(unknownContentTypeProduct);
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);
// we skip content of unknown type for v1 certs
assertFalse(isEncodedContentValid(map));
assertFalse(map.containsKey(CONTENT_URL_UNKNOWN_TYPE));
assertFalse(map.containsKey(CONTENT_TYPE_UNKNOWN));
assertFalse(extMapHasContentType(unknownTypeContent, extMap, "1"));
assertFalse(extMapHasContentType(unknownTypeContent, extMap, "2"));
assertFalse(extMapHasContentType(unknownTypeContent, extMap, "3"));
// make sure we don't set content type to "null"
assertFalse(extMapHasContentType(unknownTypeContent, extMap, "null"));
}
Aggregations