Search in sources :

Example 11 with Content

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));
    }
}
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 12 with Content

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;
}
Also used : Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 13 with 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());
    }
}
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)

Example 14 with Content

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));
}
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 15 with Content

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;
}
Also used : Content(org.candlepin.model.Content)

Aggregations

Content (org.candlepin.model.Content)97 Test (org.junit.Test)45 ProductContent (org.candlepin.model.ProductContent)41 Product (org.candlepin.model.Product)40 Owner (org.candlepin.model.Owner)39 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)25 HashMap (java.util.HashMap)18 EnvironmentContent (org.candlepin.model.EnvironmentContent)17 HashSet (java.util.HashSet)14 LinkedList (java.util.LinkedList)11 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)10 ArrayList (java.util.ArrayList)9 Matchers.anyString (org.mockito.Matchers.anyString)9 Transactional (com.google.inject.persist.Transactional)8 Produces (javax.ws.rs.Produces)8 Parameters (junitparams.Parameters)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)7 Path (javax.ws.rs.Path)6 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)6