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
=== modified file 'src/types/schema/schema.cpp'
--- src/types/schema/schema.cpp 2012-04-23 10:46:38 +0000
+++ src/types/schema/schema.cpp 2012-04-24 10:21:21 +0000
@@ -255,15 +255,17 @@
255 else255 else
256 return NULL; 256 return NULL;
257 }257 }
258// avoiding the warning that e is not used
259#ifdef DO_TRACE
260 catch (ZorbaException const& e) {258 catch (ZorbaException const& e) {
261 TRACE("!!! ZorbaException: " << e );259 TRACE("!!! ZorbaException: " << e );
262#else260 if ( e.diagnostic() == zerr::ZXQP0029_URI_ACCESS_DENIED )
263 catch (ZorbaException const& ) {261 {
264#endif262 throw;
265 //don't throw let Xerces resolve it263 }
266 return NULL;264 else
265 {
266 //don't throw let Xerces resolve it
267 return NULL;
268 }
267 }269 }
268 }270 }
269 }271 }
270272
=== modified file 'test/api/CMakeLists.txt'
--- test/api/CMakeLists.txt 2012-04-23 10:46:38 +0000
+++ test/api/CMakeLists.txt 2012-04-24 10:21:21 +0000
@@ -37,7 +37,12 @@
37FOREACH (test ${TestsToRun})37FOREACH (test ${TestsToRun})
38 GET_FILENAME_COMPONENT(TName ${test} NAME_WE)38 GET_FILENAME_COMPONENT(TName ${test} NAME_WE)
39 SET (TestName "test/api/${TName}")39 SET (TestName "test/api/${TName}")
40 ZORBA_ADD_TEST(${TestName} APITests ${TName})40 ZORBA_ADD_TEST(${TestName} APITests ${TName}
41 "${CMAKE_BINARY_DIR}/TEST_URI_PATH")
41ENDFOREACH(test)42ENDFOREACH(test)
4243
44# Add importing schema for userdefined_uri_resolution test
45DECLARE_ZORBA_SCHEMA(FILE import-hello.xsd
46 URI http://www.zorba-xquery.com/import-hello TEST_ONLY)
47
43EXPECTED_FAILURE(test/api/test_static_context 3118348)48EXPECTED_FAILURE(test/api/test_static_context 3118348)
4449
=== added file 'test/api/import-hello.xsd'
--- test/api/import-hello.xsd 1970-01-01 00:00:00 +0000
+++ test/api/import-hello.xsd 2012-04-24 10:21:21 +0000
@@ -0,0 +1,7 @@
1<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
2 xmlns="http://www.zorba-xquery.com/import-hello"
3 targetNamespace="http://www.zorba-xquery.com/import-hello"
4 elementFormDefault="qualified">
5 <xs:import schemaLocation="http://www.zorba-xquery.com/tutorials/helloworld.xsd"/>
6</xs:schema>
7
08
=== modified file 'test/api/userdefined_uri_resolution.cpp'
--- test/api/userdefined_uri_resolution.cpp 2012-04-23 10:46:38 +0000
+++ test/api/userdefined_uri_resolution.cpp 2012-04-24 10:21:21 +0000
@@ -82,7 +82,8 @@
82 EntityData const* aEntityData,82 EntityData const* aEntityData,
83 std::vector<zorba::String>& oUris) throw ()83 std::vector<zorba::String>& oUris) throw ()
84 {84 {
85 if(aUri == "http://www.zorba-xquery.com/to-be-denied") {85 // Deny access to an URI that would otherwise work
86 if(aUri == "http://www.zorba-xquery.com/tutorials/helloworld.xsd") {
86 oUris.push_back(URIMapper::DENY_ACCESS);87 oUris.push_back(URIMapper::DENY_ACCESS);
87 }88 }
88 }89 }
@@ -208,8 +209,7 @@
208 }209 }
209 catch (ZorbaException& e) {210 catch (ZorbaException& e) {
210 std::cerr << e.what() << std::endl;211 std::cerr << e.what() << std::endl;
211 return false;212 return false; }
212 }
213 return true;213 return true;
214}214}
215215
@@ -269,7 +269,7 @@
269 try {269 try {
270 XQuery_t lQuery = aZorba->compileQuery270 XQuery_t lQuery = aZorba->compileQuery
271 ("import schema namespace lm="271 ("import schema namespace lm="
272 "'http://www.zorba-xquery.com/to-be-denied'; "272 "'http://www.zorba-xquery.com/tutorials/helloworld.xsd'; "
273 "validate{ <p>Hello World!</p> }", lContext);273 "validate{ <p>Hello World!</p> }", lContext);
274 std::cout << lQuery << std::endl;274 std::cout << lQuery << std::endl;
275 } catch (ZorbaException& e) {275 } catch (ZorbaException& e) {
@@ -282,11 +282,44 @@
282 return false;282 return false;
283}283}
284284
285bool test_deny_access_import(Zorba* aZorba, char* aUriPath)
286{
287 StaticContext_t lContext = aZorba->createStaticContext();
288
289 DenyAccessURIMapper lMapper;
290 lContext->registerURIMapper(&lMapper);
291
292 try {
293 // Import a schema which imports the denied URI - need to use StaticContext
294 // to set the URI path for this. Merely importing this schema should fail.
295 std::vector<zorba::String> lUriPath;
296 lUriPath.push_back(aUriPath);
297 lContext->setURIPath(lUriPath);
298 XQuery_t lQuery = aZorba->compileQuery
299 ("import schema namespace lm="
300 "'http://www.zorba-xquery.com/import-hello'; "
301 "1", lContext);
302 std::cout << lQuery << std::endl;
303 } catch (ZorbaException& e) {
304 std::cout << "Caught exception: " << e.what() << std::endl;
305 if (e.diagnostic() == zerr::ZXQP0029_URI_ACCESS_DENIED) {
306 std::cout << "...the correct exception!" << std::endl;
307 return true;
308 }
309 }
310 return false;
311}
312
285/**313/**
286 * Main test entry point314 * Main test entry point
287 */315 */
288int userdefined_uri_resolution(int argc, char* argv[])316int userdefined_uri_resolution(int argc, char* argv[])
289{317{
318 if (argc != 2) {
319 std::cout << "Incorrect arguments passed to userdefined_uri_resolution()"
320 << std::endl;
321 return 1;
322 }
290 void* lStore = StoreManager::getStore();323 void* lStore = StoreManager::getStore();
291 Zorba* lZorba = Zorba::getInstance(lStore); 324 Zorba* lZorba = Zorba::getInstance(lStore);
292325
@@ -328,6 +361,12 @@
328 std::cout << " ... failed!" << std::endl;361 std::cout << " ... failed!" << std::endl;
329 }362 }
330363
364 std::cout << "test_deny_access_import" << std::endl;
365 if (!test_deny_access_import(lZorba, argv[1])) {
366 retval = 1;
367 std::cout << " ... failed!" << std::endl;
368 }
369
331 lZorba->shutdown();370 lZorba->shutdown();
332 zorba::StoreManager::shutdownStore(lStore);371 zorba::StoreManager::shutdownStore(lStore);
333 return retval;372 return retval;

Subscribers

People subscribed via source and target branches