facemock-oauth 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/facemock-oauth.gemspec +1 -1
- data/lib/facemock/oauth/authentication.rb +2 -2
- data/lib/facemock/oauth/callback_hook.rb +2 -2
- data/lib/facemock/oauth/version.rb +1 -1
- data/spec/facemock/oauth/authentication_spec.rb +8 -8
- data/spec/facemock/oauth/callback_hook_spec.rb +13 -13
- data/spec/facemock/oauth_spec.rb +1 -1
- metadata +8 -8
data/facemock-oauth.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "facemock"
|
21
|
+
spec.add_dependency "facemock", "~> 0.0.8"
|
22
22
|
spec.add_dependency "rack"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
@@ -13,9 +13,9 @@ module Facemock
|
|
13
13
|
email = body["email"]
|
14
14
|
password = body["pass"]
|
15
15
|
|
16
|
-
user = Facemock::
|
16
|
+
user = Facemock::User.find_by_email(email)
|
17
17
|
if user && user.password == password
|
18
|
-
code = Facemock::
|
18
|
+
code = Facemock::AuthorizationCode.create!(user_id: user.id)
|
19
19
|
location = location(env, CallbackHook.path, { code: code.string })
|
20
20
|
else
|
21
21
|
location = location(env, "/facemock/sign_in")
|
@@ -19,9 +19,9 @@ module Facemock
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def get_access_token(code)
|
22
|
-
authorization_code = Facemock::
|
22
|
+
authorization_code = Facemock::AuthorizationCode.find_by_string(code)
|
23
23
|
if authorization_code
|
24
|
-
user = Facemock::
|
24
|
+
user = Facemock::User.find_by_id(authorization_code.user_id)
|
25
25
|
user ? user.access_token : nil
|
26
26
|
else
|
27
27
|
nil
|
@@ -66,10 +66,10 @@ describe Facemock::OAuth::Authentication do
|
|
66
66
|
|
67
67
|
context 'when user found', assert: :RedirectToOAuthCallback do
|
68
68
|
before do
|
69
|
-
@user = Facemock::
|
70
|
-
allow(Facemock::
|
71
|
-
@authorization_code = Facemock::
|
72
|
-
allow(Facemock::
|
69
|
+
@user = Facemock::User.new({id: 1, email: email, password: password})
|
70
|
+
allow(Facemock::User).to receive(:find_by_email) { @user }
|
71
|
+
@authorization_code = Facemock::AuthorizationCode.new(user_id: @user.id)
|
72
|
+
allow(Facemock::AuthorizationCode).to receive(:create!) { @authorization_code }
|
73
73
|
@path = path
|
74
74
|
end
|
75
75
|
end
|
@@ -81,10 +81,10 @@ describe Facemock::OAuth::Authentication do
|
|
81
81
|
@path = "/test"
|
82
82
|
Facemock::OAuth::Authentication.path = @path
|
83
83
|
|
84
|
-
@user = Facemock::
|
85
|
-
allow(Facemock::
|
86
|
-
@authorization_code = Facemock::
|
87
|
-
allow(Facemock::
|
84
|
+
@user = Facemock::User.new({id: 1, email: email, password: password})
|
85
|
+
allow(Facemock::User).to receive(:find_by_email) { @user }
|
86
|
+
@authorization_code = Facemock::AuthorizationCode.new(user_id: @user.id)
|
87
|
+
allow(Facemock::AuthorizationCode).to receive(:create!) { @authorization_code }
|
88
88
|
end
|
89
89
|
after { Facemock::OAuth::Authentication.path = path }
|
90
90
|
end
|
@@ -43,30 +43,30 @@ describe Facemock::OAuth::CallbackHook do
|
|
43
43
|
|
44
44
|
context 'with code parameter' do
|
45
45
|
before do
|
46
|
-
@user = Facemock::
|
47
|
-
@authorization_code = Facemock::
|
46
|
+
@user = Facemock::User.new({ id: 1, access_token: "test_token" })
|
47
|
+
@authorization_code = Facemock::AuthorizationCode.new(user_id: @user.id)
|
48
48
|
end
|
49
49
|
|
50
50
|
context 'when authorization code does not found', assert: :RequestSuccess do
|
51
51
|
before do
|
52
|
-
allow(Facemock::
|
52
|
+
allow(Facemock::AuthorizationCode).to receive(:find_by_string) { nil }
|
53
53
|
@path = path + "?code=#{@authorization_code.string}"
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'when authorization code found but user does not found', assert: :RequestSuccess do
|
58
58
|
before do
|
59
|
-
allow(Facemock::
|
60
|
-
allow(Facemock::
|
59
|
+
allow(Facemock::AuthorizationCode).to receive(:find_by_string) { @authorization_code }
|
60
|
+
allow(Facemock::User).to receive(:find_by_id) { nil }
|
61
61
|
@path = path + "?code=#{@authorization_code.string}"
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
context 'when authorization code found by code parameter', assert: :SetAuthHash do
|
66
66
|
before do
|
67
|
-
allow(Facemock::
|
68
|
-
allow(Facemock::
|
69
|
-
allow(Facemock::
|
67
|
+
allow(Facemock::AuthorizationCode).to receive(:find_by_string) { @authorization_code }
|
68
|
+
allow(Facemock::User).to receive(:find_by_id) { @user }
|
69
|
+
allow(Facemock::User).to receive(:find_by_access_token) { @user }
|
70
70
|
@path = path
|
71
71
|
end
|
72
72
|
end
|
@@ -79,11 +79,11 @@ describe Facemock::OAuth::CallbackHook do
|
|
79
79
|
@path = "/test"
|
80
80
|
Facemock::OAuth::CallbackHook.path = @path
|
81
81
|
|
82
|
-
@user = Facemock::
|
83
|
-
@authorization_code = Facemock::
|
84
|
-
allow(Facemock::
|
85
|
-
allow(Facemock::
|
86
|
-
allow(Facemock::
|
82
|
+
@user = Facemock::User.new({ id: 1, access_token: "test_token" })
|
83
|
+
@authorization_code = Facemock::AuthorizationCode.new(user_id: @user.id)
|
84
|
+
allow(Facemock::AuthorizationCode).to receive(:find_by_string) { @authorization_code }
|
85
|
+
allow(Facemock::User).to receive(:find_by_id) { @user }
|
86
|
+
allow(Facemock::User).to receive(:find_by_access_token) { @user }
|
87
87
|
end
|
88
88
|
after { Facemock::OAuth::CallbackHook.path = path }
|
89
89
|
end
|
data/spec/facemock/oauth_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facemock-oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: facemock
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.0.8
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.0.8
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rack
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
203
203
|
version: '0'
|
204
204
|
segments:
|
205
205
|
- 0
|
206
|
-
hash:
|
206
|
+
hash: -2283618699220724282
|
207
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
208
|
none: false
|
209
209
|
requirements:
|
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
212
|
version: '0'
|
213
213
|
segments:
|
214
214
|
- 0
|
215
|
-
hash:
|
215
|
+
hash: -2283618699220724282
|
216
216
|
requirements: []
|
217
217
|
rubyforge_project:
|
218
218
|
rubygems_version: 1.8.25
|