Skip to content

Commit

Permalink
Fix some regex syntax warning issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rockychen-dpaw committed May 15, 2024
1 parent c74b144 commit 9435c85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions authome/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test_basic_auth_re(self):
testcases = [
("Basic 123456","123456"),
("Basic 123456","123456"),
("Basic 123456+=/","123456+=/"),
(" Basic 123456",None),
("Basic 123456 ",None),
("Baasic 123456 ",None),
Expand All @@ -130,6 +131,21 @@ def test_basic_auth_re(self):
m = basic_auth_re.search(text)
self.assertEqual(m.group(1) if m else None ,result,"Basic auth({}) should be {},but got {}".format(text,result,m.group(1) if m else None))

def test_bearer_token_re(self):
print("============================================================================")
from .views.views import bearer_token_re
testcases = [
("Bearer 123456","123456"),
("Bearer 123456","123456"),
(" Bearer 123456",None),
("Bearer 123456 ","123456"),
("Bearer 123456 ", "123456"),
("Bearer 123456%^&$ ", "123456%^&$")
]
for text, result in testcases:
m = bearer_token_re.search(text)
self.assertEqual(m.group(1) if m else None ,result,"The bearer token({}) should be {},but got {}".format(text,result,m.group(1) if m else None))

def test_email_re(self):
print("============================================================================")
from .views.views import email_re
Expand Down
2 changes: 1 addition & 1 deletion authome/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ def mfa_reset_complete(request,backend,*args,**kwargs):
*args, **kwargs)


bearer_token_re = re.compile("^Bearer\s+(?P<token>\S+)\s*$")
bearer_token_re = re.compile("^Bearer\\s+(?P<token>\\S+)\\s*$")
def _auth_bearer(request):
"""
Check the bearer authentication
Expand Down

0 comments on commit 9435c85

Please sign in to comment.