Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_openaccess.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package Dcp\Pu
5 */
6 
7 namespace Dcp\Pu;
8 
9 require_once 'PU_testcase_dcp_application.php';
10 
12 {
13  public static function appConfig()
14  {
15  return array(
16  "appRoot" => join(DIRECTORY_SEPARATOR, array(
18  "DCPTEST",
19  "app"
20  )) ,
21  "appName" => "TST_OPENACCESS",
22  "import" => array(
23  "PU_data_dcp_openaccess.ods"
24  ) ,
25  );
26  }
27  /**
28  * Test ACCESS on application/action
29  * @param array $data test specification
30  * @return void
31  * @dataProvider dataApplicationToken
32  */
33  public function testApplicationToken($login, $token, $actionName, $expectedGrant, $error)
34  {
35  $user = new \Account();
36  $user->setLoginName($login);
37  $this->assertTrue($user->isAffected() , sprintf("Login %s not found", $login));
38  $tokenId = $user->getUserToken($token["expire"], $token["oneshot"], $token["context"], "Tst");
39  $this->assertNotEmpty($tokenId, "Token is empty");
40 
41  $userToken = new \UserToken("", $tokenId);
42  //$mainAction = self::getAction();
43  global $action;
44  $auth = new \openAuthenticator("open", "freedom");
45 
46  $this->sudo($login);
47 
48  $mainAction = new \Action();
49  $mainAction->set($actionName, self::$app);
50  $mainAction->user = $user;
51  $mainAction->auth = $auth;
52  $mainAction->parent->permission = null;
53  setHttpVar("app", $mainAction->parent->name);
54  setHttpVar("action", $mainAction->name);
55 
56  $granted = $auth::verifyOpenAccess($userToken);
57  $notExpired = $auth::verifyOpenExpire($userToken);
58 
59  $this->assertEquals($granted && $notExpired, $expectedGrant, "Wrong open access");
60 
61  try {
62  $out = $mainAction->execute();
63  if ($error) {
64  $this->assertContains($error, "", "Error must be occur");
65  }
66  }
67  catch(\Exception $e) {
68  if ($error) {
69  if (is_array($error)) {
70  foreach ($error as $err) {
71  $this->assertContains($err, $e->getMessage() , "Incorrect error");
72  }
73  } else {
74  $this->assertContains($error, $e->getMessage() , "Incorrect error");
75  }
76  } else {
77  $this->assertEmpty($e->getMessage() , sprintf("Access must be granted : %s", $e->getMessage()));
78  }
79  }
80  $this->exitSudo();
81  }
82 
83  public function dataApplicationToken()
84  {
85  return array(
86  array(
87  "login" => "john.doe1",
88  "token" => ["expire" => 200,
89  "oneshot" => true,
90  "context" => ["app" => "TST_OPENACCESS"]],
91  "action" => "TST_OPENACCESS_ACTION_1",
92  "grant" => true,
93  "error" => "CORE0012"
94  ) ,
95 
96  array(
97  "login" => "jane.doe1",
98  "token" => ["expire" => 200,
99  "oneshot" => true,
100  "context" => ["app" => "TST_OPENACCESS"]],
101  "action" => "TST_OPENACCESS_ACTION_2",
102  "grant" => true,
103  "error" => "CORE0012"
104  ) ,
105 
106  array(
107  "login" => "admin",
108  "token" => ["expire" => 200,
109  "oneshot" => true,
110  "context" => ["app" => "TST_OPENACCESS"]],
111  "action" => "TST_OPENACCESS_ACTION_1",
112  "grant" => true,
113  "error" => "CORE0012"
114  ) ,
115  array(
116  "login" => "john.doe1",
117  "token" => ["expire" => 200,
118  "oneshot" => true,
119  "context" => ["app" => "TST_OPENACCESS"]],
120  "action" => "TST_OPENACCESS_ACTION_OPEN1",
121  "grant" => true,
122  "error" => ["CORE0006",
123  "TST_JANE_ACL"]
124  ) ,
125  array(
126  "login" => "jane.doe1",
127  "token" => ["expire" => 200,
128  "oneshot" => true,
129  "context" => ["app" => "CORE"]],
130  "action" => "TST_OPENACCESS_ACTION_OPEN1",
131  "grant" => false,
132  "error" => ""
133  ) ,
134  array(
135  "login" => "jane.doe1",
136  "token" => ["expire" => 200,
137  "oneshot" => true,
138  "context" => ["app" => "TST_OPENACCESS"]],
139  "action" => "TST_OPENACCESS_ACTION_OPEN1",
140  "grant" => true,
141  "error" => ""
142  ) ,
143  array(
144  "login" => "jane.doe1",
145  "token" => ["expire" => 200,
146  "oneshot" => true,
147  "context" => ["app" => "TST_OPENACCESS",
148  "action" => "TST_OPENACCESS_ACTION_OPEN1"]],
149  "action" => "TST_OPENACCESS_ACTION_OPEN1",
150  "grant" => true,
151  "error" => ""
152  ) ,
153  array(
154  "login" => "john.doe1",
155  "token" => ["expire" => 200,
156  "oneshot" => true,
157  "context" => ["app" => "TST_OPENACCESS",
158  "action" => "TST_OPENACCESS_ACTION_OPEN2"]],
159  "action" => "TST_OPENACCESS_ACTION_OPEN2",
160  "grant" => true,
161  "error" => ""
162  ) ,
163  array(
164  "login" => "john.doe1",
165  "token" => ["expire" => 200,
166  "oneshot" => true,
167  "context" => ["app" => "TST_OPENACCESS"]],
168  "action" => "TST_OPENACCESS_ACTION_OPEN2",
169  "grant" => true,
170  "error" => ""
171  ) ,
172  array(
173  "login" => "john.doe1",
174  "token" => ["expire" => 200,
175  "oneshot" => true,
176  "context" => []],
177  "action" => "TST_OPENACCESS_ACTION_OPEN2",
178  "grant" => true,
179  "error" => ""
180  ) ,
181  array(
182  "login" => "jane.doe1",
183  "token" => ["expire" => 200,
184  "oneshot" => true,
185  "context" => []],
186  "action" => "TST_OPENACCESS_ACTION_OPEN1",
187  "grant" => true,
188  "error" => ""
189  ) ,
190  array(
191  "login" => "jane.doe1",
192  "token" => ["expire" => 200,
193  "oneshot" => true,
194  "context" => ["app" => "TST_OPENACCESS",
195  "action" => "TST_OPENACCESS_ACTION_OPEN2"]],
196  "action" => "TST_OPENACCESS_ACTION_OPEN1",
197  "grant" => false,
198  "error" => ""
199  ) ,
200  array(
201  "login" => "john.doe1",
202  "token" => ["expire" => 200,
203  "oneshot" => true,
204  "context" => ["app" => "TST_OPENACCESS",
205  "action" => "TST_OPENACCESS_ACTION_OPEN1"]],
206  "action" => "TST_OPENACCESS_ACTION_OPEN1",
207  "grant" => true,
208  "error" => ["CORE0006",
209  "TST_JANE_ACL"]
210  ) ,
211  array(
212  "login" => "john.doe1",
213  "token" => ["expire" => 200,
214  "oneshot" => true,
215  "context" => ["app" => "TST_OPENACCESS",
216  "action" => "TST_OPENACCESS_ACTION_OPEN2"]],
217  "action" => "TST_OPENACCESS_ACTION_OPEN1",
218  "grant" => false,
219  "error" => ["CORE0006",
220  "TST_JANE_ACL"]
221  ) ,
222  array(
223  "login" => "jane.doe1",
224  "token" => ["expire" => - 200,
225  "oneshot" => true,
226  "context" => []],
227  "action" => "TST_OPENACCESS_ACTION_OPEN1",
228  "grant" => false,
229  "error" => ""
230  ) ,
231  );
232  }
233 }
static sudo($login)
global $action
if(ActionRouter::inMaintenance()) $auth
Definition: authent.php:15
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
$app
$login
Definition: dav.php:40
testApplicationToken($login, $token, $actionName, $expectedGrant, $error)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen