2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-03-19 23:18:00 -04:00
|
|
|
|
|
|
|
describe AdminDashboardData do
|
|
|
|
|
2015-08-25 20:07:40 -04:00
|
|
|
describe "adding new checks" do
|
2015-09-01 16:32:35 -04:00
|
|
|
after do
|
|
|
|
AdminDashboardData.reset_problem_checks
|
|
|
|
end
|
|
|
|
|
2015-08-25 20:07:40 -04:00
|
|
|
it 'calls the passed block' do
|
|
|
|
called = false
|
|
|
|
AdminDashboardData.add_problem_check do
|
|
|
|
called = true
|
|
|
|
end
|
|
|
|
|
|
|
|
AdminDashboardData.fetch_problems
|
|
|
|
expect(called).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls the passed method' do
|
|
|
|
$test_AdminDashboardData_global = false
|
|
|
|
class AdminDashboardData
|
|
|
|
def my_test_method
|
|
|
|
$test_AdminDashboardData_global = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
AdminDashboardData.add_problem_check :my_test_method
|
|
|
|
|
|
|
|
AdminDashboardData.fetch_problems
|
|
|
|
expect($test_AdminDashboardData_global).to eq(true)
|
|
|
|
$test_AdminDashboardData_global = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-19 23:18:00 -04:00
|
|
|
describe "rails_env_check" do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.rails_env_check }
|
2013-03-19 23:18:00 -04:00
|
|
|
|
|
|
|
it 'returns nil when running in production mode' do
|
2014-08-18 06:08:25 -04:00
|
|
|
Rails.stubs(env: ActiveSupport::StringInquirer.new('production'))
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-19 23:18:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when running in development mode' do
|
2014-08-18 06:08:25 -04:00
|
|
|
Rails.stubs(env: ActiveSupport::StringInquirer.new('development'))
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-19 23:18:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when running in test mode' do
|
2014-08-18 06:08:25 -04:00
|
|
|
Rails.stubs(env: ActiveSupport::StringInquirer.new('test'))
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-19 23:18:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-20 15:38:28 -04:00
|
|
|
describe 'host_names_check' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.host_names_check }
|
2013-03-20 15:38:28 -04:00
|
|
|
|
|
|
|
it 'returns nil when host_names is set' do
|
|
|
|
Discourse.stubs(:current_hostname).returns('something.com')
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-20 15:38:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when host_name is localhost' do
|
|
|
|
Discourse.stubs(:current_hostname).returns('localhost')
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-20 15:38:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when host_name is production.localhost' do
|
|
|
|
Discourse.stubs(:current_hostname).returns('production.localhost')
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-20 15:38:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-22 11:35:32 -04:00
|
|
|
describe 'sidekiq_check' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.sidekiq_check }
|
2013-03-22 11:35:32 -04:00
|
|
|
|
|
|
|
it 'returns nil when sidekiq processed a job recently' do
|
|
|
|
Jobs.stubs(:last_job_performed_at).returns(1.minute.ago)
|
|
|
|
Jobs.stubs(:queued).returns(0)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-22 11:35:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when last job processed was a long time ago, but no jobs are queued' do
|
|
|
|
Jobs.stubs(:last_job_performed_at).returns(7.days.ago)
|
|
|
|
Jobs.stubs(:queued).returns(0)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-22 11:35:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when no jobs have ever been processed, but no jobs are queued' do
|
|
|
|
Jobs.stubs(:last_job_performed_at).returns(nil)
|
|
|
|
Jobs.stubs(:queued).returns(0)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-22 11:35:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when no jobs were processed recently and some jobs are queued' do
|
|
|
|
Jobs.stubs(:last_job_performed_at).returns(20.minutes.ago)
|
|
|
|
Jobs.stubs(:queued).returns(1)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-22 11:35:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when no jobs have ever been processed, and some jobs are queued' do
|
|
|
|
Jobs.stubs(:last_job_performed_at).returns(nil)
|
|
|
|
Jobs.stubs(:queued).returns(1)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-22 11:35:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-22 15:47:25 -04:00
|
|
|
describe 'ram_check' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.ram_check }
|
2013-03-22 15:47:25 -04:00
|
|
|
|
|
|
|
it 'returns nil when total ram is 1 GB' do
|
|
|
|
MemInfo.any_instance.stubs(:mem_total).returns(1025272)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-22 15:47:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when total ram cannot be determined' do
|
|
|
|
MemInfo.any_instance.stubs(:mem_total).returns(nil)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-22 15:47:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when total ram is less than 1 GB' do
|
|
|
|
MemInfo.any_instance.stubs(:mem_total).returns(512636)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-22 15:47:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-29 13:31:00 -04:00
|
|
|
describe 'auth_config_checks' do
|
|
|
|
|
2013-05-29 13:54:49 -04:00
|
|
|
shared_examples 'problem detection for login providers' do
|
2013-03-29 13:31:00 -04:00
|
|
|
context 'when disabled' do
|
|
|
|
it 'returns nil' do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{enable_setting}=", false)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when enabled' do
|
|
|
|
before do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{enable_setting}=", true)
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
2017-02-15 03:04:10 -05:00
|
|
|
it 'returns nil when key and secret are set' do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{key}=", '12313213')
|
|
|
|
SiteSetting.public_send("#{secret}=", '12312313123')
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to be_nil
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when key is not set' do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{key}=", '')
|
|
|
|
SiteSetting.public_send("#{secret}=", '12312313123')
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when secret is not set' do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{key}=", '123123')
|
|
|
|
SiteSetting.public_send("#{secret}=", '')
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when key and secret are not set' do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{key}=", '')
|
|
|
|
SiteSetting.public_send("#{secret}=", '')
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(subject).to_not be_nil
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'facebook' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.facebook_config_check }
|
2013-03-29 13:31:00 -04:00
|
|
|
let(:enable_setting) { :enable_facebook_logins }
|
|
|
|
let(:key) { :facebook_app_id }
|
|
|
|
let(:secret) { :facebook_app_secret }
|
2013-05-29 13:54:49 -04:00
|
|
|
include_examples 'problem detection for login providers'
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'twitter' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.twitter_config_check }
|
2013-03-29 13:31:00 -04:00
|
|
|
let(:enable_setting) { :enable_twitter_logins }
|
|
|
|
let(:key) { :twitter_consumer_key }
|
|
|
|
let(:secret) { :twitter_consumer_secret }
|
2013-05-29 13:54:49 -04:00
|
|
|
include_examples 'problem detection for login providers'
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'github' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.github_config_check }
|
2013-03-29 13:31:00 -04:00
|
|
|
let(:enable_setting) { :enable_github_logins }
|
|
|
|
let(:key) { :github_client_id }
|
|
|
|
let(:secret) { :github_client_secret }
|
2013-05-29 13:54:49 -04:00
|
|
|
include_examples 'problem detection for login providers'
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-15 03:05:58 -05:00
|
|
|
describe 's3_config_check' do
|
|
|
|
shared_examples 'problem detection for s3-dependent setting' do
|
|
|
|
subject { described_class.new.s3_config_check }
|
|
|
|
let(:access_keys) { [:s3_access_key_id, :s3_secret_access_key] }
|
|
|
|
let(:all_cred_keys) { access_keys + [:s3_use_iam_profile] }
|
|
|
|
let(:all_setting_keys) { all_cred_keys + [bucket_key] }
|
|
|
|
|
|
|
|
def all_setting_permutations(keys)
|
|
|
|
['a', ''].repeated_permutation(keys.size) do |*values|
|
|
|
|
hash = Hash[keys.zip(values)]
|
|
|
|
hash.each do |key,value|
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{key}=", value)
|
2017-02-15 03:05:58 -05:00
|
|
|
end
|
|
|
|
yield hash
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when setting is enabled' do
|
|
|
|
let(:setting_enabled) { true }
|
|
|
|
before do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{setting_key}=", setting_enabled)
|
|
|
|
SiteSetting.public_send("#{bucket_key}=", bucket_value)
|
2017-02-15 03:05:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when bucket is blank' do
|
|
|
|
let(:bucket_value) { '' }
|
|
|
|
|
|
|
|
it "always returns a string" do
|
|
|
|
all_setting_permutations(all_cred_keys) do
|
|
|
|
expect(subject).to_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when bucket is filled in' do
|
|
|
|
let(:bucket_value) { 'a' }
|
|
|
|
before do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("s3_use_iam_profile=", use_iam_profile)
|
2017-02-15 03:05:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using iam profile' do
|
|
|
|
let(:use_iam_profile) { true }
|
|
|
|
|
|
|
|
it 'always returns nil' do
|
|
|
|
all_setting_permutations(access_keys) do
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not using iam profile' do
|
|
|
|
let(:use_iam_profile) { false }
|
|
|
|
|
|
|
|
it 'returns nil only if both access key fields are filled in' do
|
|
|
|
all_setting_permutations(access_keys) do |settings|
|
|
|
|
if settings.values.all?
|
|
|
|
expect(subject).to be_nil
|
|
|
|
else
|
|
|
|
expect(subject).to_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when setting is not enabled' do
|
|
|
|
before do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.public_send("#{setting_key}=", false)
|
2017-02-15 03:05:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "always returns nil" do
|
|
|
|
all_setting_permutations(all_setting_keys) do
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'uploads' do
|
|
|
|
let(:setting_key) { :enable_s3_uploads }
|
|
|
|
let(:bucket_key) { :s3_upload_bucket }
|
|
|
|
include_examples 'problem detection for s3-dependent setting'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'backups' do
|
|
|
|
let(:setting_key) { :enable_s3_backups }
|
|
|
|
let(:bucket_key) { :s3_backup_bucket }
|
|
|
|
include_examples 'problem detection for s3-dependent setting'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-07 00:52:19 -04:00
|
|
|
describe 'stats cache' do
|
|
|
|
include_examples 'stats cachable'
|
|
|
|
end
|
|
|
|
|
2016-04-05 14:42:24 -04:00
|
|
|
describe '#problem_message_check' do
|
|
|
|
let(:key) { AdminDashboardData.problem_messages.first }
|
|
|
|
|
|
|
|
before do
|
|
|
|
described_class.clear_problem_message(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil if message has not been added' do
|
|
|
|
expect(described_class.problem_message_check(key)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a message if it was added' do
|
|
|
|
described_class.add_problem_message(key)
|
|
|
|
expect(described_class.problem_message_check(key)).to eq(I18n.t(key))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a message if it was added with an expiry' do
|
|
|
|
described_class.add_problem_message(key, 300)
|
|
|
|
expect(described_class.problem_message_check(key)).to eq(I18n.t(key))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-29 22:43:21 -04:00
|
|
|
end
|