Skip to content

Commit 3e5e59c

Browse files
authored
[Core] Adjust auth tests to avoid false CredScan flags (Azure#37267)
1 parent 197df58 commit 3e5e59c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

sdk/core/azure-mgmt-core/tests/test_authentication.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,28 @@
4242
from unittest.mock import Mock
4343

4444

45+
CLAIM_TOKEN = base64.b64encode(b'{"access_token": {"foo": "bar"}}').decode()
46+
CLAIM_NBF = base64.b64encode(b'{"access_token":{"nbf":{"essential":true, "value":"1603742800"}}}').decode()
47+
ip_claim = b'{"access_token":{"nbf":{"essential":true,"value":"1610563006"},"xms_rp_ipaddr":{"value":"1.2.3.4"}}}'
48+
CLAIM_IP = base64.b64encode(ip_claim).decode()[:-2] # Trim off padding = characters
49+
50+
4551
@pytest.mark.parametrize(
4652
"challenge,expected_claims",
4753
(
4854
# CAE - insufficient claims
4955
(
50-
'Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", client_id="00000003-0000-0000-c000-000000000000", error="insufficient_claims", claims="eyJhY2Nlc3NfdG9rZW4iOiB7ImZvbyI6ICJiYXIifX0="',
56+
f'Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", client_id="00000003-0000-0000-c000-000000000000", error="insufficient_claims", claims="{CLAIM_TOKEN}"',
5157
'{"access_token": {"foo": "bar"}}',
5258
),
5359
# CAE - sessions revoked
5460
(
55-
'Bearer authorization_uri="https://login.windows-ppe.net/", error="invalid_token", error_description="User session has been revoked", claims="eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTYwMzc0MjgwMCJ9fX0="',
61+
f'Bearer authorization_uri="https://login.windows-ppe.net/", error="invalid_token", error_description="User session has been revoked", claims={CLAIM_NBF}',
5662
'{"access_token":{"nbf":{"essential":true, "value":"1603742800"}}}',
5763
),
5864
# CAE - IP policy
5965
(
60-
'Bearer authorization_uri="https://login.windows.net/", error="invalid_token", error_description="Tenant IP Policy validate failed.", claims="eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNjEwNTYzMDA2In0sInhtc19ycF9pcGFkZHIiOnsidmFsdWUiOiIxLjIuMy40In19fQ"',
66+
f'Bearer authorization_uri="https://login.windows.net/", error="invalid_token", error_description="Tenant IP Policy validate failed.", claims={CLAIM_IP}',
6167
'{"access_token":{"nbf":{"essential":true,"value":"1610563006"},"xms_rp_ipaddr":{"value":"1.2.3.4"}}}',
6268
),
6369
# ARM

0 commit comments

Comments
 (0)