- test "login creates token with configured lifetime" do
- token_lifetime = 1.hour
- Rails.configuration.Login.TokenLifetime = token_lifetime
- authorize_with :inactive
- api_client_page = 'http://client.example.com/home'
- get :login, params: {return_to: api_client_page}
- assert_not_nil assigns(:api_client)
- api_client_auth = assigns(:api_client_auth)
- assert_in_delta(api_client_auth.expires_at,
- api_client_auth.updated_at + token_lifetime,
- 1.second)
- end
-
- test "login with remote param returns a salted token" do
- authorize_with :inactive
- api_client_page = 'http://client.example.com/home'
- remote_prefix = 'zbbbb'
- get :login, params: {return_to: api_client_page, remote: remote_prefix}
- assert_response :redirect
- api_client_auth = assigns(:api_client_auth)
- assert_not_nil api_client_auth
- assert_includes(@response.redirect_url, 'api_token='+api_client_auth.salted_token(remote: remote_prefix))
- end
-
- test "login with malformed remote param returns an error" do
- authorize_with :inactive
- api_client_page = 'http://client.example.com/home'
- remote_prefix = 'invalid_cluster_id'
- get :login, params: {return_to: api_client_page, remote: remote_prefix}
- assert_response 400
- end
-
- test "login to LoginCluster" do
- Rails.configuration.Login.LoginCluster = 'zbbbb'
- Rails.configuration.RemoteClusters['zbbbb'] = {'Host' => 'zbbbb.example.com'}
- api_client_page = 'http://client.example.com/home'
- get :login, params: {return_to: api_client_page}
- assert_response :redirect
- assert_equal("https://zbbbb.example.com/login?return_to=http%3A%2F%2Fclient.example.com%2Fhome", @response.redirect_url)
- assert_nil assigns(:api_client)
- end
-
- test "don't go into redirect loop if LoginCluster is self" do
- Rails.configuration.Login.LoginCluster = 'zzzzz'
- api_client_page = 'http://client.example.com/home'
- get :login, params: {return_to: api_client_page}
- assert_response :redirect
- assert_equal("http://test.host/auth/joshid?return_to=%2Chttp%3A%2F%2Fclient.example.com%2Fhome", @response.redirect_url)
- assert_nil assigns(:api_client)