Skip to content

Commit

Permalink
Test for curl detector plug
Browse files Browse the repository at this point in the history
  • Loading branch information
mbashia committed Nov 13, 2024
1 parent e6a1d44 commit be8088c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/phx_tools_web/plugs/curl_detector_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
defmodule PhxToolsWeb.CurlDetectorTest do
use PhxToolsWeb.ConnCase, async: true
# use Plug.Test

@script_content "#!/bin/sh"

describe "call/2" do
test "returns script content for requests with curl User-Agent on root path", %{conn: conn} do
conn =
conn
|> put_req_header("user-agent", "curl/7.68.0")
|> get("/")

assert conn.status == 200
assert String.contains?(conn.resp_body, @script_content)
end

test "returns script content for /macOS.sh regardless of User-Agent,", %{conn: conn} do
conn =
conn
|> put_req_header("user-agent", "curl/7.68.0")
|> get("/macOS.sh")

assert conn.status == 200
assert String.contains?(conn.resp_body, @script_content)
end

test "returns script content for /Linux.sh regardless of User-Agent,", %{conn: conn} do
conn =
conn
|> put_req_header("user-agent", "curl/7.68.0")
|> get("/Linux.sh")

assert conn.status == 200
assert String.contains?(conn.resp_body, @script_content)
end

test "does not return script content for requests with non-curl User-Agent", %{conn: conn} do
conn =
conn
|> put_req_header("user-agent", "Mozilla/5.0")
|> get("/macOS.sh")

assert conn.status == 200
refute conn.resp_body == @script_content
end
end
end

0 comments on commit be8088c

Please sign in to comment.