ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilWACCheckingInstanceTest.php
Go to the documentation of this file.
1 <?php
2 require_once('./libs/composer/vendor/autoload.php');
3 
5 
15 
19  protected $file_one;
23  protected $root;
24 
25 
29  protected function setUp() {
30  error_reporting(E_ALL);
31  require_once('./Services/WebAccessChecker/classes/class.ilWebAccessChecker.php');
32  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
33  require_once('./Services/WebAccessChecker/classes/class.ilWACToken.php');
34  require_once('./Services/WebAccessChecker/test/Token/mock/class.ilWACDummyCookie.php');
35  require_once('./Services/WebAccessChecker/test/Token/mock/class.ilWACDummyHeader.php');
36  require_once('./Services/WebAccessChecker/classes/class.ilWebAccessCheckerDelivery.php');
37  require_once('./libs/composer/vendor/autoload.php');
38  $this->root = vfs\vfsStream::setup('ilias.de');
39  $this->file_one = vfs\vfsStream::newFile('data/trunk/mobs/mm_123/dummy.jpg')->at($this->root)->setContent('dummy');
40  ilWACToken::setSALT('TOKEN');
41  parent::setUp();
42  }
43 
44 
51  public function tetDeliver() {
52  $base64 = "iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTExIDc5LjE1ODMyNSwgMjAxNS8wOS8xMC0wMToxMDoyMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiI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2f8sYkNugeazcbzNuWRSj8Uj6uFNIUo0fZPIT+48BoJ576uoomogrDMH0GkMvcQXsiQiNGP6RKLBlGDMVWH3Xf0+Xk4ZgfAvna09jTehCwfdsne8qX79u1Y5K1XZt8XLvpEhh6TSCP3x49eOCuivIP5/1LqNlAK4e+fG1AQ/8YJmjezWzEHK9KrhDhdnxctm3M4QN7FwAl+JzetItY9sDbDdfXQoDvo9eAHK76q2NHV+0s25Z74uihLYooKeVyw0dviBce02Pf+kfa3jePM2+MQUxya/uKRtYzP+AUv/7y6D9OVVe9DAlpMYw7A4NCxjEsp6LETpa9+w4QCggdVDMxwVRbmi/V1ZaDH3zl7MlvttptrVe8FS11nl2XTvTjM4lhigP5Zi1H+xIt0woU81oZVo2DzWbXd3cUFhaiPXv2eHVSTqVODTdbpoWGR07VG005PK+K7KAHrgT1qoC1AULpR3tya7PbbNVNDZf2f1d3YXvd+XM7ZdF5qsvaD0KWlSj2VTiNUUG++XYW12I7JKjkwvwnHti9tdSlQUVFRUin03nFUSAhPS4r8nFw4k9rVSRAb9Qk6QzGNL3BlKjWaKKBpQfBjjrXdV21K2yVJLEBtOKcraXlZGuLtRp829ctsv20xqSTQo1xaGhyosv34C7MF8je6TKEiwjyfbt+blYKTx8zHvyKLi9r0oMyCNAgQIMA9YL8X4ABAIDrBNX7nKxZAAAAAElFTkSuQmCC";
53  $image = vfs\vfsStream::newFile('data/trunk/mobs/mm_123/dummy.png')->at($this->root)->setContent($base64);
54  $this->assertEquals($base64, $image->getContent());
55 
56  require_once('./Services/PHPUnit/classes/class.ilUnitUtil.php');
57  try {
58  $_POST["username"] = 'anonymous';
59  $_POST["password"] = 'anonymous';
60  ilUnitUtil::performInitialisation();
61  } catch (ErrorException $e) {
62  // echo $e->getMessage();
63  }
64  global $ilUser;
65  $this->assertTrue($ilUser instanceof ilObjUser);
66  $this->assertEquals(0, $ilUser->getId());
67 
68  ob_start(function ($buffer) {
69  unset($buffer);
70 
71  return '';
72  });
73  ilWebAccessCheckerDelivery::run($image->url());
74  ob_end_clean();
75  ob_end_flush();
76  $this->assertEquals(404, http_response_code());
77  }
78 
79 
80  public function tstBasic() {
81  require_once('./Services/User/classes/class.ilObjUser.php');
82  $ilWebAccessChecker = new ilWebAccessChecker($this->file_one->url(), new ilWACDummyCookie());
83  $check = false;
84  try {
85  $check = $ilWebAccessChecker->check();
86  } catch (ilWACException $ilWACException) {
87  $this->assertEquals($ilWACException->getCode(), ilWACException::ACCESS_DENIED_NO_PUB);
88  }
89  $this->assertFalse($check);
90  $this->assertEquals(array(
91  $ilWebAccessChecker::CM_CHECKINGINSTANCE,
92  ), $ilWebAccessChecker->getAppliedCheckingMethods());
93  }
94 
95 
96  public function testBasicWithFileSigning() {
97  $signed_path = ilWACSignedPath::signFile($this->file_one->url());
99  $ilWACHeaderInterface = new ilWACDummyHeader();
100  $ilWebAccessChecker = new ilWebAccessChecker($signed_path, new ilWACDummyCookie(), $ilWACHeaderInterface);
101  $check = false;
102  try {
103  $check = $ilWebAccessChecker->check();
104  } catch (ilWACException $ilWACException) {
105  $this->assertEquals($ilWACException->getCode(), ilWACException::ACCESS_DENIED_NO_PUB);
106  }
107  $this->assertTrue($check);
108  $this->assertEquals(array(
109  $ilWebAccessChecker::CM_FILE_TOKEN,
110  ), $ilWebAccessChecker->getAppliedCheckingMethods());
111  $this->assertEquals(array(
112  'X-ILIAS-WebAccessChecker: checked using token',
113  ), $ilWACHeaderInterface->getSentHeaders());
114  }
115 
116 
117  public function testBasicWithFolderSigning() {
118  ilWACSignedPath::signFolderOfStartFile($this->file_one->url(), new ilWACDummyCookie());
120  $ilWACHeaderInterface = new ilWACDummyHeader();
121  $ilWebAccessChecker = new ilWebAccessChecker($this->file_one->url(), new ilWACDummyCookie(), $ilWACHeaderInterface);
122  $check = false;
123  try {
124  $check = $ilWebAccessChecker->check();
125  } catch (ilWACException $ilWACException) {
126  $this->assertEquals($ilWACException->getCode(), ilWACException::ACCESS_DENIED_NO_PUB);
127  }
128  $this->assertTrue($check);
129  $this->assertEquals(array(
130  $ilWebAccessChecker::CM_FOLDER_TOKEN,
131  ), $ilWebAccessChecker->getAppliedCheckingMethods());
132  $this->assertEquals(array(
133  'X-ILIAS-WebAccessChecker: checked using secure folder',
134  ), $ilWACHeaderInterface->getSentHeaders());
135  }
136 
137 
138  public function testNonCheckingInstanceNoSec() {
140  $file = vfs\vfsStream::newFile('data/trunk/dummy/mm_123/dummy.jpg')->at($this->root)->setContent('dummy');
141  $ilWebAccessChecker = new ilWebAccessChecker($file->url(), new ilWACDummyCookie());
142  $check = false;
143  try {
144  if (!defined('IL_PHPUNIT_TEST')) {
145  define('IL_PHPUNIT_TEST', true);
146  }
147  session_id('phpunittest');
148  $_SESSION = array();
149  include 'Services/PHPUnit/config/cfg.phpunit.php';
150 
151  $check = $ilWebAccessChecker->check();
152  } catch (ilWACException $ilWACException) {
153  $this->assertEquals($ilWACException->getCode(), ilWACException::ACCESS_DENIED_NO_PUB);
154  }
155  // $this->assertTrue($check); // Currently not able to init ILIAS in WAC during PHPUnit
156  // $this->assertEquals(array(
157  // $ilWebAccessChecker::CM_SECFOLDER,
158  // ), $ilWebAccessChecker->getAppliedCheckingMethods());
159  }
160 }
static setSALT($SALT)
Class ilWACException.
TestCase for the ilWACCheckingInstanceTest.
$_SESSION["AccountId"]
static signFolderOfStartFile($start_file_path, ilWACCookieInterface $ilWACCookieInterface=null)
Class ilWebAccessChecker.
$ilUser
Definition: imgupload.php:18
static signFile($path_to_file)
Create styles array
The data for the language used.
Class ilWACDummyCookie.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
tetDeliver()
disabled disabled disabled
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
$_POST["username"]
Class ilWACDummyHeader.