import Pleroma.Factory
describe "account fetching" do
- clear_config([:instance, :limit_to_local_content])
+ setup do: clear_config([:instance, :limit_to_local_content])
test "works by id" do
user = insert(:user)
describe "user fetching with restrict unauthenticated profiles for local and remote" do
setup do: local_and_remote_users()
- clear_config([:restrict_unauthenticated, :profiles, :local]) do
- Config.put([:restrict_unauthenticated, :profiles, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
- clear_config([:restrict_unauthenticated, :profiles, :remote]) do
- Config.put([:restrict_unauthenticated, :profiles, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
describe "user fetching with restrict unauthenticated profiles for local" do
setup do: local_and_remote_users()
- clear_config([:restrict_unauthenticated, :profiles, :local]) do
- Config.put([:restrict_unauthenticated, :profiles, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
describe "user fetching with restrict unauthenticated profiles for remote" do
setup do: local_and_remote_users()
- clear_config([:restrict_unauthenticated, :profiles, :remote]) do
- Config.put([:restrict_unauthenticated, :profiles, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
setup do: local_and_remote_users()
setup :local_and_remote_activities
- clear_config([:restrict_unauthenticated, :profiles, :local]) do
- Config.put([:restrict_unauthenticated, :profiles, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
- clear_config([:restrict_unauthenticated, :profiles, :remote]) do
- Config.put([:restrict_unauthenticated, :profiles, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
setup do: local_and_remote_users()
setup :local_and_remote_activities
- clear_config([:restrict_unauthenticated, :profiles, :local]) do
- Config.put([:restrict_unauthenticated, :profiles, :local], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
setup do: local_and_remote_users()
setup :local_and_remote_activities
- clear_config([:restrict_unauthenticated, :profiles, :remote]) do
- Config.put([:restrict_unauthenticated, :profiles, :remote], true)
- end
+ setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
[valid_params: valid_params]
end
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
test "Account registration via Application", %{conn: conn} do
conn =
- post(conn, "/api/v1/apps", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/apps", %{
client_name: "client_name",
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
scopes: "read, write, follow"
end)
end
- clear_config([:instance, :account_activation_required])
+ setup do: clear_config([:instance, :account_activation_required])
test "returns bad_request if missing email params when :account_activation_required is enabled",
%{conn: conn, valid_params: valid_params} do
res = post(conn, "/api/v1/accounts", valid_params)
assert json_response(res, 403) == %{"error" => "Invalid credentials"}
end
+
+ test "registration from trusted app" do
+ clear_config([Pleroma.Captcha, :enabled], true)
+ app = insert(:oauth_app, trusted: true, scopes: ["read", "write", "follow", "push"])
+
+ conn =
+ build_conn()
+ |> post("/oauth/token", %{
+ "grant_type" => "client_credentials",
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret
+ })
+
+ assert %{"access_token" => token, "token_type" => "Bearer"} = json_response(conn, 200)
+
+ response =
+ build_conn()
+ |> Plug.Conn.put_req_header("authorization", "Bearer " <> token)
+ |> post("/api/v1/accounts", %{
+ nickname: "nickanme",
+ agreement: true,
+ email: "email@example.com",
+ fullname: "Lain",
+ username: "Lain",
+ password: "some_password",
+ confirm: "some_password"
+ })
+ |> json_response(200)
+
+ assert %{
+ "access_token" => access_token,
+ "created_at" => _,
+ "scope" => ["read", "write", "follow", "push"],
+ "token_type" => "Bearer"
+ } = response
+
+ response =
+ build_conn()
+ |> Plug.Conn.put_req_header("authorization", "Bearer " <> access_token)
+ |> get("/api/v1/accounts/verify_credentials")
+ |> json_response(200)
+
+ assert %{
+ "acct" => "Lain",
+ "bot" => false,
+ "display_name" => "Lain",
+ "follow_requests_count" => 0,
+ "followers_count" => 0,
+ "following_count" => 0,
+ "locked" => false,
+ "note" => "",
+ "source" => %{
+ "fields" => [],
+ "note" => "",
+ "pleroma" => %{
+ "actor_type" => "Person",
+ "discoverable" => false,
+ "no_rich_text" => false,
+ "show_role" => true
+ },
+ "privacy" => "public",
+ "sensitive" => false
+ },
+ "statuses_count" => 0,
+ "username" => "Lain"
+ } = response
+ end
end
describe "create account by app / rate limit" do
- clear_config([:rate_limit, :app_account_creation], {10_000, 2})
+ setup do: clear_config([:rate_limit, :app_account_creation], {10_000, 2})
test "respects rate limit setting", %{conn: conn} do
app_token = insert(:oauth_token, user: nil)