REFACTOR: Initialize auth providers after plugin.activate!

Also added some helpful functionality for plugin developers:
- Raises RuntimeException if the auth provider has been registered too late
- Logs use of deprecated parameters
This commit is contained in:
David Taylor
2018-11-30 16:58:18 +00:00
parent 488fba3c5f
commit 4e010382cc
4 changed files with 39 additions and 23 deletions

View File

@ -133,16 +133,18 @@ describe Plugin::Instance do
# No enabled_site_setting
authenticator = Auth::Authenticator.new
plugin.auth_provider(authenticator: authenticator)
plugin.notify_after_initialize
plugin.notify_before_auth
expect(authenticator.enabled?).to eq(true)
# With enabled site setting
plugin = Plugin::Instance.new
authenticator = Auth::Authenticator.new
plugin.auth_provider(enabled_setting: 'ubuntu_login_enabled', authenticator: authenticator)
plugin.notify_after_initialize
plugin.notify_before_auth
expect(authenticator.enabled?).to eq(false)
# Defines own method
plugin = Plugin::Instance.new
SiteSetting.stubs(:ubuntu_login_enabled).returns(true)
authenticator = Class.new(Auth::Authenticator) do
def enabled?
@ -150,7 +152,7 @@ describe Plugin::Instance do
end
end.new
plugin.auth_provider(enabled_setting: 'ubuntu_login_enabled', authenticator: authenticator)
plugin.notify_after_initialize
plugin.notify_before_auth
expect(authenticator.enabled?).to eq(false)
end
@ -182,11 +184,11 @@ describe Plugin::Instance do
plugin = Plugin::Instance.new
plugin.path = "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
plugin.activate!
expect(plugin.auth_providers.count).to eq(1)
auth_provider = plugin.auth_providers[0]
expect(auth_provider.authenticator.name).to eq('ubuntu')
expect(DiscoursePluginRegistry.auth_providers.count).to eq(0)
plugin.notify_before_auth
expect(DiscoursePluginRegistry.auth_providers.count).to eq(1)
auth_provider = DiscoursePluginRegistry.auth_providers.to_a[0]
expect(auth_provider.authenticator.name).to eq('ubuntu')
end
it "finds all the custom assets" do