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
98c63208
Commit
98c63208
authored
9 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Reformat the AttributeValueMap class and its test to comply with our coding standards.
parent
f00b5f63
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/core/lib/Auth/Process/AttributeValueMap.php
+26
-19
26 additions, 19 deletions
modules/core/lib/Auth/Process/AttributeValueMap.php
tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php
+28
-13
28 additions, 13 deletions
...s/modules/core/lib/Auth/Process/AttributeValueMapTest.php
with
54 additions
and
32 deletions
modules/core/lib/Auth/Process/AttributeValueMap.php
+
26
−
19
View file @
98c63208
...
@@ -4,9 +4,10 @@
...
@@ -4,9 +4,10 @@
* Filter to create target attribute based on value(s) in source attribute
* Filter to create target attribute based on value(s) in source attribute
*
*
* @author Martin van Es, m7
* @author Martin van Es, m7
* @package
s
impleSAMLphp
* @package
S
impleSAMLphp
*/
*/
class
sspmod_core_Auth_Process_AttributeValueMap
extends
SimpleSAML_Auth_ProcessingFilter
{
class
sspmod_core_Auth_Process_AttributeValueMap
extends
SimpleSAML_Auth_ProcessingFilter
{
/**
/**
* The attributename we should assign values to (ie target)
* The attributename we should assign values to (ie target)
...
@@ -24,27 +25,29 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process
...
@@ -24,27 +25,29 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process
private
$values
=
array
();
private
$values
=
array
();
/**
/**
* Wether $sourceattribute should be kept
* W
h
ether $sourceattribute should be kept
*/
*/
private
$keep
=
false
;
private
$keep
=
false
;
/**
/**
* Wether $target attribute values should be replaced by new values
* W
h
ether $target attribute values should be replaced by new values
*/
*/
private
$replace
=
false
;
private
$replace
=
false
;
/**
/**
* Initialize this filter.
* Initialize this filter.
*
*
* @param array $config Configuration information about this filter.
* @param array $config Configuration information about this filter.
* @param mixed $reserved For future use.
* @param mixed $reserved For future use.
* @throws SimpleSAML_Error_Exception If the configuration is not valid.
*/
*/
public
function
__construct
(
$config
,
$reserved
)
{
public
function
__construct
(
$config
,
$reserved
)
{
parent
::
__construct
(
$config
,
$reserved
);
parent
::
__construct
(
$config
,
$reserved
);
assert
(
'is_array($config)'
);
assert
(
'is_array($config)'
);
/
* V
alidate configuration
. */
/
/ v
alidate configuration
foreach
(
$config
as
$name
=>
$value
)
{
foreach
(
$config
as
$name
=>
$value
)
{
if
(
is_int
(
$name
))
{
if
(
is_int
(
$name
))
{
// check if this is an option
// check if this is an option
...
@@ -58,17 +61,17 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process
...
@@ -58,17 +61,17 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process
continue
;
continue
;
}
}
//
S
et targetattribute
//
s
et targetattribute
if
(
$name
===
'targetattribute'
)
{
if
(
$name
===
'targetattribute'
)
{
$this
->
targetattribute
=
$value
;
$this
->
targetattribute
=
$value
;
}
}
//
S
et sourceattribute
//
s
et sourceattribute
if
(
$name
===
'sourceattribute'
)
{
if
(
$name
===
'sourceattribute'
)
{
$this
->
sourceattribute
=
$value
;
$this
->
sourceattribute
=
$value
;
}
}
//
S
et values
//
s
et values
if
(
$name
===
'values'
)
{
if
(
$name
===
'values'
)
{
$this
->
values
=
$value
;
$this
->
values
=
$value
;
}
}
...
@@ -77,11 +80,12 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process
...
@@ -77,11 +80,12 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process
/**
/**
* Apply filter to add groups attribute.
* Apply filter.
*
*
* @param array &$request The current request
* @param array &$request The current request
*/
*/
public
function
process
(
&
$request
)
{
public
function
process
(
&
$request
)
{
SimpleSAML_Logger
::
debug
(
'AttributeValueMap - process'
);
SimpleSAML_Logger
::
debug
(
'AttributeValueMap - process'
);
assert
(
'is_array($request)'
);
assert
(
'is_array($request)'
);
...
@@ -109,7 +113,10 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process
...
@@ -109,7 +113,10 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process
if
(
$this
->
replace
or
!@
is_array
(
$attributes
[
$this
->
targetattribute
]))
{
if
(
$this
->
replace
or
!@
is_array
(
$attributes
[
$this
->
targetattribute
]))
{
$attributes
[
$this
->
targetattribute
]
=
$targetvalues
;
$attributes
[
$this
->
targetattribute
]
=
$targetvalues
;
}
else
{
}
else
{
$attributes
[
$this
->
targetattribute
]
=
array_unique
(
array_merge
(
$attributes
[
$this
->
targetattribute
],
$targetvalues
));
$attributes
[
$this
->
targetattribute
]
=
array_unique
(
array_merge
(
$attributes
[
$this
->
targetattribute
],
$targetvalues
));
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php
+
28
−
13
View file @
98c63208
...
@@ -13,16 +13,19 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -13,16 +13,19 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
* @param array $request The request state.
* @param array $request The request state.
* @return array The state array after processing.
* @return array The state array after processing.
*/
*/
private
static
function
processFilter
(
array
$config
,
array
$request
)
{
private
static
function
processFilter
(
array
$config
,
array
$request
)
{
$filter
=
new
sspmod_core_Auth_Process_AttributeValueMap
(
$config
,
null
);
$filter
=
new
sspmod_core_Auth_Process_AttributeValueMap
(
$config
,
null
);
$filter
->
process
(
$request
);
$filter
->
process
(
$request
);
return
$request
;
return
$request
;
}
}
/**
/**
* Test the most basic functionality.
* Test the most basic functionality.
*/
*/
public
function
testBasic
()
{
public
function
testBasic
()
{
$config
=
array
(
$config
=
array
(
'sourceattribute'
=>
'memberOf'
,
'sourceattribute'
=>
'memberOf'
,
'targetattribute'
=>
'eduPersonAffiliation'
,
'targetattribute'
=>
'eduPersonAffiliation'
,
...
@@ -45,10 +48,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -45,10 +48,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
$this
->
assertEquals
(
$attributes
[
'eduPersonAffiliation'
],
array
(
'member'
));
$this
->
assertEquals
(
$attributes
[
'eduPersonAffiliation'
],
array
(
'member'
));
}
}
/**
/**
* Test basic functionality, remove duplicates
* Test basic functionality, remove duplicates
*/
*/
public
function
testNoDuplicates
()
{
public
function
testNoDuplicates
()
{
$config
=
array
(
$config
=
array
(
'sourceattribute'
=>
'memberOf'
,
'sourceattribute'
=>
'memberOf'
,
'targetattribute'
=>
'eduPersonAffiliation'
,
'targetattribute'
=>
'eduPersonAffiliation'
,
...
@@ -72,10 +77,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -72,10 +77,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
$this
->
assertEquals
(
$attributes
[
'eduPersonAffiliation'
],
array
(
'member'
,
'someValue'
));
$this
->
assertEquals
(
$attributes
[
'eduPersonAffiliation'
],
array
(
'member'
,
'someValue'
));
}
}
/**
/**
* Test the %replace functionality.
* Test the %replace functionality.
*/
*/
public
function
testReplace
()
{
public
function
testReplace
()
{
$config
=
array
(
$config
=
array
(
'sourceattribute'
=>
'memberOf'
,
'sourceattribute'
=>
'memberOf'
,
'targetattribute'
=>
'eduPersonAffiliation'
,
'targetattribute'
=>
'eduPersonAffiliation'
,
...
@@ -90,7 +97,7 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -90,7 +97,7 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
$request
=
array
(
$request
=
array
(
'Attributes'
=>
array
(
'Attributes'
=>
array
(
'memberOf'
=>
array
(
'theGroup'
),
'memberOf'
=>
array
(
'theGroup'
),
'eduPersonAffiliation'
=>
array
(
'someValue'
),
'eduPersonAffiliation'
=>
array
(
'someValue'
),
),
),
);
);
$result
=
self
::
processFilter
(
$config
,
$request
);
$result
=
self
::
processFilter
(
$config
,
$request
);
...
@@ -100,10 +107,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -100,10 +107,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
$this
->
assertEquals
(
$attributes
[
'eduPersonAffiliation'
],
array
(
'member'
));
$this
->
assertEquals
(
$attributes
[
'eduPersonAffiliation'
],
array
(
'member'
));
}
}
/**
/**
* Test the %keep functionality.
* Test the %keep functionality.
*/
*/
public
function
testKeep
()
{
public
function
testKeep
()
{
$config
=
array
(
$config
=
array
(
'sourceattribute'
=>
'memberOf'
,
'sourceattribute'
=>
'memberOf'
,
'targetattribute'
=>
'eduPersonAffiliation'
,
'targetattribute'
=>
'eduPersonAffiliation'
,
...
@@ -118,7 +127,7 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -118,7 +127,7 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
$request
=
array
(
$request
=
array
(
'Attributes'
=>
array
(
'Attributes'
=>
array
(
'memberOf'
=>
array
(
'theGroup'
),
'memberOf'
=>
array
(
'theGroup'
),
'eduPersonAffiliation'
=>
array
(
'someValue'
),
'eduPersonAffiliation'
=>
array
(
'someValue'
),
),
),
);
);
$result
=
self
::
processFilter
(
$config
,
$request
);
$result
=
self
::
processFilter
(
$config
,
$request
);
...
@@ -128,12 +137,14 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -128,12 +137,14 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
$this
->
assertEquals
(
$attributes
[
'eduPersonAffiliation'
],
array
(
'someValue'
,
'member'
));
$this
->
assertEquals
(
$attributes
[
'eduPersonAffiliation'
],
array
(
'someValue'
,
'member'
));
}
}
/**
/**
* Test unknown flag Exception
* Test unknown flag Exception
*
*
* @expectedException Exception
* @expectedException Exception
*/
*/
public
function
testUnknownFlag
()
{
public
function
testUnknownFlag
()
{
$config
=
array
(
$config
=
array
(
'%test'
,
'%test'
,
'values'
=>
array
(
'values'
=>
array
(
...
@@ -147,15 +158,17 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -147,15 +158,17 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
'memberOf'
=>
array
(
'theGroup'
),
'memberOf'
=>
array
(
'theGroup'
),
),
),
);
);
$result
=
self
::
processFilter
(
$config
,
$request
);
self
::
processFilter
(
$config
,
$request
);
}
}
/**
/**
* Test missing Source attribute
* Test missing Source attribute
*
*
* @expectedException Exception
* @expectedException Exception
*/
*/
public
function
testMissingSourceAttribute
()
{
public
function
testMissingSourceAttribute
()
{
$config
=
array
(
$config
=
array
(
'targetattribute'
=>
'affiliation'
,
'targetattribute'
=>
'affiliation'
,
'values'
=>
array
(
'values'
=>
array
(
...
@@ -169,15 +182,17 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -169,15 +182,17 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
'memberOf'
=>
array
(
'theGroup'
),
'memberOf'
=>
array
(
'theGroup'
),
),
),
);
);
$result
=
self
::
processFilter
(
$config
,
$request
);
self
::
processFilter
(
$config
,
$request
);
}
}
/**
/**
* Test missing Target attribute
* Test missing Target attribute
*
*
* @expectedException Exception
* @expectedException Exception
*/
*/
public
function
testMissingTargetAttribute
()
{
public
function
testMissingTargetAttribute
()
{
$config
=
array
(
$config
=
array
(
'sourceattribute'
=>
'memberOf'
,
'sourceattribute'
=>
'memberOf'
,
'values'
=>
array
(
'values'
=>
array
(
...
@@ -191,6 +206,6 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
...
@@ -191,6 +206,6 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas
'memberOf'
=>
array
(
'theGroup'
),
'memberOf'
=>
array
(
'theGroup'
),
),
),
);
);
$result
=
self
::
processFilter
(
$config
,
$request
);
self
::
processFilter
(
$config
,
$request
);
}
}
}
}
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