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
ae45cd82
Unverified
Commit
ae45cd82
authored
4 years ago
by
Zenon Mousmoulas
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix bug in saml:NameIDAttribute authproc filter (#1325)
Fix several bugs in saml:NameIDAttribute authproc filter & raise coverage
parent
721d73f1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/saml/lib/Auth/Process/NameIDAttribute.php
+11
-8
11 additions, 8 deletions
modules/saml/lib/Auth/Process/NameIDAttribute.php
tests/modules/saml/lib/Auth/Process/NameIDAttributeTest.php
+88
-4
88 additions, 4 deletions
tests/modules/saml/lib/Auth/Process/NameIDAttributeTest.php
with
99 additions
and
12 deletions
modules/saml/lib/Auth/Process/NameIDAttribute.php
+
11
−
8
View file @
ae45cd82
...
...
@@ -43,13 +43,13 @@ class NameIDAttribute extends \SimpleSAML\Auth\ProcessingFilter
parent
::
__construct
(
$config
,
$reserved
);
if
(
isset
(
$config
[
'attribute'
]))
{
$this
->
attribute
=
(
str
ing
)
$config
[
'attribute'
];
$this
->
attribute
=
str
val
(
$config
[
'attribute'
]
)
;
}
else
{
$this
->
attribute
=
'nameid'
;
}
if
(
isset
(
$config
[
'format'
]))
{
$format
=
(
str
ing
)
$config
[
'format'
];
$format
=
str
val
(
$config
[
'format'
]
)
;
}
else
{
$format
=
'%I!%S!%V'
;
}
...
...
@@ -119,15 +119,16 @@ class NameIDAttribute extends \SimpleSAML\Auth\ProcessingFilter
$rep
=
$state
[
'saml:sp:NameID'
];
Assert
::
notNull
(
$rep
->
getValue
());
$rep
->
{
'%'
}
=
'%'
;
if
(
$rep
->
getFormat
()
!
==
null
)
{
if
(
$rep
->
getFormat
()
=
==
null
)
{
$rep
->
setFormat
(
Constants
::
NAMEID_UNSPECIFIED
);
}
if
(
$rep
->
getNameQualifier
()
!==
null
)
{
$rep
->
setNameQualifier
(
$state
[
'Source'
][
'entityid'
]);
if
(
$rep
->
getSPNameQualifier
()
===
null
)
{
$rep
->
setSPNameQualifier
(
$state
[
'Source'
][
'entityid'
]);
}
if
(
$rep
->
get
SP
NameQualifier
()
!
==
null
)
{
$rep
->
set
SP
NameQualifier
(
$state
[
'Destination'
][
'entityid'
]);
if
(
$rep
->
getNameQualifier
()
=
==
null
)
{
$rep
->
setNameQualifier
(
$state
[
'Destination'
][
'entityid'
]);
}
$value
=
''
;
...
...
@@ -135,6 +136,8 @@ class NameIDAttribute extends \SimpleSAML\Auth\ProcessingFilter
foreach
(
$this
->
format
as
$element
)
{
if
(
$isString
)
{
$value
.
=
$element
;
}
elseif
(
$element
===
'%'
)
{
$value
.
=
'%'
;
}
else
{
$value
.
=
call_user_func
([
$rep
,
'get'
.
$element
]);
}
...
...
This diff is collapsed.
Click to expand it.
tests/modules/saml/lib/Auth/Process/NameIDAttributeTest.php
+
88
−
4
View file @
ae45cd82
...
...
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace
SimpleSAML\Test\Module\saml\Auth\Process
;
use
PHPUnit\Framework\TestCase
;
use
SimpleSAML\Error
;
use
SimpleSAML\Module\saml\Auth\Process\NameIDAttribute
;
use
SAML2\XML\saml\NameID
;
use
SAML2\Constants
;
...
...
@@ -59,7 +60,7 @@ class NameIDAttributeTest extends TestCase
'saml:sp:NameID'
=>
$nameId
,
];
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
"
{
$
s
pId
}
!
{
$
id
pId
}
!
{
$nameId
->
getValue
()
}
"
,
$result
[
'Attributes'
][
'nameid'
][
0
]);
$this
->
assertEquals
(
"
{
$
id
pId
}
!
{
$
s
pId
}
!
{
$nameId
->
getValue
()
}
"
,
$result
[
'Attributes'
][
'nameid'
][
0
]);
}
...
...
@@ -91,7 +92,7 @@ class NameIDAttributeTest extends TestCase
];
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertTrue
(
isset
(
$result
[
'Attributes'
][
$attributeName
]));
$this
->
assertEquals
(
"
{
$
s
pId
}
!
{
$
id
pId
}
!
{
$nameId
->
getValue
()
}
"
,
$result
[
'Attributes'
][
$attributeName
][
0
]);
$this
->
assertEquals
(
"
{
$
id
pId
}
!
{
$
s
pId
}
!
{
$nameId
->
getValue
()
}
"
,
$result
[
'Attributes'
][
$attributeName
][
0
]);
}
...
...
@@ -101,7 +102,7 @@ class NameIDAttributeTest extends TestCase
*/
public
function
testFormat
():
void
{
$config
=
[
'format'
=>
'%V'
];
$config
=
[
'format'
=>
'%V
!%%
'
];
$spId
=
'eugeneSP'
;
$idpId
=
'eugeneIdP'
;
...
...
@@ -121,7 +122,62 @@ class NameIDAttributeTest extends TestCase
'saml:sp:NameID'
=>
$nameId
,
];
$result
=
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
"
{
$nameId
->
getValue
()
}
"
,
$result
[
'Attributes'
][
'nameid'
][
0
]);
$this
->
assertEquals
(
"
{
$nameId
->
getValue
()
}
!%"
,
$result
[
'Attributes'
][
'nameid'
][
0
]);
}
/**
* Test invalid format throws an exception.
* @return void
*/
public
function
testInvalidFormatThrowsException
():
void
{
$config
=
[
'format'
=>
'%X'
];
$spId
=
'eugeneSP'
;
$idpId
=
'eugeneIdP'
;
$nameId
=
new
NameID
();
$nameId
->
setValue
(
'eugene@oombaas'
);
$request
=
[
'Source'
=>
[
'entityid'
=>
$spId
,
],
'Destination'
=>
[
'entityid'
=>
$idpId
,
],
'saml:sp:NameID'
=>
$nameId
,
];
$this
->
expectException
(
Error\Exception
::
class
);
$this
->
expectExceptionMessage
(
'NameIDAttribute: Invalid replacement: "%X"'
);
$this
->
processFilter
(
$config
,
$request
);
}
/**
* Test invalid request silently continues, leaving the state untouched
* @return void
*/
public
function
testInvalidRequestLeavesStateUntouched
():
void
{
$config
=
[
'format'
=>
'%V!%F'
];
$spId
=
'eugeneSP'
;
$idpId
=
'eugeneIdP'
;
$request
=
[
'Source'
=>
[
'entityid'
=>
$spId
,
],
'Destination'
=>
[
'entityid'
=>
$idpId
,
],
];
$pre
=
$request
;
$this
->
processFilter
(
$config
,
$request
);
$this
->
assertEquals
(
$pre
,
$request
);
}
...
...
@@ -155,4 +211,32 @@ class NameIDAttributeTest extends TestCase
$this
->
assertTrue
(
isset
(
$result
[
'Attributes'
][
$attributeName
]));
$this
->
assertEquals
(
"
{
$nameId
->
getValue
()
}
"
,
$result
[
'Attributes'
][
$attributeName
][
0
]);
}
/**
* Test overriding NameID Format/NameQualifier/SPNameQualifier with defaults.
* @return void
*/
public
function
testOverrideNameID
():
void
{
$spId
=
'eugeneSP'
;
$idpId
=
'eugeneIdP'
;
$nameId
=
new
NameID
();
$nameId
->
setValue
(
'eugene@oombaas'
);
$request
=
[
'Source'
=>
[
'entityid'
=>
$spId
,
],
'Destination'
=>
[
'entityid'
=>
$idpId
,
],
'saml:sp:NameID'
=>
$nameId
,
];
$this
->
processFilter
(
array
(),
$request
);
$this
->
assertEquals
(
"
{
$nameId
->
getFormat
()
}
"
,
Constants
::
NAMEID_UNSPECIFIED
);
$this
->
assertEquals
(
"
{
$nameId
->
getNameQualifier
()
}
"
,
$idpId
);
$this
->
assertEquals
(
"
{
$nameId
->
getSPNameQualifier
()
}
"
,
$spId
);
}
}
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