use of org.candlepin.model.Content 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.Content in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method createContent.
private Content createContent(String name, String id, String label, String type, String vendor, String url, String gpgUrl, String arches) {
Owner owner = TestUtil.createOwner("Example-Corporation");
Content content = TestUtil.createContent(id, name);
content.setUuid(id + "_uuid");
content.setLabel(label);
content.setType(type);
content.setVendor(vendor);
content.setContentUrl(url);
content.setGpgUrl(gpgUrl);
content.setArches(arches);
return content;
}
use of org.candlepin.model.Content 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.Content in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testContentExtensionConsumerNoArchFact.
@Test
public void testContentExtensionConsumerNoArchFact() throws IOException {
Set<Product> products = new HashSet<>();
products.add(product);
// set of content for an incompatible arch, which should
// be in the cert, since this consumer has no arch fact therefore
// should match everything
String wrongArches = "s390";
String noArchUrl = "/some/place/nice";
Content wrongArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, noArchUrl, CONTENT_GPG_URL, wrongArches);
product.setProductContent(null);
for (Content content : superContent) {
product.addContent(content, false);
}
product.addContent(wrongArchContent, false);
consumer.setFact("system.certificate_version", "3.3");
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(8, contentSetList.size());
for (String url : testUrls) {
assertTrue(contentSetList.contains("/prefix" + url));
}
// verify our new wrong arch url is in there
assertTrue(contentSetList.contains("/prefix" + noArchUrl));
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class ProductImporterTest method addContentTo.
// Returns the Content object added
private Content addContentTo(Product product) {
Content content = TestUtil.createContent("100130", "content_name");
content.setMetadataExpire(1000L);
product.addContent(content, true);
return content;
}
Aggregations