discourse/spec/jobs/invalidate_inactive_admins_spec.rb
David Taylor f524f8f811
Remove Yahoo login support from core and deprecate OpenID2.0 (#7310)
- Plugin developers using OpenID2.0 should migrate to OAuth2 or OIDC. OpenID2.0 APIs will be removed in v2.4.0

- For sites requiring Yahoo login, it can be implemented using the OpenID Connect plugin: https://meta.discourse.org/t/103632

For more information, see https://meta.discourse.org/t/113249
2019-04-08 10:38:25 +01:00

66 lines
2.4 KiB
Ruby

require 'rails_helper'
require_dependency 'jobs/scheduled/invalidate_inactive_admins'
describe Jobs::InvalidateInactiveAdmins do
let!(:active_admin) { Fabricate(:admin, last_seen_at: 1.hour.ago) }
before { active_admin.email_tokens.update_all(confirmed: true) }
subject { Jobs::InvalidateInactiveAdmins.new.execute({}) }
it "does nothing when all admins have been seen recently" do
SiteSetting.invalidate_inactive_admin_email_after_days = 365
subject
expect(active_admin.reload.active).to eq(true)
expect(active_admin.email_tokens.where(confirmed: true).exists?).to eq(true)
end
context "with an admin who hasn't been seen recently" do
let!(:not_seen_admin) { Fabricate(:admin, last_seen_at: 370.days.ago) }
before { not_seen_admin.email_tokens.update_all(confirmed: true) }
context 'invalidate_inactive_admin_email_after_days = 365' do
before do
SiteSetting.invalidate_inactive_admin_email_after_days = 365
end
it 'marks email tokens as unconfirmed' do
subject
expect(not_seen_admin.reload.email_tokens.where(confirmed: true).exists?).to eq(false)
end
it 'makes the user as not active' do
subject
expect(not_seen_admin.reload.active).to eq(false)
end
context 'with social logins' do
before do
GithubUserInfo.create!(user_id: not_seen_admin.id, screen_name: 'bob', github_user_id: 100)
UserAssociatedAccount.create!(provider_name: "google_oauth2", user_id: not_seen_admin.id, provider_uid: 100, info: { email: "bob@google.account.com" })
end
it 'removes the social logins' do
subject
expect(GithubUserInfo.where(user_id: not_seen_admin.id).exists?).to eq(false)
expect(UserAssociatedAccount.where(user_id: not_seen_admin.id).exists?).to eq(false)
end
end
end
context 'invalidate_inactive_admin_email_after_days = 0 to disable this feature' do
before do
SiteSetting.invalidate_inactive_admin_email_after_days = 0
end
it 'does nothing' do
subject
expect(active_admin.reload.active).to eq(true)
expect(active_admin.email_tokens.where(confirmed: true).exists?).to eq(true)
expect(not_seen_admin.reload.active).to eq(true)
expect(not_seen_admin.email_tokens.where(confirmed: true).exists?).to eq(true)
end
end
end
end