Prepare database to support CSP policy for whole widget.
authorAndrzej Surdej <a.surdej@samsung.com>
Fri, 25 Jan 2013 11:30:56 +0000 (12:30 +0100)
committerGerrit Code Review <gerrit2@kim11>
Wed, 6 Feb 2013 06:12:55 +0000 (15:12 +0900)
[Issue#] LINUXWRT-34
[Problem] Support for csp policy.
[Cause] N/A
[Solution] Prepared .wrt.db, widgetDAO and tests for csp handling.
[Verification] To verify build repo and run wrt-tests-dao. Two new tests
regarding csp should pass.

Change-Id: I35c332e7ebde48cc8efd7dc1e7949c7950f555ae

modules/widget_dao/dao/widget_dao.cpp
modules/widget_dao/dao/widget_dao_read_only.cpp
modules/widget_dao/include/dpl/wrt-dao-ro/config_parser_data.h
modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h
modules/widget_dao/orm/wrt_db
tests/dao/TestCases_WidgetDAO.cpp

index f22671e..3beb2ba 100644 (file)
@@ -437,6 +437,7 @@ DbWidgetHandle WidgetDAO::registerWidgetInfo(
     row.Set_author_name(widgetConfigurationInfo.authorName);
     row.Set_author_email(widgetConfigurationInfo.authorEmail);
     row.Set_author_href(widgetConfigurationInfo.authorHref);
+    row.Set_csp_policy(widgetConfigurationInfo.cspPolicy);
     row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
     row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
     row.Set_recognized(wacSecurity.isRecognized());
index 03ed365..df8421d 100644 (file)
@@ -670,6 +670,12 @@ bool WidgetDAOReadOnly::isTestWidget() const
     }
 }
 
+DPL::OptionalString WidgetDAOReadOnly::getCspPolicy() const
+{
+    WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
+    return row.Get_csp_policy();
+}
+
 bool WidgetDAOReadOnly::getWebkitPluginsRequired() const
 {
     WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
index eed7bd4..2241a7a 100755 (executable)
@@ -313,6 +313,9 @@ class ConfigParserData
     DPL::OptionalString tizenPkgId;
     DPL::OptionalString tizenAppId;
 
+    //csp polic for widget
+    DPL::OptionalString cspPolicy;
+
     //Application service model list
     ServiceInfoList appServiceList; //It will be removed.
     AppControlInfoList appControlList;
index fa09901..76292ad 100644 (file)
@@ -321,7 +321,7 @@ class WidgetDAOReadOnly
     /**
      * Returns tizenAppId for the specified widget
      *
-     * @return tzAppid; 
+     * @return tzAppid;
      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
      */
@@ -333,7 +333,7 @@ class WidgetDAOReadOnly
     /**
      * Returns WidgetPkgName for the specified widget
      *
-     * @return pkgName; 
+     * @return pkgName;
      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
      */
@@ -498,6 +498,13 @@ class WidgetDAOReadOnly
     DPL::OptionalString getVersion() const;
 
     /**
+     * This method is used as a getter for csp policy of widget. It should be
+     * provided in configuration file.
+     * @return global csp policy for widget
+     */
+    DPL::OptionalString getCspPolicy() const;
+
+    /**
      * This method returns list filed with Common Name entries from certificate.
      *
      * @return Common Name of Distribuotor End Entity certificate.
index 49ba6ee..9a41d5b 100755 (executable)
@@ -31,6 +31,7 @@ CREATE_TABLE(WidgetInfo)
     COLUMN(base_folder,             VARCHAR(256),  DEFAULT '')
     COLUMN(webkit_plugins_required, TINYINT,       DEFAULT 0)
     COLUMN(security_domain,         INT,           DEFAULT 0)
+    COLUMN(csp_policy,              TEXT,          DEFAULT '')
     COLUMN(recognized,              INT,           DEFAULT 0)
     COLUMN(wac_signed,              INT,           DEFAULT 0)
     COLUMN(distributor_signed,      INT,           DEFAULT 0)
index 13ea61c..0add48d 100644 (file)
@@ -977,4 +977,41 @@ RUNNER_TEST(widget_dao_test_wac_security)
     }
 }
 
+/*
+Name: widget_dao_test_register_scp
+Description: Tests inserting and returning scp policy information
+Expected: Value inserted into database should match values received from database
+*/
+RUNNER_TEST(widget_dao_test_register_scp)
+{
+    WacSecurityMock sec;
+    WidgetRegisterInfo regInfo;
+    DPL::OptionalString policy = DPL::FromUTF8String("Some awesome csp policy");
+    regInfo.configInfo.cspPolicy = policy;
+    {
+        // register widget
+        TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
+        WidgetDAO dao(tizenAppId);
+
+        RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getCspPolicy(), DPL::ToUTF8String(*policy));
+    }
+}
+
+/*
+Name: widget_dao_test_register_csp_empty
+Description: Tests inserting and returning empty csp policy
+Expected: Value inserted into database should match values received from database
+*/
+RUNNER_TEST(widget_dao_test_register_csp_empty)
+{
+    WacSecurityMock sec;
+    WidgetRegisterInfo regInfo;
+    {
+        // register widget
+        TizenAppId tizenAppId = REGISTER_WIDGET(regInfo, sec);
+        WidgetDAO dao(tizenAppId);
+
+        RUNNER_ASSERT_MSG(dao.getCspPolicy().IsNull(), "Policy is not null");
+    }
+}
 #undef RUNNER_ASSERT_WHAT_EQUALS