multi_auth 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/README +11 -0
  2. data/app/controllers/auth/name_controller.rb +31 -0
  3. data/app/controllers/credentials/email_controller.rb +3 -3
  4. data/app/controllers/credentials/name_controller.rb +93 -0
  5. data/app/controllers/credentials_controller.rb +6 -4
  6. data/app/models/name_credential.rb +63 -0
  7. data/app/models/name_credential_edit_form.rb +40 -0
  8. data/app/models/name_login_form.rb +14 -0
  9. data/app/models/{email_password_edit_form.rb → password_edit_form.rb} +5 -13
  10. data/app/views/auth/name/index.html.erb +89 -0
  11. data/app/views/credentials/index.html.erb +46 -0
  12. data/app/views/credentials/name/delete.html.erb +19 -0
  13. data/app/views/credentials/name/edit_password.html.erb +27 -0
  14. data/app/views/credentials/name/new.html.erb +32 -0
  15. data/config/routes.rb +8 -0
  16. data/db/development.sqlite3 +0 -0
  17. data/db/schema.rb +13 -1
  18. data/db/test.sqlite3 +0 -0
  19. data/generators/multi_auth_migration/templates/migration.rb +13 -0
  20. data/generators/multi_auth_migration/templates/upgrade_migration.rb +19 -0
  21. data/generators/multi_auth_migration/upgrade_multi_auth_tables_generator.rb +11 -0
  22. data/lib/multi_auth.rb +1 -0
  23. data/lib/multi_auth/active_record.rb +1 -0
  24. data/locale/ja/LC_MESSAGES/multi_auth.mo +0 -0
  25. data/po/ja/multi_auth.po +357 -259
  26. data/po/multi_auth.pot +309 -215
  27. data/test/functional/auth/name_controller_test.rb +77 -0
  28. data/test/functional/credentials/email_controller_test.rb +3 -4
  29. data/test/functional/credentials/name_controller_test.rb +292 -0
  30. data/test/unit/name_credential_edit_form_test.rb +151 -0
  31. data/test/unit/name_credential_test.rb +173 -0
  32. data/test/unit/name_login_form_test.rb +68 -0
  33. data/test/unit/{email_password_edit_form_test.rb → password_edit_form_test.rb} +7 -6
  34. metadata +22 -6
@@ -0,0 +1,173 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class NameCredentialTest < ActiveSupport::TestCase
5
+ def setup
6
+ @klass = NameCredential
7
+ @basic = @klass.new(:user_id => users(:yuya).id,
8
+ :name => "yuya",
9
+ :hashed_password => ("0" * 8) + ":" + ("0" * 64))
10
+ @nayutaya = name_credentials(:nayutaya)
11
+ @risa_risa = name_credentials(:risa_risa)
12
+ end
13
+
14
+ #
15
+ # 関連
16
+ #
17
+ test "belongs_to :user" do
18
+ assert_equal(users(:yuya), @nayutaya.user)
19
+ assert_equal(users(:risa), @risa_risa.user)
20
+ end
21
+
22
+ #
23
+ # 検証
24
+ #
25
+ test "all fixtures are valid" do
26
+ assert_equal(true, @klass.all.all?(&:valid?))
27
+ end
28
+
29
+ test "basic is valid" do
30
+ assert_equal(true, @basic.valid?)
31
+ end
32
+
33
+ test "validates_presence_of :name" do
34
+ @basic.name = nil
35
+ assert_equal(false, @basic.valid?)
36
+ end
37
+
38
+ test "validates_presence_of :hashed_password" do
39
+ @basic.hashed_password = nil
40
+ assert_equal(false, @basic.valid?)
41
+ end
42
+
43
+ test "validates_format_of :hashed_password" do
44
+ [
45
+ # ソルト値部分
46
+ ["01234567" + ":" + "0" * 64, true ],
47
+ ["89abcdef" + ":" + "0" * 64, true ],
48
+ ["0000000" + ":" + "0" * 64, false],
49
+ ["00000000" + ":" + "0" * 64, true ],
50
+ ["000000000" + ":" + "0" * 64, false],
51
+ ["0000000A" + ":" + "0" * 64, false],
52
+ ["0000000g" + ":" + "0" * 64, false],
53
+ # ハッシュ値部分
54
+ ["00000000" + ":" + "0123456789abcdef" + "0" * (64 - 16), true ],
55
+ ["00000000" + ":" + "0" * (64 - 1), false],
56
+ ["00000000" + ":" + "0" * 64, true ],
57
+ ["00000000" + ":" + "0" * (64 + 1), false],
58
+ ["00000000" + ":" + "0" * (64 - 1) + "A", false],
59
+ ["00000000" + ":" + "0" * (64 - 1) + "g", false],
60
+ ].each { |value, expected|
61
+ @basic.hashed_password = value
62
+ assert_equal(expected, @basic.valid?, value)
63
+ }
64
+ end
65
+
66
+ test "validates_uniqueness_of :name, on create" do
67
+ @basic.name = @nayutaya.name
68
+ assert_equal(false, @basic.valid?)
69
+ end
70
+
71
+ test "validates_uniqueness_of :name, on update" do
72
+ @nayutaya.name = @risa_risa.name
73
+ assert_equal(false, @nayutaya.valid?)
74
+ end
75
+
76
+ test "validates_each :user_id" do
77
+ srand(0)
78
+ user = users(:yuya)
79
+ create_record = proc {
80
+ user.name_credentials.create!(
81
+ :name => "name#{rand(1000)}",
82
+ :hashed_password => ("0" * 8) + ":" + ("0" * 64))
83
+ }
84
+
85
+ assert_nothing_raised {
86
+ (10 - user.name_credentials.size).times {
87
+ record = create_record[]
88
+ record.save!
89
+ }
90
+ }
91
+ assert_raise(ActiveRecord::RecordInvalid) {
92
+ create_record[]
93
+ }
94
+ end
95
+ test "self.create_hashed_password" do
96
+ assert_match(
97
+ /\A[0-9a-f]{8}:[0-9a-f]{64}\z/,
98
+ @klass.create_hashed_password("a"))
99
+
100
+ # 異なるパスワードでは、異なる値になること
101
+ assert_not_equal(
102
+ @klass.create_hashed_password("a"),
103
+ @klass.create_hashed_password("b"))
104
+
105
+ # 同一のパスワードでも、異なる値になること
106
+ assert_not_equal(
107
+ @klass.create_hashed_password("a"),
108
+ @klass.create_hashed_password("a"))
109
+ end
110
+
111
+ test "self.compare_hashed_password" do
112
+ # ソルト、パスワードが一致
113
+ assert_equal(
114
+ true,
115
+ @klass.compare_hashed_password(
116
+ "password",
117
+ "00000000:" + Digest::SHA256.hexdigest("00000000:password")))
118
+
119
+ # ソルトが不一致、パスワードが一致
120
+ assert_equal(
121
+ false,
122
+ @klass.compare_hashed_password(
123
+ "password",
124
+ "00000000:" + Digest::SHA256.hexdigest("11111111:password")))
125
+
126
+ # ソルトが一致、パスワードが不一致
127
+ assert_equal(
128
+ false,
129
+ @klass.compare_hashed_password(
130
+ "password",
131
+ "00000000:" + Digest::SHA256.hexdigest("00000000:PASSWORD")))
132
+ end
133
+
134
+ test "self.authenticate" do
135
+ assert_equal(
136
+ name_credentials(:nayutaya),
137
+ @klass.authenticate(name_credentials(:nayutaya).name, "nayutaya"))
138
+
139
+ assert_equal(
140
+ nil,
141
+ @klass.authenticate(name_credentials(:nayutaya).name, "NAYUTAYA"))
142
+
143
+ assert_equal(
144
+ nil,
145
+ @klass.authenticate(nil, nil))
146
+ end
147
+
148
+ #
149
+ # インスタンスメソッド
150
+ #
151
+
152
+ test "authenticated?" do
153
+ assert_equal(true, name_credentials(:nayutaya).authenticated?("nayutaya"))
154
+ assert_equal(false, name_credentials(:nayutaya).authenticated?("YUYA_GMAIL"))
155
+ end
156
+
157
+ test "activated?" do
158
+ assert_equal(true, name_credentials(:nayutaya).activated?)
159
+ assert_equal(true, NameCredential.new.activated?)
160
+ end
161
+
162
+ test "activate!" do
163
+ assert_equal(true, name_credentials(:nayutaya).activate!)
164
+ assert_equal(true, NameCredential.new.activate!)
165
+ end
166
+
167
+ test "login!" do
168
+ time = Time.local(2010, 1, 1)
169
+ assert_equal(nil, @risa_risa.loggedin_at)
170
+ Kagemusha::DateTime.at(time) { @risa_risa.login! }
171
+ assert_equal(time, @risa_risa.reload.loggedin_at)
172
+ end
173
+ end
@@ -0,0 +1,68 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+
5
+ class NameLoginFormTest < ActiveSupport::TestCase
6
+
7
+ def setup
8
+ @klass = NameLoginForm
9
+ @form = @klass.new
10
+ @basic = @klass.new(:name => "name", :password => "password")
11
+ end
12
+
13
+ #
14
+ # 基底クラス
15
+ #
16
+
17
+ test "superclass" do
18
+ assert_equal(ActiveForm, @klass.superclass)
19
+ end
20
+
21
+ #
22
+ # カラム
23
+ #
24
+
25
+ test "columns" do
26
+ [
27
+ [:name, nil, "str", "str"],
28
+ [:password, nil, "str", "str"],
29
+ ].each { |name, default, set_value, get_value|
30
+ form = @klass.new
31
+ assert_equal(default, form.__send__(name))
32
+ form.__send__("#{name}=", set_value)
33
+ assert_equal(get_value, form.__send__(name))
34
+ }
35
+ end
36
+
37
+ #
38
+ # 検証
39
+ #
40
+
41
+ test "basic is valid" do
42
+ assert_equal(true, @basic.valid?)
43
+ end
44
+
45
+ test "validates_presence_of :name" do
46
+ @basic.name = nil
47
+ assert_equal(false, @basic.valid?)
48
+ end
49
+
50
+ test "validates_presence_of :password" do
51
+ @basic.password = nil
52
+ assert_equal(false, @basic.valid?)
53
+ end
54
+
55
+ #
56
+ # インスタンスメソッド
57
+ #
58
+
59
+ test "authenticate, success" do
60
+ @form.name = name_credentials(:nayutaya).name
61
+ @form.password = "nayutaya"
62
+ assert_equal(name_credentials(:nayutaya), @form.authenticate)
63
+ end
64
+
65
+ test "authenticate, empty" do
66
+ assert_equal(nil, @form.authenticate)
67
+ end
68
+ end
@@ -1,9 +1,10 @@
1
+ # -*- coding: utf-8 -*-
1
2
 
