Skip to content
Snippets Groups Projects
Commit 282e1979 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Reorganize and clean tests.

parent d8b85655
No related branches found
No related tags found
No related merge requests found
<?php
/**
* Class Utils_MetadataTest
* Tests related to SAML metadata.
*/
class Utils_MetadataTest extends PHPUnit_Framework_TestCase
{
......@@ -45,7 +46,7 @@ class Utils_MetadataTest extends PHPUnit_Framework_TestCase
// test basic name parsing
$contact = array(
'contactType' => 'technical',
'name' => 'John Doe'
'name' => 'John Doe'
);
$parsed = SimpleSAML_Utils_Config_Metadata::getContact($contact);
$this->assertArrayNotHasKey('name', $parsed);
......@@ -57,7 +58,7 @@ class Utils_MetadataTest extends PHPUnit_Framework_TestCase
// test comma-separated names
$contact = array(
'contactType' => 'technical',
'name' => 'Doe, John'
'name' => 'Doe, John'
);
$parsed = SimpleSAML_Utils_Config_Metadata::getContact($contact);
$this->assertArrayHasKey('givenName', $parsed);
......@@ -68,7 +69,7 @@ class Utils_MetadataTest extends PHPUnit_Framework_TestCase
// test long names
$contact = array(
'contactType' => 'technical',
'name' => 'John Fitzgerald Doe Smith'
'name' => 'John Fitzgerald Doe Smith'
);
$parsed = SimpleSAML_Utils_Config_Metadata::getContact($contact);
$this->assertArrayNotHasKey('name', $parsed);
......@@ -79,7 +80,7 @@ class Utils_MetadataTest extends PHPUnit_Framework_TestCase
// test comma-separated long names
$contact = array(
'contactType' => 'technical',
'name' => 'Doe Smith, John Fitzgerald'
'name' => 'Doe Smith, John Fitzgerald'
);
$parsed = SimpleSAML_Utils_Config_Metadata::getContact($contact);
$this->assertArrayNotHasKey('name', $parsed);
......
<?php
/**
* Class SimpleSAML_Metadata_SAMLBuilderTest
*/
class SimpleSAML_Metadata_SAMLBuilderTest extends PHPUnit_Framework_TestCase
{
/**
* Test the requeste attributes are valued correctly.
*/
public function testAttributes()
{
$entityId = 'https://entity.example.com/id';
// test SP20 array parsing, no friendly name
$set = 'saml20-sp-remote';
$metadata = array(
'entityid' => $entityId,
'name' => array('en' => 'Test SP'),
'metadata-set' => $set,
'attributes' => array(
'urn:oid:1.3.6.1.4.1.5923.1.1.1.10',
'urn:oid:1.3.6.1.4.1.5923.1.1.1.6',
'urn:oid:0.9.2342.19200300.100.1.3',
'urn:oid:2.5.4.3',
),
);
$samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$samlBuilder->addMetadata($set, $metadata);
$spDesc = $samlBuilder->getEntityDescriptor();
$acs = $spDesc->getElementsByTagName("AttributeConsumingService");
$this->assertEquals(1, $acs->length);
$attributes = $acs->item(0)->getElementsByTagName("RequestedAttribute");
$this->assertEquals(4, $attributes->length);
for ($c = 0; $c < $attributes->length; $c++) {
$curAttribute = $attributes->item($c);
$this->assertTrue($curAttribute->hasAttribute("Name"));
$this->assertFalse($curAttribute->hasAttribute("FriendlyName"));
$this->assertEquals($metadata['attributes'][$c], $curAttribute->getAttribute("Name"));
}
// test SP20 array parsing, no friendly name
$set = 'saml20-sp-remote';
$metadata = array(
'entityid' => $entityId,
'name' => array('en' => 'Test SP'),
'metadata-set' => $set,
'attributes' => array(
'eduPersonTargetedID' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10',
'eduPersonPrincipalName' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6',
'eduPersonOrgDN' => 'urn:oid:0.9.2342.19200300.100.1.3',
'cn' => 'urn:oid:2.5.4.3',
),
);
$samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$samlBuilder->addMetadata($set, $metadata);
$spDesc = $samlBuilder->getEntityDescriptor();
$acs = $spDesc->getElementsByTagName("AttributeConsumingService");
$this->assertEquals(1, $acs->length);
$attributes = $acs->item(0)->getElementsByTagName("RequestedAttribute");
$this->assertEquals(4, $attributes->length);
$keys = array_keys($metadata['attributes']);
for ($c = 0; $c < $attributes->length; $c++) {
$curAttribute = $attributes->item($c);
$this->assertTrue($curAttribute->hasAttribute("Name"));
$this->assertTrue($curAttribute->hasAttribute("FriendlyName"));
$this->assertEquals($metadata['attributes'][$keys[$c]], $curAttribute->getAttribute("Name"));
$this->assertEquals($keys[$c], $curAttribute->getAttribute("FriendlyName"));
}
// test SP13 array parsing, no friendly name
$set = 'shib13-sp-remote';
$metadata = array(
'entityid' => $entityId,
'name' => array('en' => 'Test SP'),
'metadata-set' => $set,
'attributes' => array(
'urn:oid:1.3.6.1.4.1.5923.1.1.1.10',
'urn:oid:1.3.6.1.4.1.5923.1.1.1.6',
'urn:oid:0.9.2342.19200300.100.1.3',
'urn:oid:2.5.4.3',
),
);
$samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$samlBuilder->addMetadata($set, $metadata);
$spDesc = $samlBuilder->getEntityDescriptor();
$acs = $spDesc->getElementsByTagName("AttributeConsumingService");
$this->assertEquals(1, $acs->length);
$attributes = $acs->item(0)->getElementsByTagName("RequestedAttribute");
$this->assertEquals(4, $attributes->length);
for ($c = 0; $c < $attributes->length; $c++) {
$curAttribute = $attributes->item($c);
$this->assertTrue($curAttribute->hasAttribute("Name"));
$this->assertFalse($curAttribute->hasAttribute("FriendlyName"));
$this->assertEquals($metadata['attributes'][$c], $curAttribute->getAttribute("Name"));
}
// test SP20 array parsing, no friendly name
$set = 'shib13-sp-remote';
$metadata = array(
'entityid' => $entityId,
'name' => array('en' => 'Test SP'),
'metadata-set' => $set,
'attributes' => array(
'eduPersonTargetedID' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10',
'eduPersonPrincipalName' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6',
'eduPersonOrgDN' => 'urn:oid:0.9.2342.19200300.100.1.3',
'cn' => 'urn:oid:2.5.4.3',
),
);
$samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$samlBuilder->addMetadata($set, $metadata);
$spDesc = $samlBuilder->getEntityDescriptor();
$acs = $spDesc->getElementsByTagName("AttributeConsumingService");
$this->assertEquals(1, $acs->length);
$attributes = $acs->item(0)->getElementsByTagName("RequestedAttribute");
$this->assertEquals(4, $attributes->length);
$keys = array_keys($metadata['attributes']);
for ($c = 0; $c < $attributes->length; $c++) {
$curAttribute = $attributes->item($c);
$this->assertTrue($curAttribute->hasAttribute("Name"));
$this->assertTrue($curAttribute->hasAttribute("FriendlyName"));
$this->assertEquals($metadata['attributes'][$keys[$c]], $curAttribute->getAttribute("Name"));
$this->assertEquals($keys[$c], $curAttribute->getAttribute("FriendlyName"));
}
}
}
<?php
/**
* Class SimpleSAML_Metadata_SAMLBuilderTest
*/
class SimpleSAML_Metadata_SAMLBuilderTest extends PHPUnit_Framework_TestCase
{
/**
* Test the requeste attributes are valued correctly.
*/
public function testAttributes()
{
$entityId = 'https://entity.examle.com/id';
// test SP20 array parsing, no friendly name
$set = 'saml20-sp-remote';
$metadata = array(
'entityid' => $entityId,
'name' => array('en' => 'Test SP'),
'metadata-set' => $set,
'attributes' => array(
'urn:oid:1.3.6.1.4.1.5923.1.1.1.10',
'urn:oid:1.3.6.1.4.1.5923.1.1.1.6',
'urn:oid:0.9.2342.19200300.100.1.3',
'urn:oid:2.5.4.3',
),
);
$samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$samlBuilder->addMetadata($set, $metadata);
$spDesc = $samlBuilder->getEntityDescriptor();
$acs = $spDesc->getElementsByTagName("AttributeConsumingService");
$this->assertEquals(1, $acs->length);
$attributes = $acs->item(0)->getElementsByTagName("RequestedAttribute");
$this->assertEquals(4, $attributes->length);
for ($c = 0; $c < $attributes->length; $c++) {
$curAttribute = $attributes->item($c);
$this->assertTrue($curAttribute->hasAttribute("Name"));
$this->assertFalse($curAttribute->hasAttribute("FriendlyName"));
$this->assertEquals($metadata['attributes'][$c], $curAttribute->getAttribute("Name"));
}
// test SP20 array parsing, no friendly name
$set = 'saml20-sp-remote';
$metadata = array(
'entityid' => $entityId,
'name' => array('en' => 'Test SP'),
'metadata-set' => $set,
'attributes' => array(
'eduPersonTargetedID' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10',
'eduPersonPrincipalName' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6',
'eduPersonOrgDN' => 'urn:oid:0.9.2342.19200300.100.1.3',
'cn' => 'urn:oid:2.5.4.3',
),
);
$samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$samlBuilder->addMetadata($set, $metadata);
$spDesc = $samlBuilder->getEntityDescriptor();
$acs = $spDesc->getElementsByTagName("AttributeConsumingService");
$this->assertEquals(1, $acs->length);
$attributes = $acs->item(0)->getElementsByTagName("RequestedAttribute");
$this->assertEquals(4, $attributes->length);
$keys = array_keys($metadata['attributes']);
for ($c = 0; $c < $attributes->length; $c++) {
$curAttribute = $attributes->item($c);
$this->assertTrue($curAttribute->hasAttribute("Name"));
$this->assertTrue($curAttribute->hasAttribute("FriendlyName"));
$this->assertEquals($metadata['attributes'][$keys[$c]], $curAttribute->getAttribute("Name"));
$this->assertEquals($keys[$c], $curAttribute->getAttribute("FriendlyName"));
}
// test SP13 array parsing, no friendly name
$set = 'shib13-sp-remote';
$metadata = array(
'entityid' => $entityId,
'name' => array('en' => 'Test SP'),
'metadata-set' => $set,
'attributes' => array(
'urn:oid:1.3.6.1.4.1.5923.1.1.1.10',
'urn:oid:1.3.6.1.4.1.5923.1.1.1.6',
'urn:oid:0.9.2342.19200300.100.1.3',
'urn:oid:2.5.4.3',
),
);
$samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$samlBuilder->addMetadata($set, $metadata);
$spDesc = $samlBuilder->getEntityDescriptor();
$acs = $spDesc->getElementsByTagName("AttributeConsumingService");
$this->assertEquals(1, $acs->length);
$attributes = $acs->item(0)->getElementsByTagName("RequestedAttribute");
$this->assertEquals(4, $attributes->length);
for ($c = 0; $c < $attributes->length; $c++) {
$curAttribute = $attributes->item($c);
$this->assertTrue($curAttribute->hasAttribute("Name"));
$this->assertFalse($curAttribute->hasAttribute("FriendlyName"));
$this->assertEquals($metadata['attributes'][$c], $curAttribute->getAttribute("Name"));
}
// test SP20 array parsing, no friendly name
$set = 'shib13-sp-remote';
$metadata = array(
'entityid' => $entityId,
'name' => array('en' => 'Test SP'),
'metadata-set' => $set,
'attributes' => array(
'eduPersonTargetedID' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10',
'eduPersonPrincipalName' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6',
'eduPersonOrgDN' => 'urn:oid:0.9.2342.19200300.100.1.3',
'cn' => 'urn:oid:2.5.4.3',
),
);
$samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$samlBuilder->addMetadata($set, $metadata);
$spDesc = $samlBuilder->getEntityDescriptor();
$acs = $spDesc->getElementsByTagName("AttributeConsumingService");
$this->assertEquals(1, $acs->length);
$attributes = $acs->item(0)->getElementsByTagName("RequestedAttribute");
$this->assertEquals(4, $attributes->length);
$keys = array_keys($metadata['attributes']);
for ($c = 0; $c < $attributes->length; $c++) {
$curAttribute = $attributes->item($c);
$this->assertTrue($curAttribute->hasAttribute("Name"));
$this->assertTrue($curAttribute->hasAttribute("FriendlyName"));
$this->assertEquals($metadata['attributes'][$keys[$c]], $curAttribute->getAttribute("Name"));
$this->assertEquals($keys[$c], $curAttribute->getAttribute("FriendlyName"));
}
}
}
......@@ -2,9 +2,9 @@
/**
* Class Utils_Arrays
* Tests for SimpleSAML_Utils_Arrays.
*/
class Utils_Arrays extends PHPUnit_Framework_TestCase
class Utils_ArraysTest extends PHPUnit_Framework_TestCase
{
/**
......@@ -12,7 +12,8 @@ class Utils_Arrays extends PHPUnit_Framework_TestCase
*
* @expectedException SimpleSAML_Error_Exception
*/
public function testNormalizeAttributesArrayBadInput() {
public function testNormalizeAttributesArrayBadInput()
{
SimpleSAML_Utils_Arrays::normalizeAttributesArray('string');
}
......@@ -21,7 +22,8 @@ class Utils_Arrays extends PHPUnit_Framework_TestCase
*
* @expectedException SimpleSAML_Error_Exception
*/
public function testNormalizeAttributesArrayBadKeys() {
public function testNormalizeAttributesArrayBadKeys()
{
SimpleSAML_Utils_Arrays::normalizeAttributesArray(array('attr1' => 'value1', 1 => 'value2'));
}
......@@ -30,14 +32,16 @@ class Utils_Arrays extends PHPUnit_Framework_TestCase
*
* @expectedException SimpleSAML_Error_Exception
*/
public function testNormalizeAttributesArrayBadValues() {
public function testNormalizeAttributesArrayBadValues()
{
SimpleSAML_Utils_Arrays::normalizeAttributesArray(array('attr1' => 'value1', 'attr2' => 0));
}
/**
* Test the normalizeAttributesArray() function.
*/
public function testNormalizeAttributesArray() {
public function testNormalizeAttributesArray()
{
$attributes = array(
'key1' => 'value1',
'key2' => array('value2', 'value3'),
......
<?php
/**
* Class Utils_Net
* Tests for SimpleSAML_Utils_Test.
*/
class Utils_Net extends PHPUnit_Framework_TestCase
class Utils_Net_Test extends PHPUnit_Framework_TestCase
{
......@@ -19,8 +20,8 @@ class Utils_Net extends PHPUnit_Framework_TestCase
$this->assertFalse(SimpleSAML_Utils_Net::ipCIDRcheck('127.0.0.256/24', '127.0.0.1'));
// check wrong IP
$this->assertTrue(SimpleSAML_Utils_Net::ipCIDRcheck('127.0.0.0/24', '127.0.0'));
$this->assertTrue(SimpleSAML_Utils_Net::ipCIDRcheck('127.0.0.0/24', '127.0.0.*'));
$this->assertFalse(SimpleSAML_Utils_Net::ipCIDRcheck('127.0.0.0/24', '127.0.0'));
$this->assertFalse(SimpleSAML_Utils_Net::ipCIDRcheck('127.0.0.0/24', '127.0.0.*'));
// check limits for standard classes
$this->assertTrue(SimpleSAML_Utils_Net::ipCIDRcheck('127.0.0.0/24', '127.0.0.0'));
......
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
......@@ -11,8 +10,11 @@
syntaxCheck="false"
bootstrap="./../../vendor/autoload.php">
<testsuites>
<testsuite name="Test Suite">
<directory>./../../tests</directory>
<testsuite name="Utils">
<directory>./../../tests/Utils/</directory>
</testsuite>
<testsuite name="Metadata">
<directory>./../../tests/Metadata/</directory>
</testsuite>
</testsuites>
<filter>
......
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