Skip to content

Commit deea2ef

Browse files
committed
test(scorm): add coverage for usernames with dots
- stop encoding '.' to '%2e' in scorm_path helper, so tests exercise the real route - add test_username_with_dot_fails_without_fix to ensure lookups succeed for usernames containing '.' (fails without the route fix, passes with it)
1 parent e88ec77 commit deea2ef

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/api/scorm_api_test.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ def app
1010
end
1111

1212
def scorm_path(task_def, user, file, token_type = :scorm)
13-
"/api/scorm/#{task_def.id}/#{user.username.gsub('.', '%2e')}/#{auth_token(user, token_type)}/#{file}"
13+
# NOTE: Do not encode '.' to '%2e' here. That hid the bug because the request worked regardless
14+
# of the route constraint. Keeping the raw username ensures tests fail without the fix and pass
15+
# with it.
16+
"/api/scorm/#{task_def.id}/#{user.username}/#{auth_token(user, token_type)}/#{file}"
1417
end
1518

1619
def test_serve_scorm_content
@@ -86,4 +89,22 @@ def test_serve_scorm_content
8689
td.destroy!
8790
unit.destroy!
8891
end
92+
93+
def test_username_with_dot_fails_without_fix
94+
unit = FactoryBot.create(:unit)
95+
user = unit.projects.first.student
96+
user.update!(username: "user.name")
97+
98+
td = FactoryBot.create(:task_definition,
99+
unit: unit,
100+
tutorial_stream: unit.tutorial_streams.first,
101+
scorm_enabled: true
102+
)
103+
td.add_scorm_data(test_file_path("numbas.zip"), copy: true)
104+
td.save!
105+
106+
# This should fail without the route fix (Rails interprets '.' as format separator)
107+
get scorm_path(td, user, "index.html")
108+
assert_equal 200, last_response.status
109+
end
89110
end

0 commit comments

Comments
 (0)