summaryrefslogtreecommitdiffstats
path: root/tests/lib/SimpleSAML/ConfigurationTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/SimpleSAML/ConfigurationTest.php')
-rw-r--r--tests/lib/SimpleSAML/ConfigurationTest.php214
1 files changed, 122 insertions, 92 deletions
diff --git a/tests/lib/SimpleSAML/ConfigurationTest.php b/tests/lib/SimpleSAML/ConfigurationTest.php
index 076b8b0..129f658 100644
--- a/tests/lib/SimpleSAML/ConfigurationTest.php
+++ b/tests/lib/SimpleSAML/ConfigurationTest.php
@@ -40,17 +40,17 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
*/
public function testGetValue() {
$c = SimpleSAML_Configuration::loadFromArray(array(
- 'exists_true' => TRUE,
- 'exists_null' => NULL,
+ 'exists_true' => true,
+ 'exists_null' => null,
));
- $this->assertEquals($c->getValue('missing'), NULL);
- $this->assertEquals($c->getValue('missing', TRUE), TRUE);
- $this->assertEquals($c->getValue('missing', TRUE), TRUE);
+ $this->assertEquals($c->getValue('missing'), null);
+ $this->assertEquals($c->getValue('missing', true), true);
+ $this->assertEquals($c->getValue('missing', true), true);
- $this->assertEquals($c->getValue('exists_true'), TRUE);
+ $this->assertEquals($c->getValue('exists_true'), true);
- $this->assertEquals($c->getValue('exists_null'), NULL);
- $this->assertEquals($c->getValue('exists_null', FALSE), NULL);
+ $this->assertEquals($c->getValue('exists_null'), null);
+ $this->assertEquals($c->getValue('exists_null', false), null);
}
/**
@@ -67,12 +67,12 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
*/
public function testHasValue() {
$c = SimpleSAML_Configuration::loadFromArray(array(
- 'exists_true' => TRUE,
- 'exists_null' => NULL,
+ 'exists_true' => true,
+ 'exists_null' => null,
));
- $this->assertEquals($c->hasValue('missing'), FALSE);
- $this->assertEquals($c->hasValue('exists_true'), TRUE);
- $this->assertEquals($c->hasValue('exists_null'), TRUE);
+ $this->assertEquals($c->hasValue('missing'), false);
+ $this->assertEquals($c->hasValue('exists_true'), true);
+ $this->assertEquals($c->hasValue('exists_null'), true);
}
/**
@@ -80,17 +80,17 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
*/
public function testHasValueOneOf() {
$c = SimpleSAML_Configuration::loadFromArray(array(
- 'exists_true' => TRUE,
- 'exists_null' => NULL,
+ 'exists_true' => true,
+ 'exists_null' => null,
));
- $this->assertEquals($c->hasValueOneOf(array()), FALSE);
- $this->assertEquals($c->hasValueOneOf(array('missing')), FALSE);
- $this->assertEquals($c->hasValueOneOf(array('exists_true')), TRUE);
- $this->assertEquals($c->hasValueOneOf(array('exists_null')), TRUE);
+ $this->assertEquals($c->hasValueOneOf(array()), false);
+ $this->assertEquals($c->hasValueOneOf(array('missing')), false);
+ $this->assertEquals($c->hasValueOneOf(array('exists_true')), true);
+ $this->assertEquals($c->hasValueOneOf(array('exists_null')), true);
- $this->assertEquals($c->hasValueOneOf(array('missing1', 'missing2')), FALSE);
- $this->assertEquals($c->hasValueOneOf(array('exists_true', 'missing')), TRUE);
- $this->assertEquals($c->hasValueOneOf(array('missing', 'exists_true')), TRUE);
+ $this->assertEquals($c->hasValueOneOf(array('missing1', 'missing2')), false);
+ $this->assertEquals($c->hasValueOneOf(array('exists_true', 'missing')), true);
+ $this->assertEquals($c->hasValueOneOf(array('missing', 'exists_true')), true);
}
/**
@@ -100,61 +100,91 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
$c = SimpleSAML_Configuration::loadFromArray(array());
$this->assertEquals($c->getBaseURL(), 'simplesaml/');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => 'simplesaml/',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'simplesaml/'));
$this->assertEquals($c->getBaseURL(), 'simplesaml/');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => '/simplesaml/',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => '/simplesaml/'));
$this->assertEquals($c->getBaseURL(), 'simplesaml/');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => 'path/to/simplesaml/',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'path/to/simplesaml/'));
$this->assertEquals($c->getBaseURL(), 'path/to/simplesaml/');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => '/path/to/simplesaml/',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => '/path/to/simplesaml/'));
$this->assertEquals($c->getBaseURL(), 'path/to/simplesaml/');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => 'https://example.org/ssp/',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'https://example.org/ssp/'));
$this->assertEquals($c->getBaseURL(), 'ssp/');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => 'https://example.org/',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'https://example.org/'));
$this->assertEquals($c->getBaseURL(), '');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => 'http://example.org/ssp/',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'http://example.org/ssp/'));
$this->assertEquals($c->getBaseURL(), 'ssp/');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => '',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => ''));
$this->assertEquals($c->getBaseURL(), '');
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => '/',
- ));
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => '/'));
$this->assertEquals($c->getBaseURL(), '');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'simplesaml'));
+ $this->assertEquals($c->getBaseURL(), 'simplesaml/');
}
/**
- * Test that SimpleSAML_Configuration::getBaseURL() fails if given a path without trailing slash
- * @expectedException \SimpleSAML\Error\CriticalConfigurationError
+ * Test SimpleSAML_Configuration::getBasePath()
*/
- public function testGetBaseURLError() {
- $c = SimpleSAML_Configuration::loadFromArray(array(
- 'baseurlpath' => 'simplesaml',
- ));
- $c->getBaseURL();
+ public function testGetBasePath() {
+ $c = SimpleSAML_Configuration::loadFromArray(array());
+ $this->assertEquals($c->getBasePath(), '/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'simplesaml/'));
+ $this->assertEquals($c->getBasePath(), '/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => '/simplesaml/'));
+ $this->assertEquals($c->getBasePath(), '/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'simplesaml'));
+ $this->assertEquals($c->getBasePath(), '/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => '/simplesaml'));
+ $this->assertEquals($c->getBasePath(), '/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'path/to/simplesaml/'));
+ $this->assertEquals($c->getBasePath(), '/path/to/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => '/path/to/simplesaml/'));
+ $this->assertEquals($c->getBasePath(), '/path/to/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => '/path/to/simplesaml'));
+ $this->assertEquals($c->getBasePath(), '/path/to/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'https://example.org/ssp/'));
+ $this->assertEquals($c->getBasePath(), '/ssp/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'https://example.org/'));
+ $this->assertEquals($c->getBasePath(), '/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'http://example.org/ssp/'));
+ $this->assertEquals($c->getBasePath(), '/ssp/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'http://example.org/ssp/simplesaml'));
+ $this->assertEquals($c->getBasePath(), '/ssp/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'http://example.org/ssp/simplesaml/'));
+ $this->assertEquals($c->getBasePath(), '/ssp/simplesaml/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => ''));
+ $this->assertEquals($c->getBasePath(), '/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => '/'));
+ $this->assertEquals($c->getBasePath(), '/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'https://example.org:8443'));
+ $this->assertEquals($c->getBasePath(), '/');
+
+ $c = SimpleSAML_Configuration::loadFromArray(array('baseurlpath' => 'https://example.org:8443/'));
+ $this->assertEquals($c->getBasePath(), '/');
}
/**
@@ -165,7 +195,7 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
'basedir' => '/basedir/',
));
- $this->assertEquals($c->resolvePath(NULL), NULL);
+ $this->assertEquals($c->resolvePath(null), null);
$this->assertEquals($c->resolvePath('/otherdir'), '/otherdir');
$this->assertEquals($c->resolvePath('relativedir'), '/basedir/relativedir');
@@ -183,7 +213,7 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
'slashes_opt' => 'slashes//',
));
- $this->assertEquals($c->getPathValue('missing'), NULL);
+ $this->assertEquals($c->getPathValue('missing'), null);
$this->assertEquals($c->getPathValue('path_opt'), '/basedir/path/');
$this->assertEquals($c->getPathValue('slashes_opt'), '/basedir/slashes/');
}
@@ -211,12 +241,12 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
*/
public function testGetBoolean() {
$c = SimpleSAML_Configuration::loadFromArray(array(
- 'true_opt' => TRUE,
- 'false_opt' => FALSE,
+ 'true_opt' => true,
+ 'false_opt' => false,
));
$this->assertEquals($c->getBoolean('missing_opt', '--missing--'), '--missing--');
- $this->assertEquals($c->getBoolean('true_opt', '--missing--'), TRUE);
- $this->assertEquals($c->getBoolean('false_opt', '--missing--'), FALSE);
+ $this->assertEquals($c->getBoolean('true_opt', '--missing--'), true);
+ $this->assertEquals($c->getBoolean('false_opt', '--missing--'), false);
}
/**
@@ -265,7 +295,7 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
*/
public function testGetStringWrong() {
$c = SimpleSAML_Configuration::loadFromArray(array(
- 'wrong' => FALSE,
+ 'wrong' => false,
));
$c->getString('wrong');
}
@@ -494,8 +524,8 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
*/
public function testGetOptions() {
$c = SimpleSAML_Configuration::loadFromArray(array(
- 'a' => TRUE,
- 'b' => NULL,
+ 'a' => true,
+ 'b' => null,
));
$this->assertEquals($c->getOptions(), array('a', 'b'));
}
@@ -505,10 +535,10 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
*/
public function testToArray() {
$c = SimpleSAML_Configuration::loadFromArray(array(
- 'a' => TRUE,
- 'b' => NULL,
+ 'a' => true,
+ 'b' => null,
));
- $this->assertEquals($c->toArray(), array('a' => TRUE, 'b' => NULL));
+ $this->assertEquals($c->toArray(), array('a' => true, 'b' => null));
}
@@ -536,14 +566,14 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
array(
array(
'Location' => 'https://example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
),
),
// define the ResponseLocation too
array(
array(
'Location' => 'https://example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
'ResponseLocation' => 'https://example.com/endpoint.php',
),
),
@@ -552,12 +582,12 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
array(
'index' => 1,
'Location' => 'https://www1.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_REDIRECT,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT,
),
array(
'index' => 2,
'Location' => 'https://www2.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
),
),
// make sure isDefault has priority over indexes
@@ -565,13 +595,13 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
array(
'index' => 1,
'Location' => 'https://www2.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
),
array(
'index' => 2,
'isDefault' => true,
'Location' => 'https://www1.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_REDIRECT,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT,
),
),
// make sure endpoints with invalid bindings are ignored and those marked as NOT default are still used
@@ -585,7 +615,7 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
'index' => 2,
'isDefault' => false,
'Location' => 'https://www2.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
),
),
);
@@ -593,34 +623,34 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
// output should be completed with the default binding (HTTP-POST for ACS)
array(
'Location' => 'https://example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
),
// we should just get the first endpoint with the default binding
array(
'Location' => 'https://www1.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
),
// if we specify the binding, we should get it back
array(
'Location' => 'https://example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST
),
// if we specify ResponseLocation, we should get it back too
array(
'Location' => 'https://example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
'ResponseLocation' => 'https://example.com/endpoint.php',
),
// indexes must NOT be taken into account, order is the only thing that matters here
array(
'Location' => 'https://www1.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_REDIRECT,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT,
'index' => 1,
),
// isDefault must have higher priority than indexes
array(
'Location' => 'https://www1.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_REDIRECT,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT,
'isDefault' => true,
'index' => 2,
),
@@ -629,7 +659,7 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
'index' => 2,
'isDefault' => false,
'Location' => 'https://www2.example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_POST,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_POST,
)
);
@@ -644,11 +674,11 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
);
$valid_bindings = array(
- SAML2_Const::BINDING_HTTP_POST,
- SAML2_Const::BINDING_HTTP_REDIRECT,
- SAML2_Const::BINDING_HOK_SSO,
- SAML2_Const::BINDING_HTTP_ARTIFACT.
- SAML2_Const::BINDING_SOAP,
+ \SAML2\Constants::BINDING_HTTP_POST,
+ \SAML2\Constants::BINDING_HTTP_REDIRECT,
+ \SAML2\Constants::BINDING_HOK_SSO,
+ \SAML2\Constants::BINDING_HTTP_ARTIFACT.
+ \SAML2\Constants::BINDING_SOAP,
);
// run all general tests with AssertionConsumerService endpoint type
@@ -676,14 +706,14 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
$this->assertEquals(
array(
'Location' => 'https://example.com/ars',
- 'Binding' => SAML2_Const::BINDING_SOAP,
+ 'Binding' => \SAML2\Constants::BINDING_SOAP,
),
$c->getDefaultEndpoint('ArtifactResolutionService')
);
$this->assertEquals(
array(
'Location' => 'https://example.com/slo',
- 'Binding' => SAML2_Const::BINDING_HTTP_REDIRECT,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT,
),
$c->getDefaultEndpoint('SingleLogoutService')
);
@@ -743,7 +773,7 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
$e = array(
array(
'Location' => 'https://example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_REDIRECT,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT,
'ResponseLocation' => 'https://example.com/response.php',
)
);
@@ -794,7 +824,7 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
array(
array(
'Location' => 'https://example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_REDIRECT,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT,
'ResponseLocation' => 1234,
),
),
@@ -802,7 +832,7 @@ class Test_SimpleSAML_Configuration extends PHPUnit_Framework_TestCase
array(
array(
'Location' => 'https://example.com/endpoint.php',
- 'Binding' => SAML2_Const::BINDING_HTTP_REDIRECT,
+ 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT,
'index' => 'string',
),
),