diff --git a/modules/autotest/default-disable b/modules/autotest/default-disable new file mode 100644 index 0000000000000000000000000000000000000000..fa0bd82e2df7bd79d57593d35bc53c1f9d3ef71f --- /dev/null +++ b/modules/autotest/default-disable @@ -0,0 +1,3 @@ +This file indicates that the default state of this module +is disabled. To enable, create a file named enable in the +same directory as this file. diff --git a/modules/autotest/docs/test.txt b/modules/autotest/docs/test.txt new file mode 100644 index 0000000000000000000000000000000000000000..34d9ea40303ceb66253f491dca3ed604d7d26eb6 --- /dev/null +++ b/modules/autotest/docs/test.txt @@ -0,0 +1,18 @@ +`autotest` module +================= + +This module provides an interface to do automatic testing of authentication sources. +To enable it, create a file named "enable" in modules/autotest. + +It provides three webpages: +- https://.../simplesaml/module.php/autotest/login.php +- https://.../simplesaml/module.php/autotest/logout.php +- https://.../simplesaml/module.php/autotest/attributes.php + +All the webpages have a mandatory paremeter 'SourceID', which is the name of the authentication source. + +On success, the web pages print a single line with "OK". +The attributes page will also list all the attributes of the user. +On error they set the HTTP status code to 500 Internal Server Error, print a line with "ERROR" and then any information about the error. + +Note that you still have to parse the login pages to extract the parameters in the login form. diff --git a/modules/autotest/www/attributes.php b/modules/autotest/www/attributes.php new file mode 100644 index 0000000000000000000000000000000000000000..e50a4747325861f4f09b5a820396dc06cacbee8f --- /dev/null +++ b/modules/autotest/www/attributes.php @@ -0,0 +1,31 @@ +<?php + +try { + if (!isset($_GET['SourceID'])) { + throw new SimpleSAML_Error_BadRequest('Missing SourceID parameter'); + } + $sourceId = $_GET['SourceID']; + + $as = new SimpleSAML_Auth_Simple($sourceId); + + if (!$as->isAuthenticated()) { + throw new SimpleSAML_Error_Exception('Not authenticated.'); + } + + $attributes = $as->getAttributes(); + + header('Content-Type: text/plain; charset=utf-8'); + echo("OK\n"); + foreach ($attributes as $name => $values) { + echo("$name\n"); + foreach ($values as $value) { + echo("\t$value\n"); + } + } + +} catch (Exception $e) { + header('HTTP/1.0 500 Internal Server Error'); + header('Content-Type: text/plain; charset=utf-8'); + echo("ERROR\n"); + echo($e->getMessage() . "\n"); +} diff --git a/modules/autotest/www/login.php b/modules/autotest/www/login.php new file mode 100644 index 0000000000000000000000000000000000000000..da26db51ed74179c64a087e0861031d3ead65c79 --- /dev/null +++ b/modules/autotest/www/login.php @@ -0,0 +1,20 @@ +<?php + +try { + if (!isset($_GET['SourceID'])) { + throw new SimpleSAML_Error_BadRequest('Missing SourceID parameter'); + } + $sourceId = $_GET['SourceID']; + + $as = new SimpleSAML_Auth_Simple($sourceId); + + $as->requireAuth(); + + header('Content-Type: text/plain; charset=utf-8'); + echo("OK\n"); +} catch (Exception $e) { + header('HTTP/1.0 500 Internal Server Error'); + header('Content-Type: text/plain; charset=utf-8'); + echo("ERROR\n"); + echo($e->getMessage() . "\n"); +} diff --git a/modules/autotest/www/logout.php b/modules/autotest/www/logout.php new file mode 100644 index 0000000000000000000000000000000000000000..81f50d7584434fac862ff080641dfa4e035443ae --- /dev/null +++ b/modules/autotest/www/logout.php @@ -0,0 +1,24 @@ +<?php + +try { + if (!isset($_GET['SourceID'])) { + throw new SimpleSAML_Error_BadRequest('Missing SourceID parameter'); + } + $sourceId = $_GET['SourceID']; + + $as = new SimpleSAML_Auth_Simple($sourceId); + + if ($as->isAuthenticated()) { + $as->logout(); + } + + + header('Content-Type: text/plain; charset=utf-8'); + echo("OK\n"); + +} catch (Exception $e) { + header('HTTP/1.0 500 Internal Server Error'); + header('Content-Type: text/plain; charset=utf-8'); + echo("ERROR\n"); + echo($e->getMessage() . "\n"); +}