-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1012 from OpenFn/downloads-auth-hot-fix
Downloads auth hot fix
- Loading branch information
Showing
5 changed files
with
68 additions
and
12 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
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
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
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
40 changes: 40 additions & 0 deletions
40
test/lightning_web/controllers/download_controller_test.exs
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,40 @@ | ||
defmodule LightningWeb.DownloadControllerTest do | ||
use LightningWeb.ConnCase, async: true | ||
|
||
import Lightning.Factories | ||
|
||
describe "GET /downloads/yaml" do | ||
setup :register_and_log_in_user | ||
setup :create_project_for_current_user | ||
|
||
test "correctly renders a project yaml", %{conn: conn, project: project} do | ||
response = | ||
conn | ||
|> get(~p"/download/yaml?#{%{id: project.id}}") | ||
|
||
assert response.status == 200 | ||
end | ||
|
||
test "renders a 404? when the user isn't authorized", %{conn: conn} do | ||
p = insert(:project) | ||
|
||
response = | ||
conn | ||
|> get(~p"/download/yaml?#{%{id: p.id}}") | ||
|
||
assert response.status == 401 | ||
end | ||
end | ||
|
||
describe "when not logged in" do | ||
test "redirects when you are not logged in", %{conn: conn} do | ||
response = | ||
conn | ||
|> get("/download/yaml?id=#{Ecto.UUID.generate()}") | ||
|
||
assert response.status == 302 | ||
assert response.resp_headers | ||
assert {"location", "/users/log_in"} in response.resp_headers | ||
end | ||
end | ||
end |