Ejemplo n.º 1
0
  @Before
  public void setUp() {
    MockitoAnnotations.initMocks(this);

    // Load the default production rules:
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    when(cacheProvider.get()).thenReturn(cache);
    provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    quantityRules = new QuantityRules(provider.get());

    owner = new Owner("Test Owner " + TestUtil.randomInt());
    product = TestUtil.createProduct();
    pool = TestUtil.createPool(owner, product);
    pool.setId("fakepoolid");

    consumer = TestUtil.createConsumer(owner);
    Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, new EntitlementCertificate());

    Set<Entitlement> entSet = new HashSet<Entitlement>();
    entSet.add(e);

    pool.setEntitlements(entSet);
    pool.getProduct().setAttribute("multi-entitlement", "yes");
    pool.getProduct().setAttribute("stacking_id", "1");
  }
Ejemplo n.º 2
0
  @Test
  public void exportConsumer() throws ExportCreationException, IOException {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
    config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
    Rules mrules = mock(Rules.class);
    Consumer consumer = mock(Consumer.class);
    Principal principal = mock(Principal.class);

    when(mrules.getRules()).thenReturn("foobar");
    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(rc.getRules()).thenReturn(mrules);
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");

    // specific to this test
    IdentityCertificate idcert = new IdentityCertificate();
    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);

    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
    when(consumer.getUuid()).thenReturn("8auuid");
    when(consumer.getName()).thenReturn("consumer_name");
    when(consumer.getType()).thenReturn(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));

    // FINALLY test this badboy
    Exporter e =
        new Exporter(
            ctc,
            me,
            ce,
            cte,
            re,
            ece,
            ecsa,
            pe,
            psa,
            pce,
            ec,
            ee,
            pki,
            config,
            exportRules,
            pprov,
            dvc,
            dve,
            cdnc,
            cdne);
    File export = e.getFullExport(consumer);

    verifyContent(export, "export/consumer.json", new VerifyConsumer("consumer.json"));
  }
Ejemplo n.º 3
0
  @Test
  public void exportIdentityCertificate() throws Exception {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    Rules mrules = mock(Rules.class);
    Consumer consumer = mock(Consumer.class);
    Principal principal = mock(Principal.class);

    when(mrules.getRules()).thenReturn("foobar");
    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(rc.getRules()).thenReturn(mrules);
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");

    // specific to this test
    IdentityCertificate idcert = new IdentityCertificate();
    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);

    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());

    // FINALLY test this badboy
    Exporter e =
        new Exporter(
            ctc,
            me,
            ce,
            cte,
            re,
            ece,
            ecsa,
            pe,
            psa,
            pce,
            ec,
            ee,
            pki,
            config,
            exportRules,
            pprov,
            dvc,
            dve,
            cdnc,
            cdne);
    File export = e.getFullExport(consumer);

    // VERIFY
    assertNotNull(export);
    assertTrue(export.exists());
    verifyContent(export, "export/upstream_consumer/10.pem", new VerifyIdentityCert("10.pem"));
  }
 @Before
 public void setUp() {
   MockitoAnnotations.initMocks(this);
   // Load the default production rules:
   InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
   Rules rules = new Rules(Util.readFile(is));
   when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
   when(rulesCuratorMock.getRules()).thenReturn(rules);
   provider = new JsRunnerProvider(rulesCuratorMock);
   poolTypeRules = new PoolComplianceTypeRules(provider.get());
 }
Ejemplo n.º 5
0
  @Before
  public void setUp() {
    MockitoAnnotations.initMocks(this);

    // Load the default production rules:
    InputStream is = this.getClass().getResourceAsStream(RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    provider = new JsRulesProvider(rulesCuratorMock);
    compliance = new ComplianceRules(provider.get(), entCurator);
    owner = new Owner("test");
  }
 @Before
 public void setupTest() {
   InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
   rulesCuratorMock = mock(RulesCurator.class);
   config = mock(Configuration.class);
   cacheProvider = mock(Provider.class);
   cache = mock(JsRunnerRequestCache.class);
   Rules rules = new Rules(Util.readFile(is));
   when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
   when(rulesCuratorMock.getRules()).thenReturn(rules);
   when(cacheProvider.get()).thenReturn(cache);
   provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
   overrideRules = new OverrideRules(provider.get(), config);
   validator = new ContentOverrideValidator(i18n, overrideRules);
 }
Ejemplo n.º 7
0
  @Test
  public void exportMetadata() throws ExportCreationException, IOException {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    Date start = new Date();
    Rules mrules = mock(Rules.class);
    Consumer consumer = mock(Consumer.class);
    Principal principal = mock(Principal.class);
    IdentityCertificate idcert = new IdentityCertificate();

    when(mrules.getRules()).thenReturn("foobar");
    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(rc.getRules()).thenReturn(mrules);
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");

    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);

    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());

    // FINALLY test this badboy
    Exporter e =
        new Exporter(
            ctc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov);
    File export = e.getFullExport(consumer);

    // VERIFY
    assertNotNull(export);
    assertTrue(export.exists());
    verifyContent(export, "export/meta.json", new VerifyMetadata(start));

    // cleanup the mess
    FileUtils.deleteDirectory(export.getParentFile());
    assertTrue(new File("/tmp/consumer_export.zip").delete());
    assertTrue(new File("/tmp/meta.json").delete());
  }
