use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class DefaultIdentityCertServiceAdapterTest method testGenerate.
@Test
public void testGenerate() throws GeneralSecurityException, IOException {
Consumer consumer = mock(Consumer.class);
when(consumer.getId()).thenReturn("42");
when(consumer.getUuid()).thenReturn(Util.generateUUID());
KeyPair kp = createKeyPair();
when(kpc.getConsumerKeyPair(consumer)).thenReturn(kp);
when(idcur.find(consumer.getId())).thenReturn(null);
when(csc.create(any(CertificateSerial.class))).thenAnswer(new Answer<CertificateSerial>() {
public CertificateSerial answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
CertificateSerial cs = (CertificateSerial) args[0];
cs.setId(42L);
return cs;
}
});
when(pki.getPemEncoded(any(X509Certificate.class))).thenReturn("x509cert".getBytes());
when(pki.getPemEncoded(any(PrivateKey.class))).thenReturn("priv".getBytes());
when(idcur.create(any(IdentityCertificate.class))).thenAnswer(new Answer<IdentityCertificate>() {
public IdentityCertificate answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
IdentityCertificate ic = (IdentityCertificate) args[0];
ic.setId("42");
return ic;
}
});
IdentityCertificate ic = dicsa.generateIdentityCert(consumer);
assertNotNull(ic);
assertEquals("priv", ic.getKey());
assertEquals("x509cert", ic.getCert());
assertNotNull(ic.getCertAsBytes());
assertNotNull(ic.getKeyAsBytes());
verify(consumer).setIdCert(ic);
verify(csc).create(any(CertificateSerial.class));
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class DefaultIdentityCertServiceAdapterTest method testRegenerateCallsDeletes.
@Test
public void testRegenerateCallsDeletes() throws GeneralSecurityException, IOException {
Consumer consumer = mock(Consumer.class);
IdentityCertificate mockic = mock(IdentityCertificate.class);
when(consumer.getIdCert()).thenReturn(mockic);
when(mockic.getId()).thenReturn("43");
when(idcur.find(mockic.getId())).thenReturn(mockic);
KeyPair kp = createKeyPair();
when(kpc.getConsumerKeyPair(consumer)).thenReturn(kp);
when(csc.create(any(CertificateSerial.class))).thenAnswer(new Answer<CertificateSerial>() {
public CertificateSerial answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
CertificateSerial cs = (CertificateSerial) args[0];
cs.setId(42L);
return cs;
}
});
when(pki.getPemEncoded(any(X509Certificate.class))).thenReturn("x509cert".getBytes());
when(pki.getPemEncoded(any(PrivateKey.class))).thenReturn("priv".getBytes());
when(idcur.create(any(IdentityCertificate.class))).thenAnswer(new Answer<IdentityCertificate>() {
public IdentityCertificate answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
IdentityCertificate ic = (IdentityCertificate) args[0];
ic.setId("42");
return ic;
}
});
IdentityCertificate ic = dicsa.regenerateIdentityCert(consumer);
verify(consumer).setIdCert(null);
verify(idcur).delete(mockic);
assertNotSame(ic, mockic);
assertEquals("priv", ic.getKey());
assertEquals("x509cert", ic.getCert());
assertNotNull(ic.getCertAsBytes());
assertNotNull(ic.getKeyAsBytes());
verify(consumer).setIdCert(ic);
verify(csc).create(any(CertificateSerial.class));
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class DefaultIdentityCertServiceAdapterTest method testRegenerate.
@Test
public void testRegenerate() throws GeneralSecurityException, IOException {
Consumer consumer = mock(Consumer.class);
when(consumer.getId()).thenReturn("42L");
when(consumer.getUuid()).thenReturn(Util.generateUUID());
when(idcur.find(consumer.getId())).thenReturn(null);
KeyPair kp = createKeyPair();
when(kpc.getConsumerKeyPair(consumer)).thenReturn(kp);
when(csc.create(any(CertificateSerial.class))).thenAnswer(new Answer<CertificateSerial>() {
public CertificateSerial answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
CertificateSerial cs = (CertificateSerial) args[0];
cs.setId(42L);
return cs;
}
});
when(pki.getPemEncoded(any(X509Certificate.class))).thenReturn("x509cert".getBytes());
when(pki.getPemEncoded(any(PrivateKey.class))).thenReturn("priv".getBytes());
when(idcur.create(any(IdentityCertificate.class))).thenAnswer(new Answer<IdentityCertificate>() {
public IdentityCertificate answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
IdentityCertificate ic = (IdentityCertificate) args[0];
ic.setId("42");
return ic;
}
});
IdentityCertificate ic = dicsa.regenerateIdentityCert(consumer);
assertNotNull(ic);
verify(consumer, never()).setIdCert(null);
verify(idcur, never()).delete(any(IdentityCertificate.class));
assertEquals("priv", ic.getKey());
assertEquals("x509cert", ic.getCert());
assertNotNull(ic.getCertAsBytes());
assertNotNull(ic.getKeyAsBytes());
verify(consumer).setIdCert(ic);
verify(csc).create(any(CertificateSerial.class));
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class DefaultIdentityCertServiceAdapterTest method testReturnExisting.
@Test
public void testReturnExisting() throws GeneralSecurityException, IOException {
Consumer consumer = mock(Consumer.class);
IdentityCertificate mockic = mock(IdentityCertificate.class);
when(consumer.getIdCert()).thenReturn(mockic);
when(idcur.find(mockic.getId())).thenReturn(mockic);
when(idcur.find(consumer.getId())).thenReturn(mockic);
IdentityCertificate ic = dicsa.generateIdentityCert(consumer);
assertNotNull(ic);
assertEquals(ic, mockic);
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class ExporterTest method exportConsumer.
@Test
public void exportConsumer() throws ExportCreationException, IOException {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
Rules mrules = mock(Rules.class);
Consumer consumer = mock(Consumer.class);
Principal principal = mock(Principal.class);
when(mrules.getRules()).thenReturn("foobar");
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(rc.getRules()).thenReturn(mrules);
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
// specific to this test
IdentityCertificate idcert = new IdentityCertificate();
idcert.setSerial(new CertificateSerial(10L, new Date()));
idcert.setKey("euh0876puhapodifbvj094");
idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
idcert.setCreated(new Date());
idcert.setUpdated(new Date());
when(consumer.getIdCert()).thenReturn(idcert);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
ctype.setId("test-ctype");
KeyPair keyPair = createKeyPair();
when(consumer.getKeyPair()).thenReturn(keyPair);
when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
when(consumer.getUuid()).thenReturn("8auuid");
when(consumer.getName()).thenReturn("consumer_name");
when(consumer.getContentAccessMode()).thenReturn("access_mode");
when(consumer.getTypeId()).thenReturn(ctype.getId());
when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
when(ctc.listAll()).thenReturn(cqmock);
CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
when(cdnc.listAll()).thenReturn(emptyIteratorMock);
// FINALLY test this badboy
Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
File export = e.getFullExport(consumer);
verifyContent(export, "export/consumer.json", new VerifyConsumer("consumer.json"));
}
Aggregations