Search in sources :

Example 96 with Consumer

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

the class SSLAuthTest method noUuidOnCert.

/**
 * DN is set but does not contain UID
 *
 * @throws Exception
 */
@Test
public void noUuidOnCert() throws Exception {
    mockCert("OU=something");
    when(this.consumerCurator.findByUuid(anyString())).thenReturn(new Consumer("machine_name", "test user", null, null));
    assertNull(this.auth.getPrincipal(httpRequest));
}
Also used : Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 97 with Consumer

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

the class SSLAuthTest method correctUserName.

/**
 * Happy path - parses the username from the cert's DN correctly.
 *
 * @throws Exception
 */
@Test
public void correctUserName() throws Exception {
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
    ctype.setId("test-ctype");
    Owner owner = new Owner("test owner");
    owner.setId(TestUtil.randomString());
    Consumer consumer = new Consumer("machine_name", "test user", owner, ctype);
    ConsumerPrincipal expected = new ConsumerPrincipal(consumer, owner);
    String dn = "CN=453-44423-235";
    mockCert(dn);
    when(this.consumerCurator.getConsumer("453-44423-235")).thenReturn(consumer);
    when(this.ownerCurator.findOwnerById(owner.getOwnerId())).thenReturn(owner);
    assertEquals(expected, this.auth.getPrincipal(httpRequest));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Example 98 with Consumer

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

the class TrustedUserPrincipalTest method access.

@Test
public void access() {
    Consumer c = mock(Consumer.class);
    Pool p = mock(Pool.class);
    assertTrue(principal.canAccess(c, SubResource.NONE, Access.ALL));
    assertTrue(principal.canAccess(null, SubResource.NONE, Access.NONE));
    assertTrue(principal.canAccessAll(null, SubResource.NONE, Access.NONE));
    assertTrue(principal.canAccess(p, SubResource.NONE, Access.ALL));
    assertTrue(principal.canAccess("always true", SubResource.NONE, Access.READ_ONLY));
}
Also used : Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 99 with Consumer

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

the class ConsumerPrincipalTest method accessToConsumer.

@Test
public void accessToConsumer() {
    Consumer c = mock(Consumer.class);
    when(c.getUuid()).thenReturn("consumer-uuid");
    assertTrue(principal.canAccess(consumer, SubResource.NONE, Access.ALL));
}
Also used : Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 100 with Consumer

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

the class ConsumerPrincipalTest method equalsDifferentConsumer.

@Test
public void equalsDifferentConsumer() {
    ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM);
    ctype.setId("test-ctype");
    Consumer c = new Consumer("Test Consumer", "test-consumer", new Owner("o1"), ctype);
    ConsumerPrincipal cp = new ConsumerPrincipal(c, o);
    assertFalse(principal.equals(cp));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Aggregations

Consumer (org.candlepin.model.Consumer)470 Test (org.junit.Test)345 Entitlement (org.candlepin.model.Entitlement)162 Owner (org.candlepin.model.Owner)126 Pool (org.candlepin.model.Pool)114 Product (org.candlepin.model.Product)112 Date (java.util.Date)102 ConsumerType (org.candlepin.model.ConsumerType)94 LinkedList (java.util.LinkedList)73 ArrayList (java.util.ArrayList)71 HashSet (java.util.HashSet)69 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)69 HashMap (java.util.HashMap)48 ApiOperation (io.swagger.annotations.ApiOperation)43 Produces (javax.ws.rs.Produces)43 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)40 ApiResponses (io.swagger.annotations.ApiResponses)38 GuestId (org.candlepin.model.GuestId)37 Path (javax.ws.rs.Path)36 List (java.util.List)35