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)
committerUze Choi <uzchoi@samsung.com>
Tue, 31 Jan 2017 01:50:25 +0000 (01:50 +0000)
[KIM JungYong]
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.

[Philippe Coval]
Ported from 1.2-rel to master branch

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>
Signed-off-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16867
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Ziran Sun <ziran.sun@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 13436b5..86be73c 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 dab7ddd..992243e 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'])
 
 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
        container_gtest_env.AppendUnique(LIBS = ['resource_directory'])
@@ -165,7 +163,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 84624e1..490905e 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 7a5b8ca..59e7ff3 100644 (file)
@@ -73,8 +73,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
@@ -87,11 +91,19 @@ rcs_test_env.AppendTarget('rcs_client_test')
 
 # TODO: fix this test on linux and remove commented lines
 if rcs_test_env.get('TEST') == '1':
-    target_os = rcs_test_env.get('TARGET_OS')
-    if target_os in ['linux'] and rcs_test_env.get('SECURED') != '1':
+    if target_os in ['linux']:
         from tools.scons.RunTest import run_test
         run_test(rcs_test_env,
 #                'service_resource-encapsulation_unittests_rcs_client_test.memcheck',
                  '',
-                 'service/resource-encapsulation/unittests/rcs_client_test',
-                 rcs_client_test)
+                 '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"
+    }
+}