Search in sources :

Example 36 with Owner

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

the class PoolResourceTest method testUnauthorizedUserRequestingPool.

@Test(expected = NotFoundException.class)
public void testUnauthorizedUserRequestingPool() {
    Owner owner2 = createOwner();
    ownerCurator.create(owner2);
    poolResource.getPool(pool1.getId(), passConsumer.getUuid(), null, setupPrincipal(owner2, Access.NONE));
}
Also used : Owner(org.candlepin.model.Owner) Test(org.junit.Test)

Example 37 with Owner

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

the class UserResourceTest method testListOwnersForMySystemsAdmin.

@Test
public void testListOwnersForMySystemsAdmin() {
    User user = new User();
    user.setUsername("dummyuser" + TestUtil.randomInt());
    user.setPassword("password");
    userResource.createUser(user);
    Owner owner1 = createOwner();
    Role owner1Role = new Role(owner1.getKey() + " role");
    owner1Role.addPermission(new PermissionBlueprint(PermissionType.USERNAME_CONSUMERS, owner1, Access.ALL));
    owner1Role.addUser(user);
    roleCurator.create(owner1Role);
    Set<Permission> perms = new HashSet<>();
    perms.add(new UsernameConsumersPermission(user, owner1));
    Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
    Iterable<Owner> response = userResource.listUsersOwners(user.getUsername(), userPrincipal);
    List<Owner> owners = new LinkedList<>();
    for (Object entity : response) {
        owners.add((Owner) entity);
    }
    assertEquals(1, owners.size());
    assertEquals(owner1.getKey(), owners.get(0).getKey());
}
Also used : Owner(org.candlepin.model.Owner) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) LinkedList(java.util.LinkedList) Role(org.candlepin.model.Role) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with Owner

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

the class DefaultUserServiceAdapterTest method superAdminRole.

@Test
@Ignore("Find a way to do this with permissions")
public void superAdminRole() {
    Set<Owner> owners = new HashSet<>();
    owners.add(owner);
    User user = new User("super_admin", "password", true);
    this.service.createUser(user);
    Assert.assertTrue(this.service.findByLogin("super_admin").getRoles().contains(Access.ALL));
}
Also used : Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 39 with Owner

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

the class ImporterTest method testImportWithNonZipArchive.

