Skip to content

Commit f1d58c5

Browse files
author
Val Brodsky
committed
Update invite tests to reflect that the invite id is not returned any more
1 parent b6427ed commit f1d58c5

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

libs/labelbox/tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ def environ() -> Environ:
336336
raise Exception(f"Missing env key in: {os.environ}")
337337

338338

339+
@pytest.mark.skip(
340+
"Test disabled - due to security reasons, invite uid is not returned"
341+
)
339342
def cancel_invite(client, invite_id):
340343
"""
341344
Do not use. Only for testing.

libs/labelbox/tests/integration/test_user_management.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
from typing import Optional
2+
13
import pytest
4+
from faker import Faker
25

36
from labelbox import ProjectRole
4-
from faker import Faker
7+
from labelbox.schema.invite import Invite
58

69
faker = Faker()
710

811

12+
def find_invite_and_id_by_email(
13+
queries, client, invite_email
14+
) -> Optional[Invite]:
15+
"""For security reasons, invite uid is not returned for a query for a single invite.
16+
This function is a workaround to find the invite uid by email using another query that returns all invites.
17+
"""
18+
outstanding_invites = queries.get_invites(client)
19+
20+
for outstanding_invite in outstanding_invites:
21+
if outstanding_invite.email == invite_email:
22+
return outstanding_invite
23+
return None
24+
25+
926
@pytest.fixture
1027
def org_invite(client, organization, environ, queries):
1128
role = client.get_roles()["LABELER"]
@@ -27,7 +44,9 @@ def org_invite(client, organization, environ, queries):
2744

2845
yield invite, invite_limit
2946

30-
queries.cancel_invite(client, invite.uid)
47+
found_invite = find_invite_and_id_by_email(queries, client, invite.email)
48+
assert found_invite is not None, "Invite not found"
49+
queries.cancel_invite(client, found_invite.uid)
3150

3251

3352
@pytest.fixture
@@ -60,30 +79,32 @@ def create_project_invite(
6079

6180
yield invite
6281

63-
queries.cancel_invite(client, invite.uid)
82+
found_invite = find_invite_and_id_by_email(queries, client, invite.email)
83+
assert found_invite is not None, "Invite not found"
84+
queries.cancel_invite(client, found_invite.uid)
6485

6586

6687
def test_org_invite(client, organization, environ, queries, org_invite):
6788
invite, invite_limit = org_invite
6889
role = client.get_roles()["LABELER"]
6990

91+
assert (
92+
invite.uid == "invited"
93+
) # for security reasons we don't return the invite uid
94+
7095
if environ.value == "prod":
7196
invite_limit_after = organization.invite_limit()
7297
# One user added
7398
assert invite_limit.remaining - invite_limit_after.remaining == 1
7499
# An invite shouldn't effect the user count until after it is accepted
75100

76-
outstanding_invites = queries.get_invites(client)
77-
in_list = False
101+
found_invite = find_invite_and_id_by_email(queries, client, invite.email)
78102

79-
for outstanding_invite in outstanding_invites:
80-
if outstanding_invite.uid == invite.uid:
81-
in_list = True
82-
org_role = outstanding_invite.organization_role_name.lower()
83-
assert (
84-
org_role == role.name.lower()
85-
), "Role should be labeler. Found {org_role} "
86-
assert in_list, "Invite not found"
103+
assert found_invite is not None, "Invite not found"
104+
org_role = found_invite.organization_role_name.lower()
105+
assert (
106+
org_role == role.name.lower()
107+
), "Role should be labeler. Found {org_role} "
87108

88109

89110
def test_cancel_invite(
@@ -96,6 +117,10 @@ def test_cancel_invite(
96117
"".join(faker.random_letters(26))
97118
)
98119
invite = organization.invite_user(dummy_email, role)
120+
found_invite = find_invite_and_id_by_email(queries, client, invite.email)
121+
assert found_invite is not None, "Invite not found"
122+
invite.uid = found_invite.uid # for security reasons we don't return the invite uid directly but need it in order to cancel the invite
123+
99124
queries.cancel_invite(client, invite.uid)
100125
outstanding_invites = [i.uid for i in queries.get_invites(client)]
101126
assert invite.uid not in outstanding_invites

0 commit comments

Comments
 (0)