ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilWACCheckingInstanceTest Class Reference

TestCase for the ilWACCheckingInstanceTest. More...

+ Inheritance diagram for ilWACCheckingInstanceTest:
+ Collaboration diagram for ilWACCheckingInstanceTest:

Public Member Functions

 testBasic ()
 
 testBasicWithFileSigning ()
 
 testBasicWithFolderSigning ()
 
 testNonCheckingInstanceNoSec ()
 

Protected Member Functions

 setUp ()
 Setup. More...
 

Protected Attributes

 $file_one
 
 $root
 

Private Attributes

 $http
 

Detailed Description

TestCase for the ilWACCheckingInstanceTest.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

needsInstalledILIAS

disabled disabled disabled

Definition at line 27 of file ilWACCheckingInstanceTest.php.

Member Function Documentation

◆ setUp()

ilWACCheckingInstanceTest::setUp ( )
protected

Setup.

Definition at line 47 of file ilWACCheckingInstanceTest.php.

References $c, $container, $GLOBALS, $http, $ilUser, $request, ILIAS\FileDelivery\http(), ilWebAccessCheckerDelivery\run(), and ilWACToken\setSALT().

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  }
$container
Definition: wac.php:13
static http()
Fetches the global http state from ILIAS.
static setSALT($salt)
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:

◆ testBasic()

ilWACCheckingInstanceTest::testBasic ( )

Definition at line 146 of file ilWACCheckingInstanceTest.php.

References ilWACException\ACCESS_DENIED_NO_PUB, and ilWebAccessChecker\check().

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  }
Class ilWACException.
Class ilWebAccessChecker.
+ Here is the call graph for this function:

◆ testBasicWithFileSigning()

ilWACCheckingInstanceTest::testBasicWithFileSigning ( )

Definition at line 167 of file ilWACCheckingInstanceTest.php.

References $response, ilWACException\ACCESS_DENIED_NO_PUB, ILIAS\FileDelivery\http(), and ilWACSignedPath\signFile().

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  }
Class ilWACException.
static http()
Fetches the global http state from ILIAS.
Class ilWebAccessChecker.
static signFile($path_to_file)
$response
+ Here is the call graph for this function:

◆ testBasicWithFolderSigning()

ilWACCheckingInstanceTest::testBasicWithFolderSigning ( )

Definition at line 192 of file ilWACCheckingInstanceTest.php.

References $response, ilWACException\ACCESS_DENIED_NO_PUB, ILIAS\FileDelivery\http(), and ilWACSignedPath\signFolderOfStartFile().

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  }
Class ilWACException.
static signFolderOfStartFile($start_file_path)
static http()
Fetches the global http state from ILIAS.
Class ilWebAccessChecker.
$response
+ Here is the call graph for this function:

◆ testNonCheckingInstanceNoSec()

ilWACCheckingInstanceTest::testNonCheckingInstanceNoSec ( )

Definition at line 219 of file ilWACCheckingInstanceTest.php.

References $_SESSION, ilWACException\ACCESS_DENIED_NO_PUB, and ilWebAccessChecker\check().

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  }
Class ilWACException.
$_SESSION["AccountId"]
Class ilWebAccessChecker.
+ Here is the call graph for this function:

Field Documentation

◆ $file_one

ilWACCheckingInstanceTest::$file_one
protected

Definition at line 33 of file ilWACCheckingInstanceTest.php.

◆ $http

ilWACCheckingInstanceTest::$http
private

Definition at line 41 of file ilWACCheckingInstanceTest.php.

Referenced by setUp().

◆ $root

ilWACCheckingInstanceTest::$root
protected

Definition at line 37 of file ilWACCheckingInstanceTest.php.


The documentation for this class was generated from the following file: