-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |