2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dpl/test/test_runner.h>
19 #include <vcore/Certificate.h>
21 #include "test-common.h"
23 using namespace ValidationCore;
25 RUNNER_TEST_GROUP_INIT(T0030_Certificate)
28 * test: class Certificate
29 * description: Certificate should parse data passed to object constructor.
30 * expected: Getters should be able to return certificate information.
32 RUNNER_TEST(T0031_Certificate)
34 Certificate cert(TestData::certVerisign, Certificate::FORM_BASE64);
37 result = cert.getCommonName(Certificate::FIELD_SUBJECT);
38 RUNNER_ASSERT_MSG(!result.empty(), "No common name");
39 RUNNER_ASSERT_MSG(!result.compare("www.verisign.com"), "CommonName mismatch");
41 result = cert.getCommonName(Certificate::FIELD_ISSUER);
42 RUNNER_ASSERT_MSG(!result.empty(), "No common name");
43 RUNNER_ASSERT_MSG(!result.compare("VeriSign Class 3 Extended Validation SSL SGC CA"),
44 "CommonName mismatch");
46 result = cert.getCountryName();
47 RUNNER_ASSERT_MSG(!result.empty(), "No country");
48 RUNNER_ASSERT_MSG(!result.compare("US"), "Country mismatch");
52 * test: Certificate::getFingerprint
53 * description: Certificate should parse data passed to object constructor.
54 * expected: Function fingerprint should return valid fingerprint.
56 RUNNER_TEST(T0032_Certificate)
58 Certificate cert(TestData::certVerisign, Certificate::FORM_BASE64);
60 Certificate::Fingerprint fin =
61 cert.getFingerprint(Certificate::FINGERPRINT_SHA1);
63 unsigned char buff[20] = {
64 0xb9, 0x72, 0x1e, 0xd5, 0x49,
65 0xed, 0xbf, 0x31, 0x84, 0xd8,
66 0x27, 0x0c, 0xfe, 0x03, 0x11,
67 0x19, 0xdf, 0xc2, 0x2b, 0x0a};
68 RUNNER_ASSERT_MSG(fin.size() == 20, "Wrong size of fingerprint");
70 for (size_t i = 0; i<20; ++i) {
71 RUNNER_ASSERT_MSG(fin[i] == buff[i], "Fingerprint mismatch");
76 * test: Certificate::getAlternativeNameDNS
77 * description: Certificate should parse data passed to object constructor.
78 * expected: Function getAlternativeNameDNS should return list of
79 * alternativeNames hardcoded in certificate.
81 RUNNER_TEST(T0033_Certificate)
83 Certificate cert(TestData::certVerisign, Certificate::FORM_BASE64);
85 Certificate::AltNameSet nameSet = cert.getAlternativeNameDNS();
87 RUNNER_ASSERT(nameSet.size() == 8);
89 std::string str("verisign.com");
90 RUNNER_ASSERT(nameSet.find(str) != nameSet.end());
92 str = std::string("fake.com");
93 RUNNER_ASSERT(nameSet.find(str) == nameSet.end());
98 * test: Certificate::isCA
99 * description: Certificate should parse data passed to object constructor.
100 * expected: 1st and 2nd certificate should be identified as CA.
102 RUNNER_TEST(T0034_Certificate_isCA)
104 Certificate cert1(TestData::googleCA, Certificate::FORM_BASE64);
105 RUNNER_ASSERT(cert1.isCA() > 0);
107 Certificate cert2(TestData::google2nd, Certificate::FORM_BASE64);
108 RUNNER_ASSERT(cert2.isCA() > 0);
110 Certificate cert3(TestData::google3rd, Certificate::FORM_BASE64);
111 RUNNER_ASSERT(cert3.isCA() == 0);