File tree Expand file tree Collapse file tree
manage_breast_screening/dicom Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -119,3 +119,10 @@ def test_with_valid_token(
119119 assert validator (Mock (headers = {"Authorization" : "Bearer abc123" })) == {
120120 "sub" : "1234567890"
121121 }
122+
123+ def test_authentication_bypass_enabled (self , mock_logger ):
124+ with patch .dict ("os.environ" , {"BYPASS_API_TOKEN_AUTH" : "true" }):
125+ validator = TokenValidator ()
126+ assert validator (Mock (headers = {"Authorization" : "Bearer anytoken" })) == {
127+ "sub" : "bypass_user"
128+ }
Original file line number Diff line number Diff line change 1313
1414class TokenValidator (HttpBearer ):
1515 def __init__ (self ):
16+ self .bypass_auth = os .getenv ("BYPASS_API_TOKEN_AUTH" , "false" ).lower () == "true"
1617 self .api_audience = os .getenv ("API_AUDIENCE" , "" )
1718 self .tenant_id = os .getenv ("TENANT_ID" , "" )
1819 self .discovery_keys_url = (
@@ -23,6 +24,10 @@ def __init__(self):
2324 self .issuer_url = "https://sts.windows.net/" + self .tenant_id + "/"
2425
2526 def authenticate (self , request , token ) -> dict | None :
27+ if self .bypass_auth :
28+ logger .warning ("Authentication bypass is enabled." )
29+ return {"sub" : "bypass_user" }
30+
2631 rsa_key = self ._rsa_key (token )
2732 if rsa_key :
2833 return self ._decode (token , rsa_key )
You can’t perform that action at this time.
0 commit comments