Search in sources :

Example 16 with Product

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()));
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) ProductContent(org.candlepin.model.ProductContent) 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) BigInteger(java.math.BigInteger) StringTokenizer(java.util.StringTokenizer) 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)

Example 17 with Product

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"));
}
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 18 with Product

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));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with Product

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"));
}
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 20 with Product

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"));
}
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)

Aggregations

Product (org.candlepin.model.Product)407 Test (org.junit.Test)281 Pool (org.candlepin.model.Pool)216 Owner (org.candlepin.model.Owner)153 Consumer (org.candlepin.model.Consumer)112 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)108 HashSet (java.util.HashSet)84 Date (java.util.Date)74 ArrayList (java.util.ArrayList)69 Entitlement (org.candlepin.model.Entitlement)67 LinkedList (java.util.LinkedList)66 HashMap (java.util.HashMap)65 Subscription (org.candlepin.model.dto.Subscription)47 Content (org.candlepin.model.Content)40 ValidationResult (org.candlepin.policy.ValidationResult)38 SourceSubscription (org.candlepin.model.SourceSubscription)36 Matchers.anyString (org.mockito.Matchers.anyString)31 List (java.util.List)29 PoolQuantity (org.candlepin.model.PoolQuantity)29 DateRange (org.candlepin.policy.js.compliance.DateRange)27