Skip to content

Commit 8ca067d

Browse files
Merge branch 'master' into feature-hide-assertion-consumer-service
2 parents 47cbd12 + 6d22008 commit 8ca067d

File tree

9 files changed

+73
-9
lines changed

9 files changed

+73
-9
lines changed

src/saml2/client_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ def create_authn_request(self, destination, vorg="", scoping=None,
339339
except KeyError:
340340
nsprefix = None
341341

342+
try:
343+
force_authn = kwargs['force_authn']
344+
except KeyError:
345+
force_authn = self.config.getattr('force_authn', 'sp')
346+
finally:
347+
if force_authn:
348+
args['force_authn'] = 'true'
349+
342350
if kwargs:
343351
_args, extensions = self._filter_args(AuthnRequest(), extensions,
344352
**kwargs)

src/saml2/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"logout_requests_signed",
7878
"requested_attribute_name_format",
7979
"hide_assertion_consumer_service",
80+
"force_authn",
8081
]
8182

8283
AA_IDP_ARGS = [
@@ -208,7 +209,6 @@ def __init__(self, homedir="."):
208209
self.crypto_backend = 'xmlsec1'
209210
self.scope = ""
210211
self.allow_unknown_attributes = False
211-
self.allow_unsolicited = False
212212
self.extension_schema = {}
213213
self.cert_handler_extra_class = None
214214
self.verify_encrypt_cert_advice = None

src/saml2/mdstore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def load(self, *args, **kwargs):
750750
"""
751751
response = self.http.send(self.url)
752752
if response.status_code == 200:
753-
_txt = response.text.encode("utf-8")
753+
_txt = response.content
754754
return self.parse_and_check_signature(_txt)
755755
else:
756756
logger.info("Response status: %s", response.status_code)
@@ -814,7 +814,7 @@ def __getitem__(self, item):
814814
response = requests.get(mdx_url, headers={
815815
'Accept': SAML_METADATA_CONTENT_TYPE})
816816
if response.status_code == 200:
817-
_txt = response.text.encode("utf-8")
817+
_txt = response.content
818818

819819
if self.parse_and_check_signature(_txt):
820820
return self.entity[item]

src/saml2/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def get_identity(self):
666666
_attr_statem = _assertion.attribute_statement[0]
667667
ava.update(self.read_attribute_statement(_attr_statem))
668668
if not ava:
669-
logger.error("Missing Attribute Statement")
669+
logger.debug("Assertion contains no attribute statements")
670670
return ava
671671

672672
def _bearer_confirmed(self, data):

tests/SWITCHaaiRootCA.crt.pem

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDnzCCAoegAwIBAgINSWITCHaai+Root+CAzANBgkqhkiG9w0BAQUFADBrMQsw
3+
CQYDVQQGEwJDSDFAMD4GA1UEChM3U3dpdGNoIC0gVGVsZWluZm9ybWF0aWtkaWVu
4+
c3RlIGZ1ZXIgTGVocmUgdW5kIEZvcnNjaHVuZzEaMBgGA1UEAxMRU1dJVENIYWFp
5+
IFJvb3QgQ0EwHhcNMDgwNTE1MDYzMDAwWhcNMjgwNTE1MDYyOTU5WjBrMQswCQYD
6+
VQQGEwJDSDFAMD4GA1UEChM3U3dpdGNoIC0gVGVsZWluZm9ybWF0aWtkaWVuc3Rl
7+
IGZ1ZXIgTGVocmUgdW5kIEZvcnNjaHVuZzEaMBgGA1UEAxMRU1dJVENIYWFpIFJv
8+
b3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDUSWbn/rhWew/s
9+
LJRyciyRKDGyFXSgiDO/EohYuZLw6EAKLLlhZorNtEHQbbn0Oo13S33MclHMvGWT
10+
KJM0u1hG+6gLy78EPmJbqAE1Uv23wVEH4SX0VJfl3JVqIebiAH/CjuLubgMUspDI
11+
jOdQHNLS7pthTbm7Tgh7zMsiLPyMTZJep5CGbqv8NoK6bMaF0Z+Bt7e1JRlhHFCV
12+
iJJaR/+hfpzLsJ8NWVivvrpRGaGJ1XR+9FGsTkjNdMCirNJJZ6XvUOe5w7pHSd9M
13+
cppFP0eyLs02AMzMXI4iz6PK/w3EdzXGXpK+gSgvLxWYct4xHpv1e2NXhNgdJOSN
14+
9ra/wJLVAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEG
15+
MB0GA1UdDgQWBBTpmuIGWOsP14EDXVyXubG1k307hDANBgkqhkiG9w0BAQUFAAOC
16+
AQEAMV/eIW6pFB+mbk7rD7hUPTWDRaoca3kHqmFGFnHfuY8+c0/Mqjh8Y/jyX1yb
17+
f58crTSWrbyGbUZ3oxDGQ34tuZSkmeR32NqryiX3sP5qlNSozVguQKt8o4vhS1Qe
18+
WPsXALs3em2pdKuIGSOpbuDnopPcmU2g5Zi2R5P7qpKDKAKtNUEwV+LW7GBMEksO
19+
Nj7BFXk4AFBFBijaYJGgHmoKSImVgeNIvsV+BSv5HJ4q6vcxfnwuvvGHM0AGphYO
20+
6f5qtHMUgvAblI8M/2QsBgethaGrirtKJ3aCRLdaR2R1QfaGRpck/Ron5/MpMxiJ
21+
wLT8YlW/zjx2yNABhPSAjfzeMw==
22+
-----END CERTIFICATE-----

tests/conftest.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import os
2+
import pytest
23

34
#TODO: On my system this function seems to be returning an incorrect location
4-
def pytest_funcarg__xmlsec(request):
5+
@pytest.fixture
6+
def xmlsec(request):
57
for path in os.environ["PATH"].split(":"):
68
fil = os.path.join(path, "xmlsec1")
79
if os.access(fil,os.X_OK):
810
return fil
911

1012
raise Exception("Can't find xmlsec1")
11-
12-
def pytest_funcarg__AVA(request):
13+
14+
@pytest.fixture
15+
def AVA(request):
1316
return [
1417
{
1518
"surName": ["Jeter"],
@@ -27,4 +30,4 @@ def pytest_funcarg__AVA(request):
2730
"surName": ["Hedberg"],
2831
"givenName": ["Roland"],
2932
},
30-
]
33+
]

tests/test_30_mdstore.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from future.backports.urllib.parse import quote_plus
88

99
from saml2.config import Config
10-
from saml2.mdstore import MetadataStore
10+
from saml2.mdstore import MetadataStore, MetaDataExtern
1111
from saml2.mdstore import MetaDataMDX
1212
from saml2.mdstore import SAML_METADATA_CONTENT_TYPE
1313
from saml2.mdstore import destinations
1414
from saml2.mdstore import name
1515
from saml2 import sigver
16+
from saml2.httpbase import HTTPBase
1617
from saml2 import BINDING_SOAP
1718
from saml2 import BINDING_HTTP_REDIRECT
1819
from saml2 import BINDING_HTTP_POST
@@ -385,6 +386,14 @@ def test_load_local():
385386
assert cfg
386387

387388

389+
def test_load_remote_encoding():
390+
crypto = sigver._get_xmlsec_cryptobackend()
391+
sc = sigver.SecurityContext(crypto, key_type="", cert_type="")
392+
httpc = HTTPBase()
393+
mds = MetaDataExtern(ATTRCONV, 'http://metadata.aai.switch.ch/metadata.aaitest.xml', sc, full_path('SWITCHaaiRootCA.crt.pem'), httpc)
394+
mds.load()
395+
396+
388397
def test_load_string():
389398
sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
390399
mds = MetadataStore(ATTRCONV, sec_config,

tests/test_31_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
},
6969
"authn_requests_signed": True,
7070
"logout_requests_signed": True,
71+
"force_authn": True,
7172
}
7273
},
7374
#"xmlsec_binary" : "/opt/local/bin/xmlsec1",
@@ -408,5 +409,15 @@ def test_crypto_backend():
408409
sec = security_context(idpc)
409410
assert isinstance(sec.crypto, CryptoBackendXMLSecurity)
410411

412+
def test_unset_force_authn():
413+
cnf = SPConfig().load(sp1)
414+
assert bool(cnf.getattr('force_authn', 'sp')) == False
415+
416+
417+
def test_set_force_authn():
418+
cnf = SPConfig().load(sp2)
419+
assert bool(cnf.getattr('force_authn', 'sp')) == True
420+
421+
411422
if __name__ == "__main__":
412423
test_crypto_backend()

tests/test_51_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ def test_create_auth_request_0(self):
280280
assert nid_policy.allow_create == "false"
281281
assert nid_policy.format == saml.NAMEID_FORMAT_TRANSIENT
282282

283+
def test_create_auth_request_unset_force_authn(self):
284+
req_id, req = self.client.create_authn_request(
285+
"http://www.example.com/sso", sign=False, message_id="id1")
286+
assert bool(req.force_authn) == False
287+
288+
def test_create_auth_request_set_force_authn(self):
289+
req_id, req = self.client.create_authn_request(
290+
"http://www.example.com/sso", sign=False, message_id="id1",
291+
force_authn="true")
292+
assert bool(req.force_authn) == True
293+
283294
def test_create_auth_request_nameid_policy_allow_create(self):
284295
conf = config.SPConfig()
285296
conf.load_file("sp_conf_nameidpolicy")

0 commit comments

Comments
 (0)