Fix merge conflict in CHANGELOG.md
This commit is contained in:
commit
ffeae7ef2c
30 changed files with 550 additions and 54 deletions
|
|
@ -46,6 +46,7 @@ defmodule Pleroma.Gun.ConnectionPoolTest do
|
|||
end
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "connection limit is respected with concurrent requests" do
|
||||
clear_config([:connections_pool, :max_connections]) do
|
||||
clear_config([:connections_pool, :max_connections], 1)
|
||||
|
|
|
|||
|
|
@ -1798,6 +1798,30 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [%{"id" => ^id2}] = result
|
||||
end
|
||||
|
||||
test "account lookup", %{conn: conn} do
|
||||
%{nickname: acct} = insert(:user, %{nickname: "nickname"})
|
||||
%{nickname: acct_two} = insert(:user, %{nickname: "nickname@notlocaldoma.in"})
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/accounts/lookup?acct=#{acct}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{"acct" => ^acct} = result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/accounts/lookup?acct=#{acct_two}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{"acct" => ^acct_two} = result
|
||||
|
||||
_result =
|
||||
conn
|
||||
|> get("/api/v1/accounts/lookup?acct=unexisting_nickname")
|
||||
|> json_response_and_validate_schema(404)
|
||||
end
|
||||
|
||||
test "create a note on a user" do
|
||||
%{conn: conn} = oauth_access(["write:accounts", "read:follows"])
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,33 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
|
|||
end
|
||||
|
||||
test "creates an oauth app", %{conn: conn} do
|
||||
app_attrs = build(:oauth_app)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/apps", %{
|
||||
client_name: app_attrs.client_name,
|
||||
redirect_uris: app_attrs.redirect_uris
|
||||
})
|
||||
|
||||
[app] = Repo.all(App)
|
||||
|
||||
expected = %{
|
||||
"name" => app.client_name,
|
||||
"website" => app.website,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret,
|
||||
"id" => app.id |> to_string(),
|
||||
"redirect_uri" => app.redirect_uris,
|
||||
"vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
|
||||
}
|
||||
|
||||
assert expected == json_response_and_validate_schema(conn, 200)
|
||||
assert app.user_id == nil
|
||||
end
|
||||
|
||||
test "creates an oauth app with a user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
app_attrs = build(:oauth_app)
|
||||
|
||||
|
|
@ -60,5 +87,6 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
|
|||
}
|
||||
|
||||
assert expected == json_response_and_validate_schema(conn, 200)
|
||||
assert app.user_id == user.id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,4 +41,16 @@ defmodule Pleroma.Web.OAuth.AppTest do
|
|||
assert error.type == :unique
|
||||
end
|
||||
end
|
||||
|
||||
test "get_user_apps/1" do
|
||||
user = insert(:user)
|
||||
|
||||
apps = [
|
||||
insert(:oauth_app, user_id: user.id),
|
||||
insert(:oauth_app, user_id: user.id),
|
||||
insert(:oauth_app, user_id: user.id)
|
||||
]
|
||||
|
||||
assert App.get_user_apps(user) == apps
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.AppControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Web.OAuth.App
|
||||
alias Pleroma.Web.Push
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "apps", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
app_attrs = build(:oauth_app)
|
||||
|
||||
creation =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/apps", %{
|
||||
client_name: app_attrs.client_name,
|
||||
redirect_uris: app_attrs.redirect_uris
|
||||
})
|
||||
|
||||
[app] = App.get_user_apps(user)
|
||||
|
||||
expected = %{
|
||||
"name" => app.client_name,
|
||||
"website" => app.website,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret,
|
||||
"id" => app.id |> to_string(),
|
||||
"redirect_uri" => app.redirect_uris,
|
||||
"vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
|
||||
}
|
||||
|
||||
assert expected == json_response_and_validate_schema(creation, 200)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["read", "follow"]))
|
||||
|> get("/api/v1/pleroma/apps")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
[apps] = response
|
||||
|
||||
assert length(response) == 1
|
||||
assert apps["client_id"] == app.client_id
|
||||
end
|
||||
end
|
||||
21
test/pleroma/web/pleroma_api/views/app_view_test.exs
Normal file
21
test/pleroma/web/pleroma_api/views/app_view_test.exs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.AppViewTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Web.PleromaAPI.AppView
|
||||
import Pleroma.Factory
|
||||
|
||||
test "index.json" do
|
||||
apps = [
|
||||
insert(:oauth_app),
|
||||
insert(:oauth_app),
|
||||
insert(:oauth_app)
|
||||
]
|
||||
|
||||
results = AppView.render("index.json", %{apps: apps})
|
||||
|
||||
assert [%{client_id: _, client_secret: _}, _, _] = results
|
||||
end
|
||||
end
|
||||
60
test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs
Normal file
60
test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.EnsureStaffPrivilegedPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug
|
||||
import Pleroma.Factory
|
||||
|
||||
test "accepts a user that is an admin" do
|
||||
user = insert(:user, is_admin: true)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
|
||||
ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "accepts a user that is a moderator when :privileged_staff is enabled" do
|
||||
clear_config([:instance, :privileged_staff], true)
|
||||
user = insert(:user, is_moderator: true)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
|
||||
ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "denies a user that is a moderator when :privileged_staff is disabled" do
|
||||
clear_config([:instance, :privileged_staff], false)
|
||||
user = insert(:user, is_moderator: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> EnsureStaffPrivilegedPlug.call(%{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
|
||||
test "denies a user that isn't a staff member" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> EnsureStaffPrivilegedPlug.call(%{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
|
||||
test "denies when a user isn't set" do
|
||||
conn = EnsureStaffPrivilegedPlug.call(build_conn(), %{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue