docbrown/spec/services/authentication/providers_spec.rb
Fernando Valverde fcc5c0d2a1
Add Sign in with Apple (#11934)
* Add gem omniauth-apple

* Integrate omniauth-apple

* Integrate callback

* Add fields

* Add tests, fix bugs and make it all work

* Show only enabled providers for the current user

* Add default profile image for Apple

* Remove localhost patch

* Bring over the changed Apple username if the user changes it

* More specs fixed

* Incorporate feedback from PR

* Fix specs

* Simplify code and fix spec

* Fix Broadcast generators to take into account the new provider

* Fix spec

* Generate a truly unique apple_username

* Fix user specs

* Add omniauth-apple-0.0.2 to vendor cache

* Fix merge conflict and spec

* Update VCR fastly sloan cassette

* Revert "Generate a truly unique apple_username"

This reverts commit 2462875575b0bbd6b3c1d56b25afcd3189671608.

* Fix user specs

* Fix specs

* Fix specs

* Hide Connect Apple button behind a feature flag

* Revert "Hide Connect Apple button behind a feature flag"

This reverts commit 105bde0373389a4eb9b6e948f60734c7e0e99cba.

* Fix line lengths

* Fix spec

* ES tag

* CSRF bypass for Apple callback

* custom user_nickname in Apple provider with small tweaks + omniauth-apple bump

* Fixes username specs

* Makes Apple users default image Users::ProfileImageGenerator

* Fallback to mascot_image_url in test environment to avoid breaking Travis

* Fixes Apple CSRF error + makes default nickname more readable

* Trigger Travis

* Better devise config

* Apple SiteConfig entires in /admin/config

* Fixing specs

* Adds beta_access? to Authentication::Providers::Provider

* Fixes specs

* Codeclimate double quote fix in Gemfile

* Fixes /admin/config allowed params & adds feature flag for provider beta_access?

* Remove Enfile & adds temporary docs

* Adds custom apple auth provider settings

* Fix authenticator spec

* Fix configs spec (use last instead of first to avoid apple special case)

* Remove dangling fields from /admin/config

* updates feature flag

* More test fixes

* Hide config behind feature flag too

* omniauth-apple bump

* Takes care of edge case fallback

* Reverse apple_username update

* Adds auth_time to info hash in apple omniauth mock

* Switch to next instead of nesting for feature flag

* Fixes CVE-2015-9284

* Fixes specs after auth providers initiatior refactor from GET to POST

* Spec fixes

* More spec fixes

* Fix Rails codebase reference link

Co-authored-by: rhymes <rhymesete@gmail.com>
Co-authored-by: rhymes <rhymes@hey.com>
2020-12-18 10:22:33 -06:00

59 lines
1.8 KiB
Ruby

require "rails_helper"
RSpec.describe Authentication::Providers, type: :service do
describe ".get!" do
it "raises an exception if a provider is not available" do
expect do
described_class.get!(:unknown)
end.to raise_error(Authentication::Errors::ProviderNotFound)
end
it "raises an exception if a provider is available but not enabled" do
allow(SiteConfig).to receive(:authentication_providers).and_return(%w[github])
expect do
described_class.get!(:twitter)
end.to raise_error(Authentication::Errors::ProviderNotEnabled)
end
it "loads the correct provider class" do
allow(SiteConfig).to receive(:authentication_providers).and_return(described_class.available)
is_subclass_of = (
described_class.get!(:twitter) < Authentication::Providers::Provider
)
expect(is_subclass_of).to be(true)
end
end
describe ".available" do
it "lists the available providers" do
available_providers = %i[apple facebook github twitter]
expect(described_class.available).to eq(available_providers)
end
end
describe ".enabled" do
context "when one of the available providers is disabled" do
it "only lists those that remain enabled" do
allow(SiteConfig).to receive(:authentication_providers).and_return(%w[github])
expect(described_class.enabled).to eq(%i[github])
end
end
end
describe ".enabled?" do
it "returns true if a provider is enabled" do
allow(SiteConfig).to receive(:authentication_providers).and_return(%w[github])
expect(described_class.enabled?(:github)).to be(true)
end
it "returns false if a provider is not enabled" do
allow(SiteConfig).to receive(:authentication_providers).and_return(%w[twitter])
expect(described_class.enabled?(:github)).to be(false)
end
end
end