use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.
the class ConsumerResourceTest method testcheckForGuestsMigrationSerialList.
@Test
public void testcheckForGuestsMigrationSerialList() {
Consumer consumer = createConsumer(createOwner());
List<EntitlementCertificate> certificates = createEntitlementCertificates();
when(mockEntitlementCertServiceAdapter.listForConsumer(consumer)).thenReturn(certificates);
when(mockConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
when(mockEntitlementCurator.listByConsumer(consumer)).thenReturn(new ArrayList<>());
ConsumerResource consumerResource = Mockito.spy(new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, null, null, null, null, null, null, mockPoolManager, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, mockContentAccessCertService, this.factValidator, null, consumerEnricher, migrationProvider, translator));
List<CertificateSerialDto> serials = consumerResource.getEntitlementCertificateSerials(consumer.getUuid());
verify(consumerResource).revokeOnGuestMigration(consumer);
}
use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.
the class ConsumerResourceTest method createEntitlementCertificate.
protected EntitlementCertificate createEntitlementCertificate(String key, String cert) {
EntitlementCertificate toReturn = new EntitlementCertificate();
CertificateSerial certSerial = new CertificateSerial(1L, new Date());
toReturn.setKeyAsBytes(key.getBytes());
toReturn.setCertAsBytes(cert.getBytes());
toReturn.setSerial(certSerial);
return toReturn;
}
use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.
the class ConsumerResourceTest method testCheckForGuestsMigrationCertList.
@Test
public void testCheckForGuestsMigrationCertList() {
Consumer consumer = createConsumer(createOwner());
List<EntitlementCertificate> certificates = createEntitlementCertificates();
when(mockEntitlementCertServiceAdapter.listForConsumer(consumer)).thenReturn(certificates);
when(mockConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
when(mockEntitlementCurator.listByConsumer(consumer)).thenReturn(new ArrayList<>());
GuestMigration migrationSpy = Mockito.spy(testMigration);
migrationProvider = Providers.of(migrationSpy);
ConsumerResource consumerResource = Mockito.spy(new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, null, null, null, null, null, null, mockPoolManager, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, mockContentAccessCertService, this.factValidator, null, consumerEnricher, migrationProvider, translator));
Set<Long> serials = new HashSet<>();
List<CertificateDTO> certs = consumerResource.getEntitlementCertificates(consumer.getUuid(), "123");
verify(consumerResource).revokeOnGuestMigration(consumer);
}
use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.
the class ConsumerResourceTest method testGetCertSerials.
@Test
public void testGetCertSerials() {
Consumer consumer = createConsumer(createOwner());
List<EntitlementCertificate> certificates = createEntitlementCertificates();
List<Long> serialIds = new ArrayList<>();
for (EntitlementCertificate ec : certificates) {
serialIds.add(ec.getSerial().getId());
}
when(mockEntitlementCertServiceAdapter.listEntitlementSerialIds(consumer)).thenReturn(serialIds);
when(mockEntitlementCurator.listByConsumer(consumer)).thenReturn(new ArrayList<>());
ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, null, null, null, null, null, null, mockPoolManager, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, mockContentAccessCertService, this.factValidator, null, consumerEnricher, migrationProvider, translator);
List<CertificateSerialDto> serials = consumerResource.getEntitlementCertificateSerials(consumer.getUuid());
verifyCertificateSerialNumbers(serials);
}
use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.
the class ConsumerResource method getEntitlementCertificates.
@ApiOperation(notes = "Retrieves a list of Entitlement Certificates for the Consumer", value = "getEntitlementCertificates")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Path("{consumer_uuid}/certificates")
@Produces(MediaType.APPLICATION_JSON)
@UpdateConsumerCheckIn
public List<CertificateDTO> getEntitlementCertificates(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("serials") String serials) {
log.debug("Getting client certificates for consumer: {}", consumerUuid);
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("cert fetch", consumer);
return new ArrayList<>();
}
revokeOnGuestMigration(consumer);
poolManager.regenerateDirtyEntitlements(consumer);
Set<Long> serialSet = this.extractSerials(serials);
List<CertificateDTO> returnCerts = new LinkedList<>();
List<EntitlementCertificate> allCerts = entCertService.listForConsumer(consumer);
for (EntitlementCertificate cert : allCerts) {
if (serialSet.isEmpty() || serialSet.contains(cert.getSerial().getId())) {
returnCerts.add(translator.translate(cert, CertificateDTO.class));
}
}
// we want to insert the content access cert to this list if appropriate
try {
Certificate cert = contentAccessCertService.getCertificate(consumer);
if (cert != null) {
returnCerts.add(translator.translate(cert, CertificateDTO.class));
}
} catch (IOException ioe) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), ioe);
} catch (GeneralSecurityException gse) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), gse);
}
return returnCerts;
}
Aggregations