use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV3EntitlementData.
@Test
public void testPrepareV3EntitlementData() throws IOException, GeneralSecurityException {
Set<Product> products = new HashSet<>();
products.add(product);
consumer.setFact("system.certificate_version", "3.3");
consumer.setFact("uname.machine", "x86_64");
Product product = pool.getProduct();
product.setAttribute(Product.Attributes.WARNING_PERIOD, "20");
product.setAttribute(Product.Attributes.SOCKETS, "4");
product.setAttribute(Product.Attributes.RAM, "8");
product.setAttribute(Product.Attributes.CORES, "4");
product.setAttribute(Product.Attributes.MANAGEMENT_ENABLED, "true");
product.setAttribute(Product.Attributes.STACKING_ID, "45678");
pool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
product.setAttribute(Product.Attributes.SUPPORT_LEVEL, "slevel");
product.setAttribute(Product.Attributes.SUPPORT_TYPE, "stype");
pool.setAccountNumber("account1");
pool.setContractNumber("contract1");
pool.setOrderNumber("order1");
for (ProductContent pc : product.getProductContent()) {
pc.setEnabled(false);
}
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");
assertEquals(data.get("quantity"), 10);
Map<String, Object> subs = (Map<String, Object>) data.get("subscription");
assertEquals(subs.get("sku"), subscription.getProduct().getId());
assertEquals(subs.get("name"), subscription.getProduct().getName());
assertEquals(subs.get("warning"), 20);
assertEquals(subs.get("sockets"), 4);
assertEquals(subs.get("ram"), 8);
assertEquals(subs.get("cores"), 4);
assertTrue((Boolean) subs.get("management"));
assertEquals(subs.get("stacking_id"), "45678");
assertTrue((Boolean) subs.get("virt_only"));
Map<String, Object> service = (Map<String, Object>) subs.get("service");
assertEquals(service.get("level"), "slevel");
assertEquals(service.get("type"), "stype");
Map<String, Object> order = (Map<String, Object>) data.get("order");
assertEquals(order.get("number"), pool.getOrderNumber());
assertTrue(((Integer) order.get("quantity")).intValue() == subscription.getQuantity());
assertNotNull(order.get("start"));
assertNotNull(order.get("end"));
// assertEquals(order.get("contract"), subscription.getContractNumber());
// assertEquals(order.get("account"), subscription.getAccountNumber());
List<Map<String, Object>> prods = (List<Map<String, Object>>) data.get("products");
List<Map<String, Object>> contents = null;
for (Map<String, Object> prod : prods) {
assertEquals(prod.get("id"), product.getId());
assertEquals(prod.get("name"), product.getName());
assertEquals(prod.get("version"), product.getAttributeValue(Product.Attributes.VERSION));
String arch = product.hasAttribute(Product.Attributes.ARCHITECTURE) ? product.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");
for (Map<String, Object> cont : contents) {
assertEquals(cont.get("id"), CONTENT_ID);
assertEquals(cont.get("name"), CONTENT_NAME);
assertEquals(cont.get("type"), CONTENT_TYPE);
assertEquals(cont.get("label"), CONTENT_LABEL);
assertEquals(cont.get("vendor"), CONTENT_VENDOR);
assertEquals(cont.get("gpg_url"), CONTENT_GPG_URL);
assertEquals(cont.get("path"), "prefix" + CONTENT_URL);
assertFalse((Boolean) cont.get("enabled"));
assertEquals(cont.get("metadata_expire"), 3200);
List<String> arches = new ArrayList<>();
arches.add(ARCH_LABEL);
assertEquals(cont.get("arches"), arches);
String rTags = content.getRequiredTags();
st = new StringTokenizer(rTags, ",");
while (st.hasMoreElements()) {
assertTrue(((List) cont.get("required_tags")).contains(st.nextElement()));
}
}
}
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsKickstartContent.
@Test
public void testPrepareV1ExtensionsKickstartContent() throws IOException, GeneralSecurityException {
Set<Product> products = new HashSet<>();
// product with a kickstart content
Product kickstartProduct = TestUtil.createProduct("12345", "a product");
kickstartProduct.setAttribute(Product.Attributes.VERSION, "version");
kickstartProduct.setAttribute(Product.Attributes.VARIANT, "variant");
kickstartProduct.setAttribute(Product.Attributes.TYPE, "SVC");
kickstartProduct.setAttribute(Product.Attributes.ARCHITECTURE, "ALL");
kickstartProduct.addContent(kickstartContent, false);
products.add(kickstartProduct);
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);
assertTrue(isEncodedContentValid(map));
assertTrue(map.containsKey(CONTENT_TYPE_KICKSTART));
assertTrue(map.containsKey(CONTENT_URL));
assertFalse(extMapHasContentType(kickstartContent, extMap, "1"));
assertFalse(extMapHasContentType(kickstartContent, extMap, "2"));
assertTrue(extMapHasContentType(kickstartContent, extMap, "3"));
// make sure we don't set content type to "null"
assertFalse(extMapHasContentType(kickstartContent, extMap, "null"));
}
use of org.candlepin.model.Product 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.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsFileContent.
@Test
public void testPrepareV1ExtensionsFileContent() throws IOException, GeneralSecurityException {
Set<Product> products = new HashSet<>();
// product with a kickstart content
Product fileProduct = TestUtil.createProduct("12345", "a product");
fileProduct.setAttribute(Product.Attributes.VERSION, "version");
fileProduct.setAttribute(Product.Attributes.VARIANT, "variant");
fileProduct.setAttribute(Product.Attributes.TYPE, "SVC");
fileProduct.setAttribute(Product.Attributes.ARCHITECTURE, "ALL");
fileProduct.addContent(fileContent, false);
products.clear();
products.add(fileProduct);
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);
assertTrue(isEncodedContentValid(map));
assertTrue(map.containsKey(CONTENT_TYPE_FILE));
assertTrue(map.containsKey(CONTENT_URL));
assertFalse(extMapHasContentType(fileContent, extMap, "1"));
assertTrue(extMapHasContentType(fileContent, extMap, "2"));
assertFalse(extMapHasContentType(fileContent, extMap, "3"));
// make sure we don't set content type to "null"
assertFalse(extMapHasContentType(fileContent, extMap, "null"));
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testPrepareV3EntitlementDataForBooleans.
@Test
public void testPrepareV3EntitlementDataForBooleans() throws IOException {
Set<Product> products = new HashSet<>();
products.add(product);
consumer.setUuid("test-consumer");
consumer.setFact("system.certificate_version", "3.3");
consumer.setFact("uname.machine", "x86_64");
pool.getProduct().setAttribute(Product.Attributes.MANAGEMENT_ENABLED, "1");
entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
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");
assertTrue((Boolean) subs.get("management"));
assertTrue((Boolean) subs.get("virt_only"));
}
Aggregations