Imported Upstream version 1.1.1
[platform/upstream/iotivity.git] / resource / csdk / security / unittest / crlresourcetest.cpp
1 /******************************************************************
2 *
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************/
20 #ifdef __WITH_X509__
21
22 #include "gtest/gtest.h"
23 #include "logger.h"
24 #include "ocpayload.h"
25 #include "ocstack.h"
26 #include "oic_malloc.h"
27 #include "oic_string.h"
28 #include "resourcemanager.h"
29 #include "crlresource.h"
30 #include "securevirtualresourcetypes.h"
31 #include "srmtestcommon.h"
32 #include "srmutility.h"
33 #include "psinterface.h"
34 #include "security_internals.h"
35 #include "crl.h"
36
37 #define TAG  "SRM-CRL-UT"
38
39 void DeleteCrl(OicSecCrl_t *crl)
40 {
41     if (crl)
42     {
43         //Clean ThisUpdate
44         OICFree(crl->ThisUpdate.data);
45         crl->ThisUpdate.data = NULL;
46         //clean CrlData
47         OICFree(crl->CrlData.data);
48         crl->CrlData.data = NULL;
49         //Clean crl itself
50         OICFree(crl);
51         crl = NULL;
52     }
53 }
54
55  //InitCRLResource Tests
56 TEST(CRLResourceTest, InitCRLResource)
57 {
58     EXPECT_EQ(OC_STACK_INVALID_PARAM, InitCRLResource());
59 }
60
61 //DeInitCredResource Tests
62 TEST(CRLResourceTest, DeInitCRLResource)
63 {
64     EXPECT_EQ(OC_STACK_INVALID_PARAM, DeInitCRLResource());
65 }
66
67 //GetCRLResource Tests
68 TEST(CRLResourceTest, GetCRLResource)
69 {
70     OicSecCrl_t *nullCrl = GetCRLResource();
71     EXPECT_NE((OicSecCrl_t*)NULL, nullCrl);
72     DeleteCrl(nullCrl);
73 }
74
75 //CrlToCBORPayload Tests
76 TEST(CRLResourceTest, CrlToCBORPayload)
77 {
78     uint8_t *payload = NULL;
79     size_t size;
80     OicSecCrl_t *crl = GetCRLResource();
81     ASSERT_TRUE(NULL != crl);
82     size = crl->CrlData.len;
83     EXPECT_EQ(OC_STACK_OK, CrlToCBORPayload(crl, &payload, &size));
84     DeleteCrl(crl);
85     OICFree(payload);
86 }
87
88 //CBORPaylodToCrl Tests
89 TEST(CRLResourceTest, CBORPayloadToCrl)
90 {
91     uint8_t *payload = NULL;
92     size_t size;
93     OicSecCrl_t *crl = GetCRLResource();
94     ASSERT_TRUE(NULL != crl);
95     size = crl->CrlData.len;
96     EXPECT_EQ(OC_STACK_OK, CrlToCBORPayload(crl, &payload, &size));
97     DeleteCrl(crl);
98     crl = NULL;
99     EXPECT_EQ(OC_STACK_OK, CBORPayloadToCrl(payload, size, &crl));
100     DeleteCrl(crl);
101     OICFree(payload);
102 }
103
104 //GetDerCrl Tests
105 TEST(CRLResourceTest, GetDerCrl)
106 {
107     uint8_t crlData[CRL_MAX_LEN] = {0};
108     ByteArray crlArray = {crlData, CRL_MAX_LEN};
109     GetDerCrl(&crlArray);
110     EXPECT_NE(0, crlArray.len);
111 }
112
113 #endif