Merge branch '8784-dir-listings'
[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', {specimen: {}},
10          {'HTTP_ACCEPT' => ''})
11     assert_response 401
12     assert_includes(json_response['errors'], "Not logged in")
13   end
14
15   test "login prompt respects JSON Accept header" do
16     post('/arvados/v1/specimens', {specimen: {}},
17          {'HTTP_ACCEPT' => 'application/json'})
18     assert_response 401
19     assert_includes(json_response['errors'], "Not logged in")
20   end
21
22   test "login prompt respects HTML Accept header" do
23     post('/arvados/v1/specimens', {specimen: {}},
24          {'HTTP_ACCEPT' => 'text/html'})
25     assert_response 302
26     assert_match(%r{/auth/joshid$}, @response.headers['Location'],
27                  "HTML login prompt did not include expected redirect")
28   end
29 end