zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #08928
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
Till Westmann has proposed merging lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba.
Requested reviews:
Markos Zaharioudakis (markos-za)
Chris Hillery (ceejatec)
Matthias Brantner (matthias-brantner)
Related bugs:
Bug #988417 in Zorba: "block internal modules"
https://bugs.launchpad.net/zorba/+bug/988417
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-988417-block-internal-module/+merge/104207
Enables a user to disable an built-in module. This is done running through URI mapping (but not through URL resolution) during translation.
--
https://code.launchpad.net/~zorba-coders/zorba/bug-988417-block-internal-module/+merge/104207
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2012-04-26 13:25:13 +0000
+++ src/compiler/translator/translator.cpp 2012-05-01 06:06:20 +0000
@@ -2840,6 +2840,11 @@
// importing module that X has been imported.
if (atlist == NULL && static_context::is_builtin_module(targetNS))
{
+ // hust a test, this will throw, if the access is denied
+ std::vector<zstring> candidateURIs;
+ theRootSctx->get_candidate_uris(targetNS,
+ internal::EntityData::MODULE,
+ candidateURIs);
theRootSctx->add_imported_builtin_module(targetNS);
#ifdef NDEBUG
// We cannot skip the math or the sctx introspection modules because they
=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp 2012-04-27 10:20:33 +0000
+++ src/context/static_context.cpp 2012-05-01 06:06:20 +0000
@@ -1526,6 +1526,21 @@
}
}
+void static_context::get_candidate_uris(
+ zstring const& aUri,
+ internal::EntityData::Kind aEntityKind,
+ std::vector<zstring>& oComponents) const
+{
+ // Create a simple EntityData that just reports the specified Kind
+ internal::EntityData const lData(aEntityKind);
+
+ apply_uri_mappers(aUri, &lData, internal::URIMapper::CANDIDATE, oComponents);
+ if (oComponents.size() == 0)
+ {
+ oComponents.push_back(aUri);
+ }
+}
+
/***************************************************************************//**
=== modified file 'src/context/static_context.h'
--- src/context/static_context.h 2012-04-24 18:22:23 +0000
+++ src/context/static_context.h 2012-05-01 06:06:20 +0000
@@ -705,6 +705,15 @@
(zstring const& aUri, internal::EntityData::Kind aEntityKind,
std::vector<zstring>& oComponents) const;
+ /**
+ * Given a URI, populate a vector with a list of candidate URIs. If
+ * no candidate URIs are available, the vector will be populated
+ * with (only) the input URI.
+ */
+ void get_candidate_uris
+ (zstring const& aUri, internal::EntityData::Kind aEntityKind,
+ std::vector<zstring>& oComponents) const;
+
void set_uri_path(const std::vector<zstring>& aURIPath);
void get_uri_path(std::vector<zstring>& oURIPath) const;
=== modified file 'test/api/userdefined_uri_resolution.cpp'
--- test/api/userdefined_uri_resolution.cpp 2012-04-24 12:39:38 +0000
+++ test/api/userdefined_uri_resolution.cpp 2012-05-01 06:06:20 +0000
@@ -79,11 +79,13 @@
virtual ~DenyAccessURIMapper() {}
virtual void mapURI(const zorba::String aUri,
- EntityData const* aEntityData,
+ EntityData const*,
std::vector<zorba::String>& oUris) throw ()
{
// Deny access to an URI that would otherwise work
- if(aUri == "http://www.zorba-xquery.com/tutorials/helloworld.xsd";) {
+ if(aUri == "http://www.zorba-xquery.com/tutorials/helloworld.xsd"; ||
+ aUri == "http://www.zorba-xquery.com/modules/fetch"; ||
+ aUri == "http://expath.org/ns/file";) {
oUris.push_back(URIMapper::DENY_ACCESS);
}
}
@@ -259,7 +261,53 @@
return false;
}
-bool test_deny_access(Zorba* aZorba)
+bool test_deny_internal_module_access(Zorba* aZorba)
+{
+ StaticContext_t lContext = aZorba->createStaticContext();
+
+ DenyAccessURIMapper lMapper;
+ lContext->registerURIMapper(&lMapper);
+
+ try {
+ XQuery_t lQuery = aZorba->compileQuery
+ ("import module namespace fetch = "
+ "'http://www.zorba-xquery.com/modules/fetch'; "
+ "1 + 1", lContext);
+ std::cout << lQuery << std::endl;
+ } catch (ZorbaException& e) {
+ std::cout << "Caught exception: " << e.what() << std::endl;
+ if (e.diagnostic() == zerr::ZXQP0029_URI_ACCESS_DENIED) {
+ std::cout << "...the correct exception!" << std::endl;
+ return true;
+ }
+ }
+ return false;
+}
+
+bool test_deny_external_module_access(Zorba* aZorba)
+{
+ StaticContext_t lContext = aZorba->createStaticContext();
+
+ DenyAccessURIMapper lMapper;
+ lContext->registerURIMapper(&lMapper);
+
+ try {
+ XQuery_t lQuery = aZorba->compileQuery
+ ("import module namespace file = "
+ "'http://expath.org/ns/file'; "
+ "1 + 1", lContext);
+ std::cout << lQuery << std::endl;
+ } catch (ZorbaException& e) {
+ std::cout << "Caught exception: " << e.what() << std::endl;
+ if (e.diagnostic() == zerr::ZXQP0029_URI_ACCESS_DENIED) {
+ std::cout << "...the correct exception!" << std::endl;
+ return true;
+ }
+ }
+ return false;
+}
+
+bool test_deny_schema_access(Zorba* aZorba)
{
StaticContext_t lContext = aZorba->createStaticContext();
@@ -355,8 +403,20 @@
std::cout << " ...failed!" << std::endl;
}
- std::cout << "test_deny_access" << std::endl;
- if (!test_deny_access(lZorba)) {
+ std::cout << "test_deny_internal_module_access" << std::endl;
+ if (!test_deny_internal_module_access(lZorba)) {
+ retval = 1;
+ std::cout << " ... failed!" << std::endl;
+ }
+
+ std::cout << "test_deny_external_module_access" << std::endl;
+ if (!test_deny_external_module_access(lZorba)) {
+ retval = 1;
+ std::cout << " ... failed!" << std::endl;
+ }
+
+ std::cout << "test_deny_schema_access" << std::endl;
+ if (!test_deny_schema_access(lZorba)) {
retval = 1;
std::cout << " ... failed!" << std::endl;
}
Follow ups
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: noreply, 2012-05-05
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Zorba Build Bot, 2012-05-05
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Zorba Build Bot, 2012-05-05
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Till Westmann, 2012-05-04
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Till Westmann, 2012-05-04
-
Re: [Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Matthias Brantner, 2012-05-04
-
Re: [Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Markos Zaharioudakis, 2012-05-03
-
Re: [Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Chris Hillery, 2012-05-02
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Zorba Build Bot, 2012-05-02
-
Re: [Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Zorba Build Bot, 2012-05-02
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Zorba Build Bot, 2012-05-02
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Zorba Build Bot, 2012-05-02
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Till Westmann, 2012-05-02
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Till Westmann, 2012-05-02
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Till Westmann, 2012-05-02
-
[Merge] lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba
From: Till Westmann, 2012-05-01