authlogic_facebook_shim 0.3.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +113 -0
- data/README.rdoc +8 -1
- data/Rakefile +39 -20
- data/authlogic_facebook_shim.gemspec +22 -19
- data/lib/authlogic_facebook_shim/adapters/koala_adapter.rb +12 -9
- data/lib/authlogic_facebook_shim/railtie.rb +19 -0
- data/lib/authlogic_facebook_shim/session/adapter.rb +23 -0
- data/lib/authlogic_facebook_shim/session/config.rb +1 -1
- data/lib/authlogic_facebook_shim/session/facebook.rb +3 -4
- data/lib/authlogic_facebook_shim/session.rb +4 -0
- data/lib/authlogic_facebook_shim/version.rb +3 -0
- data/lib/authlogic_facebook_shim.rb +6 -9
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/{rails_root → dummy}/app/models/user.rb +1 -0
- data/test/{rails_root → dummy}/app/models/user_session.rb +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +49 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +6 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +27 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/{rails_root → dummy}/config/facebook.yml +0 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/config.ru +4 -0
- data/test/{rails_root → dummy}/db/migrate/20101217000008_create_users.rb +0 -0
- data/test/{rails_root → dummy}/db/seeds.rb +0 -0
- data/test/dummy/log/test.log +1386 -0
- data/test/test_helper.rb +20 -20
- data/test/units/adapters/koala_adapter_test.rb +202 -146
- data/test/units/session/config_test.rb +110 -108
- data/test/units/session/facebook_test.rb +175 -156
- metadata +123 -155
- data/VERSION +0 -1
- data/test/rails_root/app/controllers/application_controller.rb +0 -10
- data/test/rails_root/app/helpers/application_helper.rb +0 -3
- data/test/rails_root/config/boot.rb +0 -110
- data/test/rails_root/config/database.yml +0 -10
- data/test/rails_root/config/environment.rb +0 -31
- data/test/rails_root/config/environments/development.rb +0 -0
- data/test/rails_root/config/environments/test.rb +0 -0
- data/test/rails_root/config/initializers/authlogic_facebook_koala.rb +0 -5
- data/test/rails_root/config/initializers/new_rails_defaults.rb +0 -21
- data/test/rails_root/config/initializers/session_store.rb +0 -15
- data/test/rails_root/config/locales/en.yml +0 -5
- data/test/rails_root/config/routes.rb +0 -43
- data/test/rails_root/log/test.log +0 -1137
- data/test/rails_root/script/console +0 -3
- data/test/rails_root/script/dbconsole +0 -3
- data/test/rails_root/script/generate +0 -3
data/test/test_helper.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
+
# Load the latest minitest
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'minitest'
|
4
|
+
|
1
5
|
# Load the environment
|
2
6
|
ENV['RAILS_ENV'] = 'test'
|
3
|
-
|
4
|
-
require "#{rails_root}/config/environment.rb"
|
7
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
8
|
|
6
9
|
# Load the testing framework
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require
|
10
|
+
require 'minitest/autorun'
|
11
|
+
require 'rails/test_help'
|
12
|
+
require 'authlogic/test_case'
|
13
|
+
require 'override'
|
14
|
+
|
15
|
+
if defined?(MiniTest::Unit::TestCase)
|
16
|
+
MiniTest::Unit::TestCase.class_eval do
|
17
|
+
# Mix Authlogic::TestCase into MiniTest to make activate_authlogic and controller available
|
18
|
+
include Authlogic::TestCase
|
19
|
+
# Mix Override in because it's just stubbing and expectations that feel like MiniTest
|
20
|
+
include Override
|
21
|
+
end
|
22
|
+
end
|
10
23
|
|
11
|
-
|
24
|
+
Rails.backtrace_cleaner.remove_silencers!
|
12
25
|
|
13
26
|
# Run the migrations
|
14
27
|
ActiveRecord::Migration.verbose = false
|
15
|
-
ActiveRecord::Migrator.migrate("#{
|
16
|
-
|
17
|
-
# Setup the fixtures path
|
18
|
-
|
19
|
-
class ActiveSupport::TestCase #:nodoc:
|
20
|
-
self.fixture_path = File.join(File.dirname(__FILE__), "fixtures")
|
21
|
-
self.use_transactional_fixtures = false
|
22
|
-
self.use_instantiated_fixtures = false
|
23
|
-
self.pre_loaded_fixtures = false
|
24
|
-
|
25
|
-
fixtures :all
|
26
|
-
setup :activate_authlogic
|
27
|
-
|
28
|
-
end
|
28
|
+
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
|
29
29
|
|
30
30
|
# --- Sample valid cookie hash generated with the code below
|
31
31
|
# cookie_hash = {'fbs_233423200151' => 'access_token=233423200151|6892d62675cd952ade8b3f9b-6184456410|xrNaOlTCUF0QFZrJCHmVWzTb5Mk.&expires=0&secret=339a00cdafe6959c3caa1b8004e5f8db&session_key=6892d62675cd952ade8b3f9b-6184456410&sig=19d3c9ccb5b5a55d680ed1cf18698f57&uid=6184456410'}
|
@@ -1,182 +1,238 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
require 'koala'
|
2
3
|
|
3
|
-
|
4
|
+
describe AuthlogicFacebookShim::Adapters::KoalaAdapter do
|
4
5
|
|
5
|
-
|
6
|
+
before do
|
7
|
+
activate_authlogic
|
8
|
+
|
9
|
+
@user_info = {
|
10
|
+
'session_key' => 'mocksessionkey',
|
11
|
+
'sig' => 'cbd80b97f124bf392f76e2ee61168990',
|
12
|
+
'secret' => 'mocksecret',
|
13
|
+
'expires' => '0',
|
14
|
+
'uid' => 'mockuid',
|
15
|
+
'access_token' => 'mockaccesstoken'
|
16
|
+
}
|
17
|
+
|
18
|
+
@signed_user_info = {
|
19
|
+
"algorithm" => "HMAC-SHA256",
|
20
|
+
"code" => "mockcode",
|
21
|
+
"issued_at" => 1323717457,
|
22
|
+
"expires" => "4880",
|
23
|
+
"user_id" => "mockuserid",
|
24
|
+
"access_token" => "mockaccesstoken",
|
25
|
+
}
|
26
|
+
|
27
|
+
@mock_cookies = MockCookieJar.new
|
28
|
+
override controller, :cookies => @mock_cookies
|
29
|
+
|
30
|
+
@session = UserSession.new
|
31
|
+
override @session, :facebook_app_id => 'mockappid'
|
32
|
+
override @session, :facebook_api_key => 'mockapikey'
|
33
|
+
override @session, :facebook_secret_key => 'mocksecret'
|
34
|
+
|
35
|
+
@oauth = MiniTest::Mock.new
|
36
|
+
override Koala::Facebook::OAuth, :new => @oauth
|
37
|
+
end
|
6
38
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
'expires' => '0',
|
12
|
-
'uid' => 'mockuid',
|
13
|
-
'sig' => 'cbd80b97f124bf392f76e2ee61168990',
|
14
|
-
'secret' => 'mocksecret',
|
15
|
-
'access_token' => 'mockaccesstoken'
|
16
|
-
}
|
17
|
-
@mock_cookies = MockCookieJar.new
|
18
|
-
@mock_cookies['fbs_mockappid'] = {:value => 'access_token=mockaccesstoken&expires=0&secret=mocksecret&session_key=mocksessionkey&sig=cbd80b97f124bf392f76e2ee61168990&uid=mockuid'}
|
19
|
-
@session = flexmock(UserSession.new)
|
20
|
-
@controller = flexmock('Controller')
|
21
|
-
|
22
|
-
@session.should_receive(:facebook_app_id).and_return('mockappid').by_default
|
23
|
-
@session.should_receive(:facebook_api_key).and_return('mockapikey').by_default
|
24
|
-
@session.should_receive(:facebook_secret_key).and_return('mocksecret').by_default
|
25
|
-
@session.should_receive(:controller).and_return(@controller).by_default
|
26
|
-
@controller.should_receive(:cookies).and_return(@mock_cookies).by_default
|
39
|
+
describe "setup - for my own sanity" do
|
40
|
+
|
41
|
+
it "should set the controller" do
|
42
|
+
@session.send(:controller).must_equal controller
|
27
43
|
end
|
28
|
-
|
29
|
-
|
44
|
+
|
45
|
+
it "should set the cookies" do
|
46
|
+
@session.send(:controller).cookies.must_equal @mock_cookies
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should set the facebook_app_id" do
|
50
|
+
@session.facebook_app_id.must_equal 'mockappid'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set the facebook_secret_key" do
|
54
|
+
@session.facebook_secret_key.must_equal 'mocksecret'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set the facebook_api_key" do
|
58
|
+
@session.facebook_api_key.must_equal 'mockapikey'
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "facebook_session" do
|
64
|
+
|
65
|
+
describe "with an unsigned facebook cookie" do
|
66
|
+
|
67
|
+
describe "and koala support for get_user_info_from_cookie" do
|
30
68
|
|
31
|
-
|
32
|
-
|
33
|
-
|
69
|
+
before do
|
70
|
+
@oauth.expect :respond_to?, :true, [:get_user_info_from_cookie]
|
71
|
+
@oauth.expect :get_user_info_from_cookie, @user_info, [@mock_cookies]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return a session_key" do
|
75
|
+
@session.facebook_session.session_key.must_equal 'mocksessionkey'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return a uid" do
|
79
|
+
@session.facebook_session.uid.must_equal 'mockuid'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return a secret" do
|
83
|
+
@session.facebook_session.secret.must_equal 'mocksecret'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return a sig" do
|
87
|
+
@session.facebook_session.sig.must_equal 'cbd80b97f124bf392f76e2ee61168990'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return an access_token" do
|
91
|
+
@session.facebook_session.access_token.must_equal 'mockaccesstoken'
|
92
|
+
end
|
34
93
|
|
35
|
-
should "set the cookies" do
|
36
|
-
assert_equal @mock_cookies, @session.controller.cookies
|
37
94
|
end
|
95
|
+
|
96
|
+
describe "with previous koala api" do
|
97
|
+
|
98
|
+
it "should get user info with the get_user_from_cookie method" do
|
99
|
+
@oauth = MiniTest::Mock.new
|
100
|
+
|
101
|
+
override Koala::Facebook::OAuth, :new => @oauth
|
102
|
+
|
103
|
+
@oauth.expect :respond_to?, false, [:get_user_info_from_cookie]
|
104
|
+
@oauth.expect :get_user_from_cookie, @user_info, [@mock_cookies]
|
105
|
+
|
106
|
+
@session.facebook_session.session_key.must_equal 'mocksessionkey'
|
107
|
+
end
|
38
108
|
|
39
|
-
should "set the facebook_app_id" do
|
40
|
-
assert_equal 'mockappid', @session.facebook_app_id
|
41
109
|
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "with an signed facebook cookie" do
|
114
|
+
|
115
|
+
describe "and koala support for get_user_info_from_cookie" do
|
116
|
+
|
117
|
+
before do
|
118
|
+
@oauth.expect :respond_to?, :true, [:get_user_info_from_cookie]
|
119
|
+
@oauth.expect :get_user_info_from_cookie, @signed_user_info, [@mock_cookies]
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should return a code" do
|
123
|
+
@session.facebook_session.code.must_equal 'mockcode'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return a user_id" do
|
127
|
+
@session.facebook_session.user_id.must_equal 'mockuserid'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should return an access_token" do
|
131
|
+
@session.facebook_session.access_token.must_equal 'mockaccesstoken'
|
132
|
+
end
|
42
133
|
|
43
|
-
|
44
|
-
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "with no valid facebook cookie" do
|
139
|
+
|
140
|
+
before do
|
141
|
+
@oauth.expect :respond_to?, :true, [:get_user_info_from_cookie]
|
142
|
+
@oauth.expect :get_user_info_from_cookie, nil, [@mock_cookies]
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should return nil" do
|
146
|
+
@session.facebook_session.must_be_nil
|
45
147
|
end
|
46
148
|
|
47
|
-
|
48
|
-
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "facebook_session?" do
|
154
|
+
|
155
|
+
describe "with a valid facebook session" do
|
156
|
+
|
157
|
+
before do
|
158
|
+
@oauth.expect :respond_to?, :true, [:get_user_info_from_cookie]
|
159
|
+
override @oauth, :get_user_info_from_cookie => @signed_user_info
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should be true" do
|
163
|
+
@session.facebook_session?.must_equal true
|
49
164
|
end
|
50
165
|
|
51
166
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
context "and koala support for get_user_info_from_cookie" do
|
58
|
-
|
59
|
-
should "return a session_key" do
|
60
|
-
assert_equal 'mocksessionkey', @session.facebook_session.session_key
|
61
|
-
end
|
62
|
-
|
63
|
-
should "return a uid" do
|
64
|
-
assert_equal 'mockuid', @session.facebook_session.uid
|
65
|
-
end
|
66
|
-
|
67
|
-
should "return a secret" do
|
68
|
-
assert_equal 'mocksecret', @session.facebook_session.secret
|
69
|
-
end
|
70
|
-
|
71
|
-
should "return a sig" do
|
72
|
-
assert_equal 'cbd80b97f124bf392f76e2ee61168990', @session.facebook_session.sig
|
73
|
-
end
|
74
|
-
|
75
|
-
should "return an access_token" do
|
76
|
-
assert_equal 'mockaccesstoken', @session.facebook_session.access_token
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
context "with previous koala api" do
|
82
|
-
|
83
|
-
should "get user info with the get_user_from_cookie method" do
|
84
|
-
@oauth = flexmock('oauth')
|
85
|
-
flexmock(Koala::Facebook::OAuth).should_receive(:new).and_return(@oauth).once
|
86
|
-
@oauth.should_receive(:respond_to?).with(:get_user_info_from_cookie).and_return(false).once
|
87
|
-
@oauth.should_receive(:get_user_from_cookie).with(@mock_cookies).and_return(@user_info).once
|
88
|
-
|
89
|
-
assert_equal 'mocksessionkey', @session.facebook_session.session_key
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
167
|
+
|
168
|
+
describe "without a valid facebook session" do
|
169
|
+
|
170
|
+
before do
|
171
|
+
override @oauth, :get_user_info_from_cookie => nil
|
94
172
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
should "return nil" do
|
99
|
-
@session.should_receive('facebook_app_id').and_return(nil).once
|
100
|
-
assert_nil @session.facebook_session
|
101
|
-
end
|
102
|
-
|
173
|
+
|
174
|
+
it "should be false" do
|
175
|
+
@session.facebook_session?.must_equal false
|
103
176
|
end
|
104
177
|
|
105
178
|
end
|
106
179
|
|
107
|
-
|
108
|
-
|
109
|
-
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "facebook_user" do
|
183
|
+
|
184
|
+
describe "with a valid facebook session" do
|
110
185
|
|
111
|
-
|
112
|
-
|
113
|
-
|
186
|
+
before do
|
187
|
+
@graph_api = MiniTest::Mock.new
|
188
|
+
graph_api = Koala::Facebook.const_defined?(:API) ? Koala::Facebook::API : Koala::Facebook::GraphAPI
|
189
|
+
override graph_api, :new => @graph_api
|
190
|
+
|
191
|
+
facebook_session = MiniTest::Mock.new
|
192
|
+
access_token = MiniTest::Mock.new
|
193
|
+
facebook_session.expect :access_token, access_token
|
114
194
|
|
195
|
+
override @session, :facebook_session => facebook_session
|
196
|
+
override @session, :facebook_session? => true
|
197
|
+
|
198
|
+
@user = {
|
199
|
+
"id" => "mockid",
|
200
|
+
"name" => "Full name",
|
201
|
+
"first_name" => "First name",
|
202
|
+
"last_name" => "Last name"
|
203
|
+
}
|
204
|
+
|
205
|
+
@graph_api.expect :get_object, @user, ['me']
|
115
206
|
end
|
116
207
|
|
117
|
-
|
118
|
-
|
119
|
-
should "return nil" do
|
120
|
-
@session.should_receive('facebook_app_id').and_return(nil).once
|
121
|
-
assert_equal false, @session.facebook_session?
|
122
|
-
end
|
123
|
-
|
208
|
+
it "should return an OpenStruct" do
|
209
|
+
@session.facebook_user.must_be_instance_of OpenStruct
|
124
210
|
end
|
125
211
|
|
212
|
+
it "should return the user details" do
|
213
|
+
@session.facebook_user.name.must_equal 'Full name'
|
214
|
+
@session.facebook_user.first_name.must_equal 'First name'
|
215
|
+
@session.facebook_user.last_name.must_equal 'Last name'
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should return the facebook id as uid" do
|
219
|
+
@session.facebook_user.uid.must_equal 'mockid'
|
220
|
+
end
|
221
|
+
|
126
222
|
end
|
127
|
-
|
128
|
-
|
223
|
+
|
224
|
+
describe "with no valid facebook session" do
|
129
225
|
|
130
|
-
|
131
|
-
|
132
|
-
setup do
|
133
|
-
@user = {
|
134
|
-
"id" => "mockid",
|
135
|
-
"name" => "Full name",
|
136
|
-
"first_name" => "First name",
|
137
|
-
"last_name" => "Last name"
|
138
|
-
}
|
139
|
-
|
140
|
-
@access_token = flexmock('access token')
|
141
|
-
@session.should_receive('facebook_session.access_token').and_return(@access_token).by_default
|
142
|
-
@session.should_receive('facebook_session?').and_return(true).by_default
|
143
|
-
|
144
|
-
@graph_api = flexmock('graph api', :get_object => @user)
|
145
|
-
flexmock(Koala::Facebook::GraphAPI).should_receive(:new).and_return(@graph_api).by_default
|
146
|
-
end
|
147
|
-
|
148
|
-
should "initialize the graph api" do
|
149
|
-
flexmock(Koala::Facebook::GraphAPI).should_receive(:new).with(@access_token).and_return(@graph_api).once
|
150
|
-
@session.facebook_user
|
151
|
-
end
|
152
|
-
|
153
|
-
should "return an OpenStruct" do
|
154
|
-
assert @session.facebook_user.is_a?(OpenStruct)
|
155
|
-
end
|
156
|
-
|
157
|
-
should "return the user details" do
|
158
|
-
assert_equal 'Full name', @session.facebook_user.name
|
159
|
-
assert_equal 'First name', @session.facebook_user.first_name
|
160
|
-
assert_equal 'Last name', @session.facebook_user.last_name
|
161
|
-
end
|
162
|
-
|
163
|
-
should "return the facebook id as uid" do
|
164
|
-
assert_equal 'mockid', @session.facebook_user.uid
|
165
|
-
end
|
166
|
-
|
226
|
+
before do
|
227
|
+
override @session, :facebook_session? => false
|
167
228
|
end
|
168
|
-
|
169
|
-
context "with no valid facebook session" do
|
170
|
-
|
171
|
-
should "return nil" do
|
172
|
-
@session.should_receive('facebook_session?').and_return(false).once
|
173
|
-
assert_nil @session.facebook_user
|
174
|
-
end
|
175
229
|
|
230
|
+
it "should return nil" do
|
231
|
+
@session.facebook_user.must_be_nil
|
176
232
|
end
|
177
233
|
|
178
234
|
end
|
179
235
|
|
180
236
|
end
|
181
|
-
|
237
|
+
|
182
238
|
end
|