summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/credential-management/support/fedcm/variable_accounts.py
blob: fc4446acc49e4e1538a10478e3aa744ccc495db2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import importlib
error_checker = importlib.import_module("credential-management.support.fedcm.request-params-check")

result_json = """
{{
 "accounts": [{}]
}}
"""

one_account = """
{
   "id": "1234",
   "given_name": "John",
   "name": "John Doe",
   "email": "john_doe@idp.example",
   "picture": "https://idp.example/profile/123",
   "approved_clients": ["123", "456", "789"],
   "login_hints": ["john_doe"],
   "hosted_domains": ["idp.example", "example"]
  }
"""


two_accounts = one_account + """
, {
   "id": "jane_doe",
   "given_name": "Jane",
   "name": "Jane Doe",
   "email": "jane_doe@idp.example",
   "picture": "https://idp.example/profile/5678",
   "approved_clients": ["123", "abc"]
}
"""

def main(request, response):
  request_error = error_checker.accountsCheck(request)
  if (request_error):
    return request_error

  response.headers.set(b"Content-Type", b"application/json")

  if request.cookies.get(b"accounts") == b"1":
    return result_json.format(one_account)
  if request.cookies.get(b"accounts") == b"2":
    return result_json.format(two_accounts)

  return result_json.format("")