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
38b5cbce
Commit
38b5cbce
authored
10 years ago
by
Jaime Perez
Browse files
Options
Downloads
Patches
Plain Diff
Adding the first phpunit to SSP. Hooray!
parent
a8c989f7
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/Utils/MetadataTest.php
+201
-0
201 additions, 0 deletions
tests/Utils/MetadataTest.php
with
201 additions
and
0 deletions
tests/Utils/MetadataTest.php
0 → 100644
+
201
−
0
View file @
38b5cbce
<?php
/**
* Class Utils_MetadataTest
*/
class
Utils_MetadataTest
extends
PHPUnit_Framework_TestCase
{
/**
* Test contact configuration parsing and sanitizing.
*/
public
function
testGetContact
()
{
// test missing type
$contact
=
array
(
'name'
=>
'John Doe'
);
try
{
$parsed
=
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertStringStartsWith
(
'"contactType" is mandatory and must be one of '
,
$e
->
getMessage
());
}
// test invalid type
$contact
=
array
(
'contactType'
=>
'invalid'
);
try
{
$parsed
=
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertStringStartsWith
(
'"contactType" is mandatory and must be one of '
,
$e
->
getMessage
());
}
// test all valid contact types
foreach
(
SimpleSAML_Utils_Config_Metadata
::
$VALID_CONTACT_TYPES
as
$type
)
{
$contact
=
array
(
'contactType'
=>
$type
);
$parsed
=
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
$this
->
assertArrayHasKey
(
'contactType'
,
$parsed
);
$this
->
assertArrayNotHasKey
(
'givenName'
,
$parsed
);
$this
->
assertArrayNotHasKey
(
'surName'
,
$parsed
);
}
// test basic name parsing
$contact
=
array
(
'contactType'
=>
'technical'
,
'name'
=>
'John Doe'
);
$parsed
=
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
$this
->
assertArrayNotHasKey
(
'name'
,
$parsed
);
$this
->
assertArrayHasKey
(
'givenName'
,
$parsed
);
$this
->
assertArrayHasKey
(
'surName'
,
$parsed
);
$this
->
assertEquals
(
'John'
,
$parsed
[
'givenName'
]);
$this
->
assertEquals
(
'Doe'
,
$parsed
[
'surName'
]);
// test comma-separated names
$contact
=
array
(
'contactType'
=>
'technical'
,
'name'
=>
'Doe, John'
);
$parsed
=
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
$this
->
assertArrayHasKey
(
'givenName'
,
$parsed
);
$this
->
assertArrayHasKey
(
'surName'
,
$parsed
);
$this
->
assertEquals
(
'John'
,
$parsed
[
'givenName'
]);
$this
->
assertEquals
(
'Doe'
,
$parsed
[
'surName'
]);
// test long names
$contact
=
array
(
'contactType'
=>
'technical'
,
'name'
=>
'John Fitzgerald Doe Smith'
);
$parsed
=
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
$this
->
assertArrayNotHasKey
(
'name'
,
$parsed
);
$this
->
assertArrayHasKey
(
'givenName'
,
$parsed
);
$this
->
assertArrayNotHasKey
(
'surName'
,
$parsed
);
$this
->
assertEquals
(
'John Fitzgerald Doe Smith'
,
$parsed
[
'givenName'
]);
// test comma-separated long names
$contact
=
array
(
'contactType'
=>
'technical'
,
'name'
=>
'Doe Smith, John Fitzgerald'
);
$parsed
=
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
$this
->
assertArrayNotHasKey
(
'name'
,
$parsed
);
$this
->
assertArrayHasKey
(
'givenName'
,
$parsed
);
$this
->
assertArrayHasKey
(
'surName'
,
$parsed
);
$this
->
assertEquals
(
'John Fitzgerald'
,
$parsed
[
'givenName'
]);
$this
->
assertEquals
(
'Doe Smith'
,
$parsed
[
'surName'
]);
// test givenName
$contact
=
array
(
'contactType'
=>
'technical'
,
);
$invalid_types
=
array
(
0
,
array
(
0
),
0.1
,
true
,
false
);
foreach
(
$invalid_types
as
$type
)
{
$contact
[
'givenName'
]
=
$type
;
try
{
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'"givenName" must be a string and cannot be empty.'
,
$e
->
getMessage
());
}
}
// test surName
$contact
=
array
(
'contactType'
=>
'technical'
,
);
$invalid_types
=
array
(
0
,
array
(
0
),
0.1
,
true
,
false
);
foreach
(
$invalid_types
as
$type
)
{
$contact
[
'surName'
]
=
$type
;
try
{
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'"surName" must be a string and cannot be empty.'
,
$e
->
getMessage
());
}
}
// test company
$contact
=
array
(
'contactType'
=>
'technical'
,
);
$invalid_types
=
array
(
0
,
array
(
0
),
0.1
,
true
,
false
);
foreach
(
$invalid_types
as
$type
)
{
$contact
[
'company'
]
=
$type
;
try
{
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'"company" must be a string and cannot be empty.'
,
$e
->
getMessage
());
}
}
// test emailAddress
$contact
=
array
(
'contactType'
=>
'technical'
,
);
$invalid_types
=
array
(
0
,
0.1
,
true
,
false
,
array
());
foreach
(
$invalid_types
as
$type
)
{
$contact
[
'emailAddress'
]
=
$type
;
try
{
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'"emailAddress" must be a string or an array and cannot be empty.'
,
$e
->
getMessage
()
);
}
}
$invalid_types
=
array
(
array
(
"string"
,
true
),
array
(
"string"
,
0
));
foreach
(
$invalid_types
as
$type
)
{
$contact
[
'emailAddress'
]
=
$type
;
try
{
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'Email addresses must be a string and cannot be empty.'
,
$e
->
getMessage
()
);
}
}
// test telephoneNumber
$contact
=
array
(
'contactType'
=>
'technical'
,
);
$invalid_types
=
array
(
0
,
0.1
,
true
,
false
,
array
());
foreach
(
$invalid_types
as
$type
)
{
$contact
[
'telephoneNumber'
]
=
$type
;
try
{
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'"telephoneNumber" must be a string or an array and cannot be empty.'
,
$e
->
getMessage
()
);
}
}
$invalid_types
=
array
(
array
(
"string"
,
true
),
array
(
"string"
,
0
));
foreach
(
$invalid_types
as
$type
)
{
$contact
[
'telephoneNumber'
]
=
$type
;
try
{
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
}
catch
(
InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'Telephone numbers must be a string and cannot be empty.'
,
$e
->
getMessage
());
}
}
// test completeness
$contact
=
array
();
foreach
(
SimpleSAML_Utils_Config_Metadata
::
$VALID_CONTACT_OPTIONS
as
$option
)
{
$contact
[
$option
]
=
'string'
;
}
$contact
[
'contactType'
]
=
'technical'
;
$contact
[
'name'
]
=
'to_be_removed'
;
$parsed
=
SimpleSAML_Utils_Config_Metadata
::
getContact
(
$contact
);
foreach
(
array_keys
(
$parsed
)
as
$key
)
{
$this
->
assertEquals
(
$parsed
[
$key
],
$contact
[
$key
]);
}
$this
->
assertArrayNotHasKey
(
'name'
,
$parsed
);
}
}
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