ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractBearerTest.php
Go to the documentation of this file.
1<?php
2
4
5use Sabre\HTTP;
6
7require_once 'Sabre/HTTP/ResponseMock.php';
8
10
11 function testCheckNoHeaders() {
12
13 $request = new HTTP\Request();
14 $response = new HTTP\Response();
15
16 $backend = new AbstractBearerMock();
17
18 $this->assertFalse(
19 $backend->check($request, $response)[0]
20 );
21
22 }
23
25
27 'HTTP_AUTHORIZATION' => 'Bearer foo',
28 ]);
29 $response = new HTTP\Response();
30
31 $backend = new AbstractBearerMock();
32
33 $this->assertFalse(
34 $backend->check($request, $response)[0]
35 );
36
37 }
38
39 function testCheckSuccess() {
40
42 'HTTP_AUTHORIZATION' => 'Bearer valid',
43 ]);
44 $response = new HTTP\Response();
45
46 $backend = new AbstractBearerMock();
47 $this->assertEquals(
48 [true, 'principals/username'],
49 $backend->check($request, $response)
50 );
51
52 }
53
54 function testRequireAuth() {
55
56 $request = new HTTP\Request();
57 $response = new HTTP\Response();
58
59 $backend = new AbstractBearerMock();
60 $backend->setRealm('writing unittests on a saturday night');
61 $backend->challenge($request, $response);
62
63 $this->assertEquals(
64 'Bearer realm="writing unittests on a saturday night"',
65 $response->getHeader('WWW-Authenticate')
66 );
67
68 }
69
70}
71
72
74
84 function validateBearerToken($bearerToken) {
85
86 return 'valid' === $bearerToken ? 'principals/username' : false;
87
88 }
89
90}
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
validateBearerToken($bearerToken)
Validates a bearer token.
HTTP Bearer authentication backend class.
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
$response