13647: Update keepstore install docs, eliminate keep_services step.
[arvados.git] / services / api / test / functional / user_sessions_controller_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 UserSessionsControllerTest < ActionController::TestCase
8
9   test "new user from new api client" do
10     authorize_with :inactive
11     api_client_page = 'http://client.example.com/home'
12     get :login, params: {return_to: api_client_page}
13     assert_response :redirect
14     assert_equal(0, @response.redirect_url.index(api_client_page + '?'),
15                  'Redirect url ' + @response.redirect_url +
16                  ' should start with ' + api_client_page + '?')
17     assert_not_nil assigns(:api_client)
18   end
19
20   test "login with remote param returns a salted token" do
21     authorize_with :inactive
22     api_client_page = 'http://client.example.com/home'
23     remote_prefix = 'zbbbb'
24     get :login, params: {return_to: api_client_page, remote: remote_prefix}
25     assert_response :redirect
26     api_client_auth = assigns(:api_client_auth)
27     assert_not_nil api_client_auth
28     assert_includes(@response.redirect_url, 'api_token='+api_client_auth.salted_token(remote: remote_prefix))
29   end
30
31   test "login with malformed remote param returns an error" do
32     authorize_with :inactive
33     api_client_page = 'http://client.example.com/home'
34     remote_prefix = 'invalid_cluster_id'
35     get :login, params: {return_to: api_client_page, remote: remote_prefix}
36     assert_response 400
37   end
38 end