X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fsignature_test.exs;h=04736d8b9b788e7a0b85265c53840704679a4414;hb=d191b0942f64a32a2bf450318fac85981aa17c83;hp=26337eaf9ee7da5e71f8d865edf8632513e443a5;hpb=638f772356afdb92a722ae54059604dbbab94d58;p=akkoma
diff --git a/test/signature_test.exs b/test/signature_test.exs
index 26337eaf9..04736d8b9 100644
--- a/test/signature_test.exs
+++ b/test/signature_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.SignatureTest do
@@ -8,6 +8,7 @@ defmodule Pleroma.SignatureTest do
import ExUnit.CaptureLog
import Pleroma.Factory
import Tesla.Mock
+ import Mock
alias Pleroma.Signature
@@ -41,7 +42,7 @@ defmodule Pleroma.SignatureTest do
test "it returns key" do
expected_result = {:ok, @rsa_public_key}
- user = insert(:user, %{info: %{source_data: %{"publicKey" => @public_key}}})
+ user = insert(:user, source_data: %{"publicKey" => @public_key})
assert Signature.fetch_public_key(make_fake_conn(user.ap_id)) == expected_result
end
@@ -53,7 +54,7 @@ defmodule Pleroma.SignatureTest do
end
test "it returns error if public key is empty" do
- user = insert(:user, %{info: %{source_data: %{"publicKey" => %{}}}})
+ user = insert(:user, source_data: %{"publicKey" => %{}})
assert Signature.fetch_public_key(make_fake_conn(user.ap_id)) == {:error, :error}
end
@@ -68,8 +69,7 @@ defmodule Pleroma.SignatureTest do
test "it returns error when not found user" do
assert capture_log(fn ->
- assert Signature.refetch_public_key(make_fake_conn("test-ap_id")) ==
- {:error, {:error, :ok}}
+ {:error, _} = Signature.refetch_public_key(make_fake_conn("test-ap_id"))
end) =~ "[error] Could not decode user"
end
end
@@ -79,7 +79,7 @@ defmodule Pleroma.SignatureTest do
user =
insert(:user, %{
ap_id: "https://mastodon.social/users/lambadalambda",
- info: %{keys: @private_key}
+ keys: @private_key
})
assert Signature.sign(
@@ -93,8 +93,7 @@ defmodule Pleroma.SignatureTest do
end
test "it returns error" do
- user =
- insert(:user, %{ap_id: "https://mastodon.social/users/lambadalambda", info: %{keys: ""}})
+ user = insert(:user, %{ap_id: "https://mastodon.social/users/lambadalambda", keys: ""})
assert Signature.sign(
user,
@@ -114,4 +113,17 @@ defmodule Pleroma.SignatureTest do
"https://example.com/users/1234"
end
end
+
+ describe "signed_date" do
+ test "it returns formatted current date" do
+ with_mock(NaiveDateTime, utc_now: fn -> ~N[2019-08-23 18:11:24.822233] end) do
+ assert Signature.signed_date() == "Fri, 23 Aug 2019 18:11:24 GMT"
+ end
+ end
+
+ test "it returns formatted date" do
+ assert Signature.signed_date(~N[2019-08-23 08:11:24.822233]) ==
+ "Fri, 23 Aug 2019 08:11:24 GMT"
+ end
+ end
end