|
|
@@ -261,11 +261,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
conn = |
|
|
|
conn |
|
|
|
|> assign(:token, nil) |
|
|
|
|> post( |
|
|
|
"/api/pleroma/change_email?#{ |
|
|
|
URI.encode_query(%{password: "hi", email: "test@test.com"}) |
|
|
|
}" |
|
|
|
) |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_email", %{password: "hi", email: "test@test.com"}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 403) == %{ |
|
|
|
"error" => "Insufficient permissions: write:accounts." |
|
|
@@ -274,12 +271,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
|
|
|
|
test "with proper permissions and invalid password", %{conn: conn} do |
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_email?#{ |
|
|
|
URI.encode_query(%{password: "hi", email: "test@test.com"}) |
|
|
|
}" |
|
|
|
) |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_email", %{password: "hi", email: "test@test.com"}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."} |
|
|
|
end |
|
|
@@ -288,10 +282,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
conn: conn |
|
|
|
} do |
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: "foobar"})}" |
|
|
|
) |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_email", %{password: "test", email: "foobar"}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{ |
|
|
|
"error" => "Email has invalid format." |
|
|
@@ -301,7 +294,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
test "with proper permissions, valid password and no email", %{ |
|
|
|
conn: conn |
|
|
|
} do |
|
|
|
conn = post(conn, "/api/pleroma/change_email?#{URI.encode_query(%{password: "test"})}") |
|
|
|
conn = |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_email", %{password: "test"}) |
|
|
|
|
|
|
|
assert %{"error" => "Missing field: email."} = json_response_and_validate_schema(conn, 400) |
|
|
|
end |
|
|
@@ -310,10 +306,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
conn: conn |
|
|
|
} do |
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: ""})}" |
|
|
|
) |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_email", %{password: "test", email: ""}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Email can't be blank."} |
|
|
|
end |
|
|
@@ -324,10 +319,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
user = insert(:user) |
|
|
|
|
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: user.email})}" |
|
|
|
) |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_email", %{password: "test", email: user.email}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{ |
|
|
|
"error" => "Email has already been taken." |
|
|
@@ -338,12 +332,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
conn: conn |
|
|
|
} do |
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_email?#{ |
|
|
|
URI.encode_query(%{password: "test", email: "cofe@foobar.com"}) |
|
|
|
}" |
|
|
|
) |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_email", %{password: "test", email: "cofe@foobar.com"}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"} |
|
|
|
end |
|
|
@@ -356,15 +347,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
conn = |
|
|
|
conn |
|
|
|
|> assign(:token, nil) |
|
|
|
|> post( |
|
|
|
"/api/pleroma/change_password?#{ |
|
|
|
URI.encode_query(%{ |
|
|
|
password: "hi", |
|
|
|
new_password: "newpass", |
|
|
|
new_password_confirmation: "newpass" |
|
|
|
}) |
|
|
|
}" |
|
|
|
) |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_password", %{ |
|
|
|
"password" => "hi", |
|
|
|
"new_password" => "newpass", |
|
|
|
"new_password_confirmation" => "newpass" |
|
|
|
}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 403) == %{ |
|
|
|
"error" => "Insufficient permissions: write:accounts." |
|
|
@@ -373,16 +361,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
|
|
|
|
test "with proper permissions and invalid password", %{conn: conn} do |
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_password?#{ |
|
|
|
URI.encode_query(%{ |
|
|
|
password: "hi", |
|
|
|
new_password: "newpass", |
|
|
|
new_password_confirmation: "newpass" |
|
|
|
}) |
|
|
|
}" |
|
|
|
) |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_password", %{ |
|
|
|
"password" => "hi", |
|
|
|
"new_password" => "newpass", |
|
|
|
"new_password_confirmation" => "newpass" |
|
|
|
}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."} |
|
|
|
end |
|
|
@@ -392,16 +377,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
conn: conn |
|
|
|
} do |
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_password?#{ |
|
|
|
URI.encode_query(%{ |
|
|
|
password: "test", |
|
|
|
new_password: "newpass", |
|
|
|
new_password_confirmation: "notnewpass" |
|
|
|
}) |
|
|
|
}" |
|
|
|
) |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_password", %{ |
|
|
|
"password" => "test", |
|
|
|
"new_password" => "newpass", |
|
|
|
"new_password_confirmation" => "notnewpass" |
|
|
|
}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{ |
|
|
|
"error" => "New password does not match confirmation." |
|
|
@@ -412,12 +394,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
conn: conn |
|
|
|
} do |
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_password?#{ |
|
|
|
URI.encode_query(%{password: "test", new_password: "", new_password_confirmation: ""}) |
|
|
|
}" |
|
|
|
) |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post("/api/pleroma/change_password", %{ |
|
|
|
password: "test", |
|
|
|
new_password: "", |
|
|
|
new_password_confirmation: "" |
|
|
|
}) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{ |
|
|
|
"error" => "New password can't be blank." |
|
|
@@ -429,15 +412,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |
|
|
|
user: user |
|
|
|
} do |
|
|
|
conn = |
|
|
|
post( |
|
|
|
conn, |
|
|
|
"/api/pleroma/change_password?#{ |
|
|
|
URI.encode_query(%{ |
|
|
|
password: "test", |
|
|
|
new_password: "newpass", |
|
|
|
new_password_confirmation: "newpass" |
|
|
|
}) |
|
|
|
}" |
|
|
|
conn |
|
|
|
|> put_req_header("content-type", "multipart/form-data") |
|
|
|
|> post( |
|
|
|
"/api/pleroma/change_password", |
|
|
|
%{ |
|
|
|
password: "test", |
|
|
|
new_password: "newpass", |
|
|
|
new_password_confirmation: "newpass" |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"} |
|
|
|