Search in sources :

Example 31 with Principal

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);
}
Also used : NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Test(org.junit.Test)

Example 32 with Principal

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());
}
Also used : User(org.candlepin.model.User) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 33 with Principal

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());
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) ProductCurator(org.candlepin.model.ProductCurator) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 34 with Principal

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\"}]" + "}]}";
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) GuestMigration(org.candlepin.resource.util.GuestMigration) Owner(org.candlepin.model.Owner) ConsumerTypeCurator(org.candlepin.model.ConsumerTypeCurator) ConsumerResource(org.candlepin.resource.ConsumerResource) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) ConsumerType(org.candlepin.model.ConsumerType) Principal(org.candlepin.auth.Principal) ConsumerCurator(org.candlepin.model.ConsumerCurator) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) Before(org.junit.Before)

Example 35 with Principal

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());
}
Also used : Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ExporterMetadata(org.candlepin.model.ExporterMetadata) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Aggregations

Principal (org.candlepin.auth.Principal)74 Test (org.junit.Test)54 UserPrincipal (org.candlepin.auth.UserPrincipal)40 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)20 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)17 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)15 Consumer (org.candlepin.model.Consumer)15 Owner (org.candlepin.model.Owner)15 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)14 Date (java.util.Date)12 ConsumerType (org.candlepin.model.ConsumerType)11 HashSet (java.util.HashSet)10 Pool (org.candlepin.model.Pool)10 JobDetail (org.quartz.JobDetail)10 Method (java.lang.reflect.Method)9 Permission (org.candlepin.auth.permissions.Permission)9 JobDataMap (org.quartz.JobDataMap)9 CandlepinQuery (org.candlepin.model.CandlepinQuery)8 File (java.io.File)7 FileInputStream (java.io.FileInputStream)7