2 * Copyright (c) 2000 - 2017 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
16 #include <ckm/ckm-manager-async.h>
17 #include <boost/test/unit_test.hpp>
24 class TestObserver : public ManagerAsync::Observer {
26 void ReceivedError(int) { throw std::invalid_argument("test observer recv err"); }
29 const std::string CERT_PEM =
30 "-----BEGIN CERTIFICATE-----\n"
31 "MIIDnzCCAoegAwIBAgIJAMH/ADkC5YSTMA0GCSqGSIb3DQEBBQUAMGYxCzAJBgNV\n"
32 "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMQ0wCwYDVQQKDARBQ01FMRAwDgYD\n"
33 "VQQLDAdUZXN0aW5nMSEwHwYDVQQDDBhUZXN0IHJvb3QgY2EgY2VydGlmaWNhdGUw\n"
34 "HhcNMTQxMjMwMTcyMTUyWhcNMjQxMjI3MTcyMTUyWjBmMQswCQYDVQQGEwJBVTET\n"
35 "MBEGA1UECAwKU29tZS1TdGF0ZTENMAsGA1UECgwEQUNNRTEQMA4GA1UECwwHVGVz\n"
36 "dGluZzEhMB8GA1UEAwwYVGVzdCByb290IGNhIGNlcnRpZmljYXRlMIIBIjANBgkq\n"
37 "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7QxvDKzyFCF3w9vC\n"
38 "9IDE/Yr12w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh7xk8qfEgH3da\n"
39 "eDoV59IZ9r543KM+g8jm6KffYGX1bIJVVY5OhBRbO9nY6byYpd5kbCIUB6dCf7/W\n"
40 "rQl1aIdLGFIegAzPGFPXDcU6F192686x54bxt/itMX4agHJ9ZC/rrTBIZghVsjJo\n"
41 "5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY+Cgw1Yoz+HHv31AllgFs\n"
42 "BquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsqGQIDAQABo1Aw\n"
43 "TjAdBgNVHQ4EFgQUt6pkzFt1PZlfYRL/HGnufF4frdwwHwYDVR0jBBgwFoAUt6pk\n"
44 "zFt1PZlfYRL/HGnufF4frdwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC\n"
45 "AQEAld7Qwq0cdzDQ51w1RVLwTR8Oy25PB3rzwEHcSGJmdqlMi3xOdaz80S1R1BBX\n"
46 "ldvGBG5Tn0vT7xSuhmSgI2/HnBpy9ocHVOmhtNB4473NieEpfTYrnGXrFxu46Wus\n"
47 "9m/ZnugcQ2G6C54A/NFtvgLmaC8uH8M7gKdS6uYUwJFQEofkjmd4UpOYSqmcRXhS\n"
48 "Jzd5FYFWkJhKJYp3nlENSOD8CUFFVGekm05nFN2gRVc/qaqQkEX77+XYvhodLRsV\n"
49 "qMn7nf7taidDKLO2T4bhujztnTYOhhaXKgPy7AtZ28N2wvX96VyAPB/vrchGmyBK\n"
50 "kOg11TpPdNDkhb1J4ZCh2gupDg==\n"
51 "-----END CERTIFICATE-----\n";
55 BOOST_AUTO_TEST_SUITE(ASYNC_OBSERVER_TEST)
57 BOOST_AUTO_TEST_CASE(base)
61 BOOST_REQUIRE_THROW(o.ReceivedError(0), std::invalid_argument);
63 BOOST_REQUIRE_NO_THROW(o.ReceivedSaveKey());
64 BOOST_REQUIRE_NO_THROW(o.ReceivedSaveCertificate());
65 BOOST_REQUIRE_NO_THROW(o.ReceivedSaveData());
66 BOOST_REQUIRE_NO_THROW(o.ReceivedSavePKCS12());
67 BOOST_REQUIRE_NO_THROW(o.ReceivedRemovedAlias());
69 BOOST_REQUIRE_NO_THROW(o.ReceivedKey(std::move(*Key::createAES(RawBuffer({
70 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
71 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
73 BOOST_REQUIRE_NO_THROW(o.ReceivedCertificate(std::move(*Certificate::create(
74 RawBuffer(CERT_PEM.begin(), CERT_PEM.end()), DataFormat::FORM_PEM))));
75 BOOST_REQUIRE_NO_THROW(o.ReceivedData(RawBuffer()));
76 BOOST_REQUIRE_NO_THROW(o.ReceivedPKCS12(PKCS12ShPtr()));
78 BOOST_REQUIRE_NO_THROW(o.ReceivedKeyAliasVector(AliasVector()));
79 BOOST_REQUIRE_NO_THROW(o.ReceivedCertificateAliasVector(AliasVector()));
80 BOOST_REQUIRE_NO_THROW(o.ReceivedDataAliasVector(AliasVector()));
82 BOOST_REQUIRE_NO_THROW(o.ReceivedCreateKeyAES());
83 BOOST_REQUIRE_NO_THROW(o.ReceivedCreateKeyPair());
85 BOOST_REQUIRE_NO_THROW(o.ReceivedGetCertificateChain(CertificateShPtrVector()));
87 BOOST_REQUIRE_NO_THROW(o.ReceivedCreateSignature(RawBuffer()));
88 BOOST_REQUIRE_NO_THROW(o.ReceivedVerifySignature());
89 BOOST_REQUIRE_NO_THROW(o.ReceivedOCSPCheck(0));
90 BOOST_REQUIRE_NO_THROW(o.ReceivedSetPermission());
91 BOOST_REQUIRE_NO_THROW(o.ReceivedEncrypted(RawBuffer()));
92 BOOST_REQUIRE_NO_THROW(o.ReceivedDecrypted(RawBuffer()));
95 BOOST_AUTO_TEST_SUITE_END()