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
0
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
3a6e1507
Commit
3a6e1507
authored
9 years ago
by
Thijs Kinkhorst
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for ScopeFromAttribute filter.
parent
f14d48a3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/modules/core/lib/Auth/Process/ScopeFromAttributeTest.php
+122
-0
122 additions, 0 deletions
.../modules/core/lib/Auth/Process/ScopeFromAttributeTest.php
with
122 additions
and
0 deletions
tests/modules/core/lib/Auth/Process/ScopeFromAttributeTest.php
0 → 100644
+
122
−
0
View file @
3a6e1507
<?php
/**
* Test for the core:ScopeFromAttribute filter.
*/
class
Test_Core_Auth_Process_ScopeFromAttribute
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
static
function
processFilter
(
array
$config
,
array
$request
)
{
$filter
=
new
sspmod_core_Auth_Process_ScopeFromAttribute
(
$config
,
NULL
);
$filter
->
process
(
$request
);
return
$request
;
}
/*
* Test the most basic functionality.
*/
public
function
testBasic
()
{
$config
=
array
(
'sourceAttribute'
=>
'eduPersonPrincipalName'
,
'targetAttribute'
=>
'scope'
,
);
$request
=
array
(
'Attributes'
=>
array
(
'eduPersonPrincipalName'
=>
array
(
'jdoe@example.com'
),
)
);
$result
=
self
::
processFilter
(
$config
,
$request
);
$attributes
=
$result
[
'Attributes'
];
$this
->
assertArrayHasKey
(
'scope'
,
$attributes
);
$this
->
assertEquals
(
$attributes
[
'scope'
],
array
(
'example.com'
));
}
/*
* If scope already set, module must not overwrite.
*/
public
function
testNoOverwrite
()
{
$config
=
array
(
'sourceAttribute'
=>
'eduPersonPrincipalName'
,
'targetAttribute'
=>
'scope'
,
);
$request
=
array
(
'Attributes'
=>
array
(
'eduPersonPrincipalName'
=>
array
(
'jdoe@example.com'
),
'scope'
=>
array
(
'example.edu'
)
)
);
$result
=
self
::
processFilter
(
$config
,
$request
);
$attributes
=
$result
[
'Attributes'
];
$this
->
assertEquals
(
$attributes
[
'scope'
],
array
(
'example.edu'
));
}
/*
* If source attribute not set, nothing happens
*/
public
function
testNoSourceAttribute
()
{
$config
=
array
(
'sourceAttribute'
=>
'eduPersonPrincipalName'
,
'targetAttribute'
=>
'scope'
,
);
$request
=
array
(
'Attributes'
=>
array
(
'mail'
=>
array
(
'j.doe@example.edu'
,
'john@example.org'
),
'scope'
=>
array
(
'example.edu'
)
)
);
$result
=
self
::
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
$request
[
'Attributes'
],
$result
[
'Attributes'
]);
}
/*
* When multiple @ signs in attribute, should use last one.
*/
public
function
testMultiAt
()
{
$config
=
array
(
'sourceAttribute'
=>
'eduPersonPrincipalName'
,
'targetAttribute'
=>
'scope'
,
);
$request
=
array
(
'Attributes'
=>
array
(
'eduPersonPrincipalName'
=>
array
(
'john@doe@example.com'
),
)
);
$result
=
self
::
processFilter
(
$config
,
$request
);
$attributes
=
$result
[
'Attributes'
];
$this
->
assertEquals
(
$attributes
[
'scope'
],
array
(
'example.com'
));
}
/*
* When the source attribute doesn't have a scope, a warning is emitted
* NOTE: currently disabled: this triggers a warning and a warning
* wants to start a session which we cannot do in phpunit. How to fix?
*/
/* public function testNoAt()
{
$config = array(
'sourceAttribute' => 'eduPersonPrincipalName',
'targetAttribute' => 'scope',
);
$request = array(
'Attributes' => array(
'eduPersonPrincipalName' => array('johndoe'),
)
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertArrayNotHasKey('scope', $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