Unique apps.client_id for new installations, fixes #2022
authorAlex Gleason <alex@alexgleason.me>
Tue, 4 Aug 2020 03:32:51 +0000 (22:32 -0500)
committerAlex Gleason <alex@alexgleason.me>
Tue, 4 Aug 2020 18:31:40 +0000 (13:31 -0500)
priv/repo/migrations/20200804183107_add_unique_index_to_app_client_id.exs [new file with mode: 0644]
test/web/oauth/app_test.exs

diff --git a/priv/repo/migrations/20200804183107_add_unique_index_to_app_client_id.exs b/priv/repo/migrations/20200804183107_add_unique_index_to_app_client_id.exs
new file mode 100644 (file)
index 0000000..83de180
--- /dev/null
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.AddUniqueIndexToAppClientId do
+  use Ecto.Migration
+
+  def change do
+    create(unique_index(:apps, [:client_id]))
+  end
+end
index 899af648e98b4fac425ae4e826fb141a67715cb1..993a490e0519538c37f1ca17d4cdab3686d87929 100644 (file)
@@ -29,5 +29,16 @@ defmodule Pleroma.Web.OAuth.AppTest do
       assert exist_app.id == app.id
       assert exist_app.scopes == ["read", "write", "follow", "push"]
     end
+
+    test "has unique client_id" do
+      insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop")
+
+      error =
+        catch_error(insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop"))
+
+      assert %Ecto.ConstraintError{} = error
+      assert error.constraint == "apps_client_id_index"
+      assert error.type == :unique
+    end
   end
 end