diff options
author | lambda <pleromagit@rogerbraun.net> | 2019-02-20 16:15:45 +0000 |
---|---|---|
committer | lambda <pleromagit@rogerbraun.net> | 2019-02-20 16:15:45 +0000 |
commit | dff5e1e46ab5e622ae0cc4b4422ae57ce0a0d5de (patch) | |
tree | 3e71afab323f4677b142ed6e9f45e6ecab226b1e /test/web/oauth/authorization_test.exs | |
parent | 11b3c10c54254ecad4b52f27856b8d95629e541c (diff) | |
parent | b574d97c2ee5ea926342b6ef00d9c22c1cc7ebdd (diff) | |
download | pleroma-dff5e1e46ab5e622ae0cc4b4422ae57ce0a0d5de.tar.gz pleroma-dff5e1e46ab5e622ae0cc4b4422ae57ce0a0d5de.zip |
Merge branch '468_oauth2_scopes' into 'develop'
[#468] OAuth2 scopes
Closes #468
See merge request pleroma/pleroma!799
Diffstat (limited to 'test/web/oauth/authorization_test.exs')
-rw-r--r-- | test/web/oauth/authorization_test.exs | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs index 81618e935..306db2e62 100644 --- a/test/web/oauth/authorization_test.exs +++ b/test/web/oauth/authorization_test.exs @@ -8,36 +8,37 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do alias Pleroma.Web.OAuth.App import Pleroma.Factory - test "create an authorization token for a valid app" do + setup do {:ok, app} = Repo.insert( App.register_changeset(%App{}, %{ client_name: "client", - scopes: "scope", + scopes: ["read", "write"], redirect_uris: "url" }) ) + %{app: app} + end + + test "create an authorization token for a valid app", %{app: app} do user = insert(:user) - {:ok, auth} = Authorization.create_authorization(app, user) + {:ok, auth1} = Authorization.create_authorization(app, user) + assert auth1.scopes == app.scopes - assert auth.user_id == user.id - assert auth.app_id == app.id - assert String.length(auth.token) > 10 - assert auth.used == false - end + {:ok, auth2} = Authorization.create_authorization(app, user, ["read"]) + assert auth2.scopes == ["read"] - test "use up a token" do - {:ok, app} = - Repo.insert( - App.register_changeset(%App{}, %{ - client_name: "client", - scopes: "scope", - redirect_uris: "url" - }) - ) + for auth <- [auth1, auth2] do + assert auth.user_id == user.id + assert auth.app_id == app.id + assert String.length(auth.token) > 10 + assert auth.used == false + end + end + test "use up a token", %{app: app} do user = insert(:user) {:ok, auth} = Authorization.create_authorization(app, user) @@ -61,16 +62,7 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do assert {:error, "token expired"} == Authorization.use_token(expired_auth) end - test "delete authorizations" do - {:ok, app} = - Repo.insert( - App.register_changeset(%App{}, %{ - client_name: "client", - scopes: "scope", - redirect_uris: "url" - }) - ) - + test "delete authorizations", %{app: app} do user = insert(:user) {:ok, auth} = Authorization.create_authorization(app, user) |