Commit 492772b0 authored by Oleksandr Dmytrenko's avatar Oleksandr Dmytrenko Committed by Aleksey

the security provisioning unittests

the security provisioning unittests
coverage up t0 75

Change-Id: Idd98ddf4c61de900842c4c7e9567c1ed527dc59a
Signed-off-by: default avatarOleksandr Dmytrenko <o.dmytrenko@samsung.com>
parent a05a151f
......@@ -59,7 +59,6 @@ cfg_client = 'oic_svr_db_client.dat'
server_bin = 'sample_server' + sptest_env.get('PROGSUFFIX')
unittest_bin = 'unittest' + sptest_env.get('PROGSUFFIX')
######################################################################
# Functions
######################################################################
......@@ -74,10 +73,9 @@ def clean_config():
safe_remove('oic_svr_db_server1.dat')
safe_remove('oic_svr_db_server2.dat')
safe_remove(cfg_client)
safe_remove('test.db')
safe_remove('PDM.db')
safe_remove('secureresourceprovider.dat')
safe_remove('device_properties.dat')
safe_remove('LIB_UNITTEST.dat')
safe_remove('secureresourceprovider.dat')
def start_srv(num):
......@@ -85,7 +83,10 @@ def start_srv(num):
print("no executable file")
return
cfg_srv = 'oic_svr_db_server' + num + '.dat'
copyfile(sec_provisioning_src_dir + 'oic_svr_db_server_justworks.dat', cfg_srv)
cfg = sec_provisioning_src_dir + 'oic_svr_db_server_justworks.dat'
if not path.exists(cfg):
raise Exception("cannot copy file: "+cfg)
copyfile(cfg, cfg_srv)
if not sptest_env.get('RELEASE'):
po = Popen(
unittest_build_dir + server_bin + ' ' + num + ' ' + cfg_srv,
......@@ -133,20 +134,20 @@ def kill_all():
def run_test(target, source, env):
kill_all()
clean_config()
copyfile(sec_provisioning_src_dir + 'oic_svr_db_client.dat', cfg_client)
cfg = sec_provisioning_src_dir + 'oic_svr_db_client.dat'
if not path.exists(cfg):
raise Exception("cannot copy file: "+cfg)
copyfile(cfg, cfg_client)
po_srv1 = start_srv(str(1))
po_srv2 = start_srv(str(2))
print("Waiting for servers start")
sleep(3)
call([unittest_build_dir + unittest_bin])
print("Servers are stopping")
sleep(3)
po_srv1.terminate()
po_srv2.terminate()
clean_config()
kill_all()
######################################################################
# Build flags
######################################################################
......@@ -178,7 +179,9 @@ sptest_env.PrependUnique(CPPPATH=[
'#resource/csdk/security/include',
'#resource/csdk/security/include/experimental',
'#resource/csdk/security/provisioning/src/cloud',
'#resource/csdk/security/provisioning/include/cloud/'
'#resource/csdk/security/provisioning/include/cloud/',
'#resource/csdk/logger/include/experimental',
'#extlibs/sqlite3'
])
sptest_env.PrependUnique(LIBS=[
......@@ -216,26 +219,29 @@ else:
# Source files and Targets
######################################################################
unittest_src = [
'pmutilitytest.cpp',
'secureresourceprovider.cpp',
'provisioningdatabasemanager.cpp',
'ocprovisioningmanager.cpp',
'credentialgeneratortest.cpp',
'otmunittest.cpp',
]
if sptest_env.get('WITH_TCP') == True and sptest_env.get('WITH_CLOUD') == True:
unittest_src = unittest_src + [
'cloudresource.cpp',
if target_os in ['linux']:
unittest_src = [
'tools.cpp',
'ocprovisioningmanager.cpp',
'pmutilitytest.cpp',
'secureresourceprovider.cpp',
'provisioningdatabasemanager.cpp',
'oxmjustworks.cpp',
'otmcontextlist.cpp',
'ownershiptransfermanager.cpp',
'oxmmanufacturercert.cpp',
'oxmrandompin.cpp',
'credentialgenerator.cpp',
'otmunittest.cpp'
]
if sptest_env.get('WITH_TCP') == True and sptest_env.get('WITH_CLOUD') == True:
unittest_src.append('cloudresource.cpp')
tests = sptest_env.Program(unittest_bin, unittest_src)
server = sptest_env.Program(server_bin, ['sampleserver.cpp'])
tests = sptest_env.Program(unittest_bin, unittest_src)
server = sptest_env.Program(server_bin, ['sampleserver.cpp'])
Alias('build', [tests, server])
Alias('build', [tests, server])
if sptest_env.get('TEST') == '1':
if target_os in ['linux', 'windows']:
if sptest_env.get('TEST') == '1':
print("Start tests")
sptest_env.Command('start', [server_bin, unittest_bin], Action(run_test))
/* *****************************************************************
*
* Copyright 2015 Samsung Electronics All Rights Reserved.
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
*
*
......@@ -17,15 +17,50 @@
* limitations under the License.
*
* *****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gtest/gtest.h>
#include "credentialgenerator.h"
#include "oic_malloc.h"
#ifdef __cplusplus
extern "C" {
#endif
TEST(PMGeneratePairWiseCredentialsTest, InvalidFirstDevID)
#include "ocprovisioningmanager.h"
#include "../src/credentialgenerator.c"
#include "tools.h"
#undef TAG
#ifdef __cplusplus
}
#endif
#undef TAG
#define TAG "CG_UNITTEST"
#define SVR_DB_FILE_NAME TAG".dat"
#define PM_DB_FILE_NAME TAG".db"
using namespace std;
class CG : public ::testing::Test
{
public:
static void SetUpTestCase()
{
IOT_Init(PM_DB_FILE_NAME);
}
static void TearDownTestCase()
{
IOT_DeInit(PM_DB_FILE_NAME);
}
};
TEST_F(CG, PMGeneratePairWiseCredentialsInvalidFirstDevID)
{
OicUuid_t *SecondDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
if(SecondDevID)
OicUuid_t *SecondDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
if (SecondDevID)
{
SecondDevID->id[0] = 2;
}
......@@ -37,15 +72,15 @@ TEST(PMGeneratePairWiseCredentialsTest, InvalidFirstDevID)
OICFree(SecondDevID);
}
TEST(PMGeneratePairWiseCredentialsTest, InvalidSecondDevID)
TEST_F(CG, PMGeneratePairWiseCredentialsInvalidSecondDevID)
{
OicUuid_t *firstDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
if(firstDevID)
OicUuid_t *firstDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
if (firstDevID)
{
firstDevID->id[0] = 1;
}
OicUuid_t *provisioningDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
if(provisioningDevID)
OicUuid_t *provisioningDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
if (provisioningDevID)
{
provisioningDevID->id[0] = 2;
}
......@@ -58,20 +93,20 @@ TEST(PMGeneratePairWiseCredentialsTest, InvalidSecondDevID)
OICFree(provisioningDevID);
}
TEST(PMGeneratePairWiseCredentialsTest, InvalidCred)
TEST_F(CG, PMGeneratePairWiseCredentialsInvalidCred)
{
OicUuid_t *firstDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
if(firstDevID)
OicUuid_t *firstDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
if (firstDevID)
{
firstDevID->id[0] = 1;
}
OicUuid_t *SecondDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
if(SecondDevID)
OicUuid_t *SecondDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
if (SecondDevID)
{
SecondDevID->id[0] = 2;
}
OicUuid_t *provisioningDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
if(provisioningDevID)
OicUuid_t *provisioningDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
if (provisioningDevID)
{
provisioningDevID->id[0] = 3;
}
......@@ -82,3 +117,29 @@ TEST(PMGeneratePairWiseCredentialsTest, InvalidCred)
OICFree(SecondDevID);
OICFree(provisioningDevID);
}
TEST_F(CG, PMGeneratePairWiseCredentialsFull)
{
OicUuid_t *firstDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
EXPECT_TRUE(NULL != firstDevID);
ConvertStrToUuid("11111111-1234-1234-1234-123456789011", firstDevID);
OicUuid_t *secondDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
EXPECT_TRUE(NULL != secondDevID);
ConvertStrToUuid("11111111-1234-1234-1234-123456789012", secondDevID);
OicSecRole_t *firstRole = (OicSecRole_t *)OICMalloc(sizeof(OicSecRole_t));
OicSecRole_t *secondRole = (OicSecRole_t *)OICMalloc(sizeof(OicSecRole_t));
OicSecCred_t *firstCred = NULL;
OicSecCred_t *secondCred = NULL;
EXPECT_EQ(OC_STACK_OK, PMGeneratePairWiseCredentials(SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_256,
firstDevID, secondDevID, firstRole, secondRole, &firstCred, &secondCred));
OICFree(firstCred->privateData.data);
OICFree(secondCred->privateData.data);
OICFree(secondCred);
OICFree(firstCred);
OICFree(secondRole);
OICFree(firstRole);
OICFree(firstDevID);
OICFree(secondDevID);
}
/* *****************************************************************
*
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* *****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gtest/gtest.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "ocprovisioningmanager.h"
#include "../src/otmcontextlist.c"
#include "tools.h"
#undef TAG
#ifdef __cplusplus
}
#endif
#undef TAG
#define TAG "OCL_UNITTEST"
#define SVR_DB_FILE_NAME TAG".dat"
#define PM_DB_FILE_NAME TAG".db"
using namespace std;
class OCL : public ::testing::Test
{
public:
static void SetUpTestCase()
{
IOT_Init(PM_DB_FILE_NAME);
}
static void TearDownTestCase()
{
IOT_DeInit(PM_DB_FILE_NAME);
}
};
/* *****************************************************************
*
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* *****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gtest/gtest.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "ocprovisioningmanager.h"
#include "../src/oxmjustworks.c"
#include "tools.h"
#undef TAG
#ifdef __cplusplus
}
#endif
#define TAG "OXMJW_UNITTEST"
#define SVR_DB_FILE_NAME "oic_oxmjustworks.dat"
#define PM_DB_FILE_NAME "oic_oxmjustworks.db"
using namespace std;
class OXMJW : public ::testing::Test
{
public:
static void SetUpTestCase()
{
IOT_Init(PM_DB_FILE_NAME);
}
static void TearDownTestCase()
{
IOT_DeInit(PM_DB_FILE_NAME);
}
OCProvisionDev_t *g_ownedDevices = NULL;
};
TEST_F(OXMJW, CreateMVJustWorksSelectOxmPayload)
{
uint8_t *payload = NULL;
size_t size = 0;
bool propertiesToInclude[DOXM_PROPERTY_COUNT];
memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
propertiesToInclude[DOXM_OXMS] = true;
propertiesToInclude[DOXM_OXMSEL] = true;
propertiesToInclude[DOXM_SCT] = true;
propertiesToInclude[DOXM_OWNED] = true;
propertiesToInclude[DOXM_DEVICEUUID] = true;
propertiesToInclude[DOXM_DEVOWNERUUID] = true;
OTMContext_t *otmCtx = createOTMContext();
EXPECT_EQ(OC_STACK_OK, CreateMVJustWorksSelectOxmPayload(otmCtx, &payload, &size));
EXPECT_TRUE(payload != NULL);
freeOTMContext(otmCtx);
}
/* *****************************************************************
*
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* *****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gtest/gtest.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "ocprovisioningmanager.h"
#include "../src/oxmmanufacturercert.c"
#include "tools.h"
#undef TAG
#ifdef __cplusplus
}
#endif
#define TAG "OXMMCERT_UNITTEST"
#define SVR_DB_FILE_NAME TAG".dat"
#define PM_DB_FILE_NAME TAG".db"
using namespace std;
class OXMMCERT : public ::testing::Test
{
public:
static void SetUpTestCase()
{
IOT_Init(PM_DB_FILE_NAME);
}
static void TearDownTestCase()
{
IOT_DeInit(PM_DB_FILE_NAME);
}
};
TEST_F(OXMMCERT, CreateMCertificateBasedSelectOxmPayload)
{
OTMContext_t *ctx = createOTMContext();
uint8_t *payload = NULL;
size_t size = 0;
EXPECT_EQ(OC_STACK_OK, CreateMCertificateBasedSelectOxmPayload(ctx, &payload, &size));
freeOTMContext(ctx);
}
TEST_F(OXMMCERT, CreateConMCertificateBasedSelectOxmPayload)
{
OTMContext_t *ctx = createOTMContext();
uint8_t *payload = NULL;
size_t size = 0;
EXPECT_EQ(OC_STACK_INVALID_PARAM, CreateConMCertificateBasedSelectOxmPayload(NULL, &payload,
&size));
EXPECT_EQ(OC_STACK_OK, CreateConMCertificateBasedSelectOxmPayload(ctx, &payload, &size));
freeOTMContext(ctx);
}
TEST_F(OXMMCERT, CreateMCertificateBasedOwnerTransferPayload)
{
OTMContext_t *ctx = createOTMContext();
uint8_t *payload = NULL;
size_t size = 0;
EXPECT_EQ(OC_STACK_OK, CreateMCertificateBasedOwnerTransferPayload(ctx, &payload, &size));
freeOTMContext(ctx);
}
TEST_F(OXMMCERT, PrepareMCertificateCallback)
{
OTMContext_t *ctx = createOTMContext();
EXPECT_EQ(OC_STACK_OK, PrepareMCertificateCallback(ctx));
freeOTMContext(ctx);
}
TEST_F(OXMMCERT, CreateSecureSessionMCertificateCallback)
{
OTMContext_t *ctx = createOTMContext();
EXPECT_EQ(OC_STACK_OK, CreateSecureSessionMCertificateCallback(ctx));
freeOTMContext(ctx);
}
/* *****************************************************************
*
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* *****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gtest/gtest.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "tools.h"
#include "ocprovisioningmanager.h"
#include "../src/oxmrandompin.c"
#undef TAG
#ifdef __cplusplus
}
#endif
#undef TAG
#define TAG "ORP_UNITTEST"
#define SVR_DB_FILE_NAME TAG".dat"
#define PM_DB_FILE_NAME TAG".db"
using namespace std;
class ORP : public ::testing::Test
{
public:
static void SetUpTestCase()
{
IOT_Init(PM_DB_FILE_NAME);
}
static void TearDownTestCase()
{
IOT_DeInit(PM_DB_FILE_NAME);
}
};
TEST_F(ORP, CreatePinBasedOwnerTransferPayload)
{
OTMContext_t *ctx = createOTMContext();
uint8_t *payload = NULL;
size_t size = 0;
EXPECT_EQ(OC_STACK_OK, CreatePinBasedOwnerTransferPayload(ctx, &payload, &size));
ctx->selectedDeviceInfo->doxm->owned = false;
EXPECT_EQ(OC_STACK_INVALID_PARAM, CreatePinBasedOwnerTransferPayload(ctx, &payload, &size));
freeOTMContext(ctx);
}
TEST_F(ORP, InputPinCodeCallback)
{
OTMContext_t *ctx = createOTMContext();
EXPECT_EQ(OC_STACK_ERROR, InputPinCodeCallback(ctx));
freeOTMContext(ctx);
}
#if !defined(_WIN32)
TEST_F(ORP, CreateSecureSessionRandomPinCallback)
{
OTMContext_t *ctx = createOTMContext();
EXPECT_EQ(OC_STACK_OK, CreateSecureSessionRandomPinCallback(ctx));
freeOTMContext(ctx);
}
#endif
This diff is collapsed.
/* *****************************************************************
*
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* *****************************************************************/
#ifndef __UNITTEST_TOOLS__
#define __UNITTEST_TOOLS__
#ifdef __cplusplus
extern "C" {
#endif
#include "securevirtualresourcetypes.h"
#include "octypes.h"
#include "pmtypes.h"
#include "ownershiptransfermanager.h"
#include "cacommon.h"
#ifdef __cplusplus
}
#endif
#define UUID_SRV1 "11111111-1234-1234-1234-123456789011"
#define UUID_SRV2 "11111111-1234-1234-1234-123456789012"
FILE *fopen_config(const char *path, const char *mode);
OicSecDoxm_t *createDoxm();
void freeDoxm(OicSecDoxm_t *doxm);
OCDevAddr *setAddr(const char *ip, uint16_t port, OCTransportAdapter adapter);
OCProvisionDev_t *createProvisionDev();
void freeProvisionDev(OCProvisionDev_t *pd);
OTMContext_t *createOTMContext();
void freeOTMContext(OTMContext_t *otmCtx);
CAEndpoint_t *createEndpoint();
void freeEndpoint(CAEndpoint_t *endpoint);
OicUuid_t *createUuid();
OicUuid_t *createUuidWith(const char *uuidStr);
void freeUuid(OicUuid_t *uuid);
uint8_t *certData();
uint8_t *keyData();
const char *getPem