2 * Copyright (c) 2016 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);
36 result = cert.getCommonName(Certificate::FIELD_SUBJECT);
37 RUNNER_ASSERT_MSG(!result.empty(), "No common name");
38 RUNNER_ASSERT_MSG(!result.compare("www.verisign.com"), "CommonName mismatch");
39 result = cert.getCommonName(Certificate::FIELD_ISSUER);
40 RUNNER_ASSERT_MSG(!result.empty(), "No common name");
41 RUNNER_ASSERT_MSG(!result.compare("VeriSign Class 3 Extended Validation SSL SGC CA"),
42 "CommonName mismatch");
43 result = cert.getCountryName();
44 RUNNER_ASSERT_MSG(!result.empty(), "No country");
45 RUNNER_ASSERT_MSG(!result.compare("US"), "Country mismatch");
49 * test: Certificate::getFingerprint
50 * description: Certificate should parse data passed to object constructor.
51 * expected: Function fingerprint should return valid fingerprint.
53 RUNNER_TEST(T0032_Certificate)
55 Certificate cert(TestData::certVerisign, Certificate::FORM_BASE64);
56 Certificate::Fingerprint fin =
57 cert.getFingerprint(Certificate::FINGERPRINT_SHA1);
58 unsigned char buff[20] = {
59 0xb9, 0x72, 0x1e, 0xd5, 0x49,
60 0xed, 0xbf, 0x31, 0x84, 0xd8,
61 0x27, 0x0c, 0xfe, 0x03, 0x11,
62 0x19, 0xdf, 0xc2, 0x2b, 0x0a
64 RUNNER_ASSERT_MSG(fin.size() == 20, "Wrong size of fingerprint");
66 for (size_t i = 0; i < 20; ++i) {
67 RUNNER_ASSERT_MSG(fin[i] == buff[i], "Fingerprint mismatch");
72 * test: Certificate::getAlternativeNameDNS
73 * description: Certificate should parse data passed to object constructor.
74 * expected: Function getAlternativeNameDNS should return list of
75 * alternativeNames hardcoded in certificate.
77 RUNNER_TEST(T0033_Certificate)
79 Certificate cert(TestData::certVerisign, Certificate::FORM_BASE64);
80 Certificate::AltNameSet nameSet = cert.getAlternativeNameDNS();
81 RUNNER_ASSERT(nameSet.size() == 8);
82 std::string str("verisign.com");
83 RUNNER_ASSERT(nameSet.find(str) != nameSet.end());
84 str = std::string("fake.com");
85 RUNNER_ASSERT(nameSet.find(str) == nameSet.end());
89 * test: Certificate::isCA
90 * description: Certificate should parse data passed to object constructor.
91 * expected: 1st and 2nd certificate should be identified as CA.
93 RUNNER_TEST(T0034_Certificate_isCA)
95 Certificate cert1(TestData::googleCA, Certificate::FORM_BASE64);
96 RUNNER_ASSERT(cert1.isCA() > 0);
97 Certificate cert2(TestData::google2nd, Certificate::FORM_BASE64);
98 RUNNER_ASSERT(cert2.isCA() > 0);
99 Certificate cert3(TestData::google3rd, Certificate::FORM_BASE64);
100 RUNNER_ASSERT(cert3.isCA() == 0);
104 * test: Certificate::getAlternativeNameURI
105 * description: Certificate should parse data passed to object constructor.
106 * expected: Function getAlternativeNameURI should return list of
107 * alternativeNames hardcoded in certificate.
109 RUNNER_TEST(T0035_Certificate_AltNameURI)
111 Certificate cert(TestData::certGenUriIncluded, Certificate::FORM_BASE64);
112 Certificate::AltNameSet nameSet = cert.getAlternativeNameURI();
113 RUNNER_ASSERT(nameSet.size() == 8);
114 std::string str("URN:tizen:deviceid=2.0#R1q+lPsGCM7PAEPvzUcc38xPCLw=");
115 RUNNER_ASSERT(nameSet.find(str) != nameSet.end());
116 str = std::string("fakeURI");
117 RUNNER_ASSERT(nameSet.find(str) == nameSet.end());