service: [IOT-1562] Fix for unittest with SECURED at RE/RC
authorKIM JungYong <jyong2.kim@samsung.com>
Mon, 28 Nov 2016 08:33:18 +0000 (17:33 +0900)
committerPhil Coval <philippe.coval@osg.samsung.com>
Thu, 1 Dec 2016 13:59:10 +0000 (13:59 +0000)
When IoTivity was built with SECURED and TEST,
some of test case at RE and RC occurring crash.
because RE and RC has not set the precondition of security.

In this patch, added the security flow and persistence storage files at RE.
related security test case is disabled at RC.

Change-Id: I4094bd01cba84d395c408a56f4c57d4ebcb45b44
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Bug: https://jira.iotivity.org/browse/IOT-1562
Reviewed-on: https://gerrit.iotivity.org/gerrit/14837
Tested-by: Phil Coval <philippe.coval@osg.samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
service/resource-container/unittests/ResourceContainerTest.cpp
service/resource-container/unittests/SConscript
service/resource-encapsulation/unittests/DiscoveryManagerTest.cpp
service/resource-encapsulation/unittests/SConscript
service/resource-encapsulation/unittests/oic_svr_db_re_client.dat [new file with mode: 0644]
service/resource-encapsulation/unittests/oic_svr_db_re_client.json [new file with mode: 0644]

index 94415c3ea79e036e34fcfad01ba0f0ca78fc5e25..63100fa43de423ad2efee344e4f7723eef89dcf1 100644 (file)
 #include <unistd.h>
 #endif
 
-#include <string>
-#include <map>
-#include <vector>
-#include <memory>
 #include <algorithm>
 
 #include <UnitTestHelper.h>
 #include <gtest/gtest.h>
 #include <HippoMocks/hippomocks.h>
 
-#include "Configuration.h"
-#include "BundleActivator.h"
-#include "BundleResource.h"
 #include "RCSResourceContainer.h"
-#include "ResourceContainerBundleAPI.h"
 #include "ResourceContainerImpl.h"
-#include "RemoteResourceUnit.h"
+#include "SoftSensorResource.h"
 
 #include "RCSResourceObject.h"
 #include "RCSRemoteResourceObject.h"
-#include "SoftSensorResource.h"
 
 #include "ResourceContainerTestSimulator.h"
 
@@ -815,7 +806,11 @@ TEST_F(RemoteResourceUnitTest, startMonitoring)
     ptr->startMonitoring();
 }
 
+#ifdef SECURED
+TEST_F(RemoteResourceUnitTest, DISABLED_onCacheCBCalled)
+#else
 TEST_F(RemoteResourceUnitTest, onCacheCBCalled)
