]> WPIA git - cassiopeia.git/blob - test/src/X509Req.cpp
add: Unit test for parsing X509-Req (CSR) and SPKAC
[cassiopeia.git] / test / src / X509Req.cpp
1 #include <iostream>
2
3 #include <boost/test/unit_test.hpp>
4
5 #include "X509.h"
6 #include "util.h"
7
8 BOOST_AUTO_TEST_SUITE( TestX509Req )
9
10 BOOST_AUTO_TEST_CASE( CSR ) {
11     // Testing a valid CSR
12     std::shared_ptr<X509Req> req( X509Req::parse( readFile( "testdata/test.csr" ) ) );
13     BOOST_REQUIRE( req );
14     BOOST_CHECK( req->verify() == 1 );
15
16     // Testing a CSR, where the signature content has been tampered with
17     req = std::shared_ptr<X509Req>( X509Req::parse( readFile( "testdata/test_false_sig.csr" ) ) );
18     BOOST_REQUIRE( req );
19     BOOST_CHECK( req->verify() == 0 );
20
21     // Testing a CSR, where the signature OID is something strange
22     req = std::shared_ptr<X509Req>( X509Req::parse( readFile( "testdata/test_invalid_sig.csr" ) ) );
23     BOOST_REQUIRE( req );
24     BOOST_CHECK( req->verify() < 0 );
25 }
26
27 BOOST_AUTO_TEST_CASE( SPKAC ) {
28     // Testing a valid SPKAC
29     std::shared_ptr<X509Req> req( X509Req::parseSPKAC( readFile( "testdata/test.spkac" ) ) );
30     BOOST_REQUIRE( req );
31     BOOST_CHECK( req->verify() == 1 );
32
33     // Testing a SPKAC, where the signature content has been tampered with
34     req = std::shared_ptr<X509Req>( X509Req::parseSPKAC( readFile( "testdata/test_false_sig.spkac" ) ) );
35     BOOST_REQUIRE( req );
36     BOOST_CHECK( req->verify() == 0 );
37
38     // Testing a SPKAC, where the signature OID is something strange
39     req = std::shared_ptr<X509Req>( X509Req::parseSPKAC( readFile( "testdata/test_invalid_sig.spkac" ) ) );
40     BOOST_REQUIRE( req );
41     BOOST_CHECK( req->verify() < 0 );
42 }
43
44 BOOST_AUTO_TEST_SUITE_END()