Search in sources :

Example 16 with IdentityCertificate

use of org.candlepin.model.IdentityCertificate in project candlepin by candlepin.

the class ConsumerResourceIntegrationTest method testReadOnlyUsersCanGenerateExports.

@Test
public void testReadOnlyUsersCanGenerateExports() {
    // add an identity certificate for the export
    IdentityCertificate idCert = TestUtil.createIdCert();
    // needs to be null to persist
    idCert.setId(null);
    certSerialCurator.create(idCert.getSerial());
    identityCertificateCurator.create(idCert);
    consumer.setIdCert(idCert);
    consumer.setType(consumerTypeCurator.create(new ConsumerType(ConsumerTypeEnum.CANDLEPIN)));
    consumerCurator.update(consumer);
    setupPrincipal(owner, Access.READ_ONLY);
    securityInterceptor.enable();
    consumerResource.exportData(mock(HttpServletResponse.class), consumer.getUuid(), null, null, null, new ArrayList<>());
// if no exception, we're good
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ConsumerType(org.candlepin.model.ConsumerType) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 17 with IdentityCertificate

use of org.candlepin.model.IdentityCertificate in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method init.

@Before
public void init() throws Exception {
    Configuration config = new CandlepinCommonTestConfig();
    this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    testMigration = new GuestMigration(consumerCurator);
    migrationProvider = Providers.of(testMigration);
    this.translator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
    this.resource = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, this.subscriptionService, this.ownerService, null, this.idCertService, null, this.i18n, this.sink, this.eventFactory, null, null, this.userService, poolManager, null, null, this.activationKeyCurator, this.entitler, this.complianceRules, this.deletedConsumerCurator, this.environmentCurator, null, config, null, null, null, this.consumerBindUtil, null, null, new FactValidator(config, this.i18n), null, consumerEnricher, migrationProvider, this.translator);
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class), any(Boolean.class))).thenReturn(new ComplianceStatus(new Date()));
    when(idCertService.regenerateIdentityCert(any(Consumer.class))).thenReturn(new IdentityCertificate());
    when(consumerEventBuilder.setEventData(any(Consumer.class))).thenReturn(consumerEventBuilder);
    when(eventFactory.getEventBuilder(any(Target.class), any(Type.class))).thenReturn(consumerEventBuilder);
}
Also used : FactValidator(org.candlepin.util.FactValidator) Configuration(org.candlepin.common.config.Configuration) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) GuestMigration(org.candlepin.resource.util.GuestMigration) Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) ConsumerType(org.candlepin.model.ConsumerType) Consumer(org.candlepin.model.Consumer) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) IdentityCertificate(org.candlepin.model.IdentityCertificate) Before(org.junit.Before)

Example 18 with IdentityCertificate

use of org.candlepin.model.IdentityCertificate in project candlepin by candlepin.

the class RulesObjectMapperTest method filterConsumerIdCert.

@Test
public void filterConsumerIdCert() {
    Consumer c = new Consumer();
    c.setTypeId("test-ctype");
    IdentityCertificate cert = new IdentityCertificate();
    cert.setCert("FILTERMEPLEASE");
    cert.setKey("KEY");
    c.setIdCert(cert);
    context.put("consumer", c);
    String output = objMapper.toJsonString(context);
    assertFalse(output.contains("FILTERMEPLEASE"));
}
Also used : Consumer(org.candlepin.model.Consumer) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 19 with IdentityCertificate

use of org.candlepin.model.IdentityCertificate in project candlepin by candlepin.

the class RulesObjectMapperTest method filterEntitlementConsumer.

@Test
public void filterEntitlementConsumer() {
    Entitlement e = new Entitlement();
    Consumer c = new Consumer();
    IdentityCertificate cert = new IdentityCertificate();
    cert.setCert("FILTERMEPLEASE");
    cert.setKey("KEY");
    c.setIdCert(cert);
    e.setConsumer(c);
    context.put("entitlement", e);
    String output = objMapper.toJsonString(context);
    assertFalse(output.contains("consumer"));
}
Also used : Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 20 with IdentityCertificate

use of org.candlepin.model.IdentityCertificate in project candlepin by candlepin.

the class HypervisorResourceTest method ensureEmptyHypervisorIdsAreIgnored.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
@Test
public void ensureEmptyHypervisorIdsAreIgnored() throws Exception {
    Owner owner = new Owner("admin");
    owner.setId("test-id");
    Map<String, List<GuestIdDTO>> hostGuestMap = new HashMap<>();
    hostGuestMap.put("", new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_A"), TestUtil.createGuestIdDTO("GUEST_B"))));
    hostGuestMap.put("HYPERVISOR_A", new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_C"), TestUtil.createGuestIdDTO("GUEST_D"))));
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(consumerCurator.getHostConsumersMap(any(Owner.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    when(consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(principal.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    when(idCertService.generateIdentityCert(any(Consumer.class))).thenReturn(new IdentityCertificate());
    HypervisorCheckInResult result = hypervisorResource.hypervisorUpdate(hostGuestMap, principal, owner.getKey(), true);
    assertNotNull(result);
    assertEquals(1, result.getCreated().size());
    List<Consumer> created = new ArrayList<>(result.getCreated());
    assertEquals("hypervisor_a", created.get(0).getHypervisorId().getHypervisorId());
}
Also used : Owner(org.candlepin.model.Owner) Set(java.util.Set) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IdentityCertificate(org.candlepin.model.IdentityCertificate) HypervisorCheckInResult(org.candlepin.resource.dto.HypervisorCheckInResult) Test(org.junit.Test)

Aggregations

IdentityCertificate (org.candlepin.model.IdentityCertificate)39 Consumer (org.candlepin.model.Consumer)25 Test (org.junit.Test)25 CertificateSerial (org.candlepin.model.CertificateSerial)16 Date (java.util.Date)14 Owner (org.candlepin.model.Owner)13 ConsumerType (org.candlepin.model.ConsumerType)10 File (java.io.File)8 ArrayList (java.util.ArrayList)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 ZipInputStream (java.util.zip.ZipInputStream)7 Principal (org.candlepin.auth.Principal)7 CandlepinQuery (org.candlepin.model.CandlepinQuery)7 List (java.util.List)6 Set (java.util.Set)6 KeyPair (org.candlepin.model.KeyPair)6 Rules (org.candlepin.model.Rules)6 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)6