2016-04-01 05:33:25 +08:00
|
|
|
require 'rails_helper'
|
2013-10-28 13:29:07 +08:00
|
|
|
|
|
|
|
# In the ghetto ... getting the spec to run in autospec
|
|
|
|
# thing is we need to load up all auth really early pre-fork
|
|
|
|
# it means that the require is not going to get a new copy
|
|
|
|
Auth.send(:remove_const, :OpenIdAuthenticator)
|
|
|
|
load 'auth/open_id_authenticator.rb'
|
|
|
|
|
|
|
|
describe Auth::OpenIdAuthenticator do
|
|
|
|
|
|
|
|
it "can lookup pre-existing user if trusted" do
|
|
|
|
auth = Auth::OpenIdAuthenticator.new("test", "id", trusted: true)
|
|
|
|
|
|
|
|
user = Fabricate(:user)
|
2014-03-26 11:52:50 +08:00
|
|
|
response = OpenStruct.new(identity_url: 'abc')
|
|
|
|
result = auth.after_authenticate(info: {email: user.email}, extra: {response: response})
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(result.user).to eq(user)
|
2013-10-28 13:29:07 +08:00
|
|
|
end
|
2014-08-08 01:28:50 +08:00
|
|
|
|
|
|
|
it "raises an exception when email is missing" do
|
|
|
|
auth = Auth::OpenIdAuthenticator.new("test", "id", trusted: true)
|
|
|
|
response = OpenStruct.new(identity_url: 'abc')
|
2015-01-10 00:34:37 +08:00
|
|
|
expect { auth.after_authenticate(info: {}, extra: { response: response }) }.to raise_error(Discourse::InvalidParameters)
|
2014-08-08 01:28:50 +08:00
|
|
|
end
|
2013-10-28 13:29:07 +08:00
|
|
|
end
|