summaryrefslogtreecommitdiff
path: root/test/plugs/idempotency_plug_test.exs
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-10-17 13:12:39 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-10-17 13:12:39 +0300
commit049ece1ef38f1aeb656a88ed1d15bf3d4a364e01 (patch)
tree16d4a05e533685e8b8385f886e58addb05a90d7d /test/plugs/idempotency_plug_test.exs
parent2498e569f12694439b6f99d0730f6fb36301c454 (diff)
parent023f726d7f497705d766adee8874b94efb08a0aa (diff)
downloadpleroma-049ece1ef38f1aeb656a88ed1d15bf3d4a364e01.tar.gz
pleroma-049ece1ef38f1aeb656a88ed1d15bf3d4a364e01.zip
Merge remote-tracking branch 'remotes/origin/develop' into ostatus-controller-no-auth-check-on-non-federating-instances
# Conflicts: # lib/pleroma/web/feed/user_controller.ex # lib/pleroma/web/o_status/o_status_controller.ex # lib/pleroma/web/router.ex # lib/pleroma/web/static_fe/static_fe_controller.ex
Diffstat (limited to 'test/plugs/idempotency_plug_test.exs')
-rw-r--r--test/plugs/idempotency_plug_test.exs110
1 files changed, 0 insertions, 110 deletions
diff --git a/test/plugs/idempotency_plug_test.exs b/test/plugs/idempotency_plug_test.exs
deleted file mode 100644
index 21fa0fbcf..000000000
--- a/test/plugs/idempotency_plug_test.exs
+++ /dev/null
@@ -1,110 +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.Plugs.IdempotencyPlugTest do
- use ExUnit.Case, async: true
- use Plug.Test
-
- alias Pleroma.Plugs.IdempotencyPlug
- alias Plug.Conn
-
- test "returns result from cache" do
- key = "test1"
- orig_request_id = "test1"
- second_request_id = "test2"
- body = "testing"
- status = 200
-
- :post
- |> conn("/cofe")
- |> put_req_header("idempotency-key", key)
- |> Conn.put_resp_header("x-request-id", orig_request_id)
- |> Conn.put_resp_content_type("application/json")
- |> IdempotencyPlug.call([])
- |> Conn.send_resp(status, body)
-
- conn =
- :post
- |> conn("/cofe")
- |> put_req_header("idempotency-key", key)
- |> Conn.put_resp_header("x-request-id", second_request_id)
- |> Conn.put_resp_content_type("application/json")
- |> IdempotencyPlug.call([])
-
- assert_raise Conn.AlreadySentError, fn ->
- Conn.send_resp(conn, :im_a_teapot, "no cofe")
- end
-
- assert conn.resp_body == body
- assert conn.status == status
-
- assert [^second_request_id] = Conn.get_resp_header(conn, "x-request-id")
- assert [^orig_request_id] = Conn.get_resp_header(conn, "x-original-request-id")
- assert [^key] = Conn.get_resp_header(conn, "idempotency-key")
- assert ["true"] = Conn.get_resp_header(conn, "idempotent-replayed")
- assert ["application/json; charset=utf-8"] = Conn.get_resp_header(conn, "content-type")
- end
-
- test "pass conn downstream if the cache not found" do
- key = "test2"
- orig_request_id = "test3"
- body = "testing"
- status = 200
-
- conn =
- :post
- |> conn("/cofe")
- |> put_req_header("idempotency-key", key)
- |> Conn.put_resp_header("x-request-id", orig_request_id)
- |> Conn.put_resp_content_type("application/json")
- |> IdempotencyPlug.call([])
- |> Conn.send_resp(status, body)
-
- assert conn.resp_body == body
- assert conn.status == status
-
- assert [] = Conn.get_resp_header(conn, "idempotent-replayed")
- assert [^key] = Conn.get_resp_header(conn, "idempotency-key")
- end
-
- test "passes conn downstream if idempotency is not present in headers" do
- orig_request_id = "test4"
- body = "testing"
- status = 200
-
- conn =
- :post
- |> conn("/cofe")
- |> Conn.put_resp_header("x-request-id", orig_request_id)
- |> Conn.put_resp_content_type("application/json")
- |> IdempotencyPlug.call([])
- |> Conn.send_resp(status, body)
-
- assert [] = Conn.get_resp_header(conn, "idempotency-key")
- end
-
- test "doesn't work with GET/DELETE" do
- key = "test3"
- body = "testing"
- status = 200
-
- conn =
- :get
- |> conn("/cofe")
- |> put_req_header("idempotency-key", key)
- |> IdempotencyPlug.call([])
- |> Conn.send_resp(status, body)
-
- assert [] = Conn.get_resp_header(conn, "idempotency-key")
-
- conn =
- :delete
- |> conn("/cofe")
- |> put_req_header("idempotency-key", key)
- |> IdempotencyPlug.call([])
- |> Conn.send_resp(status, body)
-
- assert [] = Conn.get_resp_header(conn, "idempotency-key")
- end
-end