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
3e0ea6e7
Commit
3e0ea6e7
authored
8 years ago
by
Jaime Pérez
Browse files
Options
Downloads
Patches
Plain Diff
tests: Add tests for the new saml:FilterScopes authproc filter.
parent
7e66127f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/modules/saml/lib/Auth/Process/FilterScopesTest.php
+137
-0
137 additions, 0 deletions
tests/modules/saml/lib/Auth/Process/FilterScopesTest.php
with
137 additions
and
0 deletions
tests/modules/saml/lib/Auth/Process/FilterScopesTest.php
0 → 100644
+
137
−
0
View file @
3e0ea6e7
<?php
/**
* Test for the saml:FilterScopes filter.
*
* @author Jaime Pérez Crespo, UNINETT AS <jaime.perez@uninett.no>
* @package SimpleSAMLphp
*/
namespace
SimpleSAML\Test\Module\saml\Auth\Process
;
class
FilterScopesTest
extends
\PHPUnit_Framework_TestCase
{
/*
* Helper function to run the filter with a given configuration.
*
* @param array $config The filter configuration.
* @param array $request The request state.
* @return array The state array after processing.
*/
private
function
processFilter
(
array
$config
,
array
$request
)
{
$filter
=
new
\SimpleSAML\Module\saml\Auth\Process\FilterScopes
(
$config
,
null
);
$filter
->
process
(
$request
);
return
$request
;
}
/**
* Test valid scopes.
*/
public
function
testValidScopes
()
{
// test declared scopes
$config
=
array
();
$request
=
array
(
'Source'
=>
array
(
'SingleSignOnService'
=>
array
(
array
(
'Binding'
=>
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
,
'Location'
=>
'https://example.org/saml2/idp/SSOService.php'
,
),
),
'scope'
=>
array
(
'example.com'
,
'example.net'
,
),
),
'Attributes'
=>
array
(
'eduPersonPrincipalName'
=>
array
(
'jdoe@example.com'
),
),
);
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
$request
[
'Attributes'
],
$result
[
'Attributes'
]);
// test multiple values
$request
[
'Attributes'
]
=
array
(
'eduPersonPrincipalName'
=>
array
(
'jdoe@example.com'
,
'jdoe@example.net'
,
),
);
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
$request
[
'Attributes'
],
$result
[
'Attributes'
]);
// test implicit scope
$request
[
'Attributes'
]
=
array
(
'eduPersonPrincipalName'
=>
array
(
'jdoe@example.org'
),
);
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
$request
[
'Attributes'
],
$result
[
'Attributes'
]);
// test alternative attributes
$config
[
'attributes'
]
=
array
(
'mail'
,
);
$request
[
'Attributes'
]
=
array
(
'mail'
=>
array
(
'john.doe@example.org'
),
);
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
$request
[
'Attributes'
],
$result
[
'Attributes'
]);
// test non-scoped attributes
$request
[
'Attributes'
][
'givenName'
]
=
'John Doe'
;
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
$request
[
'Attributes'
],
$result
[
'Attributes'
]);
}
/**
* Test invalid scopes.
*/
public
function
testInvalidScopes
()
{
// test scope not matching anything, empty attribute
$config
=
array
();
$request
=
array
(
'Source'
=>
array
(
'SingleSignOnService'
=>
array
(
array
(
'Binding'
=>
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
,
'Location'
=>
'https://example.org/saml2/idp/SSOService.php'
,
),
),
'scope'
=>
array
(
'example.com'
,
'example.net'
,
),
),
'Attributes'
=>
array
(
'eduPersonPrincipalName'
=>
array
(
'jdoe@example.edu'
),
),
);
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
array
(),
$result
[
'Attributes'
]);
// test some scopes allowed and some others not
$request
[
'Attributes'
][
'eduPersonPrincipalName'
][]
=
'jdoe@example.com'
;
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
array
(
'eduPersonPrincipalName'
=>
array
(
'jdoe@example.com'
,
),
),
$result
[
'Attributes'
]
);
// test attribute missing scope
$request
[
'Attributes'
]
=
array
(
'eduPersonPrincipalName'
=>
array
(
'jdoe'
),
);
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
$request
[
'Attributes'
],
$result
[
'Attributes'
]);
}
}
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