Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
9c3a9383
Commit
9c3a9383
authored
5 years ago
by
Tim van Dijen
Browse files
Options
Downloads
Patches
Plain Diff
Revert IndexTest
parent
21561ef9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/routers/configLoader.php
+43
-0
43 additions, 0 deletions
tests/routers/configLoader.php
tests/www/IndexTest.php
+124
-0
124 additions, 0 deletions
tests/www/IndexTest.php
with
167 additions
and
0 deletions
tests/routers/configLoader.php
0 → 100644
+
43
−
0
View file @
9c3a9383
<?php
declare
(
strict_types
=
1
);
/*
* 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
(
__FILE__
)
.
'/../../vendor/autoload.php'
);
// initialize configuration
if
(
isset
(
$config
))
{
\SimpleSAML\Configuration
::
loadFromArray
(
$config
,
'[ARRAY]'
,
'simplesaml'
);
}
// let the script proceed
// see: http://php.net/manual/en/features.commandline.webserver.php
return
false
;
This diff is collapsed.
Click to expand it.
tests/www/IndexTest.php
0 → 100644
+
124
−
0
View file @
9c3a9383
<?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
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment