9 require_once
'PU_testcase_dcp_application.php';
16 "appRoot" => join(DIRECTORY_SEPARATOR, array(
21 "appName" =>
"TST_ACCESS",
23 "PU_data_dcp_access.ods"
35 $myAction = self::getAction();
37 $appConfig = self::appConfig();
38 $this->assertTrue(is_object(
self::$app) , sprintf(
"Application '%s' is not an object.", $appConfig[
'appName']));
40 if (isset(
$data[
'import'])) {
43 if (isset(
$data[
'import:data'])) {
47 foreach (
$data[
'tests'] as $testIdx => &
$test) {
48 if (isset(
$test[
'import'])) {
51 if (isset(
$test[
'import:data'])) {
55 $this->assertTrue(isset(
$test[
'has:permission']) && is_array(
$test[
'has:permission']) , sprintf(
"test#%s> Invalid data supplied by provider.", $testIdx));
57 foreach (
$test[
'has:permission'] as $checkIdx =>
$check) {
59 $this->assertTrue(
$user->isAlive() , sprintf(
"test#%s/check#%s> Could not get user with id '%s'.", $testIdx, $checkIdx,
$check[
'user']));
61 $this->assertTrue(is_numeric($wuser->id) , sprintf(
"test#%s/check#%s> Invalid user what id '%s' for user '%s'.", $testIdx, $checkIdx, $wuser->id,
$check[
'user']));
63 $this->
sudo($wuser->login);
65 $perm = $myAction->hasPermission(
$check[
'acl'],
$check[
'app']);
66 $err = sprintf(
"test#%s/check#%s> Unexpected permission %s (should be %s) for user %s on acl %s from app %s", $testIdx, $checkIdx, $perm ?
'true' :
'false',
$check[
'permission'] ?
'true' :
'false',
$check[
'user'],
$check[
'acl'],
$check[
'app']);
67 if ($perm !=
$check[
'permission']) {
69 $err.=
"\n\t" . $this->
prettySqlRelation(sprintf(
"Groups test#%s/check#%s", $testIdx, $checkIdx) ,
"SELECT l.login AS user, r.login AS group FROM users AS l, groups AS g, users AS r WHERE g.iduser = l.id AND g.idgroup = r.id");
70 $err.=
"\n\t" . $this->
prettySqlRelation(sprintf(
"Permission test#%s/check#%s", $testIdx, $checkIdx) ,
"SELECT u.login AS user, a.name AS app, c.name AS acl, p.id_acl AS permission, p.computed AS computed FROM users AS u, permission AS p, application AS a, acl AS c WHERE u.id = p.id_user AND p.id_application = a.id AND abs(p.id_acl) = c.id AND a.name = 'TST_ACCESS'");
72 $this->assertTrue($perm ==
$check[
'permission'],
$err);
74 $perm = $myAction->canExecute(
$check[
'action'],
$check[
'app']);
75 if (
$check[
'permission']) {
76 $this->assertTrue(
'' === $perm, sprintf(
"test#%s/check#%s> Unexpected canExecute %s (should be '') for user %s on action %s from app %s", $testIdx, $checkIdx, var_export($perm,
true) ,
$check[
'user'],
$check[
'action'],
$check[
'app']));
78 $regexp = sprintf(
'/no privilege (.+) for (\d+) %s/',
$check[
'action']);
79 $this->assertRegExp($regexp, $perm, sprintf(
"test#%s/check#%s> Unexpected canExecute %s (should match %s) for user %s on action %s from app %s", $testIdx, $checkIdx, var_export($perm,
true) , $regexp,
$check[
'user'],
$check[
'action'],
$check[
'app']));
90 $res = pg_query(self::$odb->dbid,
$sql);
94 $res = pg_fetch_all($res);
95 if (!is_array($res)) {
100 $colsWidth = array();
102 foreach ($res as $tuple) {
103 foreach ($tuple as $k => $v) {
104 if (!array_key_exists($k, $colsWidth)) {
105 $colsWidth[$k] = strlen($k);
107 $colsWidth[$k] = max($colsWidth[$k], strlen($v));
111 foreach ($res as $i => $tuple) {
113 foreach ($tuple as $k => $v) {
114 $line[] = sprintf(
"%" . ($colsWidth[$k] + 2) .
"s", $v);
119 foreach ($tuple as $k => $v) {
120 $header[] = sprintf(
"%" . ($colsWidth[$k] + 2) .
"s", $k);
122 $header = join(
" | ", $header);
125 $title = sprintf(
"%" . (
int)(strlen($header) / 2 + strlen(
$title) / 2) .
"s",
$title);
127 $out[] = str_repeat(
"-", strlen($header));
130 $out[] = str_repeat(
"-", strlen($header));
133 $out[] = join(
" | ", $line);
136 return join(
"\n",
$out) .
"\n";
150 "has:permission" => array(
153 "user" =>
"TST_U_HOMER_SIMPSON",
154 "app" =>
"TST_ACCESS",
155 "acl" =>
"TST_ACCESS_ACL_1",
156 "action" =>
"TST_ACCESS_ACTION_1",
160 "user" =>
"TST_U_HOMER_SIMPSON",
161 "app" =>
"TST_ACCESS",
162 "acl" =>
"TST_ACCESS_ACL_2",
163 "action" =>
"TST_ACCESS_ACTION_2",
164 "permission" =>
false
167 "user" =>
"TST_U_HOMER_SIMPSON",
168 "app" =>
"TST_ACCESS",
170 "action" =>
"TST_ACCESS_ACTION_FREE",
175 "user" =>
"TST_U_MARGE_SIMPSON",
176 "app" =>
"TST_ACCESS",
177 "acl" =>
"TST_ACCESS_ACL_1",
178 "action" =>
"TST_ACCESS_ACTION_1",
182 "user" =>
"TST_U_MARGE_SIMPSON",
183 "app" =>
"TST_ACCESS",
184 "acl" =>
"TST_ACCESS_ACL_2",
185 "action" =>
"TST_ACCESS_ACTION_2",
189 "user" =>
"TST_U_MARGE_SIMPSON",
190 "app" =>
"TST_ACCESS",
192 "action" =>
"TST_ACCESS_ACTION_FREE",
197 "user" =>
"TST_U_BART_SIMPSON",
198 "app" =>
"TST_ACCESS",
199 "acl" =>
"TST_ACCESS_ACL_1",
200 "action" =>
"TST_ACCESS_ACTION_1",
201 "permission" =>
false
204 "user" =>
"TST_U_BART_SIMPSON",
205 "app" =>
"TST_ACCESS",
206 "acl" =>
"TST_ACCESS_ACL_2",
207 "action" =>
"TST_ACCESS_ACTION_2",
208 "permission" =>
false
211 "user" =>
"TST_U_BART_SIMPSON",
212 "app" =>
"TST_ACCESS",
214 "action" =>
"TST_ACCESS_ACTION_FREE",
219 "user" =>
"TST_U_LISA_SIMPSON",
220 "app" =>
"TST_ACCESS",
221 "acl" =>
"TST_ACCESS_ACL_1",
222 "action" =>
"TST_ACCESS_ACTION_1",
223 "permission" =>
false
226 "user" =>
"TST_U_LISA_SIMPSON",
227 "app" =>
"TST_ACCESS",
228 "acl" =>
"TST_ACCESS_ACL_2",
229 "action" =>
"TST_ACCESS_ACTION_2",
233 "user" =>
"TST_U_LISA_SIMPSON",
234 "app" =>
"TST_ACCESS",
236 "action" =>
"TST_ACCESS_ACTION_FREE",
241 "user" =>
"TST_U_MAGGIE_SIMPSON",
242 "app" =>
"TST_ACCESS",
243 "acl" =>
"TST_ACCESS_ACL_1",
244 "action" =>
"TST_ACCESS_ACTION_1",
245 "permission" =>
false
248 "user" =>
"TST_U_MAGGIE_SIMPSON",
249 "app" =>
"TST_ACCESS",
250 "acl" =>
"TST_ACCESS_ACL_2",
251 "action" =>
"TST_ACCESS_ACTION_2",
255 "user" =>
"TST_U_MAGGIE_SIMPSON",
256 "app" =>
"TST_ACCESS",
258 "action" =>
"TST_ACCESS_ACTION_FREE",
265 "import:data" =>
"ACCESS;TST_G_G2;TST_ACCESS;TST_ACCESS_ACL_1",
266 "has:permission" => array(
268 "user" =>
"TST_U_MAGGIE_SIMPSON",
269 "app" =>
"TST_ACCESS",
270 "acl" =>
"TST_ACCESS_ACL_1",
271 "action" =>
"TST_ACCESS_ACTION_1",
275 "user" =>
"TST_U_MAGGIE_SIMPSON",
276 "app" =>
"TST_ACCESS",
278 "action" =>
"TST_ACCESS_ACTION_FREE",
285 "import:data" =>
"ACCESS;TST_G_G21;TST_ACCESS;-TST_ACCESS_ACL_1",
286 "has:permission" => array(
288 "user" =>
"TST_U_MAGGIE_SIMPSON",
289 "app" =>
"TST_ACCESS",
290 "acl" =>
"TST_ACCESS_ACL_1",
291 "action" =>
"TST_ACCESS_ACTION_1",
292 "permission" =>
false
295 "user" =>
"TST_U_MAGGIE_SIMPSON",
296 "app" =>
"TST_ACCESS",
298 "action" =>
"TST_ACCESS_ACTION_FREE",
dataTestAccessApplication()
static importDocument($file)
testAccessApplication($data)
prettySqlRelation($title, $sql)
if($file) if($subject==""&&$file) if($subject=="") $err