use of org.candlepin.pki.X509ExtensionWrapper 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.pki.X509ExtensionWrapper 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.pki.X509ExtensionWrapper 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"));
}
use of org.candlepin.pki.X509ExtensionWrapper in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method testContentExtentionIncludesPromotedContent.
@Test
public void testContentExtentionIncludesPromotedContent() throws CertificateSizeException {
// Environment, with promoted content:
Environment e = this.mockEnvironment(new Environment("env1", "Env 1", owner));
e.getEnvironmentContent().add(new EnvironmentContent(e, content, true));
this.consumer.setEnvironment(e);
Map<String, EnvironmentContent> promotedContent = new HashMap<>();
promotedContent.put(content.getId(), e.getEnvironmentContent().iterator().next());
Set<X509ExtensionWrapper> contentExtensions = extensionUtil.contentExtensions(product.getProductContent(), null, promotedContent, entitlement.getConsumer(), product);
Map<String, X509ExtensionWrapper> encodedContent = getEncodedContent(contentExtensions);
assertTrue(isEncodedContentValid(encodedContent));
assertTrue(encodedContent.containsKey(content.getLabel()));
}
use of org.candlepin.pki.X509ExtensionWrapper 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());
}
}
Aggregations