Ejemplo n.º 1
0
  private void exportEntitlementsCerts(
      File baseDir, Consumer consumer, Set<Long> serials, boolean manifest) throws IOException {

    File entCertDir = new File(baseDir.getCanonicalPath(), "entitlement_certificates");
    entCertDir.mkdir();

    for (EntitlementCertificate cert : entCertAdapter.listForConsumer(consumer)) {
      if (manifest && !this.exportRules.canExport(cert.getEntitlement())) {
        if (log.isDebugEnabled()) {
          log.debug(
              "Skipping export of entitlement cert with product: {}",
              cert.getEntitlement().getPool().getProductId());
        }
        continue;
      }

      if ((serials == null) || (serials.contains(cert.getSerial().getId()))) {
        log.debug("Exporting entitlement certificate: " + cert.getSerial());
        File file = new File(entCertDir.getCanonicalPath(), cert.getSerial().getId() + ".pem");
        FileWriter writer = null;
        try {
          writer = new FileWriter(file);
          entCert.export(writer, cert);
        } finally {
          if (writer != null) {
            writer.close();
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  @Test
  public void testGetCertSerials() {
    Consumer consumer = createConsumer();
    List<EntitlementCertificate> certificates = createEntitlementCertificates();

    when(mockedEntitlementCertServiceAdapter.listForConsumer(consumer)).thenReturn(certificates);
    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockedEntitlementCurator.listByConsumer(consumer))
        .thenReturn(new ArrayList<Entitlement>());

    ConsumerResource consumerResource =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            mockedEntitlementCurator,
            null,
            mockedEntitlementCertServiceAdapter,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedPoolManager,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    List<CertificateSerialDto> serials =
        consumerResource.getEntitlementCertificateSerials(consumer.getUuid());

    verifyCertificateSerialNumbers(serials);
  }
Ejemplo n.º 3
0
  @Before
  public void init() throws Exception {
    product = TestUtil.createProduct();
    o = new Owner("key", "displayname");
    pool = TestUtil.createPool(o, product);

    when(mockConfig.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    this.productCache = new ProductCache(mockConfig, mockProductAdapter);

    this.principal = TestUtil.createOwnerPrincipal();
    this.manager =
        spy(
            new CandlepinPoolManager(
                mockPoolCurator,
                mockSubAdapter,
                productCache,
                entCertAdapterMock,
                mockEventSink,
                eventFactory,
                mockConfig,
                enforcerMock,
                poolRulesMock,
                entitlementCurator,
                consumerCuratorMock,
                certCuratorMock,
                complianceRules,
                envCurator,
                autobindRules));

    when(entCertAdapterMock.generateEntitlementCert(
            any(Entitlement.class), any(Subscription.class), any(Product.class)))
        .thenReturn(new EntitlementCertificate());

    dummyComplianceStatus = new ComplianceStatus(new Date());
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class)))
        .thenReturn(dummyComplianceStatus);
  }
Ejemplo n.º 4
0
  @Test(expected = RuntimeException.class)
  public void testExceptionFromCertGen() throws Exception {
    Consumer consumer = createConsumer();

    Entitlement e = Mockito.mock(Entitlement.class);
    Pool p = Mockito.mock(Pool.class);
    Subscription s = Mockito.mock(Subscription.class);
    when(e.getPool()).thenReturn(p);
    when(p.getSubscriptionId()).thenReturn("4444");

    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockedEntitlementCurator.find(eq("9999"))).thenReturn(e);
    when(mockedSubscriptionServiceAdapter.getSubscription(eq("4444"))).thenReturn(s);

    when(mockedEntitlementCertServiceAdapter.generateEntitlementCert(
            any(Entitlement.class), any(Product.class)))
        .thenThrow(new IOException());

    CandlepinPoolManager poolManager =
        new CandlepinPoolManager(
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            mockedEntitlementCurator,
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            mockedActivationKeyRules,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null);

    ConsumerResource consumerResource =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            mockedEntitlementCurator,
            null,
            mockedEntitlementCertServiceAdapter,
            null,
            null,
            null,
            null,
            null,
            null,
            poolManager,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.regenerateEntitlementCertificates(consumer.getUuid(), "9999", false);
  }