File tree Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change 21
21
22
22
logging .getLogger ("requests_oauthlib" ).addHandler (logging .NullHandler ())
23
23
logging .getLogger ("requests_oauthlib" ).addFilter (DebugModeTokenFilter ())
24
+
25
+ for filter_ in logging .getLogger ("requests_oauthlib" ).filters :
26
+ if isinstance (filter_ , DebugModeTokenFilter ):
27
+ if filter_ .mode == 'DEFAULT' :
28
+ msg = "Your logger, when in DEBUG mode, will log TOKENS"
29
+ logging .warning (msg )
30
+ break
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ def __init__(self):
20
20
environment variable.
21
21
"""
22
22
super ().__init__ ()
23
- self .mode = os .getenv ('DEBUG_MODE_TOKEN_FILTER' , 'DEFAULT' ).upper ()
23
+ self .mode = os .getenv ('DEBUG_MODE_TOKEN_FILTER' , 'DEFAULT' ).upper ()
24
24
25
25
def filter (self , record ):
26
26
"""
@@ -37,7 +37,4 @@ def filter(self, record):
37
37
record .msg = re .sub (r'Bearer (\w+)' , '[MASKED]' , record .getMessage ())
38
38
elif self .mode == "SUPPRESS" :
39
39
return False
40
- elif self .mode == "DEFAULT" :
41
- msg = "Your logger, when in DEBUG mode, will log TOKENS"
42
- raise Warning (msg )
43
- return True
40
+ return True # if mode is not MASKED then DEFAULT is implied
Original file line number Diff line number Diff line change @@ -23,9 +23,8 @@ def test_suppress_mode(self):
23
23
@patch .dict ('os.environ' , {'DEBUG_MODE_TOKEN_FILTER' : 'DEFAULT' })
24
24
def test_default_mode_raises_warning (self ):
25
25
filter = DebugModeTokenFilter ()
26
- with self .assertRaises (Warning ) as context :
27
- filter .filter (self .record )
28
- self .assertTrue ("Your logger, when in DEBUG mode, will log TOKENS" in str (context .exception ))
26
+ result = filter .filter (self .record )
27
+ self .assertTrue (result )
29
28
30
29
if __name__ == '__main__' :
31
30
unittest .main ()
You can’t perform that action at this time.
0 commit comments