work in progress, get specs to work.
This commit is contained in:
parent
eebe21a8c8
commit
af356e58d4
|
@ -2,187 +2,211 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Users::OmniauthCallbacksController do
|
describe Users::OmniauthCallbacksController do
|
||||||
|
|
||||||
let(:auth) { {info: {email: 'eviltrout@made.up.email', name: 'Robin Ward', uid: 123456789}, "extra" => {"raw_info" => {} } } }
|
context ".find_authenticator" do
|
||||||
let(:cas_auth) { { 'uid' => 'casuser', extra: { user: 'casuser'} } }
|
it "fails if a provider is disabled" do
|
||||||
|
SiteSetting.stubs("enable_twitter_logins?").returns(false)
|
||||||
shared_examples_for "an authenticaton provider" do |provider|
|
expect(lambda {
|
||||||
context "when #{provider} logins are disabled" do
|
Users::OmniauthCallbacksController.find_authenticator("twitter")
|
||||||
before do
|
}).to raise_error
|
||||||
SiteSetting.stubs("enable_#{provider}_logins?").returns(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fails" do
|
|
||||||
get :complete, provider: provider
|
|
||||||
response.should_not be_success
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when #{provider} logins are enabled" do
|
it "fails for unknown" do
|
||||||
before do
|
expect(lambda {
|
||||||
SiteSetting.stubs("enable_#{provider}_logins?").returns(true)
|
Users::OmniauthCallbacksController.find_authenticator("twitter1")
|
||||||
end
|
}).to raise_error
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
end
|
it "finds an authenticator when enabled" do
|
||||||
|
SiteSetting.stubs("enable_twitter_logins?").returns(true)
|
||||||
describe 'invalid provider' do
|
expect(Users::OmniauthCallbacksController.find_authenticator("twitter")).not_to eq(nil)
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
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
|
# let(:auth) { {info: {email: 'eviltrout@made.up.email', name: 'Robin Ward', uid: 123456789}, "extra" => {"raw_info" => {} } } }
|
||||||
it_behaves_like "an authenticaton provider", 'google'
|
# let(:cas_auth) { { 'uid' => 'casuser', extra: { user: 'casuser'} } }
|
||||||
end
|
|
||||||
|
|
||||||
describe "yahoo" do
|
# shared_examples_for "an authenticaton provider" do |provider|
|
||||||
it_behaves_like "an authenticaton provider", 'yahoo'
|
# context "when #{provider} logins are disabled" do
|
||||||
end
|
# before do
|
||||||
|
# SiteSetting.stubs("enable_#{provider}_logins?").returns(false)
|
||||||
|
# end
|
||||||
|
|
||||||
end
|
# it "fails" do
|
||||||
|
# get :complete, provider: provider
|
||||||
|
# response.should_not be_success
|
||||||
|
# end
|
||||||
|
|
||||||
describe 'github' do
|
# end
|
||||||
|
|
||||||
before do
|
# context "when #{provider} logins are enabled" do
|
||||||
request.env["omniauth.auth"] = auth
|
# before do
|
||||||
end
|
# SiteSetting.stubs("enable_#{provider}_logins?").returns(true)
|
||||||
|
# end
|
||||||
|
|
||||||
it_behaves_like "an authenticaton provider", 'github'
|
# it "succeeds" do
|
||||||
|
# get :complete, provider: provider
|
||||||
|
# response.should be_success
|
||||||
|
# end
|
||||||
|
|
||||||
end
|
# context "and 'invite only' site setting is enabled" do
|
||||||
|
# before do
|
||||||
|
# SiteSetting.stubs(:invite_only?).returns(true)
|
||||||
|
# end
|
||||||
|
|
||||||
describe 'persona' do
|
# it "informs the user they are awaiting approval" do
|
||||||
|
# xhr :get, :complete, provider: provider, format: :json
|
||||||
|
|
||||||
before do
|
# expect(
|
||||||
request.env["omniauth.auth"] = auth
|
# JSON.parse(response.body)['awaiting_approval']
|
||||||
end
|
# ).to be_true
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
it_behaves_like "an authenticaton provider", 'persona'
|
# end
|
||||||
|
|
||||||
end
|
# end
|
||||||
|
|
||||||
describe 'oauth2' do
|
# describe 'invalid provider' 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
|
# it "fails" do
|
||||||
context "User already exists" do
|
# request.env["omniauth.auth"] = auth
|
||||||
before do
|
# get :complete, provider: 'hackprovider'
|
||||||
User.stubs(:find_by_email).returns(Fabricate(:user))
|
# response.should_not be_success
|
||||||
end
|
# end
|
||||||
|
|
||||||
it "should create an OauthUserInfo" do
|
# end
|
||||||
expect {
|
|
||||||
post :complete, provider: 'my_oauth2_provider'
|
# describe 'twitter' do
|
||||||
}.to change { Oauth2UserInfo.count }.by(1)
|
|
||||||
end
|
# before do
|
||||||
end
|
# request.env["omniauth.auth"] = auth
|
||||||
end
|
# end
|
||||||
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
|
end
|
||||||
|
|
|
@ -1,65 +1,37 @@
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
require_dependency "auth/result"
|
||||||
|
|
||||||
describe "users/omniauth_callbacks/complete.html.erb" do
|
describe "users/omniauth_callbacks/complete.html.erb" do
|
||||||
it "renders facebook data " do
|
|
||||||
assign(:data, {username: "username", :auth_provider=> "Facebook", :awaiting_activation=>true})
|
let :rendered_data do
|
||||||
|
returned = JSON.parse(rendered.match(/window.opener.Discourse.authenticationComplete\((.*)\)/)[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders auth info" do
|
||||||
|
result = Auth::Result.new
|
||||||
|
result.user = User.new
|
||||||
|
|
||||||
|
assign(:data, result)
|
||||||
|
|
||||||
render
|
render
|
||||||
|
|
||||||
rendered_data = JSON.parse(rendered.match(/window.opener.Discourse.authenticationComplete\((.*)\)/)[1])
|
rendered_data["authenticated"].should eq(false)
|
||||||
|
rendered_data["awaiting_activation"].should eq(false)
|
||||||
rendered_data["username"].should eq("username")
|
rendered_data["awaiting_approval"].should eq(false)
|
||||||
rendered_data["auth_provider"].should eq("Facebook")
|
|
||||||
rendered_data["awaiting_activation"].should eq(true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders cas data " do
|
it "renders cas data " do
|
||||||
assign(:data, {username: "username", :auth_provider=> "CAS", :awaiting_activation=>true})
|
result = Auth::Result.new
|
||||||
|
|
||||||
|
result.email = "xxx@xxx.com"
|
||||||
|
result.auth_provider = "CAS"
|
||||||
|
|
||||||
|
assign(:data, result)
|
||||||
|
|
||||||
render
|
render
|
||||||
|
|
||||||
rendered_data = JSON.parse(rendered.match(/window.opener.Discourse.authenticationComplete\((.*)\)/)[1])
|
rendered_data["email"].should result.email
|
||||||
|
|
||||||
rendered_data["username"].should eq("username")
|
|
||||||
rendered_data["auth_provider"].should eq("CAS")
|
rendered_data["auth_provider"].should eq("CAS")
|
||||||
rendered_data["awaiting_activation"].should eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "renders twitter data " do
|
|
||||||
assign(:data, {username: "username", :auth_provider=>"Twitter", :awaiting_activation=>true})
|
|
||||||
|
|
||||||
render
|
|
||||||
|
|
||||||
rendered_data = JSON.parse(rendered.match(/window.opener.Discourse.authenticationComplete\((.*)\)/)[1])
|
|
||||||
|
|
||||||
rendered_data["username"].should eq("username")
|
|
||||||
rendered_data["auth_provider"].should eq("Twitter")
|
|
||||||
rendered_data["awaiting_activation"].should eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
it "renders openid data " do
|
|
||||||
assign(:data, {username: "username", :auth_provider=>"OpenId", :awaiting_activation=>true})
|
|
||||||
|
|
||||||
render
|
|
||||||
|
|
||||||
rendered_data = JSON.parse(rendered.match(/window.opener.Discourse.authenticationComplete\((.*)\)/)[1])
|
|
||||||
|
|
||||||
rendered_data["username"].should eq("username")
|
|
||||||
rendered_data["auth_provider"].should eq("OpenId")
|
|
||||||
rendered_data["awaiting_activation"].should eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "renders github data " do
|
|
||||||
assign(:data, {username: "username", :auth_provider=>"Github", :awaiting_activation=>true})
|
|
||||||
|
|
||||||
render
|
|
||||||
|
|
||||||
rendered_data = JSON.parse(rendered.match(/window.opener.Discourse.authenticationComplete\((.*)\)/)[1])
|
|
||||||
|
|
||||||
rendered_data["username"].should eq("username")
|
|
||||||
rendered_data["auth_provider"].should eq("Github")
|
|
||||||
rendered_data["awaiting_activation"].should eq(true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue