Merge lp:~zorba-coders/zorba/staticcontextentityresolver-ignores-deny-access into lp:zorba

Proposed by Dennis Knochenwefel
Status: Merged
Approved by: Chris Hillery
Approved revision: 10776
Merged at revision: 10791
Proposed branch: lp:~zorba-coders/zorba/staticcontextentityresolver-ignores-deny-access
Merge into: lp:zorba
Diff against target: 149 lines (+65/-12)
4 files modified
src/types/schema/schema.cpp (+9/-7)
test/api/CMakeLists.txt (+6/-1)
test/api/import-hello.xsd (+7/-0)
test/api/userdefined_uri_resolution.cpp (+43/-4)
To merge this branch: bzr merge lp:~zorba-coders/zorba/staticcontextentityresolver-ignores-deny-access
Reviewer Review Type Date Requested Status
Chris Hillery Approve
Review via email: mp+102506@code.launchpad.net

Commit message

added a check and rethrow for error zerr::ZXQP0029_URI_ACCESS_DENIED when importing schemas

Description of the change

fix for bug #984759 (StaticContextEntityResolver ignores deny_access)

To post a comment you must log in.
10776. By Chris Hillery

Add test case demonstrating fix for bug 984759.

Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Chris Hillery (ceejatec) wrote :

I've added a test case and a commit message. Dennis, you should add an "Approve" review comment so it can clear the remote queue.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job staticcontextentityresolver-ignores-deny-access-2012-04-24T10-27-59.764Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/types/schema/schema.cpp'
2--- src/types/schema/schema.cpp 2012-04-23 10:46:38 +0000
3+++ src/types/schema/schema.cpp 2012-04-24 10:21:21 +0000
4@@ -255,15 +255,17 @@
5 else
6 return NULL;
7 }
8-// avoiding the warning that e is not used
9-#ifdef DO_TRACE
10 catch (ZorbaException const& e) {
11 TRACE("!!! ZorbaException: " << e );
12-#else
13- catch (ZorbaException const& ) {
14-#endif
15- //don't throw let Xerces resolve it
16- return NULL;
17+ if ( e.diagnostic() == zerr::ZXQP0029_URI_ACCESS_DENIED )
18+ {
19+ throw;
20+ }
21+ else
22+ {
23+ //don't throw let Xerces resolve it
24+ return NULL;
25+ }
26 }
27 }
28 }
29
30=== modified file 'test/api/CMakeLists.txt'
31--- test/api/CMakeLists.txt 2012-04-23 10:46:38 +0000
32+++ test/api/CMakeLists.txt 2012-04-24 10:21:21 +0000
33@@ -37,7 +37,12 @@
34 FOREACH (test ${TestsToRun})
35 GET_FILENAME_COMPONENT(TName ${test} NAME_WE)
36 SET (TestName "test/api/${TName}")
37- ZORBA_ADD_TEST(${TestName} APITests ${TName})
38+ ZORBA_ADD_TEST(${TestName} APITests ${TName}
39+ "${CMAKE_BINARY_DIR}/TEST_URI_PATH")
40 ENDFOREACH(test)
41
42+# Add importing schema for userdefined_uri_resolution test
43+DECLARE_ZORBA_SCHEMA(FILE import-hello.xsd
44+ URI http://www.zorba-xquery.com/import-hello TEST_ONLY)
45+
46 EXPECTED_FAILURE(test/api/test_static_context 3118348)
47
48=== added file 'test/api/import-hello.xsd'
49--- test/api/import-hello.xsd 1970-01-01 00:00:00 +0000
50+++ test/api/import-hello.xsd 2012-04-24 10:21:21 +0000
51@@ -0,0 +1,7 @@
52+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
53+ xmlns="http://www.zorba-xquery.com/import-hello"
54+ targetNamespace="http://www.zorba-xquery.com/import-hello"
55+ elementFormDefault="qualified">
56+ <xs:import schemaLocation="http://www.zorba-xquery.com/tutorials/helloworld.xsd"/>
57+</xs:schema>
58+
59
60=== modified file 'test/api/userdefined_uri_resolution.cpp'
61--- test/api/userdefined_uri_resolution.cpp 2012-04-23 10:46:38 +0000
62+++ test/api/userdefined_uri_resolution.cpp 2012-04-24 10:21:21 +0000
63@@ -82,7 +82,8 @@
64 EntityData const* aEntityData,
65 std::vector<zorba::String>& oUris) throw ()
66 {
67- if(aUri == "http://www.zorba-xquery.com/to-be-denied") {
68+ // Deny access to an URI that would otherwise work
69+ if(aUri == "http://www.zorba-xquery.com/tutorials/helloworld.xsd") {
70 oUris.push_back(URIMapper::DENY_ACCESS);
71 }
72 }
73@@ -208,8 +209,7 @@
74 }
75 catch (ZorbaException& e) {
76 std::cerr << e.what() << std::endl;
77- return false;
78- }
79+ return false; }
80 return true;
81 }
82
83@@ -269,7 +269,7 @@
84 try {
85 XQuery_t lQuery = aZorba->compileQuery
86 ("import schema namespace lm="
87- "'http://www.zorba-xquery.com/to-be-denied'; "
88+ "'http://www.zorba-xquery.com/tutorials/helloworld.xsd'; "
89 "validate{ <p>Hello World!</p> }", lContext);
90 std::cout << lQuery << std::endl;
91 } catch (ZorbaException& e) {
92@@ -282,11 +282,44 @@
93 return false;
94 }
95
96+bool test_deny_access_import(Zorba* aZorba, char* aUriPath)
97+{
98+ StaticContext_t lContext = aZorba->createStaticContext();
99+
100+ DenyAccessURIMapper lMapper;
101+ lContext->registerURIMapper(&lMapper);
102+
103+ try {
104+ // Import a schema which imports the denied URI - need to use StaticContext
105+ // to set the URI path for this. Merely importing this schema should fail.
106+ std::vector<zorba::String> lUriPath;
107+ lUriPath.push_back(aUriPath);
108+ lContext->setURIPath(lUriPath);
109+ XQuery_t lQuery = aZorba->compileQuery
110+ ("import schema namespace lm="
111+ "'http://www.zorba-xquery.com/import-hello'; "
112+ "1", lContext);
113+ std::cout << lQuery << std::endl;
114+ } catch (ZorbaException& e) {
115+ std::cout << "Caught exception: " << e.what() << std::endl;
116+ if (e.diagnostic() == zerr::ZXQP0029_URI_ACCESS_DENIED) {
117+ std::cout << "...the correct exception!" << std::endl;
118+ return true;
119+ }
120+ }
121+ return false;
122+}
123+
124 /**
125 * Main test entry point
126 */
127 int userdefined_uri_resolution(int argc, char* argv[])
128 {
129+ if (argc != 2) {
130+ std::cout << "Incorrect arguments passed to userdefined_uri_resolution()"
131+ << std::endl;
132+ return 1;
133+ }
134 void* lStore = StoreManager::getStore();
135 Zorba* lZorba = Zorba::getInstance(lStore);
136
137@@ -328,6 +361,12 @@
138 std::cout << " ... failed!" << std::endl;
139 }
140
141+ std::cout << "test_deny_access_import" << std::endl;
142+ if (!test_deny_access_import(lZorba, argv[1])) {
143+ retval = 1;
144+ std::cout << " ... failed!" << std::endl;
145+ }
146+
147 lZorba->shutdown();
148 zorba::StoreManager::shutdownStore(lStore);
149 return retval;

Subscribers

People subscribed via source and target branches