Skip to content

Commit 6d7af45

Browse files
committed
Attempt at a database unittest
1 parent 5191ef2 commit 6d7af45

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ matrix:
1111
allow_failures:
1212
- php: hhvm
1313

14+
services:
15+
- mysql
16+
17+
# Set up a test database we can use for the the unit tests
18+
before_install:
19+
- mysql -e 'CREATE DATABASE IF NOT EXISTS simplesamlphp;'
20+
- mysql -e 'CREATE TABLE `AttributeFromSQL` (
21+
`uid` VARCHAR(100) NOT NULL,
22+
`sp` VARCHAR(250) DEFAULT "%",
23+
`attribute` VARCHAR(30) NOT NULL,
24+
`value` TEXT
25+
) DEFAULT CHARSET=utf8;
26+
GRANT ALL ON `simplesamlphp`.* TO `phpunit`@`localhost` IDENTIFIED BY "phpunit";
27+
' simplesamlphp
28+
- mysql -e "
29+
INSERT INTO AttributeFromSQL (uid, sp, attribute, value) VALUES ('user@example.org', '%', 'eduPersonEntitlement', 'urn:mace:exampleIdP.org:demoservice:demo-admin');
30+
INSERT INTO AttributeFromSQL (uid, sp, attribute, value) VALUES ('user@example.org', 'https://idp.example.org/idp/shibboleth', 'eduPersonEntitlement', 'urn:mace:grnet.gr:eduroam:admin');
31+
INSERT INTO AttributeFromSQL (uid, sp, attribute, value) VALUES ('user@example.org', '%', 'eduPersonAffiliation', 'faculty');
32+
INSERT INTO AttributeFromSQL (uid, attribute, value) VALUES ('user@example.org', 'mail', 'user@example.org');
33+
" simplesamlphp
34+
1435
before_script:
1536
composer update --dev
1637

tests/lib/Auth/Process/AttributeFromSQLTest.php

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,82 @@ protected function setUp()
2525
\SimpleSAML_Configuration::loadFromArray(array(), '[ARRAY]', 'simplesaml');
2626
}
2727

28-
public function testAny()
28+
/**
29+
* Test the example from docs
30+
*/
31+
public function testExample()
32+
{
33+
$config = array(
34+
'attribute' => 'eduPersonPrincipalName',
35+
'limit' => array('eduPersonEntitlement', 'eduPersonAffiliation'),
36+
'replace' => false,
37+
'database' => array(
38+
'username' => 'phpunit',
39+
'password' => 'phpunit',
40+
),
41+
);
42+
$request = array(
43+
'Attributes' => array(
44+
'eduPersonPrincipalName' => array('user@example.org'),
45+
'eduPersonAffiliation' => array('member'),
46+
'displayName' => array('Example User'),
47+
),
48+
'Destination' => array(
49+
'entityid' => 'https://idp.example.org/idp/shibboleth',
50+
),
51+
);
52+
$result = self::processFilter($config, $request);
53+
$attributes = $result['Attributes'];
54+
$expectedData = array(
55+
'eduPersonPrincipalName' => array('user@example.org'),
56+
'displayName' => array('Example User'),
57+
'eduPersonEntitlement' => array(
58+
'urn:mace:exampleIdP.org:demoservice:demo-admin',
59+
'urn:mace:grnet.gr:eduroam:admin',
60+
),
61+
'eduPersonAffiliation' => array(
62+
'member',
63+
'faculty',
64+
),
65+
);
66+
$this->assertEquals($expectedData, $attributes, "Expected data was not correct");
67+
}
68+
69+
/**
70+
* Test attribute replacement
71+
*/
72+
public function testReplace()
2973
{
30-
$this->assertTrue(true, 'Just for travis.yml test');
74+
$config = array(
75+
'attribute' => 'eduPersonPrincipalName',
76+
'limit' => array('mail', 'eduPersonAffiliation'),
77+
'replace' => true,
78+
'database' => array(
79+
'username' => 'phpunit',
80+
'password' => 'phpunit',
81+
),
82+
);
83+
$request = array(
84+
'Attributes' => array(
85+
'eduPersonPrincipalName' => array('user@example.org'),
86+
'eduPersonAffiliation' => array('member'),
87+
'displayName' => array('Example User'),
88+
),
89+
'Destination' => array(
90+
'entityid' => 'https://idp.example.org/idp/shibboleth',
91+
),
92+
);
93+
$result = self::processFilter($config, $request);
94+
$attributes = $result['Attributes'];
95+
$expectedData = array(
96+
'eduPersonPrincipalName' => array('user@example.org'),
97+
'displayName' => array('Example User'),
98+
'eduPersonAffiliation' => array(
99+
'faculty',
100+
),
101+
'mail' => array('user@example.org'),
102+
);
103+
$this->assertEquals($expectedData, $attributes, "Expected data was not correct");
31104
}
105+
32106
}

0 commit comments

Comments
 (0)