Search in sources :

Example 6 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method tooManyContentSetsAcrossMultipleProducts.

@Test(expected = CertificateSizeException.class)
public void tooManyContentSetsAcrossMultipleProducts() throws Exception {
    Set<Product> providedProducts = new HashSet<>();
    Product pp1 = new Product("12346", "Provided 1", "variant", "version", ARCH_LABEL, "SVC");
    for (Content content : generateContent(100, "PP1")) {
        pp1.addContent(content, false);
    }
    providedProducts.add(pp1);
    Product pp2 = new Product("12347", "Provided 2", "variant", "version", ARCH_LABEL, "SVC");
    for (Content content : generateContent(100, "PP2")) {
        pp2.addContent(content, false);
    }
    providedProducts.add(pp2);
    // TODO: Is this even needed anymore?
    // subscription.setProvidedProducts(providedProducts);
    certServiceAdapter.createX509Certificate(consumer, owner, pool, entitlement, product, providedProducts, getProductModels(product, providedProducts, "prefix", entitlement), new BigInteger("1234"), keyPair, true);
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) Product(org.candlepin.model.Product) BigInteger(java.math.BigInteger) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsNoCompatibleArch.

@Test
public void testPrepareV1ExtensionsNoCompatibleArch() 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.add(wrongArchProduct);
    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);
    assertFalse(isEncodedContentValid(map));
    assertFalse(map.containsKey(CONTENT_URL));
    // make sure we don't set content type to "null"
    assertFalse(extMapHasContentType(kickstartContent, extMap, "null"));
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) 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 Content

use of org.candlepin.model.Content 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 9 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method testFilterProductContent.

@Test
public void testFilterProductContent() {
    Product modProduct = new Product("12345", "a product", "variant", "version", ARCH_LABEL, "SVC");
    // Use this set for successful providing queries:
    Set<Entitlement> successResult = new HashSet<>();
    // just need something in there
    successResult.add(new Entitlement());
    Content normalContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    // Change label to prevent an equals match:
    Content modContent = createContent(CONTENT_NAME, CONTENT_ID + "_2", "differentlabel", CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, ARCH_LABEL);
    modContent.setLabel("mod content");
    Set<String> modifiedProductIds = new HashSet<>(Arrays.asList(new String[] { "product1", "product2" }));
    modContent.setModifiedProductIds(modifiedProductIds);
    modProduct.addContent(normalContent, false);
    modProduct.addContent(modContent, false);
    // First check that if we have no entitlements providing the modified
    // products,
    // the content set is filtered out:
    // Mod content should get filtered out because we have no ents providing
    // the product it modifies:
    assertEquals(1, extensionUtil.filterProductContent(modProduct, consumer, new HashMap<>(), false, new HashSet<>()).size());
    // Now mock that we have an entitlement providing one of the modified
    // products,
    // and we should see both content sets included in the cert:
    Set<String> entitledProdIds = new HashSet<>();
    entitledProdIds.add("product2");
    assertEquals(2, extensionUtil.filterProductContent(modProduct, consumer, new HashMap<>(), false, entitledProdIds).size());
    // Make sure that we filter by environment when asked.
    Environment environment = this.mockEnvironment(new Environment());
    consumer.setEnvironment(environment);
    Map<String, EnvironmentContent> promotedContent = new HashMap<>();
    promotedContent.put(normalContent.getId(), new EnvironmentContent(environment, normalContent, true));
    assertEquals(1, extensionUtil.filterProductContent(modProduct, consumer, promotedContent, true, entitledProdIds).size());
}
Also used : HashMap(java.util.HashMap) Product(org.candlepin.model.Product) EnvironmentContent(org.candlepin.model.EnvironmentContent) Matchers.anyString(org.mockito.Matchers.anyString) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) Environment(org.candlepin.model.Environment) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method tooManyContentSets.

@Test(expected = CertificateSizeException.class)
public void tooManyContentSets() throws Exception {
    Set<Content> productContent = generateContent(X509ExtensionUtil.V1_CONTENT_LIMIT + 1, "TestContent");
    product.setProductContent(null);
    for (Content content : productContent) {
        product.addContent(content, false);
    }
    certServiceAdapter.createX509Certificate(consumer, owner, pool, entitlement, product, new HashSet<>(), getProductModels(product, new HashSet<>(), "prefix", entitlement), new BigInteger("1234"), keyPair, true);
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) BigInteger(java.math.BigInteger) HashSet(java.util.HashSet) Test(org.junit.Test)

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