2
3
  require 'test_helper'
3
4
 
4
- class EmailPasswordEditFormTest < ActiveSupport::TestCase
5
+ class PasswordEditFormTest < ActiveSupport::TestCase
5
6
  def setup
6
- @klass = EmailPasswordEditForm
7
+ @klass = PasswordEditForm
7
8
  @form = @klass.new
8
9
  @basic = @klass.new(
9
10
  :password => "password",
@@ -100,17 +101,17 @@ class EmailPasswordEditFormTest < ActiveSupport::TestCase
100
101
  # インスタンスメソッド
101
102
  #
102
103
 
103
- test "to_email_credential_hash, empty" do
104
- hash = @form.to_email_credential_hash
104
+ test "to_credential_hash, empty" do
105
+ hash = @form.to_credential_hash
105
106
  assert_equal([:hashed_password], hash.keys)
106
107
  assert_equal(true, EmailCredential.compare_hashed_password("", hash[:hashed_password]))
107
108
  end
108
109
 
109
- test "to_email_credential_hash, full" do
110
+ test "to_credential_hash, full" do
110
111
  @form.attributes = {
111
112
  :password => "foo",
112
113
  }
113
- hash = @form.to_email_credential_hash
114
+ hash = @form.to_credential_hash
114
115
  assert_equal([:hashed_password], hash.keys)
115
116
  assert_equal(true, EmailCredential.compare_hashed_password(@form.password, hash[:hashed_password]))
116
117
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_auth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - okkez
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-02 00:00:00 +09:00
19
+ date: 2010-08-16 00:00:00 +09:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -74,19 +74,24 @@ files:
74
74
  - app/controllers/credentials_controller.rb
75
75
  - app/controllers/application_controller.rb
76
76
  - app/controllers/credentials/email_controller.rb
77
+ - app/controllers/credentials/name_controller.rb
77
78
  - app/controllers/credentials/open_id_controller.rb
78
79
  - app/controllers/signup/email_controller.rb
79
80
  - app/controllers/signup/open_id_controller.rb
80
81
  - app/controllers/signup_controller.rb
81
82
  - app/controllers/auth/email_controller.rb
83
+ - app/controllers/auth/name_controller.rb
82
84
  - app/controllers/auth/open_id_controller.rb
83
85
  - app/models/email_login_form.rb
84
86
  - app/models/email_credential_edit_form.rb
85
87
  - app/models/open_id_login_form.rb
88
+ - app/models/name_credential_edit_form.rb
89
+ - app/models/name_credential.rb
86
90
  - app/models/session.rb
87
91
  - app/models/email_credential.rb
92
+ - app/models/password_edit_form.rb
88
93
  - app/models/activation_mailer.rb
89
- - app/models/email_password_edit_form.rb
94
+ - app/models/name_login_form.rb
90
95
  - app/models/dummy_user.rb
91
96
  - app/models/open_id_credential.rb
92
97
  - app/helpers/application_helper.rb
@@ -96,6 +101,9 @@ files:
96
101
  - app/views/activation_mailer/complete_for_notice.erb
97
102
  - app/views/activation_mailer/request_for_credential.erb
98
103
  - app/views/activation_mailer/complete_for_signup.erb
104
+ - app/views/credentials/name/delete.html.erb
105
+ - app/views/credentials/name/new.html.erb
106
+ - app/views/credentials/name/edit_password.html.erb
99
107
  - app/views/credentials/email/delete.html.erb
100
108
  - app/views/credentials/email/activated.html.erb
101
109
  - app/views/credentials/email/activation.html.erb
@@ -115,6 +123,7 @@ files:
115
123
  - app/views/signup/open_id/authenticated.html.erb
116
124
  - app/views/signup/open_id/index.html.erb
117
125
  - app/views/signup/open_id/created.html.erb
126
+ - app/views/auth/name/index.html.erb
118
127
  - app/views/auth/email/index.html.erb
119
128
  - app/views/auth/_header.html.erb
120
129
  - app/views/auth/logged_out.html.erb
@@ -168,6 +177,8 @@ files:
168
177
  - generators/multi_auth_public_assets/multi_auth_public_assets_generator.rb
169
178
  - generators/multi_auth_public_assets/USAGE
170
179
  - generators/multi_auth_migration/multi_auth_migration_generator.rb
180
+ - generators/multi_auth_migration/upgrade_multi_auth_tables_generator.rb
181
+ - generators/multi_auth_migration/templates/upgrade_migration.rb
171
182
  - generators/multi_auth_migration/templates/migration.rb
172
183
  - generators/multi_auth_migration/USAGE
173
184
  - po/multi_auth.pot
@@ -176,11 +187,13 @@ files:
176
187
  - test/test_helper.rb
177
188
  - test/performance/browsing_test.rb
178
189
  - test/functional/auth_controller_test.rb
190
+ - test/functional/credentials/name_controller_test.rb
179
191
  - test/functional/credentials/email_controller_test.rb
180
192
  - test/functional/credentials/open_id_controller_test.rb
181
193
  - test/functional/credentials_controller_test.rb
182
194
  - test/functional/signup/email_controller_test.rb
183
195
  - test/functional/signup/open_id_controller_test.rb
196
+ - test/functional/auth/name_controller_test.rb
184
197
  - test/functional/auth/email_controller_test.rb
185
198
  - test/functional/auth/open_id_controller_test.rb
186
199
  - test/functional/signup_controller_test.rb
@@ -188,12 +201,16 @@ files:
188
201
  - test/unit/multi_auth_public_assets_generator_test.rb
189
202
  - test/unit/action_mailer_util_test.rb
190
203
  - test/unit/session_test.rb
204
+ - test/unit/password_edit_form_test.rb
205
+ - test/unit/name_credential_edit_form_test.rb
191
206
  - test/unit/email_login_form_test.rb
192
207
  - test/unit/email_credential_edit_form_test.rb
193
208
  - test/unit/notice_formatter_test.rb
194
209
  - test/unit/open_id_login_form_test.rb
195
210
  - test/unit/dummy_user_test.rb
211
+ - test/unit/name_credential_test.rb
196
212
  - test/unit/open_id_credential_test.rb
213
+ - test/unit/name_login_form_test.rb
197
214
  - test/unit/activation_mailer_test.rb
198
215
  - test/unit/helpers/email_signup_helper_test.rb
199
216
  - test/unit/helpers/email_auth_helper_test.rb
@@ -207,7 +224,6 @@ files:
207
224
  - test/unit/helpers/password_auth_helper_test.rb
208
225
  - test/unit/helpers/credentials_helper_test.rb
209
226
  - test/unit/token_util_test.rb
210
- - test/unit/email_password_edit_form_test.rb
211
227
  - README
212
228
  has_rdoc: true
213
229
  homepage: https://github.com/okkez/multi_auth