use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class ConsumerResourceCreationTest method registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner.
@Test
public void registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner() {
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
ConsumerTypeDTO ctypeDTO = this.modelTranslator.translate(ctype, ConsumerTypeDTO.class);
this.mockConsumerType(ctype);
// Disable autobind for the owner.
owner.setAutobindDisabled(true);
// Create a key that has autobind disabled.
ActivationKey key = new ActivationKey("autobind-disabled-key", owner);
key.setAutoAttach(true);
when(activationKeyCurator.lookupForOwner(key.getName(), owner)).thenReturn(key);
// No auth should be required for registering with keys:
Principal p = new NoAuthPrincipal();
ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, ctypeDTO);
resource.create(consumer, p, null, owner.getKey(), key.getName(), true);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method userwithEmail.
@Test
public void userwithEmail() {
String username = "(foo)@{baz}.[com]&?";
User u = userCurator.create(new User(username, "dontcare"));
ownerAdminRole.addUser(u);
roleCurator.merge(ownerAdminRole);
Principal emailuser = TestUtil.createPrincipal(username, owner, Access.ALL);
setupPrincipal(emailuser);
ConsumerDTO personal = createConsumerDTO(personTypeDTO, ownerDTO);
personal.setName(((UserPrincipal) emailuser).getUsername());
personal = consumerResource.create(personal, emailuser, username, null, null, true);
// Not sure if this should be hard-coded to default
assertEquals(username, personal.getName());
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class OwnerResourceTest method upstreamConsumers.
@Test
public void upstreamConsumers() {
Principal p = mock(Principal.class);
OwnerCurator oc = mock(OwnerCurator.class);
ProductCurator pc = mock(ProductCurator.class);
UpstreamConsumer upstream = mock(UpstreamConsumer.class);
Owner owner = mock(Owner.class);
OwnerResource ownerres = new OwnerResource(oc, pc, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
when(oc.lookupByKey(eq("admin"))).thenReturn(owner);
when(owner.getUpstreamConsumer()).thenReturn(upstream);
List<UpstreamConsumerDTO> results = ownerres.getUpstreamConsumers(p, "admin");
assertNotNull(results);
assertEquals(1, results.size());
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class HypervisorUpdateJobTest method init.
@Before
public void init() {
super.init();
i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.READ_PROPERTIES | I18nFactory.FALLBACK);
owner = mock(Owner.class);
principal = mock(Principal.class);
ownerCurator = mock(OwnerCurator.class);
consumerCurator = mock(ConsumerCurator.class);
consumerResource = mock(ConsumerResource.class);
consumerTypeCurator = mock(ConsumerTypeCurator.class);
subAdapter = mock(SubscriptionServiceAdapter.class);
complianceRules = mock(ComplianceRules.class);
when(owner.getId()).thenReturn("joe");
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.HYPERVISOR);
ctype.setId("test-ctype");
when(consumerTypeCurator.lookupByLabel(eq(ConsumerTypeEnum.HYPERVISOR.getLabel()))).thenReturn(ctype);
when(consumerTypeCurator.lookupByLabel(eq(ConsumerTypeEnum.HYPERVISOR.getLabel()), anyBoolean())).thenReturn(ctype);
when(owner.getKey()).thenReturn("joe");
when(principal.getUsername()).thenReturn("joe user");
testMigration = new GuestMigration(consumerCurator);
migrationProvider = Providers.of(testMigration);
hypervisorJson = "{\"hypervisors\":" + "[{" + "\"name\" : \"hypervisor_999\"," + "\"hypervisorId\" : {\"hypervisorId\":\"uuid_999\"}," + "\"guestIds\" : [{\"guestId\" : \"guestId_1_999\"}]" + "}]}";
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class UndoImportsJobTest method testUndoImport.
@Test
public void testUndoImport() throws JobExecutionException, IOException, ImporterException {
// We need proper curators for this test
this.poolManager = this.poolManagerBase;
this.ownerCurator = super.ownerCurator;
this.exportCurator = this.exportCuratorBase;
this.undoImportsJob = new UndoImportsJob(this.i18n, this.ownerCurator, this.poolManager, this.subAdapter, this.exportCurator, this.importRecordCurator);
// Create owner w/upstream consumer
Owner owner1 = TestUtil.createOwner();
Owner owner2 = TestUtil.createOwner();
ConsumerType type = this.createConsumerType();
UpstreamConsumer uc1 = new UpstreamConsumer("uc1", null, type, "uc1");
UpstreamConsumer uc2 = new UpstreamConsumer("uc2", null, type, "uc2");
this.ownerCurator.create(owner1);
this.ownerCurator.create(owner2);
owner1.setUpstreamConsumer(uc1);
owner1.setUpstreamConsumer(uc2);
this.ownerCurator.merge(owner1);
this.ownerCurator.merge(owner2);
// Create metadata
ExporterMetadata metadata1 = new ExporterMetadata(ExporterMetadata.TYPE_PER_USER, new Date(), owner1);
ExporterMetadata metadata2 = new ExporterMetadata(ExporterMetadata.TYPE_PER_USER, new Date(), owner2);
this.exportCurator.create(metadata1);
this.exportCurator.create(metadata2);
// Create pools w/upstream pool IDs
Pool pool1 = this.createPool("pool1", owner1, true, PoolType.NORMAL);
Pool pool2 = this.createPool("pool2", owner1, true, PoolType.BONUS);
Pool pool3 = this.createPool("pool3", owner1, false, PoolType.NORMAL);
Pool pool4 = this.createPool("pool4", owner1, false, PoolType.BONUS);
Pool pool5 = this.createPool("pool5", owner1, true, PoolType.ENTITLEMENT_DERIVED);
Pool pool6 = this.createPool("pool6", owner1, false, PoolType.ENTITLEMENT_DERIVED);
Pool pool7 = this.createPool("pool7", owner2, true, PoolType.NORMAL);
Pool pool8 = this.createPool("pool8", owner2, true, PoolType.BONUS);
Pool pool9 = this.createPool("pool9", owner2, true, PoolType.ENTITLEMENT_DERIVED);
// Create an ueber certificate for the owner.
UeberCertificate uebercert = ueberCertGenerator.generate(owner1.getKey(), this.setupAdminPrincipal("test_admin"));
assertNotNull(uebercert);
// Verify initial state
assertEquals(Arrays.asList(pool1, pool2, pool3, pool4, pool5, pool6), this.poolManager.listPoolsByOwner(owner1).list());
assertEquals(Arrays.asList(pool7, pool8, pool9), this.poolManager.listPoolsByOwner(owner2).list());
assertEquals(metadata1, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner1));
assertEquals(metadata2, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner2));
assertEquals(0, this.importRecordCurator.findRecords(owner1).list().size());
assertEquals(0, this.importRecordCurator.findRecords(owner2).list().size());
// Execute job
Principal principal = new UserPrincipal("JarJarBinks", null, true);
this.jobDataMap.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
this.jobDataMap.put(JobStatus.TARGET_ID, owner1.getId());
this.jobDataMap.put(UndoImportsJob.OWNER_KEY, owner1.getKey());
this.jobDataMap.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
// since we locking owner we need start transaction
beginTransaction();
this.undoImportsJob.toExecute(this.jobContext);
commitTransaction();
// Verify deletions -- Ueber pools should not get deleted.
assertEquals(Arrays.asList(pool3, pool4, pool5, pool6), this.poolManager.listPoolsByOwner(owner1).list());
assertEquals(Arrays.asList(pool7, pool8, pool9), this.poolManager.listPoolsByOwner(owner2).list());
assertNull(exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner1));
assertEquals(metadata2, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner2));
assertNull(owner1.getUpstreamConsumer());
List<ImportRecord> records = this.importRecordCurator.findRecords(owner1).list();
assertEquals(1, records.size());
assertEquals(ImportRecord.Status.DELETE, records.get(0).getStatus());
assertEquals(0, this.importRecordCurator.findRecords(owner2).list().size());
}
Aggregations