@Test
public void testImportWithNonZipArchive() throws IOException, ImporterException {
    Importer i = new Importer(null, null, null, null, null, null, null, null, config, null, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    Owner owner = mock(Owner.class);
    ConflictOverrides co = mock(ConflictOverrides.class);
    File archive = new File(folder.getRoot(), "non_zip_file.zip");
    FileWriter fw = new FileWriter(archive);
    fw.write("Just a flat file");
    fw.close();
    String m = i18n.tr("The archive {0} is not a properly compressed file or is empty", "non_zip_file.zip");
    ee.expect(ImportExtractionException.class);
    ee.expectMessage(m);
    i.loadExport(owner, archive, co, "original_file.zip");
}
Also used : Owner(org.candlepin.model.Owner) FileWriter(java.io.FileWriter) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Example 40 with Owner

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

the class ImporterTest method testReturnsSubscriptionsFromManifest.

@Test
public void testReturnsSubscriptionsFromManifest() throws IOException, ImporterException {
    Owner owner = new Owner("admin", "Admin Owner");
    ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
    when(emc.lookupByTypeAndOwner("per_user", owner)).thenReturn(null);
    ConsumerType stype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
    stype.setId("test-ctype");
    when(consumerTypeCurator.lookupByLabel(eq("system"))).thenReturn(stype);
    when(consumerTypeCurator.find(eq(stype.getId()))).thenReturn(stype);
    OwnerCurator oc = mock(OwnerCurator.class);
    when(oc.lookupWithUpstreamUuid(any(String.class))).thenReturn(null);
    PoolManager pm = mock(PoolManager.class);
    Refresher refresher = mock(Refresher.class);
    when(pm.getRefresher(any(SubscriptionServiceAdapter.class), any(OwnerServiceAdapter.class))).thenReturn(refresher);
    Map<String, File> importFiles = new HashMap<>();
    File ruleDir = mock(File.class);
    File[] rulesFiles = createMockJsFile(mockJsPath);
    when(ruleDir.listFiles()).thenReturn(rulesFiles);
    File actualmeta = createFile("meta.json", "0.0.3", new Date(), "test_user", "prefix");
    importFiles.put(ImportFile.META.fileName(), actualmeta);
    ConsumerDTO consumerDTO = new ConsumerDTO();
    consumerDTO.setUuid("eb5e04bf-be27-44cf-abe3-0c0b1edd523e");
    consumerDTO.setName("mymachine");
    ConsumerTypeDTO typeDTO = new ConsumerTypeDTO();
    typeDTO.setLabel("candlepin");
    typeDTO.setManifest(true);
    consumerDTO.setType(typeDTO);
    consumerDTO.setUrlWeb("foo.example.com/subscription");
    consumerDTO.setUrlApi("/candlepin");
    consumerDTO.setContentAccessMode("");
    OwnerDTO ownerDTO = new OwnerDTO();
    ownerDTO.setKey("admin");
    ownerDTO.setDisplayName("Admin Owner");
    consumerDTO.setOwner(ownerDTO);
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
    ctype.setId("test-ctype");
    when(consumerTypeCurator.lookupByLabel(eq("candlepin"))).thenReturn(ctype);
    when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    File consumerFile = new File(folder.getRoot(), "consumer.json");
    mapper.writeValue(consumerFile, consumerDTO);
    importFiles.put(ImportFile.CONSUMER.fileName(), consumerFile);
    File cTypes = mock(File.class);
    when(cTypes.listFiles()).thenReturn(new File[] {});
    importFiles.put(ImportFile.CONSUMER_TYPE.fileName(), cTypes);
    Product prod = new Product("prodId", "prodTest", null);
    prod.setDependentProductIds(null);
    File prodFile = new File(folder.getRoot(), "product.json");
    mapper.writeValue(prodFile, prod);
    File products = mock(File.class);
    when(products.listFiles()).thenReturn(new File[] { prodFile });
    importFiles.put(ImportFile.PRODUCTS.fileName(), products);
    Entitlement ent = new Entitlement();
    Pool pool = new Pool();
    pool.setProduct(prod);
    ent.setPool(pool);
    ent.setQuantity(2);
    File entFile = new File(folder.getRoot(), "entitlement.json");
    mapper.writeValue(entFile, ent);
    File entitlements = mock(File.class);
    when(entitlements.listFiles()).thenReturn(new File[] { entFile });
    importFiles.put(ImportFile.ENTITLEMENTS.fileName(), entitlements);
    RulesImporter ri = mock(RulesImporter.class);
    importFiles.put(ImportFile.RULES_FILE.fileName(), rulesFiles[0]);
    ConflictOverrides co = mock(ConflictOverrides.class);
    Importer i = new Importer(consumerTypeCurator, pc, ri, oc, null, null, pm, null, config, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    List<Subscription> subscriptions = i.importObjects(owner, importFiles, co);
    assertEquals(1, subscriptions.size());
    assertEquals("prodId", subscriptions.get(0).getProduct().getId());
    assertEquals(2, subscriptions.get(0).getQuantity().longValue());
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ExporterMetadataCurator(org.candlepin.model.ExporterMetadataCurator) Product(org.candlepin.model.Product) OwnerCurator(org.candlepin.model.OwnerCurator) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Subscription(org.candlepin.model.dto.Subscription) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) Refresher(org.candlepin.controller.Refresher) PoolManager(org.candlepin.controller.PoolManager) Date(java.util.Date) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) Entitlement(org.candlepin.model.Entitlement) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Owner (org.candlepin.model.Owner)405 Test (org.junit.Test)254 Product (org.candlepin.model.Product)153 Consumer (org.candlepin.model.Consumer)127 Pool (org.candlepin.model.Pool)79 Date (java.util.Date)72 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)71 ArrayList (java.util.ArrayList)58 Produces (javax.ws.rs.Produces)52 ConsumerType (org.candlepin.model.ConsumerType)52 ApiOperation (io.swagger.annotations.ApiOperation)50 HashSet (java.util.HashSet)44 Entitlement (org.candlepin.model.Entitlement)44 Path (javax.ws.rs.Path)42 HashMap (java.util.HashMap)41 ApiResponses (io.swagger.annotations.ApiResponses)40 Content (org.candlepin.model.Content)39 BadRequestException (org.candlepin.common.exceptions.BadRequestException)37 Subscription (org.candlepin.model.dto.Subscription)32 List (java.util.List)29