Merge test folder of test branch
[iotivity.git] / test / src / tc / cs / gtest / csdk / src / stc / CSCsdkGetInvitationTest.cpp
1 /******************************************************************
2  *
3  * Copyright 2018 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  ******************************************************************/
21 #ifdef TC_DISABLE
22
23 #include "CSCsdkCloudHelper.h"
24 #include "CSCsdkUtilityHelper.h"
25
26
27 class CSCsdkGetInvitationTest_stc: public ::testing::Test
28 {
29 protected:
30
31     CSCsdkCloudHelper m_CloudAclHelper;
32     string m_hostAddress = COAP_HOST_ADDRESS;
33     string m_authProvider = "github";
34     string m_authCode = "";
35     string m_groupId = "";
36     string m_aclId = "";
37     string m_uidControlee = "";
38     string m_authTokenControlee = "";
39
40     OCAccountManager::Ptr m_accountMgrControlee = nullptr;
41
42     std::vector< std::string > m_deviceIdAddded;
43     std::vector< std::string > m_deviceIdRemoving;
44     uint16_t m_credId = 0;
45     ByteArray_t m_trustCertChainArray =
46     { 0, 0 };
47
48     OCDevAddr m_endPoint;
49     cloudAce_t *m_aces = NULL;
50
51     virtual void SetUp()
52     {
53         CommonUtil::copyFile(CLOUD_ACL_CONTROLLER_DAT_BACKUP, CLOUD_ACL_CONTROLLER_DAT);
54         CommonUtil::copyFile(ROOT_CERT_FILE_BACKUP, ROOT_CERT_FILE);
55         CommonTestUtil::runCommonTCSetUpPart();
56
57         if (!m_CloudAclHelper.initCloudACLClient())
58         {
59             SET_FAILURE(m_CloudAclHelper.getFailureMessage());
60             return;
61         }
62
63         m_hostAddress = CloudCommonUtil::getDefaultHostAddess();
64         m_endPoint = CloudCommonUtil::getDefaultEndPoint();
65         m_aces = CSCsdkUtilityHelper::createCloudAces();
66
67 #ifdef __TLS_ON__
68         setCoapPrefix(true);
69         CASelectCipherSuite(MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256, CA_ADAPTER_TCP);
70 #endif
71
72         CSCsdkCloudHelper::readFile(ROOT_CERT_FILE, (OCByteString *) &m_trustCertChainArray);
73         m_accountMgrControlee = OCPlatform::constructAccountManagerObject(m_hostAddress,
74                 CT_ADAPTER_TCP);
75
76         if (!m_CloudAclHelper.saveTrustCertChain(m_trustCertChainArray.data, m_trustCertChainArray.len,
77                         OIC_ENCODING_PEM, &m_credId, OC_STACK_OK))
78         {
79             SET_FAILURE(m_CloudAclHelper.getFailureMessage());
80             return;
81         }
82
83         if (!CloudCommonUtil::signIn(m_accountMgrControlee))
84         {
85             SET_FAILURE(ERROR_SIGN_IN);
86             return;
87         }
88     }
89
90     virtual void TearDown()
91     {
92         CommonTestUtil::runCommonTCTearDownPart();
93     }
94 };
95
96 /**
97  * @since           2017-02-23
98  * @see             OCStackResult OCRegisterPersistentStorageHandler(OCPersistentStorage* persistentStorageHandler)
99  * @see             OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode)
100  * @see             void setCoapPrefix(bool secured)
101  * @see             CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter)
102  * @see             OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize, OicEncodingType_t encodingType, uint16_t *credId)
103  * @see            OCStackResult signIn(const std::string& userUuid, const std::string& accessToken, PostCallback cloudConnectHandler)
104  * @objective       Test OCCloudAclGetInvitation positively with regular data
105  * @target          OCStackResult OCCloudAclGetInvitation(void* ctx, const char *userId, const OCDevAddr *endPoint, OCCloudResponseCB callback)
106  * @test_data       regular data for target API
107  * @pre_condition   Run iotivity_cs_server
108  * @procedure       1. call OCRegisterPersistentStorageHandler
109  *                  2. call OCInit
110  *                  3. call setCoapPrefix wtih true param
111  *                  4. call CASelectCipherSuite with MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA and CA_ADAPTER_TCP
112  *                  5. call signIn
113  *                  6. call OCCloudAclGetInvitation
114  * @post_condition  none
115  * @expected        OCCloudAclGetInvitation will return OC_STACK_OK
116  */
117 #if defined(__LINUX__) || defined(__TIZEN__)
118 TEST_F(CSCsdkGetInvitationTest_stc, OCCloudAclGetInvitation_SRC_P)
119 {
120     if (!m_CloudAclHelper.cloudAclGetInvitation((void*)CTX_GET_GROUP_INVITATION, NULL, &m_endPoint, CSCsdkCloudHelper::cloudResponseCB, OC_STACK_OK))
121     {
122         SET_FAILURE(m_CloudAclHelper.getFailureMessage());
123     }
124 }
125 #endif
126
127 /**
128  * @since           2017-02-23
129  * @see             OCStackResult OCRegisterPersistentStorageHandler(OCPersistentStorage* persistentStorageHandler)
130  * @see             OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode)
131  * @see             void setCoapPrefix(bool secured)
132  * @see             CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter)
133  * @see             OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize, OicEncodingType_t encodingType, uint16_t *credId)
134  * @see             OCStackResult signIn(const std::string& userUuid, const std::string& accessToken, PostCallback cloudConnectHandler)
135  * @see             OCStackResult OCCloudAclGetInvitation(void* ctx, const char *userId, const OCDevAddr *endPoint, OCCloudResponseCB callback)
136  * @objective       Test OCCloudAclGetInvitation positively with regular data
137  * @target          OCStackResult OCCloudAclDeleteInvitation(void* ctx, const char *userId, const char *groupId, const OCDevAddr *endPoint, OCCloudResponseCB callback)
138  * @test_data       regular data for target API
139  * @pre_condition   Run iotivity_cs_server
140  * @procedure       1. call OCRegisterPersistentStorageHandler
141  *                  2. call OCInit
142  *                  3. call setCoapPrefix wtih true param
143  *                  4. call CASelectCipherSuite with MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA and CA_ADAPTER_TCP
144  *                  5. call signIn
145  *                  6. call OCCloudAclGetInvitation
146  *                  7. call OCCloudAclDeleteInvitation
147  * @post_condition  none
148  * @expected        OCCloudAclDeleteInvitation will return OC_STACK_OK
149  */
150 #if defined(__LINUX__) || defined(__TIZEN__)
151 TEST_F(CSCsdkGetInvitationTest_stc, OCCloudAclDeleteInvitation_SRC_P)
152 {
153     if (!m_CloudAclHelper.cloudAclGetInvitation((void*)CTX_GET_GROUP_INVITATION, NULL, &m_endPoint, CSCsdkCloudHelper::cloudResponseCB, OC_STACK_OK))
154     {
155         SET_FAILURE(m_CloudAclHelper.getFailureMessage());
156         return;
157     }
158
159     if (!m_CloudAclHelper.cloudAclDeleteInvitation((void*)CTX_DELETE_INVITATION, NULL, m_groupId.c_str(), &m_endPoint, CSCsdkCloudHelper::cloudResponseCB, OC_STACK_OK))
160     {
161         SET_FAILURE(m_CloudAclHelper.getFailureMessage());
162     }
163 }
164 #endif
165
166 /**
167  * @since           2017-02-23
168  * @see             OCStackResult OCRegisterPersistentStorageHandler(OCPersistentStorage* persistentStorageHandler)
169  * @see             OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode)
170  * @see             void setCoapPrefix(bool secured)
171  * @see             CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter)
172  * @see             OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize, OicEncodingType_t encodingType, uint16_t *credId)
173  * @see             OCStackResult signIn(const std::string& userUuid, const std::string& accessToken, PostCallback cloudConnectHandler)
174  * @see             OCStackResult OCCloudAclGetInvitation(void* ctx, const char *userId, const OCDevAddr *endPoint, OCCloudResponseCB callback)
175  * @objective       Test OCCloudAclJoinToInvitedGroup positively with regular data
176  * @target          OCStackResult OCCloudAclJoinToInvitedGroup(void* ctx, const char *groupId, const OCDevAddr *endPoint, OCCloudResponseCB callback)
177  * @test_data       regular data for target API
178  * @pre_condition   Run iotivity_cs_server
179  * @procedure       1. call OCRegisterPersistentStorageHandler
180  *                  2. call OCInit
181  *                  3. call setCoapPrefix wtih true param
182  *                  4. call CASelectCipherSuite with MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA and CA_ADAPTER_TCP
183  *                  5. call signIn
184  *                  6. call OCCloudAclGetInvitation
185  *                  7. call OCCloudAclJoinToInvitedGroup
186  * @post_condition  none
187  * @expected        OCCloudAclJoinToInvitedGroup will return OC_STACK_OK
188  */
189 #if defined(__LINUX__) || defined(__TIZEN__)
190 TEST_F(CSCsdkGetInvitationTest_stc, OCCloudAclJoinToInvitedGroup_SRC_P)
191 {
192     if (!m_CloudAclHelper.cloudAclGetInvitation((void*)CTX_GET_GROUP_INVITATION, NULL, &m_endPoint, CSCsdkCloudHelper::cloudResponseCB, OC_STACK_OK))
193     {
194         SET_FAILURE(m_CloudAclHelper.getFailureMessage());
195         return;
196     }
197
198     if (!m_CloudAclHelper.cloudAclJoinToInvitedGroup((void*)CTX_JOIN_GROUP, m_groupId.c_str(), &m_endPoint, CSCsdkCloudHelper::cloudResponseCB, OC_STACK_OK))
199     {
200         SET_FAILURE(m_CloudAclHelper.getFailureMessage());
201     }
202 }
203 #endif
204
205 /**
206  * @since           2017-02-23
207  * @see             OCStackResult OCRegisterPersistentStorageHandler(OCPersistentStorage* persistentStorageHandler)
208  * @see             OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode)
209  * @see             void setCoapPrefix(bool secured)
210  * @see             CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter)
211  * @see             OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize, OicEncodingType_t encodingType, uint16_t *credId)
212  * @see             OCStackResult signIn(const std::string& userUuid, const std::string& accessToken, PostCallback cloudConnectHandler)
213  * @see             OCStackResult OCCloudAclGetInvitation(void* ctx, const char *userId, const OCDevAddr *endPoint, OCCloudResponseCB callback)
214  * @see             OCStackResult OCCloudAclJoinToInvitedGroup(void* ctx, const char *groupId, const OCDevAddr *endPoint, OCCloudResponseCB callback)
215  * @objective       Test OCCloudAclObserveGroup positively with regular data
216  * @target          OCStackResult OCCloudAclObserveGroup(void* ctx,const char *groupId, const OCDevAddr *endPoint, OCCloudResponseCB callback)
217  * @test_data       regular data for target API
218  * @pre_condition   Run iotivity_cs_server
219  * @procedure       1. call OCRegisterPersistentStorageHandler
220  *                  2. call OCInit
221  *                  3. call setCoapPrefix wtih true param
222  *                  4. call CASelectCipherSuite with MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA and CA_ADAPTER_TCP
223  *                  5. call signIn
224  *                  6. call OCCloudAclGetInvitation
225  *                  7. call OCCloudAclJoinToInvitedGroup
226  *                  8. call OCCloudAclObserveGroup
227  * @post_condition  none
228  * @expected        OCCloudAclObserveGroup will return OC_STACK_OK
229  */
230 #if defined(__LINUX__) || defined(__TIZEN__)
231 TEST_F(CSCsdkGetInvitationTest_stc, OCCloudAclObserveGroup_SRC_P)
232 {
233     if (!m_CloudAclHelper.cloudAclGetInvitation((void*)CTX_GET_GROUP_INVITATION, NULL, &m_endPoint, CSCsdkCloudHelper::cloudResponseCB, OC_STACK_OK))
234     {
235         SET_FAILURE(m_CloudAclHelper.getFailureMessage());
236         return;
237     }
238
239     if (!m_CloudAclHelper.cloudAclJoinToInvitedGroup((void*)CTX_JOIN_GROUP, m_groupId.c_str(), &m_endPoint, CSCsdkCloudHelper::cloudResponseCB, OC_STACK_OK))
240     {
241         SET_FAILURE(m_CloudAclHelper.getFailureMessage());
242         return;
243     }
244
245     if (!m_CloudAclHelper.cloudAclObserveGroup((void*)CTX_OBSERVER_GROUP, m_groupId.c_str(), &m_endPoint, CSCsdkCloudHelper::cloudResponseCB, OC_STACK_OK))
246     {
247         SET_FAILURE(m_CloudAclHelper.getFailureMessage());
248     }
249 }
250 #endif
251 #endif