Merge branch 'master' into 3118-docker-fixes
[arvados.git] / apps / workbench / test / integration / errors_test.rb
1 require 'integration_helper'
2
3 class ErrorsTest < ActionDispatch::IntegrationTest
4   BAD_UUID = "ffffffffffffffffffffffffffffffff+0"
5
6   test "error page renders user navigation" do
7     visit(page_with_token("active", "/collections/#{BAD_UUID}"))
8     assert(page.has_text?(api_fixture("users")["active"]["email"]),
9            "User information missing from error page")
10     assert(page.has_no_text?(/log ?in/i),
11            "Logged in user prompted to log in on error page")
12   end
13
14   test "no user navigation with expired token" do
15     visit(page_with_token("expired", "/collections/#{BAD_UUID}"))
16     assert(page.has_no_text?(api_fixture("users")["active"]["email"]),
17            "Page visited with expired token included user information")
18     assert(page.has_selector?("a", text: /log ?in/i),
19            "Login prompt missing on expired token error page")
20   end
21
22   test "error page renders without login" do
23     visit "/collections/download/#{BAD_UUID}/#{@@API_AUTHS['active']['api_token']}"
24     assert(page.has_no_text?(/\b500\b/),
25            "Error page without login returned 500")
26   end
27
28   test "'object not found' page includes search link" do
29     visit(page_with_token("active", "/collections/#{BAD_UUID}"))
30     assert(all("a").any? { |a| a[:href] =~ %r{/collections/?(\?|$)} },
31            "no search link found on 404 page")
32   end
33
34   def now_timestamp
35     Time.now.utc.to_i
36   end
37
38   def page_has_error_token?(start_stamp)
39     matching_stamps = (start_stamp .. now_timestamp).to_a.join("|")
40     # Check the page HTML because we really don't care how it's presented.
41     # I think it would even be reasonable to put it in a comment.
42     page.html =~ /\b(#{matching_stamps})\+[0-9A-Fa-f]{8}\b/
43   end
44
45   # We use API tokens with limited scopes as the quickest way to get the API
46   # server to return an error.  If Workbench gets smarter about coping when
47   # it has a too-limited token, these tests will need to be adjusted.
48   test "API error page includes error token" do
49     start_stamp = now_timestamp
50     visit(page_with_token("active_readonly", "/authorized_keys"))
51     click_on "Add a new authorized key"
52     assert(page.has_text?(/fiddlesticks/i),
53            "Not on an error page after making an SSH key out of scope")
54     assert(page_has_error_token?(start_stamp), "no error token on 404 page")
55   end
56
57   test "showing a bad UUID returns 404" do
58     visit(page_with_token("active", "/pipeline_templates/zzz"))
59     assert(page.has_no_text?(/fiddlesticks/i),
60            "trying to show a bad UUID rendered a fiddlesticks page, not 404")
61   end
62
63   test "404 page includes information about missing object" do
64     visit(page_with_token("active", "/groups/zazazaz"))
65     assert(page.has_text?(/group with UUID zazazaz/i),
66            "name of searched group missing from 404 page")
67   end
68
69   test "unrouted 404 page works" do
70     visit(page_with_token("active", "/__asdf/ghjk/zxcv"))
71     assert(page.has_text?(/not found/i),
72            "unrouted page missing 404 text")
73     assert(page.has_no_text?(/fiddlesticks/i),
74            "unrouted request returned a generic error page, not 404")
75   end
76 end