split test for update profile fields

This commit is contained in:
kPherox 2020-04-01 00:05:13 +09:00
parent d191b0942f
commit dbf9d719f9
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D
1 changed files with 53 additions and 45 deletions

View File

@ -273,7 +273,7 @@ test "updates profile emojos", %{user: user, conn: conn} do
test "update fields", %{conn: conn} do test "update fields", %{conn: conn} do
fields = [ fields = [
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "<script>bar</script>"}, %{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "<script>bar</script>"},
%{"name" => "link", "value" => "cofe.io"} %{"name" => "link.io", "value" => "cofe.io"}
] ]
account_data = account_data =
@ -283,7 +283,10 @@ test "update fields", %{conn: conn} do
assert account_data["fields"] == [ assert account_data["fields"] == [
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"}, %{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"},
%{"name" => "link", "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)} %{
"name" => "link.io",
"value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)
}
] ]
assert account_data["source"]["fields"] == [ assert account_data["source"]["fields"] == [
@ -291,14 +294,16 @@ test "update fields", %{conn: conn} do
"name" => "<a href=\"http://google.com\">foo</a>", "name" => "<a href=\"http://google.com\">foo</a>",
"value" => "<script>bar</script>" "value" => "<script>bar</script>"
}, },
%{"name" => "link", "value" => "cofe.io"} %{"name" => "link.io", "value" => "cofe.io"}
] ]
end
test "update fields by urlencoded", %{conn: conn} do
fields = fields =
[ [
"fields_attributes[1][name]=link", "fields_attributes[1][name]=link",
"fields_attributes[1][value]=cofe.io", "fields_attributes[1][value]=http://cofe.io",
"fields_attributes[0][name]=<a href=\"http://google.com\">foo</a>", "fields_attributes[0][name]=foo",
"fields_attributes[0][value]=bar" "fields_attributes[0][value]=bar"
] ]
|> Enum.join("&") |> Enum.join("&")
@ -310,51 +315,20 @@ test "update fields", %{conn: conn} do
|> json_response(200) |> json_response(200)
assert account["fields"] == [ assert account["fields"] == [
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"}, %{"name" => "foo", "value" => "bar"},
%{"name" => "link", "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)} %{
"name" => "link",
"value" => ~S(<a href="http://cofe.io" rel="ugc">http://cofe.io</a>)
}
] ]
assert account["source"]["fields"] == [ assert account["source"]["fields"] == [
%{ %{"name" => "foo", "value" => "bar"},
"name" => "<a href=\"http://google.com\">foo</a>", %{"name" => "link", "value" => "http://cofe.io"}
"value" => "bar"
},
%{"name" => "link", "value" => "cofe.io"}
] ]
end
name_limit = Pleroma.Config.get([:instance, :account_field_name_length]) test "update fields with empty name", %{conn: conn} do
value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
fields = [%{"name" => "<b>foo<b>", "value" => long_value}]
assert %{"error" => "Invalid request"} ==
conn
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
fields = [%{"name" => long_name, "value" => "bar"}]
assert %{"error" => "Invalid request"} ==
conn
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
Pleroma.Config.put([:instance, :max_account_fields], 1)
fields = [
%{"name" => "<b>foo<b>", "value" => "<i>bar</i>"},
%{"name" => "link", "value" => "cofe.io"}
]
assert %{"error" => "Invalid request"} ==
conn
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
fields = [ fields = [
%{"name" => "foo", "value" => ""}, %{"name" => "foo", "value" => ""},
%{"name" => "", "value" => "bar"} %{"name" => "", "value" => "bar"}
@ -369,5 +343,39 @@ test "update fields", %{conn: conn} do
%{"name" => "foo", "value" => ""} %{"name" => "foo", "value" => ""}
] ]
end end
test "update fields when invalid request", %{conn: conn} do
name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
fields = [%{"name" => "foo", "value" => long_value}]
assert %{"error" => "Invalid request"} ==
conn
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
fields = [%{"name" => long_name, "value" => "bar"}]
assert %{"error" => "Invalid request"} ==
conn
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
Pleroma.Config.put([:instance, :max_account_fields], 1)
fields = [
%{"name" => "foo", "value" => "bar"},
%{"name" => "link", "value" => "cofe.io"}
]
assert %{"error" => "Invalid request"} ==
conn
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
end
end end
end end