+ test "requesting to the API server includes X-Request-Id header" do
+ got_header = nil
+ stub_api_calls
+ stub_api_client.stubs(:post).with do |url, query, header={}|
+ got_header = header
+ true
+ end.returns fake_api_response('{}', 200, {})
+
+ Rails.configuration.anonymous_user_token =
+ api_fixture("api_client_authorizations", "anonymous", "api_token")
+ @controller = ProjectsController.new
+ test_uuid = "zzzzz-j7d0g-zzzzzzzzzzzzzzz"
+ get(:show, params: {id: test_uuid})
+
+ assert_not_nil got_header
+ assert_includes got_header, 'X-Request-Id'
+ assert_match /^req-[0-9a-zA-Z]{20}$/, got_header["X-Request-Id"]
+ end
+
+ test "current request_id is nil after a request" do
+ @controller = NodesController.new
+ get(:index, params: {}, session: session_for(:active))
+ assert_nil Thread.current[:request_id]
+ end
+
+ test "X-Request-Id header" do
+ @controller = NodesController.new
+ get(:index, params: {}, session: session_for(:active))
+ assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id']
+ end
+
+ [".navbar .login-menu a",
+ ".navbar .login-menu .dropdown-menu a"
+ ].each do |css_selector|
+ test "login link at #{css_selector.inspect} includes return_to param" do
+ # Without an anonymous token, we're immediately redirected to login.
+ Rails.configuration.anonymous_user_token =
+ api_fixture("api_client_authorizations", "anonymous", "api_token")
+ @controller = ProjectsController.new
+ test_uuid = "zzzzz-j7d0g-zzzzzzzzzzzzzzz"
+ get(:show, params: {id: test_uuid})
+ login_link = css_select(css_selector).first
+ assert_not_nil(login_link, "failed to select login link")
+ login_href = URI.unescape(login_link.attributes["href"].value)
+ # The parameter needs to include the full URL to work.
+ assert_includes(login_href, "://")
+ assert_match(/[\?&]return_to=[^&]*\/projects\/#{test_uuid}(&|$)/,
+ login_href)
+ end
+ end
+