auth_test.rb
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'test_helper'
class AuthTest < ActiveSupport::TestCase
def setup
@person = fast_create(Person)
@provider = fast_create(OauthClientPlugin::Provider, name: "GitHub")
@external_person = fast_create(ExternalPerson, name: "testuser", email: "test@email.com",
identifier: "testuser")
OauthClientPlugin::Auth.any_instance.stubs(:external_person_image_url).returns("http://some.host/image")
OauthClientPlugin::Auth.any_instance.stubs(:external_person_uid).returns("j4b25cj234hb5n235")
OauthClientPlugin::Provider.any_instance.stubs(:client_options).returns({site: "http://host.com"})
end
should "not create an auth without a related profile or external person" do
auth = OauthClientPlugin::Auth.new(provider: @provider)
assert_not auth.valid?
end
should "create an auth with an external person" do
auth = OauthClientPlugin::Auth.create!(profile: @external_person,
provider: @provider)
assert auth.id.present?
end
should "create an auth with a profile" do
auth = OauthClientPlugin::Auth.create!(profile: @person, provider: @provider)
assert auth.id.present?
end
should "create an auth for a custom provider" do
auth = OauthClientPlugin::Auth.create_for_strategy("github", provider: @provider,
profile: @person)
assert auth.id.present?
assert auth.is_a? OauthClientPlugin::GithubAuth
end
STRATEGIES = %w[facebook github google_oauth2 noosfero_oauth2 twitter]
STRATEGIES.each do |strategy|
should "override the external person's image url for #{strategy} strategy" do
auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider,
profile: @external_person)
assert_not auth.image_url.nil?
end
should "override the external person's profile url for #{strategy} strategy" do
auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider,
profile: @external_person)
assert_not auth.profile_url.nil?
end
should "override the external person's profile settings url for #{strategy} strategy" do
auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider,
profile: @external_person)
assert_not auth.settings_url.nil?
end
end
end