Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Merge branch 'issue-563' of github.com:dmcassel/roxy into issue-563
Browse files Browse the repository at this point in the history
Conflicts:
	src/test/suites/Framework Tests/routing.xqy
	src/test/suites/Framework Tests/site-index.xqy
  • Loading branch information
dmcassel committed Oct 24, 2016
2 parents a60f5f3 + ee0c9a8 commit 4fefd77
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 82 deletions.
132 changes: 127 additions & 5 deletions deploy/sample/ml-config.sample.xml
Expand Up @@ -457,6 +457,12 @@
<collections>
</collections>
<privileges>
<privilege>
<privilege-name>any-uri</privilege-name>
</privilege>
<privilege>
<privilege-name>rest-reader</privilege-name>
</privilege>
<privilege>
<privilege-name>xdmp:value</privilege-name>
</privilege>
Expand All @@ -469,6 +475,41 @@
<privilege>
<privilege-name>xdmp:with-namespaces</privilege-name>
</privilege>
<!-- START: required to run Roxy's rewriter-lib -->
<privilege>
<privilege-name>xdmp:get-server-field</privilege-name>
</privilege>
<privilege>
<privilege-name>xdmp:set-server-field</privilege-name>
</privilege>
<!-- END: required to run Roxy's rewriter-lib -->
</privileges>
</role>
<role>
<role-name>${app-role}-unit-test</role-name>
<description>A role for unit testing the ${app-name} application</description>
<privileges>
<privilege>
<privilege-name>xdmp:eval</privilege-name>
</privilege>
<privilege>
<privilege-name>xdmp:eval-in</privilege-name>
</privilege>
<privilege>
<privilege-name>xdmp:http-delete</privilege-name>
</privilege>
<privilege>
<privilege-name>xdmp:http-get</privilege-name>
</privilege>
<privilege>
<privilege-name>xdmp:http-head</privilege-name>
</privilege>
<privilege>
<privilege-name>xdmp:http-post</privilege-name>
</privilege>
<privilege>
<privilege-name>xdmp:http-put</privilege-name>
</privilege>
</privileges>
</role>
</roles>
Expand All @@ -485,18 +526,99 @@
</user>
</users>
<amps xmlns="http://marklogic.com/xdmp/security">
<!--
Sample amp. See the Understanding and Using Security Guide section 5.2 for
information about amps.
http://community.marklogic.com/pubs/5.0/books/security.pdf
<!--
Sample amp. See the Understanding and Using Security Guide section 5.2 for
information about amps.
http://community.marklogic.com/pubs/5.0/books/security.pdf
<amp>
<namespace>http://marklogic.com/roxy</namespace>
<local-name>sample</local-name>
<doc-uri>/app/models/sample.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>a-privileged-role</role-name>
</amp>
-->
-->
<!-- This group of amps allows the app-user to run the unit tests. If you
aren't using the Unit Test framework, or if you run them as admin, you
can safely delete these.
-->
<amp>
<namespace>http://marklogic.com/roxy/test-helper</namespace>
<local-name>list-from-database</local-name>
<doc-uri>/test/test-helper.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test-helper</namespace>
<local-name>get-modules-file</local-name>
<doc-uri>/test/test-helper.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test-helper</namespace>
<local-name>load-test-file</local-name>
<doc-uri>/test/test-helper.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test-helper</namespace>
<local-name>remove-modules</local-name>
<doc-uri>/test/test-helper.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test-helper</namespace>
<local-name>remove-modules-directories</local-name>
<doc-uri>/test/test-helper.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test-helper</namespace>
<local-name>http-get</local-name>
<doc-uri>/test/test-helper.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test/framework</namespace>
<local-name>http-head</local-name>
<doc-uri>/test/suites/Framework Tests/lib/framework-lib.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test/framework</namespace>
<local-name>http-delete</local-name>
<doc-uri>/test/suites/Framework Tests/lib/framework-lib.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test/framework</namespace>
<local-name>http-post</local-name>
<doc-uri>/test/suites/Framework Tests/lib/framework-lib.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test/framework</namespace>
<local-name>http-put</local-name>
<doc-uri>/test/suites/Framework Tests/lib/framework-lib.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
<amp>
<namespace>http://marklogic.com/roxy/test/framework</namespace>
<local-name>create-delete-target</local-name>
<doc-uri>/test/suites/Framework Tests/lib/framework-lib.xqy</doc-uri>
<db-name>${app-modules-db}</db-name>
<role-name>${app-role}-unit-test</role-name>
</amp>
</amps>
<privileges xmlns="http://marklogic.com/xdmp/security">
<!--
Expand Down
22 changes: 2 additions & 20 deletions src/test/default.xqy
Expand Up @@ -34,24 +34,6 @@ declare variable $FS-PATH as xs:string :=

