Skip to content

Commit 3a514b4

Browse files
Egor Panfilovc00kiemon5ter
authored andcommitted
Various small refactor
1 parent a8c6320 commit 3a514b4

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

src/saml2/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ def prepare_for_negotiated_authenticate(
8484
nameid_format=None, scoping=None, consent=None, extensions=None,
8585
sign=None, response_binding=saml2.BINDING_HTTP_POST, **kwargs):
8686
""" Makes all necessary preparations for an authentication request
87-
that negotiates
88-
which binding to use for authentication.
87+
that negotiates which binding to use for authentication.
8988
9089
:param entityid: The entity ID of the IdP to send the request to
9190
:param relay_state: To where the user should be returned after

src/saml2/client_base.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"""
88
import threading
99
import six
10+
import time
11+
import logging
1012

1113
from saml2.entity import Entity
1214

@@ -25,7 +27,6 @@
2527
from saml2.extension import requested_attributes
2628

2729
import saml2
28-
import time
2930
from saml2.soap import make_soap_enveloped_saml_thingy
3031

3132
from six.moves.urllib.parse import parse_qs
@@ -94,7 +95,7 @@ class Base(Entity):
9495
""" The basic pySAML2 service provider class """
9596

9697
def __init__(self, config=None, identity_cache=None, state_cache=None,
97-
virtual_organization="", config_file="", msg_cb=None):
98+
virtual_organization="", config_file="", msg_cb=None):
9899
"""
99100
:param config: A saml2.config.Config instance
100101
:param identity_cache: Where the class should store identity information
@@ -133,10 +134,12 @@ def __init__(self, config=None, identity_cache=None, state_cache=None,
133134

134135
setattr(self, attr, val)
135136

136-
if self.entity_type == "sp" and not any([self.want_assertions_signed,
137-
self.want_response_signed]):
138-
logger.warning("The SAML service provider accepts unsigned SAML Responses " +
139-
"and Assertions. This configuration is insecure.")
137+
if (self.entity_type == "sp"
138+
and not any([self.want_assertions_signed,
139+
self.want_response_signed])):
140+
logger.warning("The SAML service provider accepts unsigned SAML "
141+
"Responses and Assertions. This configuration is "
142+
"insecure.")
140143

141144
self.artifact2response = {}
142145

src/saml2/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,11 @@ def _load(self, fil):
381381

382382
return importlib.import_module(tail)
383383

384-
def load_file(self, config_file, metadata_construction=False):
385-
if config_file.endswith(".py"):
386-
config_file = config_file[:-3]
384+
def load_file(self, config_filename, metadata_construction=False):
385+
if config_filename.endswith(".py"):
386+
config_filename = config_filename[:-3]
387387

388-
mod = self._load(config_file)
388+
mod = self._load(config_filename)
389389
return self.load(copy.deepcopy(mod.CONFIG), metadata_construction)
390390

391391
def load_metadata(self, metadata_conf):

src/saml2/ecp_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333

3434

3535
class Client(Entity):
36+
"""ECP-aware client that works on the client (application) side.
37+
38+
You can use this class when you want to login user through
39+
ECP-aware SP and IdP.
40+
"""
41+
3642
def __init__(self, user, passwd, sp="", idp=None, metadata_file=None,
3743
xmlsec_binary=None, verbose=0, ca_certs="",
3844
disable_ssl_certificate_validation=True, key_file=None,
@@ -221,7 +227,8 @@ def ecp_conversation(self, respdict, idp_entity_id=None):
221227

222228
return None
223229

224-
def add_paos_headers(self, headers=None):
230+
@staticmethod
231+
def add_paos_headers(headers=None):
225232
if headers:
226233
headers = set_list2dict(headers)
227234
headers["PAOS"] = PAOS_HEADER_INFO
@@ -283,7 +290,7 @@ def operation(self, url, idp_entity_id, op, **opargs):
283290
# should by now be authenticated so this should go smoothly
284291
response = self.send(url, op, **opargs)
285292
except (soap.XmlParseError, AssertionError, KeyError):
286-
pass
293+
raise
287294

288295
if response.status_code >= 400:
289296
raise SAMLError("Error performing operation: %s" % (

src/saml2/entity.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
from saml2.sigver import security_context
6464
from saml2.sigver import response_factory
6565
from saml2.sigver import SigverError
66-
from saml2.sigver import CryptoBackendXmlSec1
6766
from saml2.sigver import make_temp
6867
from saml2.sigver import pre_encryption_part
6968
from saml2.sigver import pre_signature_part
@@ -554,7 +553,6 @@ def _encrypt_assertion(self, encrypt_cert, sp_entity_id, response,
554553
_certs = []
555554

556555
if encrypt_cert:
557-
_certs = []
558556
_certs.append(encrypt_cert)
559557
elif sp_entity_id is not None:
560558
_certs = self.metadata.certs(sp_entity_id, "any", "encryption")
@@ -1134,11 +1132,11 @@ def _parse_response(self, xmlstr, response_cls, service, binding,
11341132
raise
11351133

11361134
xmlstr = self.unravel(xmlstr, binding, response_cls.msgtype)
1137-
origxml = xmlstr
11381135
if not xmlstr: # Not a valid reponse
11391136
return None
11401137

11411138
try:
1139+
origxml = xmlstr
11421140
response = response.loads(xmlstr, False, origxml=origxml)
11431141
except SigverError as err:
11441142
logger.error("Signature Error: %s", err)

src/saml2/population.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import logging
2+
23
import six
4+
35
from saml2.cache import Cache
4-
from saml2.ident import code
56

67
logger = logging.getLogger(__name__)
78

src/saml2/s2repoze/plugins/sp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,7 @@ def make_plugin(remember_name=None, # plugin for remember
651651
sid_store="",
652652
identity_cache="",
653653
discovery="",
654-
idp_query_param=""
655-
):
654+
idp_query_param=""):
656655
if saml_conf is "":
657656
raise ValueError(
658657
'must include saml_conf in configuration')

0 commit comments

Comments
 (0)