Ejemplo n.º 8
0
  @Before
  public void createEnforcer() throws Exception {
    MockitoAnnotations.initMocks(this);

    when(config.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    productCache = new ProductCache(config, productAdapter);

    owner = createOwner();
    ownerCurator.create(owner);

    consumer = TestUtil.createConsumer(owner);
    consumerTypeCurator.create(consumer.getType());
    consumerCurator.create(consumer);

    BufferedReader reader =
        new BufferedReader(
            new InputStreamReader(getClass().getResourceAsStream("/rules/test-rules.js")));
    StringBuilder builder = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
      builder.append(line + "\n");
    }
    reader.close();

    Rules rules = mock(Rules.class);
    when(rules.getRules()).thenReturn(builder.toString());
    when(rulesCurator.getRules()).thenReturn(rules);
    when(rulesCurator.getUpdated()).thenReturn(TestDateUtil.date(2010, 1, 1));

    JsRunner jsRules = new JsRunnerProvider(rulesCurator).get();

    enforcer =
        new EntitlementRules(
            new DateSourceForTesting(2010, 1, 1),
            jsRules,
            productCache,
            i18n,
            config,
            consumerCurator,
            poolCurator);
  }
Ejemplo n.º 9
0
  @SuppressWarnings("unchecked")
  @Test
  public void exportProducts() throws Exception {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    Consumer consumer = mock(Consumer.class);
    Entitlement ent = mock(Entitlement.class);
    ProvidedProduct pp = mock(ProvidedProduct.class);
    Pool pool = mock(Pool.class);
    Rules mrules = mock(Rules.class);
    Principal principal = mock(Principal.class);
    IdentityCertificate idcert = new IdentityCertificate();

    Set<ProvidedProduct> ppset = new HashSet<ProvidedProduct>();
    ppset.add(pp);

    Set<Entitlement> entitlements = new HashSet<Entitlement>();
    entitlements.add(ent);

    Product prod = new Product("12345", "RHEL Product");
    prod.setMultiplier(1L);
    prod.setCreated(new Date());
    prod.setUpdated(new Date());
    prod.setHref("http://localhost");
    prod.setAttributes(Collections.EMPTY_SET);

    Product prod1 = new Product("MKT-prod", "RHEL Product");
    prod1.setMultiplier(1L);
    prod1.setCreated(new Date());
    prod1.setUpdated(new Date());
    prod1.setHref("http://localhost");
    prod1.setAttributes(Collections.EMPTY_SET);

    ProductCertificate pcert = new ProductCertificate();
    pcert.setKey("euh0876puhapodifbvj094");
    pcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    pcert.setCreated(new Date());
    pcert.setUpdated(new Date());

    when(pp.getProductId()).thenReturn("12345");
    when(pool.getProvidedProducts()).thenReturn(ppset);
    when(pool.getProductId()).thenReturn("MKT-prod");
    when(ent.getPool()).thenReturn(pool);
    when(mrules.getRules()).thenReturn("foobar");
    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(rc.getRules()).thenReturn(mrules);
    when(consumer.getEntitlements()).thenReturn(entitlements);
    when(psa.getProductById("12345")).thenReturn(prod);
    when(psa.getProductById("MKT-prod")).thenReturn(prod1);
    when(psa.getProductCertificate(any(Product.class))).thenReturn(pcert);
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");
    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);

    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());

    // FINALLY test this badboy
    Exporter e =
        new Exporter(
            ctc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov);

    File export = e.getFullExport(consumer);

    // VERIFY
    assertNotNull(export);
    verifyContent(export, "export/products/12345.pem", new VerifyProductCert("12345.pem"));
    assertFalse(verifyHasEntry(export, "export/products/MKT-prod.pem"));
    FileUtils.deleteDirectory(export.getParentFile());
    assertTrue(new File("/tmp/consumer_export.zip").delete());
    assertTrue(new File("/tmp/12345.pem").delete());
  }