Skip to content

Commit 66b5b4c

Browse files
committed
Add test cases for assets for staff
Create test cases to indicate that non-admin staff can only read assets, but not create, modify, or delete them.
1 parent 410d030 commit 66b5b4c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/cadet_web/router.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ defmodule CadetWeb.Router do
136136
scope "/v2/courses/:course_id/admin", CadetWeb do
137137
pipe_through([:api, :auth, :ensure_auth, :course, :ensure_admin])
138138

139-
get("/assets/:foldername", AdminAssetsController, :index)
140139
post("/assets/:foldername/*filename", AdminAssetsController, :upload)
141140
delete("/assets/:foldername/*filename", AdminAssetsController, :delete)
142141

@@ -189,6 +188,8 @@ defmodule CadetWeb.Router do
189188
:get_score_leaderboard
190189
)
191190

191+
get("/assets/:foldername", AdminAssetsController, :index)
192+
192193
get("/grading", AdminGradingController, :index)
193194
get("/grading/summary", AdminGradingController, :grading_summary)
194195

test/cadet_web/admin_controllers/admin_assets_controller_test.exs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,35 @@ defmodule CadetWeb.AdminAssetsControllerTest do
6868
end
6969
end
7070

71+
describe "read-only permission for staff" do
72+
@tag authenticate: :staff
73+
test "GET /assets/:foldername", %{conn: conn} do
74+
course_id = conn.assigns.course_id
75+
conn = get(conn, build_url(course_id, "testFolder"), %{})
76+
assert response(conn, 200) =~ "OK"
77+
end
78+
79+
@tag authenticate: :staff
80+
test "DELETE /assets/:foldername/*filename", %{conn: conn} do
81+
course_id = conn.assigns.course_id
82+
conn = delete(conn, build_url(course_id, "testFolder/testFile.png"))
83+
84+
assert response(conn, 403) =~ "Forbidden"
85+
end
86+
87+
@tag authenticate: :staff
88+
test "POST /assets/:foldername/*filename", %{conn: conn} do
89+
course_id = conn.assigns.course_id
90+
91+
conn =
92+
post(conn, build_url(course_id, "testFolder/testFile.png"), %{
93+
:upload => build_upload("test/fixtures/upload.png")
94+
})
95+
96+
assert response(conn, 403) =~ "Forbidden"
97+
end
98+
end
99+
71100
describe "inaccessible folder name" do
72101
@tag authenticate: :staff
73102
test "index files", %{conn: conn} do

0 commit comments

Comments
 (0)