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
}
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);
}
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"));
}
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"));
}
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());
}
Aggregations