Merge remote-tracking branch 'origin/master' into 15106-trgm-text-search
[arvados.git] / services / api / test / integration / login_workflow_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class LoginWorkflowTest < ActionDispatch::IntegrationTest
8   test "default prompt to login is JSON" do
9     post('/arvados/v1/specimens',
10       params: {specimen: {}},
11       headers: {'HTTP_ACCEPT' => ''})
12     assert_response 401
13     assert_includes(json_response['errors'], "Not logged in")
14   end
15
16   test "login prompt respects JSON Accept header" do
17     post('/arvados/v1/specimens',
18       params: {specimen: {}},
19       headers: {'HTTP_ACCEPT' => 'application/json'})
20     assert_response 401
21     assert_includes(json_response['errors'], "Not logged in")
22   end
23
24   test "login prompt respects HTML Accept header" do
25     post('/arvados/v1/specimens',
26       params: {specimen: {}},
27       headers: {'HTTP_ACCEPT' => 'text/html'})
28     assert_response 302
29     assert_match(%r{/auth/joshid$}, @response.headers['Location'],
30                  "HTML login prompt did not include expected redirect")
31   end
32 end