|
4 | 4 |
|
5 | 5 | namespace SimpleSAML\Test\Module\saml\Controller; |
6 | 6 |
|
| 7 | +use ArgumentCountError; |
7 | 8 | use Exception; |
8 | 9 | use PHPUnit\Framework\TestCase; |
9 | 10 | use SimpleSAML\Auth; |
@@ -46,6 +47,7 @@ protected function setUp(): void |
46 | 47 | [ |
47 | 48 | 'module.enable' => ['saml' => true], |
48 | 49 | 'admin.protectmetadata' => false, |
| 50 | + 'trusted.url.domains' => ['example.org'], |
49 | 51 | ], |
50 | 52 | '[ARRAY]', |
51 | 53 | 'simplesaml' |
@@ -79,6 +81,87 @@ public function requireAdmin(): void |
79 | 81 | } |
80 | 82 |
|
81 | 83 |
|
| 84 | + /** |
| 85 | + * Test that accessing the login-endpoint without AuthID leads to an exception |
| 86 | + * |
| 87 | + * @return void |
| 88 | + */ |
| 89 | + public function testLoginMissingAuthId(): void |
| 90 | + { |
| 91 | + $request = Request::create( |
| 92 | + '/sp/login', |
| 93 | + 'GET', |
| 94 | + ); |
| 95 | + |
| 96 | + $c = new Controller\ServiceProvider($this->config, $this->session); |
| 97 | + |
| 98 | + $this->expectException(ArgumentCountError::class); |
| 99 | + $c->login($request); |
| 100 | + } |
| 101 | + |
| 102 | + |
| 103 | + /** |
| 104 | + * Test that accessing the login-endpoint with a non-SP authsource leads to an exception |
| 105 | + * |
| 106 | + * @return void |
| 107 | + */ |
| 108 | + public function testLoginWrongAuthSource(): void |
| 109 | + { |
| 110 | + $request = Request::create( |
| 111 | + '/sp/login/admin', |
| 112 | + 'GET', |
| 113 | + ); |
| 114 | + |
| 115 | + $c = new Controller\ServiceProvider($this->config, $this->session); |
| 116 | + |
| 117 | + $this->expectException(Error\Exception::class); |
| 118 | + $this->expectExceptionMessage('Authsource must be of type saml:SP.'); |
| 119 | + $c->login($request, 'admin'); |
| 120 | + } |
| 121 | + |
| 122 | + |
| 123 | + /** |
| 124 | + * Test that accessing the login-endpoint without ReturnTo parameter leads to an exception |
| 125 | + * |
| 126 | + * @return void |
| 127 | + */ |
| 128 | + public function testLoginMissingReturnTo(): void |
| 129 | + { |
| 130 | + $request = Request::create( |
| 131 | + '/sp/login/phpunit', |
| 132 | + 'GET', |
| 133 | + ); |
| 134 | + |
| 135 | + $c = new Controller\ServiceProvider($this->config, $this->session); |
| 136 | + |
| 137 | + $this->expectException(Error\BadRequest::class); |
| 138 | + $this->expectExceptionMessage('Missing ReturnTo parameter.'); |
| 139 | + $c->login($request, 'phpunit'); |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | + /** |
| 144 | + * @TODO: This cannot be tested until we are PSR-7 compliant |
| 145 | + * |
| 146 | + * Test that accessing the login-endpoint with ReturnTo parameter leads to a RunnableResponse |
| 147 | + * |
| 148 | + * @return void |
| 149 | + public function testLogin(): void |
| 150 | + { |
| 151 | + $request = Request::create( |
| 152 | + '/sp/login/phpunit', |
| 153 | + 'GET', |
| 154 | + ['ReturnTo' => 'https://localhost'], |
| 155 | + ); |
| 156 | +
|
| 157 | + $c = new Controller\ServiceProvider($this->config, $this->session); |
| 158 | + $response = $c->login($request, 'phpunit'); |
| 159 | +
|
| 160 | + $this->assertInstanceOf(RunnableResponse::class, $response); |
| 161 | + } |
| 162 | + */ |
| 163 | + |
| 164 | + |
82 | 165 | /** |
83 | 166 | * Test that accessing the discoResponse-endpoint without AuthID leads to an exception |
84 | 167 | * |
@@ -459,7 +542,7 @@ public function testMetadataUnknownEntityThrowsError(): void |
459 | 542 |
|
460 | 543 | $this->expectException(\SimpleSAML\Error\Error::class); |
461 | 544 | $this->expectExceptionMessage("Error with authentication source 'phpnonunit': Could not find authentication source."); |
462 | | - $result = $c->metadata($request, 'phpnonunit'); |
| 545 | + $c->metadata($request, 'phpnonunit'); |
463 | 546 | } |
464 | 547 |
|
465 | 548 | /** |
|
0 commit comments