|
@@ -1,53 +1,38 @@
|
|
require 'rails_helper'
|
|
require 'rails_helper'
|
|
|
|
|
|
RSpec.describe 'Sessions endpoints', type: :request do
|
|
RSpec.describe 'Sessions endpoints', type: :request do
|
|
- # The frontend sends a device fingerprint in the request parameters during authentication
|
|
|
|
- # (as part of App.Auth.loginCheck() and App.WebSocket.auth()).
|
|
|
|
- #
|
|
|
|
- # Without this parameter, the controller will raise a 422 Unprocessable Entity error
|
|
|
|
- # (in ApplicationController::HandlesDevices#user_device_log).
|
|
|
|
- let(:fingerprint) { { fingerprint: 'foo' } }
|
|
|
|
-
|
|
|
|
- describe 'GET /api/v1/signshow (single sign-on)' do
|
|
|
|
|
|
+
|
|
|
|
+ describe 'GET /auth/sso (single sign-on)' do
|
|
context 'with invalid user login' do
|
|
context 'with invalid user login' do
|
|
let(:login) { User.pluck(:login).max.next }
|
|
let(:login) { User.pluck(:login).max.next }
|
|
|
|
|
|
context 'in "REMOTE_USER" request env var' do
|
|
context 'in "REMOTE_USER" request env var' do
|
|
let(:env) { { 'REMOTE_USER' => login } }
|
|
let(:env) { { 'REMOTE_USER' => login } }
|
|
|
|
|
|
- it 'returns invalid session response' do
|
|
|
|
- get '/api/v1/signshow', as: :json, env: env, params: fingerprint
|
|
|
|
|
|
+ it 'returns unauthorized response' do
|
|
|
|
+ get '/auth/sso', as: :json, env: env
|
|
|
|
|
|
- expect(response).to have_http_status(:ok)
|
|
|
|
- expect(json_response)
|
|
|
|
- .to include('error' => 'no valid session')
|
|
|
|
- .and not_include('session')
|
|
|
|
|
|
+ expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
context 'in "HTTP_REMOTE_USER" request env var' do
|
|
context 'in "HTTP_REMOTE_USER" request env var' do
|
|
let(:env) { { 'HTTP_REMOTE_USER' => login } }
|
|
let(:env) { { 'HTTP_REMOTE_USER' => login } }
|
|
|
|
|
|
- it 'returns invalid session response' do
|
|
|
|
- get '/api/v1/signshow', as: :json, env: env, params: fingerprint
|
|
|
|
|
|
+ it 'returns unauthorized response' do
|
|
|
|
+ get '/auth/sso', as: :json, env: env
|
|
|
|
|
|
- expect(response).to have_http_status(:ok)
|
|
|
|
- expect(json_response)
|
|
|
|
- .to include('error' => 'no valid session')
|
|
|
|
- .and not_include('session')
|
|
|
|
|
|
+ expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
context 'in "X-Forwarded-User" request header' do
|
|
context 'in "X-Forwarded-User" request header' do
|
|
let(:headers) { { 'X-Forwarded-User' => login } }
|
|
let(:headers) { { 'X-Forwarded-User' => login } }
|
|
|
|
|
|
- it 'returns invalid session response' do
|
|
|
|
- get '/api/v1/signshow', as: :json, headers: headers, params: fingerprint
|
|
|
|
|
|
+ it 'returns unauthorized response' do
|
|
|
|
+ get '/auth/sso', as: :json, headers: headers
|
|
|
|
|
|
- expect(response).to have_http_status(:ok)
|
|
|
|
- expect(json_response)
|
|
|
|
- .to include('error' => 'no valid session')
|
|
|
|
- .and not_include('session')
|
|
|
|
|
|
+ expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
@@ -63,7 +48,7 @@ RSpec.describe 'Sessions endpoints', type: :request do
|
|
let(:env) { { 'REMOTE_USER' => login } }
|
|
let(:env) { { 'REMOTE_USER' => login } }
|
|
|
|
|
|
it 'returns 401 unauthorized' do
|
|
it 'returns 401 unauthorized' do
|
|
- get '/api/v1/signshow', as: :json, env: env, params: fingerprint
|
|
|
|
|
|
+ get '/auth/sso', as: :json, env: env
|
|
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
expect(response).to have_http_status(:unauthorized)
|
|
expect(json_response).to include('error' => 'Maintenance mode enabled!')
|
|
expect(json_response).to include('error' => 'Maintenance mode enabled!')
|
|
@@ -74,7 +59,7 @@ RSpec.describe 'Sessions endpoints', type: :request do
|
|
let(:env) { { 'HTTP_REMOTE_USER' => login } }
|
|
let(:env) { { 'HTTP_REMOTE_USER' => login } }
|
|
|
|
|
|
it 'returns 401 unauthorized' do
|
|
it 'returns 401 unauthorized' do
|
|
- get '/api/v1/signshow', as: :json, env: env, params: fingerprint
|
|
|
|
|
|
+ get '/auth/sso', as: :json, env: env
|
|
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
expect(response).to have_http_status(:unauthorized)
|
|
expect(json_response).to include('error' => 'Maintenance mode enabled!')
|
|
expect(json_response).to include('error' => 'Maintenance mode enabled!')
|
|
@@ -85,7 +70,7 @@ RSpec.describe 'Sessions endpoints', type: :request do
|
|
let(:headers) { { 'X-Forwarded-User' => login } }
|
|
let(:headers) { { 'X-Forwarded-User' => login } }
|
|
|
|
|
|
it 'returns 401 unauthorized' do
|
|
it 'returns 401 unauthorized' do
|
|
- get '/api/v1/signshow', as: :json, headers: headers, params: fingerprint
|
|
|
|
|
|
+ get '/auth/sso', as: :json, headers: headers
|
|
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
expect(response).to have_http_status(:unauthorized)
|
|
expect(json_response).to include('error' => 'Maintenance mode enabled!')
|
|
expect(json_response).to include('error' => 'Maintenance mode enabled!')
|
|
@@ -97,81 +82,45 @@ RSpec.describe 'Sessions endpoints', type: :request do
|
|
let(:env) { { 'REMOTE_USER' => login } }
|
|
let(:env) { { 'REMOTE_USER' => login } }
|
|
|
|
|
|
it 'returns a new user-session response' do
|
|
it 'returns a new user-session response' do
|
|
- get '/api/v1/signshow', as: :json, env: env, params: fingerprint
|
|
|
|
|
|
+ get '/auth/sso', as: :json, env: env
|
|
|
|
|
|
- expect(json_response)
|
|
|
|
- .to include('session' => hash_including('login' => login))
|
|
|
|
- .and not_include('error')
|
|
|
|
|
|
+ expect(response).to redirect_to('/#')
|
|
end
|
|
end
|
|
|
|
|
|
it 'sets the :user_id session parameter' do
|
|
it 'sets the :user_id session parameter' do
|
|
- expect { get '/api/v1/signshow', as: :json, env: env, params: fingerprint }
|
|
|
|
|
|
+ expect { get '/auth/sso', as: :json, env: env }
|
|
.to change { request&.session&.fetch(:user_id) }.to(user.id)
|
|
.to change { request&.session&.fetch(:user_id) }.to(user.id)
|
|
end
|
|
end
|
|
-
|
|
|
|
- it 'sets the :persistent session parameter' do
|
|
|
|
- expect { get '/api/v1/signshow', as: :json, env: env, params: fingerprint }
|
|
|
|
- .to change { request&.session&.fetch(:persistent) }.to(true)
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
- it 'adds an activity stream entry for the user’s session' do
|
|
|
|
- expect { get '/api/v1/signshow', as: :json, env: env, params: fingerprint }
|
|
|
|
- .to change(ActivityStream, :count).by(1)
|
|
|
|
- end
|
|
|
|
end
|
|
end
|
|
|
|
|
|
context 'in "HTTP_REMOTE_USER" request env var' do
|
|
context 'in "HTTP_REMOTE_USER" request env var' do
|
|
let(:env) { { 'HTTP_REMOTE_USER' => login } }
|
|
let(:env) { { 'HTTP_REMOTE_USER' => login } }
|
|
|
|
|
|
it 'returns a new user-session response' do
|
|
it 'returns a new user-session response' do
|
|
- get '/api/v1/signshow', as: :json, env: env, params: fingerprint
|
|
|
|
|
|
+ get '/auth/sso', as: :json, env: env
|
|
|
|
|
|
- expect(json_response)
|
|
|
|
- .to include('session' => hash_including('login' => login))
|
|
|
|
- .and not_include('error')
|
|
|
|
|
|
+ expect(response).to redirect_to('/#')
|
|
end
|
|
end
|
|
|
|
|
|
it 'sets the :user_id session parameter' do
|
|
it 'sets the :user_id session parameter' do
|
|
- expect { get '/api/v1/signshow', as: :json, env: env, params: fingerprint }
|
|
|
|
|
|
+ expect { get '/auth/sso', as: :json, env: env }
|
|
.to change { request&.session&.fetch(:user_id) }.to(user.id)
|
|
.to change { request&.session&.fetch(:user_id) }.to(user.id)
|
|
end
|
|
end
|
|
-
|
|
|
|
- it 'sets the :persistent session parameter' do
|
|
|
|
- expect { get '/api/v1/signshow', as: :json, env: env, params: fingerprint }
|
|
|
|
- .to change { request&.session&.fetch(:persistent) }.to(true)
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
- it 'adds an activity stream entry for the user’s session' do
|
|
|
|
- expect { get '/api/v1/signshow', as: :json, env: env, params: fingerprint }
|
|
|
|
- .to change(ActivityStream, :count).by(1)
|
|
|
|
- end
|
|
|
|
end
|
|
end
|
|
|
|
|
|
context 'in "X-Forwarded-User" request header' do
|
|
context 'in "X-Forwarded-User" request header' do
|
|
let(:headers) { { 'X-Forwarded-User' => login } }
|
|
let(:headers) { { 'X-Forwarded-User' => login } }
|
|
|
|
|
|
it 'returns a new user-session response' do
|
|
it 'returns a new user-session response' do
|
|
- get '/api/v1/signshow', as: :json, headers: headers, params: fingerprint
|
|
|
|
|
|
+ get '/auth/sso', as: :json, headers: headers
|
|
|
|
|
|
- expect(json_response)
|
|
|
|
- .to include('session' => hash_including('login' => login))
|
|
|
|
- .and not_include('error')
|
|
|
|
|
|
+ expect(response).to redirect_to('/#')
|
|
end
|
|
end
|
|
|
|
|
|
it 'sets the :user_id session parameter on the client' do
|
|
it 'sets the :user_id session parameter on the client' do
|
|
- expect { get '/api/v1/signshow', as: :json, headers: headers, params: fingerprint }
|
|
|
|
|
|
+ expect { get '/auth/sso', as: :json, headers: headers }
|
|
.to change { request&.session&.fetch(:user_id) }.to(user.id)
|
|
.to change { request&.session&.fetch(:user_id) }.to(user.id)
|
|
end
|
|
end
|
|
-
|
|
|
|
- it 'sets the :persistent session parameter' do
|
|
|
|
- expect { get '/api/v1/signshow', as: :json, headers: headers, params: fingerprint }
|
|
|
|
- .to change { request&.session&.fetch(:persistent) }.to(true)
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
- it 'adds an activity stream entry for the user’s session' do
|
|
|
|
- expect { get '/api/v1/signshow', as: :json, headers: headers, params: fingerprint }
|
|
|
|
- .to change(ActivityStream, :count).by(1)
|
|
|
|
- end
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|