Skip to content

Commit

Permalink
Fix testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Aug 1, 2020
1 parent d74ddc3 commit 7f787f2
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"php": ">=7.2",
"simplesamlphp/composer-module-installer": "~1.1",
"simplesamlphp/simplesamlphp": "dev-master",
"webmozart/assert": "1.8"
"webmozart/assert": "1.8",
"symfony/routing": "^4.0"
},
"require-dev": {
"simplesamlphp/simplesamlphp-test-framework": "~0.1.0",
Expand Down
4 changes: 2 additions & 2 deletions templates/loggedIn.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% set pagetitle = '{casserver:casserver:loggedin_header}'|trans %}
{% set pagetitle = '{casserver:loggedin_header}'|trans %}
{% extends "base.twig" %}

{% block content %}
<h2>{{ pagetitle }}</h2>

<p>{{ '{casserver:casserver:loggedin_description}'|trans }}</p>
<p>{{ '{casserver:loggedin_description}'|trans }}</p>
{% endblock %}

{% block postload %}
Expand Down
6 changes: 3 additions & 3 deletions templates/loggedOut.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% set pagetitle = '{casserver:casserver:loggedout_header}'|trans %}
{% set pagetitle = '{casserver:loggedout_header}'|trans %}
{% extends "base.twig" %}

{% block content %}
<h2>{{ pagetitle }}</h2>

<p>{{ '{casserver:casserver:loggedout_description}'|trans }}</p>
<p>{{ '{casserver:loggedout_description}'|trans }}</p>
{% if url is defined %}
<a href="{{ url }}">{{ '{casserver:casserver:continue_heading}'|trans }}</a>
<a href="{{ url }}">{{ '{casserver:continue_heading}'|trans }}</a>
{% endif %}
{% endblock %}

Expand Down
46 changes: 46 additions & 0 deletions tests/routers/configLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

use SimpleSAML\Configuration;

/*
* This "router" (a script that's executed for every request received by PHP's built-in web server) will look
* for a file in the system's temporary directory, with the PID of the current process as its name, and the
* '.lock' extension. If the file exists, it will try to include it and preload SimpleSAMLphp's configuration with
* the $config array defined in that file.
* This is useful to configure SimpleSAMLphp dynamically when running inside the built-in server, so that
* we can test different configurations without the need to keep a structure of files.
*
* In order to use it:
*
* 1. Create an array with the SimpleSAMLphp configuration you would like to use.
* 2. Start the built-in server passing "configLoader" as the first parameter to the constructor:
* $server = new BuiltInServer('configLoader');
* $addr = $server->start();
* 3. Get the PID of the server once it has started:
* $pid = $server->getPid();
* 4. Build the path to the file that this script will use:
* $file = sys_get_temp_dir().'/'.$pid.'.lock';
* 5. Dump the configuration array to the file:
* file_put_contents("<?php\n\$config = ".var_export($config, true).";\n");
* 6. Make a request to the server:
* $server->get($query, $parameters);
* 7. Remove the temporary file when done:
* unlink($file);
*/

include_once(sys_get_temp_dir() . '/' . getmypid() . '.lock');

// load SimpleSAMLphp's autoloader
require_once(dirname(dirname(dirname(__FILE__))) . '/vendor/autoload.php');

// initialize configuration
if (isset($config)) {
Configuration::loadFromArray($config, '[ARRAY]', 'simplesaml');
}

// let the script proceed
// see: http://php.net/manual/en/features.commandline.webserver.php
return false;

30 changes: 29 additions & 1 deletion tests/www/LoginIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Logger;
use SimpleSAML\TestUtils\BuiltInServer;

/**
Expand Down Expand Up @@ -59,11 +60,24 @@ class LoginIntegrationTest extends TestCase
*/
protected function setup(): void
{
$this->server = new BuiltInServer();
$this->server = new BuiltInServer('configLoader', dirname(dirname(dirname(__FILE__))) . '/vendor/simplesamlphp/simplesamlphp/www');
$this->server_addr = $this->server->start();
$this->server_pid = $this->server->getPid();
$this->shared_file = sys_get_temp_dir() . '/' . $this->server_pid . '.lock';
$this->cookies_file = sys_get_temp_dir() . '/' . $this->server_pid . '.cookies';


$this->updateConfig([
'baseurlpath' => '/',

'tempdir' => sys_get_temp_dir(),
'loggingdir' => sys_get_temp_dir(),

'module.enable' => [
'casserver' => true,
]
]);

}


Expand All @@ -80,6 +94,18 @@ protected function tearDown(): void
}


/**
* @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);
}


/**
* Test authenticating to the login endpoint with no parameters.'
* @return void
Expand Down Expand Up @@ -349,6 +375,7 @@ public function testValidServiceUrlWithPost()
$this->fail('Unable to parse response.');
return;
}

$this->assertEquals($service_url, $item->getAttribute('action'));
$formInputs = $dom->getElementsByTagName('input');
//note: $formInputs[0] is '<input type="submit" style="display:none;" />'. See the post.php template from SSP
Expand Down Expand Up @@ -454,6 +481,7 @@ private function execAndHandleCurlResponse($ch)
if ($resp === false) {
throw new \Exception('curl error: ' . curl_error($ch));
}

$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
/** @psalm-var string $resp */
list($header, $body) = explode("\r\n\r\n", $resp, 2);
Expand Down

0 comments on commit 7f787f2

Please sign in to comment.