openskip-repim 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -0
- data/generators/relying_party/relying_party_generator.rb +9 -1
- data/generators/relying_party/templates/spec/application_controller_spec.rb +17 -0
- data/generators/relying_party/templates/spec/sessions_controller_spec.rb +81 -0
- data/generators/relying_party/templates/spec/users_controller_spec.rb +1 -0
- data/lib/repim.rb +1 -1
- metadata +2 -2
data/ChangeLog
CHANGED
@@ -6,6 +6,8 @@ class RelyingPartyGenerator < Rails::Generator::NamedBase
|
|
6
6
|
"Specify User class name defailt is [User]"){|v| options[:user_klass] = "User" }
|
7
7
|
opt.on("--user-management=generation_type",
|
8
8
|
"'model' for generate (rspec_)model, 'singnup' for controller using Repim::Signup. default is 'signup'"){|v| options[:user_model_only] = (v == "model") }
|
9
|
+
opt.on("--without-single-access",
|
10
|
+
"Allow user login with multiple browser."){|v| options[:without_single_access] = v }
|
9
11
|
opt.on("--openid-migration=migration_name",
|
10
12
|
"Specify openid migration name, default is 'open_id_authentication_tables'. If value is 'none' generate nothing.") do |v|
|
11
13
|
options[:openid_migration] = v
|
@@ -41,7 +43,7 @@ class RelyingPartyGenerator < Rails::Generator::NamedBase
|
|
41
43
|
end
|
42
44
|
|
43
45
|
generate_user_management(m, !options[:skip_sessions_spec]) unless options[:user_model_only]
|
44
|
-
m.dependency(care_rspec("model"), [user_klass_name,
|
46
|
+
m.dependency(care_rspec("model"), [user_klass_name, user_klass_columns, @args].flatten.compact)
|
45
47
|
|
46
48
|
# FIXME very veriy dirty
|
47
49
|
# "sleep 3" is for changing timestamp of 'create_user' or 'open_id_authentication_tables'
|
@@ -68,6 +70,12 @@ class RelyingPartyGenerator < Rails::Generator::NamedBase
|
|
68
70
|
detect{|c| File.exists?(File.expand_path(c, RAILS_ROOT)) }
|
69
71
|
end
|
70
72
|
|
73
|
+
def user_klass_columns
|
74
|
+
columns = ["identity_url:string"]
|
75
|
+
columns << "single_access_token:string" unless options[:without_single_access]
|
76
|
+
columns
|
77
|
+
end
|
78
|
+
|
71
79
|
def care_rspec(base); using_rspec? ? "rspec_#{base}" : base end
|
72
80
|
|
73
81
|
def using_rspec?; File.directory?( File.expand_path("spec", RAILS_ROOT) ) end
|
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe ApplicationController do
|
4
4
|
before :all do
|
5
5
|
ApplicationController.user_klass = mock("User-Klass")
|
6
|
+
ApplicationController.with_single_access = false
|
6
7
|
end
|
7
8
|
describe "#logged in" do
|
8
9
|
before do
|
@@ -15,3 +16,19 @@ describe ApplicationController do
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
19
|
+
describe ApplicationController, "with_single_access" do
|
20
|
+
before :all do
|
21
|
+
ApplicationController.user_klass = mock("User-Klass")
|
22
|
+
ApplicationController.with_single_access = true
|
23
|
+
end
|
24
|
+
describe "#logged in" do
|
25
|
+
before do
|
26
|
+
session[:single_access_token] = 12345
|
27
|
+
ApplicationController.user_klass.should_receive(:find_by_single_access_token).with(12345).and_return(@user = mock("user"))
|
28
|
+
end
|
29
|
+
|
30
|
+
it{ controller.should be_signed_in }
|
31
|
+
it{ controller.current_user.should == @user }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe SessionsController do
|
4
4
|
before :all do
|
5
5
|
SessionsController.user_klass = mock("User-Klass")
|
6
|
+
SessionsController.with_single_access = false
|
6
7
|
end
|
7
8
|
|
8
9
|
#Delete this example and add some real ones
|
@@ -77,3 +78,83 @@ describe SessionsController do
|
|
77
78
|
it{ flash[:error].should_not be_blank }
|
78
79
|
end
|
79
80
|
end
|
81
|
+
|
82
|
+
describe SessionsController, "with_single_access" do
|
83
|
+
before :all do
|
84
|
+
SessionsController.user_klass = mock("User-Klass")
|
85
|
+
SessionsController.with_single_access = true
|
86
|
+
end
|
87
|
+
|
88
|
+
#Delete this example and add some real ones
|
89
|
+
it "should use SessionsController" do
|
90
|
+
controller.should be_an_instance_of(SessionsController)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "get new should be success" do
|
94
|
+
get :new
|
95
|
+
response.should be_success
|
96
|
+
end
|
97
|
+
|
98
|
+
def mock_out_authenticattion(controller, url, is_success)
|
99
|
+
result = mock("result")
|
100
|
+
result.should_receive(:successful?).and_return is_success
|
101
|
+
|
102
|
+
controller.
|
103
|
+
should_receive(:authenticate_with_open_id).
|
104
|
+
with(url, an_instance_of(Hash)).
|
105
|
+
and_return{|url, ax, block| block.call(result, url, ax) }
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "authentication success" do
|
109
|
+
before do
|
110
|
+
url = "---openid-url---"
|
111
|
+
|
112
|
+
@user = mock("user", :id => 12345, :single_access_token => "12345", :single_access_token= => "12345", :save => true)
|
113
|
+
SessionsController.user_klass.should_receive(:find_by_identity_url).with(url).and_return(@user)
|
114
|
+
|
115
|
+
controller.should_receive(:root_path).and_return("/")
|
116
|
+
mock_out_authenticattion(controller, url, true)
|
117
|
+
|
118
|
+
post :create, :openid_url =>url
|
119
|
+
end
|
120
|
+
|
121
|
+
it{ response.should redirect_to("/") }
|
122
|
+
it{ session[:single_access_token].should == "12345" }
|
123
|
+
it{ controller.current_user.should == @user }
|
124
|
+
it{ controller.should be_signed_in }
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "authentication success but user not found then render users/new" do
|
128
|
+
before do
|
129
|
+
url = "---openid-url---"
|
130
|
+
SessionsController.user_klass.should_receive(:find_by_identity_url).with(url).and_return(nil)
|
131
|
+
@user = mock("user", :id => 12345, :single_access_token => "12345", :single_access_token= => "12345", :save => true)
|
132
|
+
SessionsController.user_klass.should_receive(:new).with({}).and_return(@user)
|
133
|
+
|
134
|
+
mock_out_authenticattion(controller, url, true)
|
135
|
+
|
136
|
+
post :create, :openid_url =>url
|
137
|
+
end
|
138
|
+
|
139
|
+
it{ response.should render_template("users/new") }
|
140
|
+
it{ controller.current_user.should be_nil }
|
141
|
+
it{ controller.should_not be_signed_in }
|
142
|
+
it{ assigns[:user].should == @user }
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "authentication failed" do
|
146
|
+
before do
|
147
|
+
url = "---openid-url---"
|
148
|
+
|
149
|
+
mock_out_authenticattion(controller, url, false)
|
150
|
+
|
151
|
+
post :create, :openid_url =>url
|
152
|
+
end
|
153
|
+
|
154
|
+
it{ response.should render_template("sessions/new") }
|
155
|
+
it{ assigns[:user].should be_nil }
|
156
|
+
it{ controller.current_user.should be_nil }
|
157
|
+
it{ session[:single_access_token].should be_nil }
|
158
|
+
it{ flash[:error].should_not be_blank }
|
159
|
+
end
|
160
|
+
end
|
@@ -51,6 +51,7 @@ describe UsersController do
|
|
51
51
|
describe "responding to POST create" do
|
52
52
|
describe "with valid params" do
|
53
53
|
before do
|
54
|
+
UsersController.with_single_access = false
|
54
55
|
User.should_receive(:new).with({'these' => 'params'}).and_return(mock_user(:save => true))
|
55
56
|
|
56
57
|
@identity_url = session[:identity_url] = "http://moro.openid.example.com/"
|
data/lib/repim.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openskip-repim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MOROHASHI Kyosuke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|