Skip to content

Commit

Permalink
Intercept requests with and without a trailing slash (#28)
Browse files Browse the repository at this point in the history
* Intercept requests with and without a trailing slash

* add test for requests with a trailing slash
  • Loading branch information
jasonrig authored and doomspork committed Jul 19, 2016
1 parent 2c0733e commit ca31f6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ueberauth.ex
Expand Up @@ -202,7 +202,7 @@ defmodule Ueberauth do

@doc false
def call(%{request_path: request_path} = conn, opts) do
if strategy = Map.get(opts, request_path) do
if strategy = Map.get(opts, String.replace_trailing(request_path, "/", "")) do
run!(conn, strategy)
else
conn
Expand Down Expand Up @@ -237,7 +237,7 @@ defmodule Ueberauth do

defp request_path(base_path, {name, {_, opts}}) do
default_path = Path.join(["/", base_path, to_string(name)])
Keyword.get(opts, :request_path, default_path)
String.replace_trailing(Keyword.get(opts, :request_path, default_path), "/", "")
end

defp callback_path(base_path, {name, {_, opts}}) do
Expand Down
7 changes: 6 additions & 1 deletion test/ueberauth_test.exs
Expand Up @@ -32,11 +32,16 @@ defmodule UeberauthTest do
assert extra.raw_info.callback_url == "http://www.example.com/auth/simple/callback"
end

test "redirecting a request phase" do
test "redirecting a request phase without trailing slash" do
conn = conn(:get, "/auth/redirector") |> SpecRouter.call(@opts)
assert get_resp_header(conn, "location") == ["https://redirectme.example.com/foo"]
end

test "redirecting a request phase with trailing slash" do
conn = conn(:get, "/auth/redirector/") |> SpecRouter.call(@opts)
assert get_resp_header(conn, "location") == ["https://redirectme.example.com/foo"]
end

test "setting request phase path" do
conn = conn(:get, "/login") |> SpecRouter.call(@opts)
assert get_resp_header(conn, "location") == ["https://redirectme.example.com/foo"]
Expand Down

0 comments on commit ca31f6f

Please sign in to comment.