Search in sources :

Example 6 with X509ExtensionWrapper

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"));
}
Also used : Product(org.candlepin.model.Product) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with X509ExtensionWrapper

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"));
}
Also used : Product(org.candlepin.model.Product) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with X509ExtensionWrapper

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"));
}
Also used : HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpectedException(org.junit.rules.ExpectedException) CertificateSizeException(org.candlepin.util.CertificateSizeException) IOException(java.io.IOException) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with X509ExtensionWrapper

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()));
}
Also used : HashMap(java.util.HashMap) Environment(org.candlepin.model.Environment) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 10 with X509ExtensionWrapper

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());
    }
}
Also used : HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpectedException(org.junit.rules.ExpectedException) CertificateSizeException(org.candlepin.util.CertificateSizeException) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

X509ExtensionWrapper (org.candlepin.pki.X509ExtensionWrapper)25 Product (org.candlepin.model.Product)13 HashSet (java.util.HashSet)12 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)12 HashMap (java.util.HashMap)8 LinkedHashSet (java.util.LinkedHashSet)8 IOException (java.io.IOException)7 CertificateSizeException (org.candlepin.util.CertificateSizeException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 GeneralSecurityException (java.security.GeneralSecurityException)6 CertificateExpiredException (java.security.cert.CertificateExpiredException)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ProductContent (org.candlepin.model.ProductContent)6 ExpectedException (org.junit.rules.ExpectedException)6 Matchers.anyMap (org.mockito.Matchers.anyMap)6 List (java.util.List)5 EnvironmentContent (org.candlepin.model.EnvironmentContent)5 X509Certificate (java.security.cert.X509Certificate)4