From f4142ad62558b1e79ffc899d3a373b3a379de7e8 Mon Sep 17 00:00:00 2001 From: Andrzej Surdej Date: Fri, 25 Jan 2013 12:30:56 +0100 Subject: [PATCH] Prepare database to support CSP policy for whole widget. [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 | 1 + modules/widget_dao/dao/widget_dao_read_only.cpp | 6 ++++ .../include/dpl/wrt-dao-ro/config_parser_data.h | 3 ++ .../include/dpl/wrt-dao-ro/widget_dao_read_only.h | 11 +++++-- modules/widget_dao/orm/wrt_db | 1 + tests/dao/TestCases_WidgetDAO.cpp | 37 ++++++++++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/modules/widget_dao/dao/widget_dao.cpp b/modules/widget_dao/dao/widget_dao.cpp index f22671e..3beb2ba 100644 --- a/modules/widget_dao/dao/widget_dao.cpp +++ b/modules/widget_dao/dao/widget_dao.cpp @@ -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()); diff --git a/modules/widget_dao/dao/widget_dao_read_only.cpp b/modules/widget_dao/dao/widget_dao_read_only.cpp index 03ed365..df8421d 100644 --- a/modules/widget_dao/dao/widget_dao_read_only.cpp +++ b/modules/widget_dao/dao/widget_dao_read_only.cpp @@ -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); diff --git a/modules/widget_dao/include/dpl/wrt-dao-ro/config_parser_data.h b/modules/widget_dao/include/dpl/wrt-dao-ro/config_parser_data.h index eed7bd4..2241a7a 100755 --- a/modules/widget_dao/include/dpl/wrt-dao-ro/config_parser_data.h +++ b/modules/widget_dao/include/dpl/wrt-dao-ro/config_parser_data.h @@ -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; diff --git a/modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h b/modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h index fa09901..76292ad 100644 --- a/modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h +++ b/modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h @@ -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. diff --git a/modules/widget_dao/orm/wrt_db b/modules/widget_dao/orm/wrt_db index 49ba6ee..9a41d5b 100755 --- a/modules/widget_dao/orm/wrt_db +++ b/modules/widget_dao/orm/wrt_db @@ -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) diff --git a/tests/dao/TestCases_WidgetDAO.cpp b/tests/dao/TestCases_WidgetDAO.cpp index 13ea61c..0add48d 100644 --- a/tests/dao/TestCases_WidgetDAO.cpp +++ b/tests/dao/TestCases_WidgetDAO.cpp @@ -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 -- 2.7.4