Fix provisioning unit tests
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / unittest / credentialgeneratortest.cpp
1 /* *****************************************************************
2  *
3  * Copyright 2015 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 #include "gtest/gtest.h"
21 #include "credentialgenerator.h"
22 #include "oic_malloc.h"
23
24
25 TEST(PMGeneratePairWiseCredentialsTest, InvalidProvisioningtoolDevID)
26 {
27     OicUuid_t *firstDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
28     if(firstDevID)
29     {
30         firstDevID->id[0] = 1;
31     }
32     OicUuid_t *SecondDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
33     if(SecondDevID)
34     {
35         SecondDevID->id[0] = 2;
36     }
37     OicSecCred_t *cred1 = NULL;
38     OicSecCred_t *cred2 = NULL;
39     size_t keySize = OWNER_PSK_LENGTH_128;
40     EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE,
41              keySize, NULL, firstDevID, SecondDevID, NULL, NULL, &cred1, &cred2));
42     OICFree(firstDevID);
43     OICFree(SecondDevID);
44 }
45
46 TEST(PMGeneratePairWiseCredentialsTest, InvalidFirstDevID)
47 {
48     OicUuid_t *SecondDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
49     if(SecondDevID)
50     {
51         SecondDevID->id[0] = 2;
52     }
53     OicUuid_t *provisioningDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
54     if(provisioningDevID)
55     {
56         provisioningDevID->id[0] = 1;
57     }
58     OicSecCred_t *cred1 = NULL;
59     OicSecCred_t *cred2 = NULL;
60     size_t keySize = OWNER_PSK_LENGTH_128;
61     EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE,
62               keySize, provisioningDevID, NULL, SecondDevID, NULL, NULL, &cred1, &cred2));
63     OICFree(SecondDevID);
64     OICFree(provisioningDevID);
65 }
66
67 TEST(PMGeneratePairWiseCredentialsTest, InvalidSecondDevID)
68 {
69     OicUuid_t *firstDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
70     if(firstDevID)
71     {
72         firstDevID->id[0] = 1;
73     }
74     OicUuid_t *provisioningDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
75     if(provisioningDevID)
76     {
77         provisioningDevID->id[0] = 2;
78     }
79     OicSecCred_t *cred1 = NULL;
80     OicSecCred_t *cred2 = NULL;
81     size_t keySize = OWNER_PSK_LENGTH_128;
82     EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE, keySize,
83               provisioningDevID, firstDevID, NULL, NULL, NULL, &cred1, &cred2));
84     OICFree(firstDevID);
85     OICFree(provisioningDevID);
86 }
87
88 TEST(PMGeneratePairWiseCredentialsTest, InvalidCred)
89 {
90     OicUuid_t *firstDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
91     if(firstDevID)
92     {
93         firstDevID->id[0] = 1;
94     }
95     OicUuid_t *SecondDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
96     if(SecondDevID)
97     {
98         SecondDevID->id[0] = 2;
99     }
100     OicUuid_t *provisioningDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
101     if(provisioningDevID)
102     {
103         provisioningDevID->id[0] = 3;
104     }
105     size_t keySize = OWNER_PSK_LENGTH_128;
106     EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE, keySize,
107               provisioningDevID, firstDevID, SecondDevID, NULL, NULL, NULL, NULL));
108     OICFree(firstDevID);
109     OICFree(SecondDevID);
110     OICFree(provisioningDevID);
111 }