Ejemplo n.º 1
0
  // NOTE: This scenario should NEVER happen since listByConsumerAndDate should
  //       never return dates before the specified date. This test exists to
  //       test the guard clauses in the ComplianceRulesHelper in case it ever happened.
  @Test
  public void expiredEntitlementIsIgnoredWhenCalculatingCompliantUntilDate() {
    Consumer consumer = mockConsumer(new String[] {PRODUCT_1});

    Date start = TestUtil.createDate(2005, 6, 12);

    Entitlement expired =
        mockEntitlement(
            consumer,
            "Provides Product 1 past Ent3",
            TestUtil.createDate(2005, 5, 20),
            TestUtil.createDate(2005, 6, 2),
            PRODUCT_1);

    Entitlement ent =
        mockEntitlement(
            consumer,
            "Provides Product 1 For Short Period",
            start,
            TestUtil.createDate(2005, 6, 22),
            PRODUCT_1);

    // Set up entitlements at specific dates.
    when(entCurator.listByConsumerAndDate(eq(consumer), eq(start)))
        .thenReturn(Arrays.asList(expired, ent));

    when(entCurator.listByConsumerAndDate(eq(consumer), eq(addSecond(ent.getEndDate()))))
        .thenReturn(Arrays.asList(new Entitlement[0]));

    Date expectedDate = addSecond(ent.getEndDate());
    ComplianceStatus status = compliance.getStatus(consumer, start);
    assertEquals(expectedDate, status.getCompliantUntil());
  }
Ejemplo n.º 2
0
  @Test
  public void compliantUntilDateIsDateOfFirstEntitlementToExpireCausingNonCompliant() {
    Consumer consumer = mockConsumer(new String[] {PRODUCT_1, PRODUCT_2});

    Date start = TestUtil.createDate(2005, 6, 12);

    Entitlement ent1 =
        mockEntitlement(
            consumer,
            "Provides Product 1 For Short Period",
            start,
            TestUtil.createDate(2005, 6, 22),
            PRODUCT_1);

    Entitlement ent2 =
        mockEntitlement(
            consumer,
            "Provides Product 1 past Ent3",
            TestUtil.createDate(2005, 6, 20),
            TestUtil.createDate(2005, 7, 28),
            PRODUCT_1);

    Entitlement ent3 =
        mockEntitlement(
            consumer,
            "Provides Product 2 Past Ent1",
            start,
            TestUtil.createDate(2005, 7, 18),
            PRODUCT_2);

    // Set up entitlements at specific dates.
    Date statusDate = TestUtil.createDate(2005, 6, 14);
    when(entCurator.listByConsumerAndDate(eq(consumer), eq(statusDate)))
        .thenReturn(Arrays.asList(ent1, ent3));

    when(entCurator.listByConsumerAndDate(eq(consumer), eq(addSecond(ent1.getEndDate()))))
        .thenReturn(Arrays.asList(ent2, ent3));

    when(entCurator.listByConsumerAndDate(eq(consumer), eq(addSecond(ent2.getEndDate()))))
        .thenReturn(Arrays.asList(new Entitlement[0]));

    Date expectedDate = addSecond(ent3.getEndDate());
    when(entCurator.listByConsumerAndDate(eq(consumer), eq(expectedDate)))
        .thenReturn(Arrays.asList(ent2));

    ComplianceStatus status = compliance.getStatus(consumer, statusDate);
    assertEquals(expectedDate, status.getCompliantUntil());
  }
Ejemplo n.º 3
0
 @Test
 public void listModifyingNoResults() {
   Entitlement ent = setupListModifyingEntitlement();
   List<Entitlement> results =
       entitlementCurator.listModifying(
           consumer, "notarealproduct", ent.getStartDate(), ent.getEndDate());
   assertEquals(0, results.size());
 }
Ejemplo n.º 4
0
 @Test
 public void listModifyingProvided() {
   Entitlement ent = setupListModifyingEntitlement();
   List<Entitlement> results =
       entitlementCurator.listModifying(
           consumer, providedProduct1.getId(), ent.getStartDate(), ent.getEndDate());
   assertEquals(1, results.size());
 }
Ejemplo n.º 5
0
 @Test
 public void listProvidingNoResults() {
   Entitlement ent = setupListProvidingEntitlement();
   Set<Entitlement> results =
       entitlementCurator.listProviding(
           consumer, "nosuchproductid", ent.getStartDate(), ent.getEndDate());
   assertEquals(0, results.size());
 }
Ejemplo n.º 6
0
 @Test
 public void listProvidingProvidedProduct() {
   Entitlement ent = setupListProvidingEntitlement();
   // Test a successful query:
   Set<Entitlement> results =
       entitlementCurator.listProviding(
           consumer, providedProduct1.getId(), ent.getStartDate(), ent.getEndDate());
   assertEquals(1, results.size());
 }
  private EntitlementCertificate generateEntitlementCert(
      Entitlement entitlement, Subscription sub, Product product, boolean thisIsUeberCert)
      throws GeneralSecurityException, IOException {

    log.info("Generating entitlement cert.");

    KeyPair keyPair = keyPairCurator.getConsumerKeyPair(entitlement.getConsumer());
    CertificateSerial serial = new CertificateSerial(entitlement.getEndDate());
    // We need the sequence generated id before we create the EntitlementCertificate,
    // otherwise we could have used cascading create
    serial = serialCurator.create(serial);

    Set<Product> products = new HashSet<Product>(getProvidedProducts(entitlement.getPool(), sub));

    // If creating a certificate for a distributor, we need
    // to add any derived products as well so that their content
    // is available in the upstream certificate.
    products.addAll(getDerivedProductsForDistributor(sub, entitlement));

    log.info("Creating X509 cert.");
    X509Certificate x509Cert =
        createX509Certificate(
            entitlement,
            product,
            products,
            BigInteger.valueOf(serial.getId()),
            keyPair,
            !thisIsUeberCert);

    EntitlementCertificate cert = new EntitlementCertificate();
    cert.setSerial(serial);
    cert.setKeyAsBytes(pki.getPemEncoded(keyPair.getPrivate()));

    products.add(product);
    Map<String, EnvironmentContent> promotedContent = getPromotedContent(entitlement);
    String contentPrefix = getContentPrefix(entitlement, !thisIsUeberCert);

    log.info("Getting PEM encoded cert.");
    String pem = new String(this.pki.getPemEncoded(x509Cert));

    if (shouldGenerateV3(entitlement)) {
      byte[] payloadBytes =
          v3extensionUtil.createEntitlementDataPayload(
              products, entitlement, contentPrefix, promotedContent);
      String payload = "-----BEGIN ENTITLEMENT DATA-----\n";
      payload += Util.toBase64(payloadBytes);
      payload += "-----END ENTITLEMENT DATA-----\n";

      byte[] bytes = pki.getSHA256WithRSAHash(new ByteArrayInputStream(payloadBytes));
      String signature = "-----BEGIN RSA SIGNATURE-----\n";
      signature += Util.toBase64(bytes);
      signature += "-----END RSA SIGNATURE-----\n";

      pem += payload + signature;
    }

    cert.setCert(pem);

    cert.setEntitlement(entitlement);

    if (log.isDebugEnabled()) {
      log.debug("Generated cert serial number: " + serial.getId());
      log.debug("Key: " + cert.getKey());
      log.debug("Cert: " + cert.getCert());
    }

    log.info("Persisting cert.");
    entitlement.getCertificates().add(cert);
    entCertCurator.create(cert);
    return cert;
  }