+#endif
 {
     bool isCalled = false;
     mocks.ExpectCallFunc(onCacheCB).Do(
index 309da048e396af0de987dc6fc86938e2cb9e0fe5..60d468094ceaa4db37eba4e8323a59cf08a1a87e 100644 (file)
@@ -50,9 +50,6 @@ else:
 if lib_env.get('LOGGING'):
     lib_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
-
-
-
 # Add third party libraries
 SConscript(src_dir + '/service/third_party_libs.scons', 'lib_env')
 
@@ -136,8 +133,9 @@ if int(containerJavaSupport):
         print ''
 
 if container_gtest_env.get('SECURED') == '1':
-       if container_gtest_env.get('WITH_TCP') == True:
-               container_gtest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
+    container_gtest_env.AppendUnique(CPPDEFINES = ['SECURED'])
+    if container_gtest_env.get('WITH_TCP') == True:
+        container_gtest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
 
 ######################################################################
 # build test bundle
@@ -162,7 +160,10 @@ test_bundle_env.InstallTarget(TestBundle, 'libTestBundle')
 ######################################################################
 # Build Test
 ######################################################################
-container_gtest_src = container_gtest_env.Glob('./*.cpp')
+if 'g++' in container_gtest_env.get('CXX'):
+    container_gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
+
+container_gtest_src = container_gtest_env.Glob('./ResourceContainerTest.cpp')
 
 container_test = container_gtest_env.Program('container_test', container_gtest_src)
 Alias("container_test", container_test)
index 84624e1addbe48e6bad51286878aef6a2759e660..490905ecad163c2acb1aeef81ffc24a554c50806 100755 (executable)
@@ -40,6 +40,19 @@ constexpr char RESOURCE_URI[]{ "/a/TemperatureSensor" };
 constexpr char RESOURCE_TYPE[]{ "resource.type" };
 constexpr char SECOND_RESOURCETYPE[]{ "resource.type.second" };
 
+#ifdef SECURED
+const char * SVR_DB_FILE_NAME = "./oic_svr_db_re_client.dat";
+//OCPersistent Storage Handlers
+static FILE* client_open(const char * /*path*/, const char *mode)
+{
+    std::string file_name = SVR_DB_FILE_NAME;
+#ifndef LOCAL_RUNNING
+    file_name = "./service/resource-encapsulation/unittests/oic_svr_db_re_client.dat";
+#endif
+    return fopen(file_name.c_str(), mode);
+}
+#endif
+
 void onResourceDiscovered(RCSRemoteResourceObject::Ptr)
 {
 
@@ -75,6 +88,14 @@ private:
 
 TEST(DiscoveryManagerTest, ThrowIfDiscoverWithEmptyCallback)
 {
+#ifdef SECURED
+    OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
+    OC::PlatformConfig cfg
+    { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0,
+            OC::QualityOfService::LowQos, &gps };
+    OC::OCPlatform::Configure(cfg);
+#endif
+
     EXPECT_THROW(RCSDiscoveryManager::getInstance()->discoverResource(RCSAddress::multicast(), { }),
             RCSInvalidParameterException);
 }
index 9584adaa8077dcaa1828802c1227d7c546764890..4943a0d7c553624d1d6032f5edac5b92559a3e94 100644 (file)
@@ -74,8 +74,12 @@ rcs_test_env.PrependUnique(LIBS = [
     'rcs_common'])
 
 if lib_env.get('SECURED') == '1':
-       if lib_env.get('WITH_TCP') == True:
-               rcs_test_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
+    rcs_test_env.AppendUnique(CPPDEFINES = ['SECURED'])
+    if lib_env.get('WITH_TCP') == True:
+        rcs_test_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
+
+if 'g++' in rcs_test_env.get('CXX'):
+    rcs_test_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
 
 ######################################################################
 # Build Test
@@ -89,8 +93,19 @@ rcs_test_env.AppendTarget('rcs_client_test')
 if rcs_test_env.get('TEST') == '1':
     target_os = rcs_test_env.get('TARGET_OS')
 # TODO: fix this test on linux and remove this comment line
-    if target_os in ['']:
+    if target_os in ['linux']:
         run_test(rcs_test_env,
                  '',
 #                'service_resource-encapsulation_unittests_rcs_client_test.memcheck',
                  'service/resource-encapsulation/unittests/rcs_client_test')
+else:
+    rcs_test_env.AppendUnique(CPPDEFINES = ['LOCAL_RUNNING'])
+    if lib_env.get('SECURED') == '1':
+        src_dir = rcs_test_env.get('SRC_DIR')
+        svr_db_src_dir = os.path.join(src_dir, 'service/resource-encapsulation/unittests/')
+        svr_db_build_dir = os.path.join(rcs_test_env.get('BUILD_DIR'), 'service', 'resource-encapsulation', 'unittests') + os.sep
+        rcs_test_env.Alias("install",
+            rcs_test_env.Install(svr_db_build_dir,
+                  os.path.join(svr_db_src_dir,
+                               'oic_svr_db_re_client.dat')))
+
diff --git a/service/resource-encapsulation/unittests/oic_svr_db_re_client.dat b/service/resource-encapsulation/unittests/oic_svr_db_re_client.dat
new file mode 100644 (file)
index 0000000..f806a20
Binary files /dev/null and b/service/resource-encapsulation/unittests/oic_svr_db_re_client.dat differ
diff --git a/service/resource-encapsulation/unittests/oic_svr_db_re_client.json b/service/resource-encapsulation/unittests/oic_svr_db_re_client.json
new file mode 100644 (file)
index 0000000..b6ff1aa
--- /dev/null
@@ -0,0 +1,107 @@
+{
+    "acl": {
+        "aclist": {
+            "aces": [
+                {
+                    "subjectuuid": "*",
+                    "resources": [
+                        {
+                            "href": "/oic/res",
+                            "rel": "",
+                            "rt": ["oic.wk.res"],
+                            "if": ["oic.if.ll"]
+                        },
+                        {
+                            "href": "/oic/d",
+                            "rel": "",
+                            "rt": ["oic.wk.d"],
+                            "if": ["oic.if.baseline", "oic.if.r"]
+                        },
+                        {
+                            "href": "/oic/p",
+                            "rel": "",
+                            "rt": ["oic.wk.p"],
+                            "if": ["oic.if.baseline", "oic.if.r"]
+                        },
+                        {
+                            "href": "/oic/sec/acl",
+                            "rel": "",
+                            "rt": ["oic.r.acl"],
+                            "if": ["oic.if.baseline"]
+                        },
+                        {
+                            "href": "/a/TemperatureSensor",
+                            "rel": "",
+                            "rt": ["resource.type"],
+                            "if": ["oic.if.baseline"]
+                        }
+                    ],
+                    "permission": 2
+                },
+                {
+                    "subjectuuid": "*",
+                    "resources": [
+                        {
+                            "href": "/oic/sec/doxm",
+                            "rel": "",
+                            "rt": ["oic.r.doxm"],
+                            "if": ["oic.if.baseline"]
+                        },
+                        {
+                            "href": "/oic/sec/pstat",
+                            "rel": "",
+                            "rt": ["oic.r.pstat"],
+                            "if": ["oic.if.baseline"]
+                        }
+                    ],
+                    "permission": 2
+                },
+                {
+                    "subjectuuid": "*",
+                    "resources": [
+                        {
+                            "href": "/a/TemperatureSensor",
+                            "rel": "",
+                            "rt": ["resource.type"],
+                            "if": ["oic.if.baseline"]
+                        }
+                    ],
+                    "permission": 6
+                }
+            ]
+        },
+        "rowneruuid" : "32323232-3232-3232-3232-323232323232"
+    },
+    "pstat": {
+        "isop": true,
+        "deviceuuid": "32323232-3232-3232-3232-323232323232",
+        "rowneruuid": "32323232-3232-3232-3232-323232323232",
+        "cm": 0,
+        "tm": 0,
+        "om": 4,
+        "sm": 4
+        },
+    "doxm": {
+        "oxms": [0],
+        "oxmsel": 0,
+        "sct": 1,
+        "owned": true,
+        "deviceuuid": "32323232-3232-3232-3232-323232323232",
+        "devowneruuid": "32323232-3232-3232-3232-323232323232",
+        "rowneruuid": "32323232-3232-3232-3232-323232323232"
+    },
+    "cred": {
+        "creds": [
+            {
+                "credid": 1,
+                "subjectuuid": "31313131-3131-3131-3131-313131313131",
+                "credtype": 1,
+                "privatedata": {
+                    "data": "AAAAAAAAAAAAAAAA",
+                    "encoding": "oic.sec.encoding.raw"
+                }
+            }
+        ],
+        "rowneruuid": "32323232-3232-3232-3232-323232323232"
+    }
+}