2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-19 17:14:03 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'controllers/support/shared_user_context'
|
|
|
|
|
|
|
|
describe 'Maintenance Mode' do
|
2019-07-30 21:29:24 +00:00
|
|
|
page = 'http://commet'
|
|
|
|
token = 'thoathioa'
|
2018-07-19 17:14:03 +00:00
|
|
|
include_context :shared_user_context
|
|
|
|
around(:each) do |example|
|
|
|
|
example.run
|
|
|
|
Settings.reload!
|
|
|
|
end
|
|
|
|
|
|
|
|
describe OnboardController, type: :controller do
|
|
|
|
describe '(Onboard is just a basic example controller)'
|
|
|
|
it 'not in maintenance mode' do
|
|
|
|
get :index
|
|
|
|
assert_response 200
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'in maintenance' do
|
|
|
|
before(:each) do
|
2019-07-30 21:29:24 +00:00
|
|
|
Settings.merge!(maintenance:
|
|
|
|
{ maintenance_mode: true,
|
|
|
|
maintenance_token: token,
|
|
|
|
maintenance_page: page })
|
2018-07-19 17:14:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects for onboard' do
|
|
|
|
get :index
|
|
|
|
assert_redirected_to page
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows access to non-sign_in pages if youre logged in' do
|
|
|
|
sign_in user_as_np_associate
|
|
|
|
get :index
|
|
|
|
assert_response 200
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Users::SessionsController, type: :controller do
|
|
|
|
describe 'in maintenance' do
|
|
|
|
include_context :shared_user_context
|
|
|
|
around(:each) do |example|
|
|
|
|
example.run
|
|
|
|
Settings.reload!
|
|
|
|
end
|
|
|
|
|
|
|
|
before(:each) do
|
2019-07-30 21:29:24 +00:00
|
|
|
@request.env['devise.mapping'] = Devise.mappings[:user]
|
2018-07-19 17:14:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'in maintenance' do
|
|
|
|
before(:each) do
|
2019-07-30 21:29:24 +00:00
|
|
|
Settings.merge!(maintenance:
|
|
|
|
{ maintenance_mode: true,
|
|
|
|
maintenance_token: token,
|
|
|
|
maintenance_page: page })
|
2018-07-19 17:14:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects sign_in if the token is wrong' do
|
2019-07-13 09:18:45 +00:00
|
|
|
get(:new, params: { maintenance_token: "#{token}3" })
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(response.code).to eq '302'
|
2018-07-19 17:14:03 +00:00
|
|
|
expect(response.location).to eq page
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects for login' do
|
|
|
|
get(:new)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(response.code).to eq '302'
|
2018-07-19 17:14:03 +00:00
|
|
|
expect(response.location).to eq page
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects sign_in if the token is passed in wrong param' do
|
2019-07-30 21:29:24 +00:00
|
|
|
get(:new, params: { maintnancerwrwer_token: token.to_s })
|
|
|
|
expect(response.code).to eq '302'
|
2018-07-19 17:14:03 +00:00
|
|
|
expect(response.location).to eq page
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows sign_in if the token is passed' do
|
2019-07-30 21:29:24 +00:00
|
|
|
get(:new, params: { maintenance_token: token.to_s })
|
2018-07-19 17:14:03 +00:00
|
|
|
expect(response.code).to eq '200'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows sign_in.json' do
|
2019-07-30 21:29:24 +00:00
|
|
|
get(:new, params: { maintenance_token: token.to_s, format: 'json' })
|
2019-01-28 21:33:41 +00:00
|
|
|
expect(response.code).to eq '200'
|
2018-07-19 17:14:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-19 17:59:29 +00:00
|
|
|
describe 'in maintenance without maintenance_token set' do
|
|
|
|
before(:each) do
|
2019-07-30 21:29:24 +00:00
|
|
|
@request.env['devise.mapping'] = Devise.mappings[:user]
|
2018-07-19 17:59:29 +00:00
|
|
|
end
|
|
|
|
before(:each) do
|
2019-07-30 21:29:24 +00:00
|
|
|
Settings.merge!(maintenance:
|
|
|
|
{ maintenance_mode: true,
|
|
|
|
maintenance_token: nil,
|
|
|
|
maintenance_page: page })
|
2018-07-19 17:59:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects sign_in if the token is nil' do
|
|
|
|
get(:new)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(response.code).to eq '302'
|
2018-07-19 17:59:29 +00:00
|
|
|
expect(response.location).to eq page
|
|
|
|
end
|
|
|
|
end
|
2018-07-19 17:14:03 +00:00
|
|
|
end
|
|
|
|
end
|