1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
10 j = json.load(open(sys.argv[1]))
12 apiA = arvados.api(host=j["arvados_api_hosts"][0], token=j["superuser_tokens"][0], insecure=True)
13 tok = apiA.api_client_authorizations().current().execute()
14 v2_token = "v2/%s/%s" % (tok["uuid"], tok["api_token"])
16 apiB = arvados.api(host=j["arvados_api_hosts"][1], token=v2_token, insecure=True)
17 apiC = arvados.api(host=j["arvados_api_hosts"][2], token=v2_token, insecure=True)
20 ### Check users on API server "A" (the LoginCluster) ###
24 assert len(users["items"]) == 11
26 for i in range(1, 10):
28 for u in users["items"]:
29 if u["username"] == ("case%d" % i) and u["email"] == ("case%d@test" % i) and u["first_name"] == ("Case%d" % i) and u["last_name"] == "Testuser":
31 by_username[u["username"]] = u["uuid"]
35 for i in (1, 2, 3, 4, 5, 6, 7, 8):
37 for u in users["items"]:
38 if u["username"] == ("case%d" % i) and u["email"] == ("case%d@test" % i) and u["is_active"] is True:
40 assert found, "Not found case%i" % i
42 # case9 should not be active
44 for u in users["items"]:
45 if (u["username"] == "case9" and u["email"] == "case9@test" and
46 u["uuid"] == by_username[u["username"]] and u["is_active"] is False):
50 users = apiA.users().list().execute()
53 users = apiA.users().list(bypass_federation=True).execute()
57 ### Check users on API server "B" (federation member) ###
60 # check for expected migrations on B
61 users = apiB.users().list(bypass_federation=True).execute()
62 assert len(users["items"]) == 11
66 for u in users["items"]:
67 if (u["username"] == ("case%d" % i) and u["email"] == ("case%d@test" % i) and
68 u["first_name"] == ("Case%d" % i) and u["last_name"] == "Testuser" and
69 u["uuid"] == by_username[u["username"]] and u["is_active"] is True):
71 assert found, "Not found case%i" % i
74 for u in users["items"]:
75 if (u["username"] == "case9" and u["email"] == "case9@test" and
76 u["first_name"] == "Case9" and u["last_name"] == "Testuser" and
77 u["uuid"] == by_username[u["username"]] and u["is_active"] is False):
81 # check that federated user listing works
82 users = apiB.users().list().execute()
86 ### Check users on API server "C" (federation member) ###
89 # check for expected migrations on C
90 users = apiC.users().list(bypass_federation=True).execute()
91 assert len(users["items"]) == 8
93 for i in (2, 4, 6, 7, 8):
95 for u in users["items"]:
96 if (u["username"] == ("case%d" % i) and u["email"] == ("case%d@test" % i) and
97 u["first_name"] == ("Case%d" % i) and u["last_name"] == "Testuser" and
98 u["uuid"] == by_username[u["username"]] and u["is_active"] is True):
102 # cases 3, 5, 9 involve users that have never accessed cluster C so
103 # there's nothing to migrate.
106 for u in users["items"]:
107 if (u["username"] == ("case%d" % i) and u["email"] == ("case%d@test" % i) and
108 u["first_name"] == ("Case%d" % i) and u["last_name"] == "Testuser" and
109 u["uuid"] == by_username[u["username"]] and u["is_active"] is True):
113 # check that federated user listing works
114 users = apiC.users().list().execute()
121 # Check that this query returns empty, instead of returning a 500 or
123 # Yes, we're asking for a group from the users endpoint. This is not a
124 # mistake, this is something workbench does to populate the sharing
126 clusterID_B = apiB.configs().get().execute()["ClusterID"]
127 i = apiB.users().list(filters=[["uuid", "in", ["%s-j7d0g-fffffffffffffff" % clusterID_B]]], count="none").execute()
128 assert len(i["items"]) == 0
130 # Check that we can create a project and give a remote user access to it
132 tok3 = apiA.api_client_authorizations().create(body={"api_client_authorization": {"owner_uuid": by_username["case3"]}}).execute()
133 tok4 = apiA.api_client_authorizations().create(body={"api_client_authorization": {"owner_uuid": by_username["case4"]}}).execute()
135 v2_token3 = "v2/%s/%s" % (tok3["uuid"], tok3["api_token"])
136 v2_token4 = "v2/%s/%s" % (tok4["uuid"], tok4["api_token"])
138 apiB_3 = arvados.api(host=j["arvados_api_hosts"][1], token=v2_token3, insecure=True)
139 apiB_4 = arvados.api(host=j["arvados_api_hosts"][1], token=v2_token4, insecure=True)
141 assert apiB_3.users().current().execute()["uuid"] == by_username["case3"]
142 assert apiB_4.users().current().execute()["uuid"] == by_username["case4"]
144 newproject = apiB_3.groups().create(body={"group_class": "project",
145 "name":"fed test project"},
146 ensure_unique_name=True).execute()
150 apiB_4.groups().get(uuid=newproject["uuid"]).execute()
151 except arvados.errors.ApiError as e:
152 if e.resp['status'] == '404':
157 l = apiB_3.links().create(body={"link_class": "permission",
159 "tail_uuid": by_username["case4"],
160 "head_uuid": newproject["uuid"]}).execute()
163 apiB_4.groups().get(uuid=newproject["uuid"]).execute()
166 apiB_3.links().delete(uuid=l["uuid"]).execute()
169 # Expect to fail again
170 apiB_4.groups().get(uuid=newproject["uuid"]).execute()
171 except arvados.errors.ApiError as e:
172 if e.resp['status'] == '404':
177 print("Passed checks")