Skip to content

Commit cd7f239

Browse files
committed
Warn and log warning messages
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent f926ba9 commit cd7f239

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/saml2/client_base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import six
1010
import time
1111
import logging
12+
from warnings import warn as _warn
1213

1314
from saml2.entity import Entity
1415

@@ -189,10 +190,12 @@ def __init__(self, config=None, identity_cache=None, state_cache=None,
189190
self.want_assertions_or_response_signed,
190191
]
191192
):
192-
logger.warning(
193+
warn_msg = (
193194
"The SAML service provider accepts unsigned SAML Responses "
194195
"and Assertions. This configuration is insecure."
195196
)
197+
logger.warning(warn_msg)
198+
_warn(warn_msg)
196199

197200
self.artifact2response = {}
198201

src/saml2/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
import sys
1010
from logging.config import dictConfig as configure_logging_by_dict
11+
from warnings import warn as _warn
1112

1213
import six
1314

@@ -353,10 +354,12 @@ def load(self, cnf, metadata_construction=False):
353354
configure_logging_by_dict(self.logging)
354355

355356
if not self.delete_tmpfiles:
356-
logger.warning(
357-
"delete_tmpfiles is set to False; "
358-
"temporary files will not be deleted."
357+
warn_msg = (
358+
"Configuration option `delete_tmpfiles` is set to False; "
359+
"consider setting this to True to have temporary files deleted."
359360
)
361+
logger.warning(warn_msg)
362+
_warn(warn_msg)
360363

361364
if "service" in cnf:
362365
for typ in ["aa", "idp", "sp", "pdp", "aq"]:

src/saml2/cryptography/symmetric.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import base64 as _base64
88
import os as _os
9-
import warnings as _warnings
9+
import logging
10+
from warnings import warn as _warn
1011

1112
import cryptography.fernet as _fernet
1213
import cryptography.hazmat.backends as _backends
@@ -15,6 +16,9 @@
1516
from .errors import SymmetricCryptographyError
1617

1718

19+
logger = logging.getLogger(__name__)
20+
21+
1822
class Fernet(object):
1923
"""The default symmetric cryptography method."""
2024

@@ -61,7 +65,8 @@ def encrypt(self, plaintext, *args, **kwargs):
6165
"Remove any other arguements. "
6266
"In the next version, this method will not allow them."
6367
)
64-
_warnings.warn(_deprecation_msg, DeprecationWarning)
68+
logger.warning(_deprecation_msg)
69+
_warn(_deprecation_msg, DeprecationWarning)
6570

6671
ciphertext = self._symmetric.encrypt(plaintext)
6772
return ciphertext
@@ -79,7 +84,8 @@ def decrypt(self, ciphertext, *args, **kwargs):
7984
"Remove any other arguements. "
8085
"In the next version, this method will not allow them."
8186
)
82-
_warnings.warn(_deprecation_msg, DeprecationWarning)
87+
logger.warning(_deprecation_msg)
88+
_warn(_deprecation_msg, DeprecationWarning)
8389

8490
plaintext = self._symmetric.decrypt(ciphertext)
8591
return plaintext
@@ -90,7 +96,8 @@ def build_cipher(self, *args, **kwargs):
9096
"Remove any calls to this method. "
9197
"In the next version, this method will be removed."
9298
)
93-
_warnings.warn(_deprecation_msg, DeprecationWarning)
99+
logger.warning(_deprecation_msg)
100+
_warn(_deprecation_msg, DeprecationWarning)
94101

95102

96103
class AESCipher(object):
@@ -116,7 +123,8 @@ def _deprecation_notice(cls):
116123
'or saml2.cryptography.symmetric.Fernet '
117124
'instead.'
118125
).format(name=cls.__name__, type=type(cls).__name__)
119-
_warnings.warn(_deprecation_msg, DeprecationWarning)
126+
logger.warning(_deprecation_msg)
127+
_warn(_deprecation_msg, DeprecationWarning)
120128

121129
def __init__(self, key):
122130
"""

src/saml2/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import logging
99
import os
10+
from warnings import warn as _warn
1011

1112
import importlib
1213
import dbm
@@ -526,7 +527,9 @@ def create_attribute_response(self, identity, in_response_to, destination,
526527
try:
527528
name_id = self.ident.construct_nameid(userid, policy,
528529
sp_entity_id)
529-
logger.warning("Unspecified NameID format")
530+
warn_msg = "Unspecified NameID format"
531+
logger.warning(warn_msg)
532+
_warn(warn_msg)
530533
except Exception:
531534
pass
532535

0 commit comments

Comments
 (0)