ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilWACCheckingInstanceTest.php
Go to the documentation of this file.
1 <?php
2 // declare(strict_types=1);
3 
4 require_once('./libs/composer/vendor/autoload.php');
5 
10 use org\bovigo\vfs;
13 
27 class ilWACCheckingInstanceTest extends MockeryTestCase
28 {
29 
33  protected $file_one;
37  protected $root;
41  private $http;
42 
43 
47  protected function setUp()
48  {
49  //error_reporting(E_ALL);
50  parent::setUp();
51  require_once('./Services/WebAccessChecker/classes/class.ilWebAccessChecker.php');
52  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
53  require_once('./Services/WebAccessChecker/classes/class.ilWACToken.php');
54  require_once('./Services/WebAccessChecker/classes/class.ilWebAccessCheckerDelivery.php');
55  $this->root = vfs\vfsStream::setup('ilias.de');
56  $this->file_one = vfs\vfsStream::newFile('data/trunk/mobs/mm_123/dummy.jpg')
57  ->at($this->root)->setContent('dummy');
58 
59  //setup container for HttpServiceAware classes
60  $container = new \ILIAS\DI\Container();
61  $container['http'] = function ($c) {
62  return Mockery::mock(GlobalHttpState::class);
63  };
64 
65  $this->http = $container['http'];
66 
67 
68  $GLOBALS["DIC"] = $container;
69  ilWACToken::setSALT('TOKEN');
70  }
71 
72 
79  public function testDeliver()
80  {
81  self::markTestSkipped("WIP");
82  return;
83  $base64 = "iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTExIDc5LjE1ODMyNSwgMjAxNS8wOS8xMC0wMToxMDoyMCAgICAgICAgIj4gPHJk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y5lXeMSkAaS39+/acSOE3Au0zNHXQkO/VqdPzskv3IjbK5ka8AMr+YRN49mgO63d6KGmSxtuYSPWAH8a6VEuVnP65I6KHR+MAwdeyfnBol9KDyKiLXMS0jMXWrAqfC2f8sYkNugeazcbzNuWRSj8Uj6uFNIUo0fZPIT+48BoJ576uoomogrDMH0GkMvcQXsiQiNGP6RKLBlGDMVWH3Xf0+Xk4ZgfAvna09jTehCwfdsne8qX79u1Y5K1XZt8XLvpEhh6TSCP3x49eOCuivIP5/1LqNlAK4e+fG1AQ/8YJmjezWzEHK9KrhDhdnxctm3M4QN7FwAl+JzetItY9sDbDdfXQoDvo9eAHK76q2NHV+0s25Z74uihLYooKeVyw0dviBce02Pf+kfa3jePM2+MQUxya/uKRtYzP+AUv/7y6D9OVVe9DAlpMYw7A4NCxjEsp6LETpa9+w4QCggdVDMxwVRbmi/V1ZaDH3zl7MlvttptrVe8FS11nl2XTvTjM4lhigP5Zi1H+xIt0woU81oZVo2DzWbXd3cUFhaiPXv2eHVSTqVODTdbpoWGR07VG005PK+K7KAHrgT1qoC1AULpR3tya7PbbNVNDZf2f1d3YXvd+XM7ZdF5qsvaD0KWlSj2VTiNUUG++XYW12I7JKjkwvwnHti9tdSlQUVFRUin03nFUSAhPS4r8nFw4k9rVSRAb9Qk6QzGNL3BlKjWaKKBpQfBjjrXdV21K2yVJLEBtOKcraXlZGuLtRp829ctsv20xqSTQo1xaGhyosv34C7MF8je6TKEiwjyfbt+blYKTx8zHvyKLi9r0oMyCNAgQIMA9YL8X4ABAIDrBNX7nKxZAAAAAElFTkSuQmCC";
84  $image = vfs\vfsStream::newFile('data/trunk/mobs/mm_123/dummy.png')->at($this->root)
85  ->setContent($base64);
86  $this->assertEquals($base64, $image->getContent());
87 
88  require_once('./Services/PHPUnit/classes/class.ilUnitUtil.php');
89  try {
90  $GLOBALS['DIC']['ilAuthSession']->setAuthenticated(true, ANONYMOUS_USER_ID);
91  ilUnitUtil::performInitialisation();
92  } catch (ErrorException $e) {
93  // echo $e->getMessage();
94  }
95 
99  $ilUser = $GLOBALS["DIC"]->user();
100  $this->assertTrue($ilUser instanceof ilObjUser);
101 
102  ob_start(function ($buffer) {
103  unset($buffer);
104 
105  return '';
106  });
107 
111  $httpService = $this->http;
115  $request = Mockery::mock(ServerRequestInterface::class);
119  $uri = Mockery::mock(UriInterface::class);
120 
121  $uri
122  ->shouldReceive('getPath')
123  ->once()
124  ->withNoArgs()
125  ->andReturn($image->url());
126 
127  $request
128  ->shouldReceive('getUri')
129  ->once()
130  ->withNoArgs()
131  ->andReturn($uri);
132 
133  $httpService
134  ->shouldReceive('request')
135  ->once()
136  ->withNoArgs()
137  ->andReturn($uri);
138 
139  ilWebAccessCheckerDelivery::run($httpService, Mockery::mock(CookieFactory::class));
140  ob_end_clean();
141  ob_end_flush();
142  $this->assertEquals(404, $this->response()->getStatusCode());
143  }
144 
145 
146  public function testBasic()
147  {
148  self::markTestSkipped("Can't run test without db.");
149 
150  return;
151 
152  require_once('./Services/User/classes/class.ilObjUser.php');
153  $ilWebAccessChecker = new ilWebAccessChecker($this->file_one->url());
154  $check = false;
155  try {
156  $check = $ilWebAccessChecker->check();
157  } catch (ilWACException $ilWACException) {
158  $this->assertEquals($ilWACException->getCode(), ilWACException::ACCESS_DENIED_NO_PUB);
159  }
160  $this->assertFalse($check);
161  $this->assertEquals(array(
162  $ilWebAccessChecker::CM_CHECKINGINSTANCE,
163  ), $ilWebAccessChecker->getAppliedCheckingMethods());
164  }
165 
166 
167  public function testBasicWithFileSigning()
168  {
169  self::markTestSkipped("WIP");
170  return;
171  $signed_path = ilWACSignedPath::signFile($this->file_one->url());
172 
173  $ilWebAccessChecker = new ilWebAccessChecker($this->http, Mockery::mock(CookieFactory::class));
174  $check = false;
175  try {
176  $check = $ilWebAccessChecker->check();
177  } catch (ilWACException $ilWACException) {
178  $this->assertEquals($ilWACException->getCode(), ilWACException::ACCESS_DENIED_NO_PUB);
179  }
180  $this->assertTrue($check);
181  $this->assertEquals(array(
182  $ilWebAccessChecker::CM_FILE_TOKEN,
183  ), $ilWebAccessChecker->getAppliedCheckingMethods());
184 
185  $headerName = 'X-ILIAS-WebAccessChecker';
186  $response = $this->response();
187  $this->assertTrue($response->hasHeader($headerName));
188  $this->assertEquals([ 'checked using token' ], $response->getHeader($headerName));
189  }
190 
191 
192  public function testBasicWithFolderSigning()
193  {
194  self::markTestSkipped("WIP");
195  return;
196  ilWACSignedPath::signFolderOfStartFile($this->file_one->url());
197  $ilWebAccessChecker = new ilWebAccessChecker($this->http, Mockery::mock(CookieFactory::class));
198  $check = false;
199  try {
200  $check = $ilWebAccessChecker->check();
201  } catch (ilWACException $ilWACException) {
202  $this->assertEquals($ilWACException->getCode(), ilWACException::ACCESS_DENIED_NO_PUB);
203  }
204  $this->assertTrue($check);
205  $this->assertEquals(array(
206  $ilWebAccessChecker::CM_FOLDER_TOKEN,
207  ), $ilWebAccessChecker->getAppliedCheckingMethods());
208 
209  $headerName = 'X-ILIAS-WebAccessChecker';
210  $response = $this->response();
211  $this->assertTrue($response->hasHeader($headerName));
212  $this->assertEquals([ 'checked using secure folder' ], $response->getHeader($headerName));
213  }
214 
215 
220  {
221  self::markTestSkipped("Can't run test without db.");
222 
223  return;
224 
225  $file = vfs\vfsStream::newFile('data/trunk/dummy/mm_123/dummy.jpg')->at($this->root)
226  ->setContent('dummy');
227  $ilWebAccessChecker = new ilWebAccessChecker($file->url());
228  $check = false;
229  try {
230  if (!defined('IL_PHPUNIT_TEST')) {
231  define('IL_PHPUNIT_TEST', true);
232  }
233  session_id('phpunittest');
234  $_SESSION = array();
235  include 'Services/PHPUnit/config/cfg.phpunit.php';
236 
237  $check = $ilWebAccessChecker->check();
238  } catch (ilWACException $ilWACException) {
239  $this->assertEquals($ilWACException->getCode(), ilWACException::ACCESS_DENIED_NO_PUB);
240  }
241  // $this->assertTrue($check); // Currently not able to init ILIAS in WAC during PHPUnit
242  // $this->assertEquals(array(
243  // $ilWebAccessChecker::CM_SECFOLDER,
244  // ), $ilWebAccessChecker->getAppliedCheckingMethods());
245  }
246 }
Class ilWACException.
TestCase for the ilWACCheckingInstanceTest.
$_SESSION["AccountId"]
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$container
Definition: wac.php:13
static signFolderOfStartFile($start_file_path)
static http()
Fetches the global http state from ILIAS.
Class ilWebAccessChecker.
$ilUser
Definition: imgupload.php:18
static signFile($path_to_file)
static setSALT($salt)
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
$response
static run(GlobalHttpState $httpState, CookieFactory $cookieFactory)