declare option xdmp:mapping "false";

declare function t:list-from-database(
$database as xs:unsignedLong,
$root as xs:string,
$suite as xs:string?)
as xs:string*
{
xdmp:eval(
'xquery version "1.0-ml";
declare variable $PATH as xs:string external;
try { cts:uris((), (), cts:directory-query($PATH, "infinity")) }
catch ($ex) {
if ($ex/error:code ne "XDMP-URILXCNNOTFOUND") then xdmp:rethrow()
else xdmp:directory($PATH, "infinity")/xdmp:node-uri(.) }',
(xs:QName('PATH'),
fn:concat($root, 'test/suites/', ($suite, '')[1])),
<options xmlns="xdmp:eval"><database>{$database}</database></options>)
};

(:~
: Returns a list of the available tests. This list is magically computed based on the modules
:)
Expand All @@ -66,7 +48,7 @@ declare function t:list() {
if ($db-id = 0) then
xdmp:filesystem-directory(fn:concat($root, $FS-PATH, "test/suites"))/dir:entry[dir:type = "directory" and fn:not(dir:filename = $suite-ignore-list)]/dir:filename
else
let $uris := t:list-from-database($db-id, $root, ())
let $uris := helper:list-from-database($db-id, $root, ())
return
fn:distinct-values(
for $uri in $uris
Expand All @@ -79,7 +61,7 @@ declare function t:list() {
if ($db-id = 0) then
xdmp:filesystem-directory(fn:concat($root, $FS-PATH, "test/suites/", $suite))/dir:entry[dir:type = "file" and fn:not(dir:filename = $test-ignore-list)]/dir:filename[fn:ends-with(., ".xqy") or fn:ends-with(., ".sjs")]
else
let $uris := t:list-from-database(
let $uris := helper:list-from-database(
$db-id, $root, fn:concat($suite, '/'))
return
fn:distinct-values(
Expand Down
37 changes: 37 additions & 0 deletions src/test/suites/Framework Tests/lib/framework-lib.xqy
@@ -0,0 +1,37 @@
xquery version "1.0-ml";

module namespace frm = "http://marklogic.com/roxy/test/framework";

declare option xdmp:mapping "false";

(: Wrapper so that we can have an amp, allowing the default user to run this
: test without getting extra privileges.
:)
declare function frm:http-head($url, $options)
{
xdmp:http-head($url, $options)
};

(: Wrapper so that we can have an amp, allowing the default user to run this
: test without getting extra privileges.
:)
declare function frm:http-delete($url, $options)
{
xdmp:http-delete($url, $options)
};

(: Wrapper so that we can have an amp, allowing the default user to run this
: test without getting extra privileges.
:)
declare function frm:http-post($url, $options)
{
xdmp:http-post($url, $options)
};

(: Wrapper so that we can have an amp, allowing the default user to run this
: test without getting extra privileges.
:)
declare function frm:http-put($url, $options)
{
xdmp:http-put($url, $options)
};

0 comments on commit 4fefd77

Please sign in to comment.