Skip to content
Snippets Groups Projects
Commit 21561ef9 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Move IndexTest to test-framework

parent fb4b71da
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "2cdc1717baae0d13a9dadae83340bf27", "content-hash": "521de9afe6edd13fefd674606cb3029d",
"packages": [ "packages": [
{ {
"name": "gettext/gettext", "name": "gettext/gettext",
...@@ -2859,6 +2859,12 @@ ...@@ -2859,6 +2859,12 @@
"Xdebug", "Xdebug",
"performance" "performance"
], ],
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
}
],
"time": "2020-03-01T12:26:26+00:00" "time": "2020-03-01T12:26:26+00:00"
}, },
{ {
...@@ -4696,16 +4702,16 @@ ...@@ -4696,16 +4702,16 @@
}, },
{ {
"name": "simplesamlphp/simplesamlphp-test-framework", "name": "simplesamlphp/simplesamlphp-test-framework",
"version": "v0.1.4", "version": "v0.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/simplesamlphp/simplesamlphp-test-framework.git", "url": "https://github.com/simplesamlphp/simplesamlphp-test-framework.git",
"reference": "951d6a3113bee3b14355a3ea74763c735c10e157" "reference": "52b04dc7d65055113e0e2338166304e5a291b1f0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/simplesamlphp/simplesamlphp-test-framework/zipball/951d6a3113bee3b14355a3ea74763c735c10e157", "url": "https://api.github.com/repos/simplesamlphp/simplesamlphp-test-framework/zipball/52b04dc7d65055113e0e2338166304e5a291b1f0",
"reference": "951d6a3113bee3b14355a3ea74763c735c10e157", "reference": "52b04dc7d65055113e0e2338166304e5a291b1f0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -4713,7 +4719,7 @@ ...@@ -4713,7 +4719,7 @@
"phpunit/phpunit": "^8.5|^9.0", "phpunit/phpunit": "^8.5|^9.0",
"sensiolabs/security-checker": "^6.0", "sensiolabs/security-checker": "^6.0",
"squizlabs/php_codesniffer": "^3.5", "squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^3.9" "vimeo/psalm": "^3.11"
}, },
"require-dev": { "require-dev": {
"ext-curl": "*", "ext-curl": "*",
...@@ -4745,7 +4751,7 @@ ...@@ -4745,7 +4751,7 @@
"keywords": [ "keywords": [
"test-framework" "test-framework"
], ],
"time": "2020-05-05T11:05:41+00:00" "time": "2020-05-05T11:53:01+00:00"
}, },
{ {
"name": "squizlabs/php_codesniffer", "name": "squizlabs/php_codesniffer",
...@@ -5192,7 +5198,7 @@ ...@@ -5192,7 +5198,7 @@
"ext-curl": "*" "ext-curl": "*"
}, },
"platform-overrides": { "platform-overrides": {
"php": "7.2.30" "php": "7.2.40"
}, },
"plugin-api-version": "1.1.0" "plugin-api-version": "1.1.0"
} }
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\Web;
use PHPUnit\Framework\TestCase;
use SimpleSAML\TestUtils\BuiltInServer;
/**
* Simple test for the www/index.php script.
*
* This test is intended mostly as a demonstration of how to test the public web interface in SimpleSAMLphp.
*
* @author Jaime Pérez Crespo <jaime.perez@uninett.no>
* @package SimpleSAMLphp
*/
class IndexTest extends TestCase
{
/**
* @var \SimpleSAML\TestUtils\BuiltInServer
*/
protected $server;
/**
* @var string
*/
protected $server_addr;
/**
* @var int
*/
protected $server_pid;
/**
* @var string
*/
protected $shared_file;
/**
* The setup method that is run before any tests in this class.
* @return void
*/
protected function setup(): void
{
$this->server = new BuiltInServer('configLoader');
$this->server_addr = $this->server->start();
$this->server_pid = $this->server->getPid();
$this->shared_file = sys_get_temp_dir() . '/' . $this->server_pid . '.lock';
@unlink($this->shared_file); // remove it if it exists
}
/**
* @param array $config
* @return void
*/
protected function updateConfig(array $config): void
{
@unlink($this->shared_file);
$config = "<?php\n\$config = " . var_export($config, true) . ";\n";
file_put_contents($this->shared_file, $config);
}
/**
* A simple test to make sure the index.php file redirects appropriately to the right URL.
* @return void
*/
public function testRedirection(): void
{
// test most basic redirection
$this->updateConfig([
'baseurlpath' => 'http://example.org/simplesaml/'
]);
$resp = $this->server->get('/index.php', [], [
CURLOPT_FOLLOWLOCATION => 0,
]);
$this->assertEquals('302', $resp['code']);
$this->assertEquals(
'http://example.org/simplesaml/module.php/core/login',
$resp['headers']['Location']
);
// test non-default path and https
$this->updateConfig([
'baseurlpath' => 'https://example.org/'
]);
$resp = $this->server->get('/index.php', [], [
CURLOPT_FOLLOWLOCATION => 0,
]);
$this->assertEquals('302', $resp['code']);
$this->assertEquals(
'https://example.org/module.php/core/login',
$resp['headers']['Location']
);
// test URL guessing
$this->updateConfig([
'baseurlpath' => '/simplesaml/'
]);
$resp = $this->server->get('/index.php', [], [
CURLOPT_FOLLOWLOCATION => 0,
]);
$this->assertEquals('302', $resp['code']);
$this->assertEquals(
'http://' . $this->server_addr . '/simplesaml/module.php/core/login',
$resp['headers']['Location']
);
}
/**
* The tear down method that is executed after all tests in this class.
* @return void
*/
protected function tearDown(): void
{
unlink($this->shared_file);
$this->server->stop();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment