-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
2196052
commit 3287d72
Showing
4 changed files
with
1 addition
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,6 @@ | |
from ee.models.rbac.role import Role, RoleMembership | ||
from posthog.models.feature_flag import FeatureFlag | ||
from posthog.models.organization import OrganizationMembership | ||
from posthog.models.personal_api_key import PersonalAPIKey, hash_key_value | ||
from posthog.models import User | ||
from rest_framework import status | ||
from posthog.models.utils import generate_random_token_personal | ||
|
||
|
||
class TestFeatureFlagEnterpriseAPI(APILicensedTest): | ||
|
@@ -27,39 +23,3 @@ def test_adding_role_edit_access_is_not_restrictive(self): | |
flag_res = self.client.get(f"/api/projects/{self.team.id}/feature_flags/") | ||
self.assertEqual(flag_res.json()["count"], 1) | ||
self.assertEqual(flag_res.json()["results"][0]["can_edit"], True) | ||
|
||
|
||
class TestFeatureFlagLocalEvaluation(APILicensedTest): | ||
def test_local_evaluation_with_valid_personal_api_key(self): | ||
user = User.objects.create_user(email="[email protected]", first_name="Test", password="password") | ||
|
||
OrganizationMembership.objects.create(user=user, organization=self.organization) | ||
|
||
user.current_team_id = self.team.id | ||
user.save() | ||
|
||
personal_api_key = generate_random_token_personal() | ||
PersonalAPIKey.objects.create( | ||
label="X", | ||
user=user, | ||
last_used_at="2021-08-25T21:09:14", | ||
secure_value=hash_key_value(personal_api_key), | ||
) | ||
FeatureFlag.objects.create( | ||
team=self.team, | ||
name="Beta feature", | ||
key="beta-feature", | ||
created_by=self.user, | ||
filters={"groups": [{"properties": [], "rollout_percentage": 50}]}, | ||
) | ||
|
||
response = self.client.get( | ||
f"/api/projects/{self.team.id}/feature_flags/local_evaluation", | ||
HTTP_AUTHORIZATION=f"Bearer {personal_api_key}", | ||
) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(len(response.json()["flags"]), 1) | ||
self.assertEqual(response.json()["flags"][0]["key"], "beta-feature") | ||
self.assertEqual(response.json()["group_type_mapping"], {}) | ||
self.assertEqual(response.json()["cohorts"], {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -832,36 +832,6 @@ def test_personal_api_key_does_not_update_last_used_at_when_in_the_past(self): | |
model_key = PersonalAPIKey.objects.get(secure_value=hash_key_value(personal_api_key)) | ||
self.assertEqual(str(model_key.last_used_at), "2021-08-25 21:09:14+00:00") | ||
|
||
def test_personal_api_key_not_associated_with_project_or_organization(self): | ||
self.client.logout() | ||
|
||
user = User.objects.create_user(email="[email protected]", first_name="Test", password="password") | ||
|
||
personal_api_key = generate_random_token_personal() | ||
PersonalAPIKey.objects.create( | ||
label="X", | ||
user=user, | ||
last_used_at="2021-08-25T21:09:14", | ||
secure_value=hash_key_value(personal_api_key), | ||
) | ||
|
||
with freeze_time("2021-08-24T21:14:14.252"): | ||
response = self.client.get( | ||
f"/api/projects/{self.team.pk}/feature_flags/", | ||
HTTP_AUTHORIZATION=f"Bearer {personal_api_key}", | ||
) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
self.assertEqual( | ||
response.json(), | ||
{ | ||
"type": "authentication_error", | ||
"code": "authentication_failed", | ||
"detail": "Personal API key is not associated with a project or organization.", | ||
"attr": None, | ||
}, | ||
) | ||
|
||
|
||
class TestTimeSensitivePermissions(APIBaseTest): | ||
def test_after_timeout_modifications_require_reauthentication(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters