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