|
42 | 42 | from unittest.mock import Mock |
43 | 43 |
|
44 | 44 |
|
| 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 | + |
45 | 51 | @pytest.mark.parametrize( |
46 | 52 | "challenge,expected_claims", |
47 | 53 | ( |
48 | 54 | # CAE - insufficient claims |
49 | 55 | ( |
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}"', |
51 | 57 | '{"access_token": {"foo": "bar"}}', |
52 | 58 | ), |
53 | 59 | # CAE - sessions revoked |
54 | 60 | ( |
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}', |
56 | 62 | '{"access_token":{"nbf":{"essential":true, "value":"1603742800"}}}', |
57 | 63 | ), |
58 | 64 | # CAE - IP policy |
59 | 65 | ( |
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}', |
61 | 67 | '{"access_token":{"nbf":{"essential":true,"value":"1610563006"},"xms_rp_ipaddr":{"value":"1.2.3.4"}}}', |
62 | 68 | ), |
63 | 69 | # ARM |
|
0 commit comments