DefaultEntitlementCertServiceAdapter extends BaseEntitlementCertServiceAdapter { public Set<X509ByteExtensionWrapper> prepareV3ByteExtensions(Product sku, List<org.candlepin.model.dto.Product> productModels, String contentPrefix, Map<String, EnvironmentContent> promotedContent) throws IOException { Set<X509ByteExtensionWrapper> result = v3extensionUtil.getByteExtensions(sku, productModels, contentPrefix, promotedContent); return result; } @Inject  DefaultEntitlementCertServiceAdapter(PKIUtility pki,
        X509ExtensionUtil extensionUtil,
        X509V3ExtensionUtil v3extensionUtil,
        EntitlementCertificateCurator entCertCurator,
        KeyPairCurator keyPairCurator,
        CertificateSerialCurator serialCurator,
        OwnerCurator ownerCurator,
        EntitlementCurator entCurator, I18n i18n,
        Configuration config,
        ProductCurator productCurator,
        ConsumerTypeCurator consumerTypeCurator,
        EnvironmentCurator environmentCurator); @Override EntitlementCertificate generateEntitlementCert(Entitlement entitlement, Product product); @Override Map<String, EntitlementCertificate> generateEntitlementCerts(Consumer consumer,
        Map<String, PoolQuantity> poolQuantities, Map<String, Entitlement> entitlements,
        Map<String, Product> products, boolean save); X509Certificate createX509Certificate(Consumer consumer, Owner owner, Pool pool,
        Entitlement ent, Product product, Set<Product> products,
        List<org.candlepin.model.dto.Product> productModels, BigInteger serialNumber,
        KeyPair keyPair, boolean useContentPrefix); Set<X509ExtensionWrapper> prepareV1Extensions(Set<Product> products,
        Pool pool, Consumer consumer, Integer quantity, String contentPrefix,
        Map<String, EnvironmentContent> promotedContent); Set<X509ExtensionWrapper> prepareV3Extensions(); Set<X509ByteExtensionWrapper> prepareV3ByteExtensions(Product sku,
        List<org.candlepin.model.dto.Product> productModels, String contentPrefix,
        Map<String, EnvironmentContent> promotedContent); String cleanUpPrefix(String contentPrefix); List<Long> listEntitlementSerialIds(Consumer consumer);  }
@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", X509V3ExtensionUtil.CERT_VERSION); 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; 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)); } }
@Test public void testContentExtensionConsumerNoArchFact() throws IOException { Set<Product> products = new HashSet<>(); products.add(product); 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", X509V3ExtensionUtil.CERT_VERSION); 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; 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)); } assertTrue(contentSetList.contains("/prefix" + noArchUrl)); }
@Test public void testSpecificLargeContent() throws IOException { Set<Product> products = new HashSet<>(); products.add(largeContentProduct); largeContentProduct.setProductContent(null); for (Content content : largeContent) { largeContentProduct.addContent(content, false); } consumer.setFact("system.certificate_version", X509V3ExtensionUtil.CERT_VERSION); Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions( product, getProductModels(product, products, "prefix", largeContentEntitlement), "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; try { contentSetList = v3extensionUtil.hydrateContentPackage( byteMap.get("1.3.6.1.4.1.2312.9.7").getValue()); } catch (Exception e) { throw new RuntimeException(e); } assertEquals(largeContent.size(), contentSetList.size()); for (String url : largeTestUrls) { assertTrue(contentSetList.contains("/prefix" + url)); } List<String> testList = Arrays.asList(largeTestUrls); for (String url : contentSetList) { assertTrue(testList.contains(url.substring(7))); } }
@Test public void testSingleSegmentContent() throws IOException { Set<Product> products = new HashSet<>(); products.add(largeContentProduct); largeContentProduct.setProductContent(null); largeContentProduct.addContent(createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, "/single", CONTENT_GPG_URL, ARCH_LABEL), false); consumer.setFact("system.certificate_version", X509V3ExtensionUtil.CERT_VERSION); Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions( product, getProductModels(product, products, "", largeContentEntitlement), "", 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; try { contentSetList = v3extensionUtil.hydrateContentPackage( byteMap.get("1.3.6.1.4.1.2312.9.7").getValue()); } catch (Exception e) { throw new RuntimeException(e); } assertTrue(contentSetList.contains("/single")); }