Skip to content

Commit 7d81f20

Browse files
authored
Merge pull request #154 from waterkip/GL-assertion-with_correct_dates
Get the correct dates from the assertions
2 parents 844f8d1 + 6a140ca commit 7d81f20

File tree

3 files changed

+322
-6
lines changed

3 files changed

+322
-6
lines changed

lib/Net/SAML2/Protocol/Assertion.pm

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,25 @@ sub new_from_xml {
142142
$attributes->{$node->getAttribute('Name')} = [map $_->string_value, @values];
143143
}
144144

145+
my $xpath_base = '//samlp:Response/saml:Assertion/saml:Conditions/';
146+
145147
my $not_before;
146-
if($xpath->findvalue('//saml:Conditions/@NotBefore')) {
147-
$not_before = DateTime::Format::XSD->parse_datetime(
148-
$xpath->findvalue('//saml:Conditions/@NotBefore'));
148+
if (my $value = $xpath->findvalue($xpath_base . '@NotBefore')) {
149+
$not_before = DateTime::Format::XSD->parse_datetime($value);
150+
}
151+
elsif (my $global = $xpath->findvalue('//saml:Conditions/@NotBefore')) {
152+
$not_before = DateTime::Format::XSD->parse_datetime($global);
149153
}
150154
else {
151155
$not_before = DateTime::HiRes->now();
152156
}
153157

154158
my $not_after;
155-
if($xpath->findvalue('//saml:Conditions/@NotOnOrAfter')) {
156-
$not_after = DateTime::Format::XSD->parse_datetime(
157-
$xpath->findvalue('//saml:Conditions/@NotOnOrAfter'));
159+
if (my $value = $xpath->findvalue($xpath_base . '@NotOnOrAfter')) {
160+
$not_after = DateTime::Format::XSD->parse_datetime($value);
161+
}
162+
elsif (my $global = $xpath->findvalue('//saml:Conditions/@NotOnOrAfter')) {
163+
$not_after = DateTime::Format::XSD->parse_datetime($global);
158164
}
159165
else {
160166
$not_after = DateTime->from_epoch(epoch => time() + 1000);

t/03-assertions.t

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,21 @@ is($assertion->nameid_sp_provided_id,
128128
undef,
129129
"nameid_sp_provided_id undefined as expected");
130130

131+
132+
133+
lives_ok(
134+
sub {
135+
my $xml = path('t/data/eherkenning-assertion.xml')->slurp;
136+
$assertion = Net::SAML2::Protocol::Assertion->new_from_xml(xml => $xml);
137+
},
138+
"Correct parsing of dates"
139+
);
140+
141+
isa_ok($assertion, 'Net::SAML2::Protocol::Assertion');
142+
isa_ok($assertion->not_before, "DateTime", "not before is correct");
143+
isa_ok($assertion->not_after, "DateTime", "... and so it not after");
144+
145+
is($assertion->not_before, "2020-06-02T11:48:07", "... and the correct not_before");
146+
is($assertion->not_after, "2020-06-02T11:53:07", "... and the correct not_after");
147+
131148
done_testing;

0 commit comments

Comments
 (0)