[#468] Added OAuth scopes-specific tests.

This commit is contained in:
Ivan Tashkinov 2019-02-19 22:28:21 +03:00
commit 04ee877a20
6 changed files with 162 additions and 47 deletions

View file

@ -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"
})
)
user = insert(:user)
{:ok, auth} = Authorization.create_authorization(app, user)
assert auth.user_id == user.id
assert auth.app_id == app.id
assert String.length(auth.token) > 10
assert auth.used == false
%{app: app}
end
test "use up a token" do
{:ok, app} =
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client",
scopes: ["scope"],
redirect_uris: "url"
})
)
test "create an authorization token for a valid app", %{app: app} do
user = insert(:user)
{:ok, auth1} = Authorization.create_authorization(app, user)
assert auth1.scopes == app.scopes
{:ok, auth2} = Authorization.create_authorization(app, user, ["read"])
assert auth2.scopes == ["read"]
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)