Skip to content

Commit ff1249b

Browse files
committed
Metadata validUntil/cacheDuration: Add documentation, test and minor fix.
1 parent 3f90130 commit ff1249b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ In addition to the required settings data (idp, sp), there is extra information
317317
// Set true or don't present thi parameter and you will get an AuthContext 'exact' 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport'
318318
// Set an array with the possible auth context values: array ('urn:oasis:names:tc:SAML:2.0:ac:classes:Password', 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509'),
319319
'requestedAuthnContext': true,
320+
321+
// In some environment you will need to set how long the published metadata of the Service Provider gonna be valid.
322+
// is possible to not set the 2 following parameters (or set to null) and default values will be set (2 days, 1 week)
323+
// Or provide the desire TimeStamp, for example PT518400S (6 days)
324+
'metadataValidUntil': null,
325+
'metadataCacheDuration': null,
320326
},
321327

322328
// Contact information template, it is recommended to suply a

src/onelogin/saml2/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=N
5757
valid_until = int(datetime.now().strftime("%s")) + OneLogin_Saml2_Metadata.TIME_VALID
5858
if not isinstance(valid_until, basestring):
5959
if isinstance(valid_until, datetime):
60-
valid_until_time = valid_until
60+
valid_until_time = valid_until.timetuple()
6161
else:
6262
valid_until_time = gmtime(valid_until)
6363
valid_until_str = strftime(r'%Y-%m-%dT%H:%M:%SZ', valid_until_time)

tests/src/OneLogin/saml2_tests/metadata_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
# Copyright (c) 2014, OneLogin, Inc.
44
# All rights reserved.
55

6+
67
import json
78
from os.path import dirname, join, exists
9+
from time import gmtime, strftime
10+
from datetime import datetime
811
import unittest
912

1013
from onelogin.saml2.metadata import OneLogin_Saml2_Metadata
@@ -121,6 +124,21 @@ def testBuilder(self):
121124
self.assertNotIn('cacheDuration', metadata5)
122125
self.assertIn('validUntil="2014-10-01T11:04:29Z"', metadata5)
123126

127+
datetime_value = datetime.now()
128+
metadata6 = OneLogin_Saml2_Metadata.builder(
129+
sp_data, security['authnRequestsSigned'],
130+
security['wantAssertionsSigned'],
131+
datetime_value,
132+
'P1Y',
133+
contacts,
134+
organization
135+
)
136+
self.assertIsNotNone(metadata5)
137+
self.assertIn('<md:SPSSODescriptor', metadata6)
138+
self.assertIn('cacheDuration="P1Y"', metadata6)
139+
parsed_datetime = strftime(r'%Y-%m-%dT%H:%M:%SZ', datetime_value.timetuple())
140+
self.assertIn('validUntil="%s"' % parsed_datetime, metadata6)
141+
124142
def testSignMetadata(self):
125143
"""
126144
Tests the signMetadata method of the OneLogin_Saml2_Metadata

0 commit comments

Comments
 (0)