Skip to content
Permalink
Browse files

tests: add unit tests for certificate revocation

  • Loading branch information...
aberaud committed Aug 9, 2018
1 parent c794781 commit 5b510cadfb647323cfd2dd5b8aad2a90f053ffb3
Showing with 43 additions and 1 deletion.
  1. +37 −0 tests/cryptotester.cpp
  2. +6 −1 tests/cryptotester.h
@@ -46,6 +46,43 @@ CryptoTester::testSignatureEncryption() {
CPPUNIT_ASSERT(data == decrypted);
}

void
CryptoTester::testCertificateRevocation()
{
auto ca1 = dht::crypto::generateIdentity("ca1");
auto account1 = dht::crypto::generateIdentity("acc1", ca1, 4096, true);
auto device11 = dht::crypto::generateIdentity("dev11", account1);
auto device12 = dht::crypto::generateIdentity("dev12", account1);


dht::crypto::TrustList list;
list.add(*ca1.second);
auto v = list.verify(*account1.second);
CPPUNIT_ASSERT_MESSAGE(v.toString(), v);

list.add(*account1.second);
v = list.verify(*device11.second);
CPPUNIT_ASSERT_MESSAGE(v.toString(), v);
v = list.verify(*device12.second);
CPPUNIT_ASSERT_MESSAGE(v.toString(), v);

auto ca2 = dht::crypto::generateIdentity("ca2");
auto account2 = dht::crypto::generateIdentity("acc2", ca2, 4096, true);
auto device2 = dht::crypto::generateIdentity("dev2", account2);

v = list.verify(*device2.second);
CPPUNIT_ASSERT_MESSAGE(v.toString(), !v);

account1.second->revoke(*account1.first, *device11.second);
dht::crypto::TrustList list2;
list2.add(*account1.second);

v = list2.verify(*device11.second);
CPPUNIT_ASSERT_MESSAGE(v.toString(), !v);
v = list2.verify(*device12.second);
CPPUNIT_ASSERT_MESSAGE(v.toString(), v);
}

void
CryptoTester::tearDown() {

@@ -28,6 +28,7 @@ namespace test {
class CryptoTester : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(CryptoTester);
CPPUNIT_TEST(testSignatureEncryption);
CPPUNIT_TEST(testCertificateRevocation);
CPPUNIT_TEST_SUITE_END();

public:
@@ -40,9 +41,13 @@ class CryptoTester : public CppUnit::TestFixture {
*/
void tearDown();
/**
* Test the differents behaviors of constructors
* Test data signature, encryption and decryption
*/
void testSignatureEncryption();
/**
* Test certificate generation, validation and revocation
*/
void testCertificateRevocation();
};

} // namespace test

0 comments on commit 5b510ca

Please sign in to comment.
You can’t perform that action at this time.