Delete test/plausible/auth/auth_test.exs with huggingface_hub
Browse files
test/plausible/auth/auth_test.exs
DELETED
|
@@ -1,145 +0,0 @@
|
|
| 1 |
-
defmodule Plausible.AuthTest do
|
| 2 |
-
use Plausible.DataCase, async: true
|
| 3 |
-
alias Plausible.Auth
|
| 4 |
-
|
| 5 |
-
test "enterprise_configured?/1 returns whether the user has an enterprise plan" do
|
| 6 |
-
user_without_plan = new_user()
|
| 7 |
-
user_with_plan = new_user() |> subscribe_to_enterprise_plan()
|
| 8 |
-
|
| 9 |
-
user_with_plan_no_subscription =
|
| 10 |
-
new_user() |> subscribe_to_enterprise_plan(subscription?: false)
|
| 11 |
-
|
| 12 |
-
assert Plausible.Teams.Billing.enterprise_configured?(team_of(user_with_plan))
|
| 13 |
-
|
| 14 |
-
assert Plausible.Teams.Billing.enterprise_configured?(team_of(user_with_plan_no_subscription))
|
| 15 |
-
|
| 16 |
-
refute Plausible.Teams.Billing.enterprise_configured?(team_of(user_without_plan))
|
| 17 |
-
refute Plausible.Teams.Billing.enterprise_configured?(nil)
|
| 18 |
-
end
|
| 19 |
-
|
| 20 |
-
describe "create_stats_api_key/3" do
|
| 21 |
-
test "creates a new api key" do
|
| 22 |
-
user = new_user(trial_expiry_date: Date.utc_today())
|
| 23 |
-
team = team_of(user)
|
| 24 |
-
key = Ecto.UUID.generate()
|
| 25 |
-
|
| 26 |
-
assert {:ok, %Auth.ApiKey{} = api_key} =
|
| 27 |
-
Auth.create_stats_api_key(user, team, "my new key", key)
|
| 28 |
-
|
| 29 |
-
assert api_key.team_id == team.id
|
| 30 |
-
assert api_key.user_id == user.id
|
| 31 |
-
end
|
| 32 |
-
|
| 33 |
-
test "errors when key already exists" do
|
| 34 |
-
u1 = new_user(trial_expiry_date: Date.utc_today())
|
| 35 |
-
t1 = team_of(u1)
|
| 36 |
-
u2 = new_user(trial_expiry_date: Date.utc_today())
|
| 37 |
-
t2 = team_of(u2)
|
| 38 |
-
key = Ecto.UUID.generate()
|
| 39 |
-
assert {:ok, %Auth.ApiKey{}} = Auth.create_stats_api_key(u1, t1, "my new key", key)
|
| 40 |
-
assert {:error, changeset} = Auth.create_stats_api_key(u2, t2, "my other key", key)
|
| 41 |
-
|
| 42 |
-
assert changeset.errors[:key] ==
|
| 43 |
-
{"has already been taken",
|
| 44 |
-
[constraint: :unique, constraint_name: "api_keys_key_hash_index"]}
|
| 45 |
-
end
|
| 46 |
-
|
| 47 |
-
@tag :ee_only
|
| 48 |
-
test "returns error when team is on a growth plan" do
|
| 49 |
-
user = new_user() |> subscribe_to_growth_plan()
|
| 50 |
-
team = team_of(user)
|
| 51 |
-
|
| 52 |
-
assert {:error, :upgrade_required} =
|
| 53 |
-
Auth.create_stats_api_key(user, team, "my new key", Ecto.UUID.generate())
|
| 54 |
-
end
|
| 55 |
-
|
| 56 |
-
test "creates a key for user in a team with a bunsiness plan" do
|
| 57 |
-
user = new_user() |> subscribe_to_business_plan()
|
| 58 |
-
team = team_of(user)
|
| 59 |
-
another_site = new_site()
|
| 60 |
-
add_member(another_site.team, user: user, role: :owner)
|
| 61 |
-
|
| 62 |
-
assert {:ok, %Auth.ApiKey{}} =
|
| 63 |
-
Auth.create_stats_api_key(user, team, "my new key", Ecto.UUID.generate())
|
| 64 |
-
end
|
| 65 |
-
end
|
| 66 |
-
|
| 67 |
-
describe "create_sites_api_key/3" do
|
| 68 |
-
test "creates a new api key for user on enterprise plan with SitesAPI enabled" do
|
| 69 |
-
user =
|
| 70 |
-
new_user()
|
| 71 |
-
|> subscribe_to_enterprise_plan(
|
| 72 |
-
features: [Plausible.Billing.Feature.StatsAPI, Plausible.Billing.Feature.SitesAPI]
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
team = team_of(user)
|
| 76 |
-
key = Ecto.UUID.generate()
|
| 77 |
-
|
| 78 |
-
assert {:ok, %Auth.ApiKey{} = api_key} =
|
| 79 |
-
Auth.create_sites_api_key(user, team, "my new key", key)
|
| 80 |
-
|
| 81 |
-
assert api_key.team_id == team.id
|
| 82 |
-
assert api_key.user_id == user.id
|
| 83 |
-
end
|
| 84 |
-
|
| 85 |
-
test "errors when key already exists" do
|
| 86 |
-
u1 =
|
| 87 |
-
new_user()
|
| 88 |
-
|> subscribe_to_enterprise_plan(
|
| 89 |
-
features: [Plausible.Billing.Feature.StatsAPI, Plausible.Billing.Feature.SitesAPI]
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
t1 = team_of(u1)
|
| 93 |
-
|
| 94 |
-
u2 =
|
| 95 |
-
new_user()
|
| 96 |
-
|> subscribe_to_enterprise_plan(
|
| 97 |
-
features: [Plausible.Billing.Feature.StatsAPI, Plausible.Billing.Feature.SitesAPI]
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
t2 = team_of(u2)
|
| 101 |
-
key = Ecto.UUID.generate()
|
| 102 |
-
assert {:ok, %Auth.ApiKey{}} = Auth.create_sites_api_key(u1, t1, "my new key", key)
|
| 103 |
-
assert {:error, changeset} = Auth.create_sites_api_key(u2, t2, "my other key", key)
|
| 104 |
-
|
| 105 |
-
assert changeset.errors[:key] ==
|
| 106 |
-
{"has already been taken",
|
| 107 |
-
[constraint: :unique, constraint_name: "api_keys_key_hash_index"]}
|
| 108 |
-
end
|
| 109 |
-
|
| 110 |
-
@tag :ee_only
|
| 111 |
-
test "returns error when team is on a business plan" do
|
| 112 |
-
user = new_user() |> subscribe_to_business_plan()
|
| 113 |
-
team = team_of(user)
|
| 114 |
-
|
| 115 |
-
assert {:error, :upgrade_required} =
|
| 116 |
-
Auth.create_sites_api_key(user, team, "my new key", Ecto.UUID.generate())
|
| 117 |
-
end
|
| 118 |
-
end
|
| 119 |
-
|
| 120 |
-
describe "delete_api_key/2" do
|
| 121 |
-
test "deletes the record" do
|
| 122 |
-
user = new_user(trial_expiry_date: Date.utc_today())
|
| 123 |
-
team = team_of(user)
|
| 124 |
-
|
| 125 |
-
assert {:ok, api_key} =
|
| 126 |
-
Auth.create_stats_api_key(user, team, "my new key", Ecto.UUID.generate())
|
| 127 |
-
|
| 128 |
-
assert :ok = Auth.delete_api_key(user, api_key.id)
|
| 129 |
-
refute Plausible.Repo.reload(api_key)
|
| 130 |
-
end
|
| 131 |
-
|
| 132 |
-
test "returns error when api key does not exist or does not belong to user" do
|
| 133 |
-
me = new_user(trial_expiry_date: Date.utc_today())
|
| 134 |
-
|
| 135 |
-
other_user = new_user(trial_expiry_date: Date.utc_today())
|
| 136 |
-
other_team = team_of(other_user)
|
| 137 |
-
|
| 138 |
-
{:ok, other_api_key} =
|
| 139 |
-
Auth.create_stats_api_key(other_user, other_team, "my new key", Ecto.UUID.generate())
|
| 140 |
-
|
| 141 |
-
assert {:error, :not_found} = Auth.delete_api_key(me, other_api_key.id)
|
| 142 |
-
assert {:error, :not_found} = Auth.delete_api_key(me, -1)
|
| 143 |
-
end
|
| 144 |
-
end
|
| 145 |
-
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|