|
| 1 | +(: |
| 2 | + : eXist-db Open Source Native XML Database |
| 3 | + : Copyright (C) 2001 The eXist-db Authors |
| 4 | + : |
| 5 | + : info@exist-db.org |
| 6 | + : http://www.exist-db.org |
| 7 | + : |
| 8 | + : This library is free software; you can redistribute it and/or |
| 9 | + : modify it under the terms of the GNU Lesser General Public |
| 10 | + : License as published by the Free Software Foundation; either |
| 11 | + : version 2.1 of the License, or (at your option) any later version. |
| 12 | + : |
| 13 | + : This library is distributed in the hope that it will be useful, |
| 14 | + : but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + : Lesser General Public License for more details. |
| 17 | + : |
| 18 | + : You should have received a copy of the GNU Lesser General Public |
| 19 | + : License along with this library; if not, write to the Free Software |
| 20 | + : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | + :) |
| 22 | +xquery version "3.1"; |
| 23 | + |
| 24 | +(:~ |
| 25 | + : The sm: permission functions assign distinct error codes so callers can tell a |
| 26 | + : permission failure (EXXQDY0007) from an invalid-argument failure (EXXQDY0008) |
| 27 | + : by branching on $err:code rather than matching message text -- e.g. an HTTP API |
| 28 | + : mapping the former to 403 and the latter to 400. |
| 29 | + :) |
| 30 | +module namespace pec = "http://exist-db.org/test/securitymanager/permission-error-codes"; |
| 31 | + |
| 32 | +declare namespace test = "http://exist-db.org/xquery/xqsuite"; |
| 33 | +declare namespace sm = "http://exist-db.org/xquery/securitymanager"; |
| 34 | + |
| 35 | +declare variable $pec:col := "/db/permission-error-codes-test"; |
| 36 | +declare variable $pec:resource := $pec:col || "/locked.xml"; |
| 37 | + |
| 38 | +(: a resource owned by admin with no group/other access, so a non-owner non-dba |
| 39 | + (guest) is denied any chmod on it :) |
| 40 | +declare |
| 41 | + %test:setUp |
| 42 | +function pec:setup() { |
| 43 | + xmldb:create-collection("/db", "permission-error-codes-test"), |
| 44 | + xmldb:store($pec:col, "locked.xml", <locked/>), |
| 45 | + sm:chmod(xs:anyURI($pec:resource), "rwx------") |
| 46 | +}; |
| 47 | + |
| 48 | +declare |
| 49 | + %test:tearDown |
| 50 | +function pec:teardown() { |
| 51 | + if (xmldb:collection-available($pec:col)) then xmldb:remove($pec:col) else () |
| 52 | +}; |
| 53 | + |
| 54 | +(: invalid argument -> EXXQDY0008: sm:has-access requires a partial (<=3 char) mode :) |
| 55 | +declare |
| 56 | + %test:assertError("EXXQDY0008") |
| 57 | +function pec:has-access-overlong-mode() { |
| 58 | + sm:has-access(xs:anyURI("/db"), "rwxrwxrwx") |
| 59 | +}; |
| 60 | + |
| 61 | +(: invalid argument -> EXXQDY0008: sm:mode-to-octal rejects a malformed symbolic mode :) |
| 62 | +declare |
| 63 | + %test:assertError("EXXQDY0008") |
| 64 | +function pec:mode-to-octal-bad-syntax() { |
| 65 | + sm:mode-to-octal("not-a-valid-mode") |
| 66 | +}; |
| 67 | + |
| 68 | +(: permission denied -> EXXQDY0007: guest is neither owner nor dba of the locked resource :) |
| 69 | +declare |
| 70 | + %test:assertError("EXXQDY0007") |
| 71 | +function pec:guest-chmod-denied() { |
| 72 | + system:as-user("guest", "guest", sm:chmod(xs:anyURI($pec:resource), "rwxr-xr-x")) |
| 73 | +}; |
0 commit comments