tests consistency
This commit is contained in:
parent
6bf85440b3
commit
7dffaef479
258 changed files with 38 additions and 37 deletions
|
|
@ -1,36 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.DateTimeTest do
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime
|
||||
use Pleroma.DataCase
|
||||
|
||||
test "it validates an xsd:Datetime" do
|
||||
valid_strings = [
|
||||
"2004-04-12T13:20:00",
|
||||
"2004-04-12T13:20:15.5",
|
||||
"2004-04-12T13:20:00-05:00",
|
||||
"2004-04-12T13:20:00Z"
|
||||
]
|
||||
|
||||
invalid_strings = [
|
||||
"2004-04-12T13:00",
|
||||
"2004-04-1213:20:00",
|
||||
"99-04-12T13:00",
|
||||
"2004-04-12"
|
||||
]
|
||||
|
||||
assert {:ok, "2004-04-01T12:00:00Z"} == DateTime.cast("2004-04-01T12:00:00Z")
|
||||
|
||||
Enum.each(valid_strings, fn date_time ->
|
||||
result = DateTime.cast(date_time)
|
||||
assert {:ok, _} = result
|
||||
end)
|
||||
|
||||
Enum.each(invalid_strings, fn date_time ->
|
||||
result = DateTime.cast(date_time)
|
||||
assert :error == result
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ObjectValidators.Types.ObjectIDTest do
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
|
||||
use Pleroma.DataCase
|
||||
|
||||
@uris [
|
||||
"http://lain.com/users/lain",
|
||||
"http://lain.com",
|
||||
"https://lain.com/object/1"
|
||||
]
|
||||
|
||||
@non_uris [
|
||||
"https://",
|
||||
"rin",
|
||||
1,
|
||||
:x,
|
||||
%{"1" => 2}
|
||||
]
|
||||
|
||||
test "it accepts http uris" do
|
||||
Enum.each(@uris, fn uri ->
|
||||
assert {:ok, uri} == ObjectID.cast(uri)
|
||||
end)
|
||||
end
|
||||
|
||||
test "it accepts an object with a nested uri id" do
|
||||
Enum.each(@uris, fn uri ->
|
||||
assert {:ok, uri} == ObjectID.cast(%{"id" => uri})
|
||||
end)
|
||||
end
|
||||
|
||||
test "it rejects non-uri strings" do
|
||||
Enum.each(@non_uris, fn non_uri ->
|
||||
assert :error == ObjectID.cast(non_uri)
|
||||
assert :error == ObjectID.cast(%{"id" => non_uri})
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ObjectValidators.Types.RecipientsTest do
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.Recipients
|
||||
use Pleroma.DataCase
|
||||
|
||||
test "it asserts that all elements of the list are object ids" do
|
||||
list = ["https://lain.com/users/lain", "invalid"]
|
||||
|
||||
assert :error == Recipients.cast(list)
|
||||
end
|
||||
|
||||
test "it works with a list" do
|
||||
list = ["https://lain.com/users/lain"]
|
||||
assert {:ok, list} == Recipients.cast(list)
|
||||
end
|
||||
|
||||
test "it works with a list with whole objects" do
|
||||
list = ["https://lain.com/users/lain", %{"id" => "https://gensokyo.2hu/users/raymoo"}]
|
||||
resulting_list = ["https://gensokyo.2hu/users/raymoo", "https://lain.com/users/lain"]
|
||||
assert {:ok, resulting_list} == Recipients.cast(list)
|
||||
end
|
||||
|
||||
test "it turns a single string into a list" do
|
||||
recipient = "https://lain.com/users/lain"
|
||||
|
||||
assert {:ok, [recipient]} == Recipients.cast(recipient)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.SafeTextTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText
|
||||
|
||||
test "it lets normal text go through" do
|
||||
text = "hey how are you"
|
||||
assert {:ok, text} == SafeText.cast(text)
|
||||
end
|
||||
|
||||
test "it removes html tags from text" do
|
||||
text = "hey look xss <script>alert('foo')</script>"
|
||||
assert {:ok, "hey look xss alert('foo')"} == SafeText.cast(text)
|
||||
end
|
||||
|
||||
test "it keeps basic html tags" do
|
||||
text = "hey <a href='http://gensokyo.2hu'>look</a> xss <script>alert('foo')</script>"
|
||||
|
||||
assert {:ok, "hey <a href=\"http://gensokyo.2hu\">look</a> xss alert('foo')"} ==
|
||||
SafeText.cast(text)
|
||||
end
|
||||
|
||||
test "errors for non-text" do
|
||||
assert :error == SafeText.cast(1)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue