mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Fixed all broken specs
Moved middleware config into authenticators
This commit is contained in:
@@ -3,9 +3,25 @@ require_dependency 'plugin/instance'
|
||||
|
||||
describe Plugin::Instance do
|
||||
|
||||
context "find_all" do
|
||||
it "can find plugins correctly" do
|
||||
plugins = Plugin::Instance.find_all("#{Rails.root}/spec/fixtures/plugins")
|
||||
plugins.count.should == 1
|
||||
plugin =plugins[0]
|
||||
|
||||
plugin.name.should == "plugin-name"
|
||||
plugin.path.should == "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
|
||||
end
|
||||
|
||||
it "does not blow up on missing directory" do
|
||||
plugins = Plugin::Instance.find_all("#{Rails.root}/frank_zappa")
|
||||
plugins.count.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
context "activate!" do
|
||||
it "can activate plugins correctly" do
|
||||
plugin = Plugin.new
|
||||
plugin = Plugin::Instance.new
|
||||
plugin.path = "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
|
||||
junk_file = "#{plugin.auto_generated_path}/junk"
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ describe Plugin::Metadata do
|
||||
# about: about: my plugin
|
||||
# version: 0.1
|
||||
# authors: Frank Zappa
|
||||
# gem: some_gem
|
||||
# gem: some_gem, "1"
|
||||
|
||||
some_ruby
|
||||
TEXT
|
||||
@@ -19,23 +17,7 @@ TEXT
|
||||
metadata.about.should == "about: my plugin"
|
||||
metadata.version.should == "0.1"
|
||||
metadata.authors.should == "Frank Zappa"
|
||||
metadata.gems.should == ["some_gem", 'some_gem, "1"']
|
||||
end
|
||||
end
|
||||
|
||||
context "find_all" do
|
||||
it "can find plugins correctly" do
|
||||
metadatas = Plugin::Metadata.find_all("#{Rails.root}/spec/fixtures/plugins")
|
||||
metadatas.count.should == 1
|
||||
metadata = metadata[0]
|
||||
|
||||
metadata.name.should == "plugin-name"
|
||||
metadata.path.should == "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
|
||||
end
|
||||
|
||||
it "does not blow up on missing directory" do
|
||||
metadatas = Plugin.find_all("#{Rails.root}/frank_zappa")
|
||||
metadatas.count.should == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,193 +20,6 @@ describe Users::OmniauthCallbacksController do
|
||||
SiteSetting.stubs("enable_twitter_logins?").returns(true)
|
||||
expect(Users::OmniauthCallbacksController.find_authenticator("twitter")).not_to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
# let(:auth) { {info: {email: 'eviltrout@made.up.email', name: 'Robin Ward', uid: 123456789}, "extra" => {"raw_info" => {} } } }
|
||||
# let(:cas_auth) { { 'uid' => 'casuser', extra: { user: 'casuser'} } }
|
||||
|
||||
# shared_examples_for "an authenticaton provider" do |provider|
|
||||
# context "when #{provider} logins are disabled" do
|
||||
# before do
|
||||
# SiteSetting.stubs("enable_#{provider}_logins?").returns(false)
|
||||
# end
|
||||
|
||||
# it "fails" do
|
||||
# get :complete, provider: provider
|
||||
# response.should_not be_success
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# context "when #{provider} logins are enabled" do
|
||||
# before do
|
||||
# SiteSetting.stubs("enable_#{provider}_logins?").returns(true)
|
||||
# end
|
||||
|
||||
# it "succeeds" do
|
||||
# get :complete, provider: provider
|
||||
# response.should be_success
|
||||
# end
|
||||
|
||||
# context "and 'invite only' site setting is enabled" do
|
||||
# before do
|
||||
# SiteSetting.stubs(:invite_only?).returns(true)
|
||||
# end
|
||||
|
||||
# it "informs the user they are awaiting approval" do
|
||||
# xhr :get, :complete, provider: provider, format: :json
|
||||
|
||||
# expect(
|
||||
# JSON.parse(response.body)['awaiting_approval']
|
||||
# ).to be_true
|
||||
# end
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# describe 'invalid provider' do
|
||||
|
||||
# it "fails" do
|
||||
# request.env["omniauth.auth"] = auth
|
||||
# get :complete, provider: 'hackprovider'
|
||||
# response.should_not be_success
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# describe 'twitter' do
|
||||
|
||||
# before do
|
||||
# request.env["omniauth.auth"] = auth
|
||||
# end
|
||||
|
||||
# it_behaves_like "an authenticaton provider", 'twitter'
|
||||
|
||||
# end
|
||||
|
||||
# describe 'facebook' do
|
||||
|
||||
# before do
|
||||
# request.env["omniauth.auth"] = auth
|
||||
# end
|
||||
|
||||
# it_behaves_like "an authenticaton provider", 'facebook'
|
||||
|
||||
# end
|
||||
|
||||
# describe 'cas' do
|
||||
|
||||
# before do
|
||||
# request.env["omniauth.auth"] = cas_auth
|
||||
# end
|
||||
|
||||
# it_behaves_like "an authenticaton provider", 'cas'
|
||||
|
||||
# describe "extracted user data" do
|
||||
# before do
|
||||
# SiteSetting.stubs(:enable_cas_logins?).returns(true)
|
||||
# end
|
||||
|
||||
# subject {
|
||||
# xhr :get, :complete, provider: 'cas', format: :json
|
||||
# OpenStruct.new(JSON.parse(response.body))
|
||||
# }
|
||||
|
||||
# context "when no user infos are returned by cas" do
|
||||
# its(:username) { should eq 'casuser' }
|
||||
# its(:name) { should eq 'casuser' }
|
||||
# its(:email) { should eq 'casuser' } # No cas_domainname configured!
|
||||
|
||||
# context "when cas_domainname is configured" do
|
||||
# before do
|
||||
# SiteSetting.stubs(:cas_domainname).returns("example.com")
|
||||
# end
|
||||
|
||||
# its(:email) { should eq 'casuser@example.com' }
|
||||
# end
|
||||
# end
|
||||
|
||||
# context "when user infos are returned by cas" do
|
||||
# before do
|
||||
# request.env["omniauth.auth"] = cas_auth.merge({
|
||||
# info: {
|
||||
# name: 'Proper Name',
|
||||
# email: 'public@example.com'
|
||||
# }
|
||||
# })
|
||||
# end
|
||||
|
||||
# its(:username) { should eq 'casuser' }
|
||||
# its(:name) { should eq 'Proper Name' }
|
||||
# its(:email) { should eq 'public@example.com' }
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
|
||||
# describe 'open id handler' do
|
||||
|
||||
# before do
|
||||
# request.env["omniauth.auth"] = { info: {email: 'eviltrout@made.up.email'}, extra: {identity_url: 'http://eviltrout.com'}}
|
||||
# end
|
||||
|
||||
# describe "google" do
|
||||
# it_behaves_like "an authenticaton provider", 'google'
|
||||
# end
|
||||
|
||||
# describe "yahoo" do
|
||||
# it_behaves_like "an authenticaton provider", 'yahoo'
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# describe 'github' do
|
||||
|
||||
# before do
|
||||
# request.env["omniauth.auth"] = auth
|
||||
# end
|
||||
|
||||
# it_behaves_like "an authenticaton provider", 'github'
|
||||
|
||||
# end
|
||||
|
||||
# describe 'persona' do
|
||||
|
||||
# before do
|
||||
# request.env["omniauth.auth"] = auth
|
||||
# end
|
||||
|
||||
# it_behaves_like "an authenticaton provider", 'persona'
|
||||
|
||||
# end
|
||||
|
||||
# describe 'oauth2' do
|
||||
# before do
|
||||
# Discourse.stubs(:auth_providers).returns([stub(name: 'my_oauth2_provider', type: :oauth2)])
|
||||
# request.env["omniauth.auth"] = { uid: 'my-uid', provider: 'my-oauth-provider-domain.net', info: {email: 'eviltrout@made.up.email', name: 'Chatanooga'}}
|
||||
# end
|
||||
|
||||
# describe "#create_or_sign_on_user_using_oauth2" do
|
||||
# context "User already exists" do
|
||||
# before do
|
||||
# User.stubs(:find_by_email).returns(Fabricate(:user))
|
||||
# end
|
||||
|
||||
# it "should create an OauthUserInfo" do
|
||||
# expect {
|
||||
# post :complete, provider: 'my_oauth2_provider'
|
||||
# }.to change { Oauth2UserInfo.count }.by(1)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
@@ -374,32 +374,16 @@ describe UsersController do
|
||||
SiteSetting.expects(:must_approve_users).returns(true)
|
||||
end
|
||||
|
||||
it 'should create twitter user info if none exists' do
|
||||
it 'should create twitter user info if required' do
|
||||
SiteSetting.stubs(:enable_twitter_logins?).returns(true)
|
||||
twitter_auth = { twitter_user_id: 42, twitter_screen_name: "bruce" }
|
||||
session[:authentication] = twitter_auth
|
||||
TwitterUserInfo.expects(:find_by_twitter_user_id).returns(nil)
|
||||
auth = session[:authentication] = {}
|
||||
auth[:authenticator_name] = 'twitter'
|
||||
auth[:extra_data] = twitter_auth
|
||||
TwitterUserInfo.expects(:create)
|
||||
|
||||
post_user
|
||||
end
|
||||
|
||||
it 'should create facebook user info if none exists' do
|
||||
fb_auth = { facebook: { facebook_user_id: 42} }
|
||||
session[:authentication] = fb_auth
|
||||
FacebookUserInfo.expects(:find_by_facebook_user_id).returns(nil)
|
||||
FacebookUserInfo.expects(:create!)
|
||||
|
||||
post_user
|
||||
end
|
||||
|
||||
it 'should create github user info if none exists' do
|
||||
gh_auth = { github_user_id: 2, github_screen_name: "bruce" }
|
||||
session[:authentication] = gh_auth
|
||||
GithubUserInfo.expects(:find_by_github_user_id).returns(nil)
|
||||
GithubUserInfo.expects(:create)
|
||||
|
||||
post_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
require "spec_helper"
|
||||
|
||||
require "auth/authenticator"
|
||||
require_dependency "auth/result"
|
||||
|
||||
describe "users/omniauth_callbacks/complete.html.erb" do
|
||||
@@ -24,14 +26,16 @@ describe "users/omniauth_callbacks/complete.html.erb" do
|
||||
result = Auth::Result.new
|
||||
|
||||
result.email = "xxx@xxx.com"
|
||||
result.auth_provider = "CAS"
|
||||
result.authenticator_name = "CAS"
|
||||
|
||||
assign(:data, result)
|
||||
|
||||
render
|
||||
|
||||
rendered_data["email"].should result.email
|
||||
rendered_data["auth_provider"].should eq("CAS")
|
||||
rendered_data["email"].should eq(result.email)
|
||||
# TODO this is a bit weird, the upcasing is confusing,
|
||||
# clean it up throughout
|
||||
rendered_data["auth_provider"].should eq("Cas")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user