mirror of
https://github.com/edgurgel/httparrot
synced 2025-04-05 00:02:41 -04:00
Besides other documentation changes, this commit ensures the generated HTML doc for HexDocs.pm will become the source of truth for this Elixir library and leverage on latest features of ExDoc.
49 lines
1.2 KiB
Elixir
49 lines
1.2 KiB
Elixir
defmodule HTTParrot.HiddenBasicAuthHandlerTest do
|
|
use ExUnit.Case
|
|
import :meck
|
|
import HTTParrot.HiddenBasicAuthHandler
|
|
|
|
setup do
|
|
new(:cowboy_req)
|
|
new(JSX)
|
|
on_exit(fn -> unload() end)
|
|
:ok
|
|
end
|
|
|
|
test "resource_exists returns true if user and passwd match" do
|
|
expect(:cowboy_req, :binding, [
|
|
{[:user, :req1], :user},
|
|
{[:passwd, :req1], :passwd}
|
|
])
|
|
|
|
expect(:cowboy_req, :parse_header, [
|
|
{["authorization", :req1], {:basic, :user, :passwd}}
|
|
])
|
|
|
|
assert resource_exists(:req1, :state) == {true, :req1, :user}
|
|
|
|
assert validate(:cowboy_req)
|
|
assert validate(JSX)
|
|
end
|
|
|
|
test "resource_exists returns false if user and passwd doesn't match" do
|
|
expect(:cowboy_req, :binding, [{[:user, :req1], :user}, {[:passwd, :req1], :passwd}])
|
|
|
|
expect(:cowboy_req, :parse_header, [
|
|
{["authorization", :req1], {:basic, :not_the_user, :passwd}}
|
|
])
|
|
|
|
assert resource_exists(:req1, :state) == {false, :req1, :state}
|
|
|
|
assert validate(:cowboy_req)
|
|
assert validate(JSX)
|
|
end
|
|
|
|
test "returns user and if it's authenticated" do
|
|
expect(JSX, :encode!, [{[[authenticated: true, user: :user]], :json}])
|
|
|
|
assert get_json(:req1, :user) == {:json, :req1, nil}
|
|
|
|
assert validate(JSX)
|
|
end
|
|
end
|