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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations