Update Tizen 2.4 latest codes
[platform/core/security/cert-svc.git] / tests / capi / test_suite_02.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #include <string>
17
18 #include <openssl/x509.h>
19
20 #include <dpl/test/test_runner.h>
21 #include <dpl/log/log.h>
22 #include <memory>
23
24 #include <api_tests.h>
25
26 #include <cert-service.h>
27
28 RUNNER_TEST_GROUP_INIT(DEPRECATED_API)
29
30 typedef std::unique_ptr<CERT_CONTEXT, std::function<int(CERT_CONTEXT*)>> ScopedCertCtx;
31
32 /*
33  * author:      ---
34  * test:        PEM positive.
35  * description: Loading *.pem file.
36  * expect:      *.pem should load with no error.
37  */
38 RUNNER_TEST(deprecated_api_test01_pem_positive)
39 {
40     ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final);
41     RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR ==
42         cert_svc_load_file_to_context(ctx.get(), "/usr/share/cert-svc/cert-type/cert0.pem"));
43 }
44
45 /*
46  * author:      ---
47  * test:        DER positive.
48  * description: Loading *.der file.
49  * expect:      *.der file should load with no error.
50  */
51 RUNNER_TEST(deprecated_api_test02_der_positive)
52 {
53     ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final);
54     RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR ==
55         cert_svc_load_file_to_context(ctx.get(), "/usr/share/cert-svc/cert-type/cert1.der"));
56 }
57
58 /*
59  * author:      ---
60  * test:        PEM negative.
61  * description: Loading *.pem file.
62  * expect:      *.pom file should not load and return error.
63  */
64 RUNNER_TEST(deprecated_api_test03_pem_negative)
65 {
66     ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final);
67     RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR !=
68         cert_svc_load_file_to_context(ctx.get(), "/usr/share/cert-svc/cert-type/cert2fake.pem"));
69 }
70
71 /*
72  * author:      ---
73  * test:        DER negative.
74  * description: Loading *.der file.
75  * expect:      *.der file should not load and return error.
76  */
77 RUNNER_TEST(deprecated_api_test03_der_negative)
78 {
79     ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final);
80     RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR !=
81         cert_svc_load_file_to_context(ctx.get(), "/usr/share/cert-svc/cert-type/cert3fake.der"));
82 }
83