okkez-multi_auth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/README +36 -0
  2. data/app/controllers/application_controller.rb +11 -0
  3. data/app/controllers/auth/email_controller.rb +34 -0
  4. data/app/controllers/auth/open_id_controller.rb +43 -0
  5. data/app/controllers/auth_controller.rb +24 -0
  6. data/app/controllers/credentials/email_controller.rb +156 -0
  7. data/app/controllers/credentials/open_id_controller.rb +85 -0
  8. data/app/controllers/credentials_controller.rb +14 -0
  9. data/app/controllers/signup/email_controller.rb +132 -0
  10. data/app/controllers/signup/open_id_controller.rb +62 -0
  11. data/app/controllers/signup_controller.rb +8 -0
  12. data/app/helpers/application_helper.rb +5 -0
  13. data/app/models/activation_mailer.rb +114 -0
  14. data/app/models/email_credential.rb +89 -0
  15. data/app/models/email_credential_edit_form.rb +52 -0
  16. data/app/models/email_login_form.rb +24 -0
  17. data/app/models/email_password_edit_form.rb +36 -0
  18. data/app/models/open_id_credential.rb +33 -0
  19. data/app/models/open_id_login_form.rb +17 -0
  20. data/app/models/session.rb +19 -0
  21. data/app/models/user.rb +37 -0
  22. data/app/views/activation_mailer/complete_for_credential.erb +4 -0
  23. data/app/views/activation_mailer/complete_for_notice.erb +4 -0
  24. data/app/views/activation_mailer/complete_for_signup.erb +4 -0
  25. data/app/views/activation_mailer/request_for_credential.erb +11 -0
  26. data/app/views/activation_mailer/request_for_notice.erb +11 -0
  27. data/app/views/activation_mailer/request_for_signup.erb +11 -0
  28. data/app/views/auth/email/index.html.erb +90 -0
  29. data/app/views/auth/logged_in.html.erb +21 -0
  30. data/app/views/auth/logged_out.html.erb +21 -0
  31. data/app/views/auth/open_id/index.html.erb +16 -0
  32. data/app/views/credentials/email/activated.html.erb +4 -0
  33. data/app/views/credentials/email/activation.html.erb +15 -0
  34. data/app/views/credentials/email/created.html.erb +15 -0
  35. data/app/views/credentials/email/delete.html.erb +20 -0
  36. data/app/views/credentials/email/edit_password.html.erb +31 -0
  37. data/app/views/credentials/email/new.html.erb +36 -0
  38. data/app/views/credentials/index.html.erb +88 -0
  39. data/app/views/credentials/open_id/delete.html.erb +20 -0
  40. data/app/views/credentials/open_id/new.html.erb +26 -0
  41. data/app/views/signup/email/_progress.html.erb +14 -0
  42. data/app/views/signup/email/activated.html.erb +9 -0
  43. data/app/views/signup/email/activation.html.erb +27 -0
  44. data/app/views/signup/email/created.html.erb +14 -0
  45. data/app/views/signup/email/index.html.erb +34 -0
  46. data/app/views/signup/email/validated.html.erb +21 -0
  47. data/app/views/signup/index.html.erb +51 -0
  48. data/app/views/signup/open_id/authenticated.html.erb +15 -0
  49. data/app/views/signup/open_id/created.html.erb +6 -0
  50. data/app/views/signup/open_id/index.html.erb +16 -0
  51. data/config/boot.rb +110 -0
  52. data/config/database.yml +22 -0
  53. data/config/database.yml.sqlite3 +22 -0
  54. data/config/environment.rb +62 -0
  55. data/config/routes.rb +51 -0
  56. data/config/smtp.yml.example +8 -0
  57. data/db/development.sqlite3 +0 -0
  58. data/db/schema.rb +88 -0
  59. data/db/test.sqlite3 +0 -0
  60. data/lib/action_mailer_util.rb +15 -0
  61. data/lib/multi_auth.rb +64 -0
  62. data/lib/multi_auth_helper.rb +98 -0
  63. data/lib/notice_formatter.rb +106 -0
  64. data/lib/open_id_authentication/result.rb +12 -0
  65. data/lib/token_util.rb +18 -0
  66. data/public/404.html +92 -0
  67. data/public/422.html +91 -0
  68. data/public/500.html +92 -0
  69. data/public/503.html +92 -0
  70. data/public/favicon.ico +0 -0
  71. data/public/images/battery/cell.png +0 -0
  72. data/public/images/battery/level-green.png +0 -0
  73. data/public/images/battery/level-orange.png +0 -0
  74. data/public/images/battery/level-red.png +0 -0
  75. data/public/images/battery/level-yellow.png +0 -0
  76. data/public/images/battery/style.html +82 -0
  77. data/public/images/favicons/livedoor.png +0 -0
  78. data/public/images/favicons/mixi.png +0 -0
  79. data/public/images/favicons/yahoo.png +0 -0
  80. data/public/images/h1-back.png +0 -0
  81. data/public/images/icons/fam/add.png +0 -0
  82. data/public/images/icons/fam/bin.png +0 -0
  83. data/public/images/icons/fam/bomb.png +0 -0
  84. data/public/images/icons/fam/cog.png +0 -0
  85. data/public/images/icons/fam/delete.png +0 -0
  86. data/public/images/icons/fam/email-with-desc.png +0 -0
  87. data/public/images/icons/fam/email.png +0 -0
  88. data/public/images/icons/fam/feed.png +0 -0
  89. data/public/images/icons/fam/help.png +0 -0
  90. data/public/images/icons/fam/key-with-desc.png +0 -0
  91. data/public/images/icons/fam/key.png +0 -0
  92. data/public/images/icons/fam/lightning.png +0 -0
  93. data/public/images/icons/fam/plugin.png +0 -0
  94. data/public/images/icons/fam/stop.png +0 -0
  95. data/public/images/icons/fam/table_save.png +0 -0
  96. data/public/images/icons/fam/tick.png +0 -0
  97. data/public/images/icons/fam/user.png +0 -0
  98. data/public/images/icons/fam/vcard.png +0 -0
  99. data/public/images/icons/openid-with-desc.png +0 -0
  100. data/public/images/icons/openid.png +0 -0
  101. data/public/images/logo-back.png +0 -0
  102. data/public/images/logo.png +0 -0
  103. data/public/images/side-column-back.png +0 -0
  104. data/public/javascripts/application.js +2 -0
  105. data/public/javascripts/controls.js +963 -0
  106. data/public/javascripts/dragdrop.js +973 -0
  107. data/public/javascripts/effects.js +1128 -0
  108. data/public/javascripts/prototype.js +4320 -0
  109. data/public/robots.txt +5 -0
  110. data/public/stylesheets/application.css +365 -0
  111. data/public/stylesheets/auth.css +22 -0
  112. data/public/stylesheets/home.css +114 -0
  113. data/rails/init.rb +24 -0
  114. data/test/functional/auth/email_controller_test.rb +102 -0
  115. data/test/functional/auth/open_id_controller_test.rb +76 -0
  116. data/test/functional/auth_controller_test.rb +74 -0
  117. data/test/functional/credentials/email_controller_test.rb +488 -0
  118. data/test/functional/credentials/open_id_controller_test.rb +308 -0
  119. data/test/functional/credentials_controller_test.rb +49 -0
  120. data/test/functional/signup/email_controller_test.rb +369 -0
  121. data/test/functional/signup/open_id_controller_test.rb +44 -0
  122. data/test/functional/signup_controller_test.rb +17 -0
  123. data/test/performance/browsing_test.rb +9 -0
  124. data/test/test_helper.rb +82 -0
  125. data/test/unit/action_mailer_util_test.rb +63 -0
  126. data/test/unit/activation_mailer_test.rb +181 -0
  127. data/test/unit/email_credential_edit_form_test.rb +173 -0
  128. data/test/unit/email_credential_test.rb +324 -0
  129. data/test/unit/email_login_form_test.rb +76 -0
  130. data/test/unit/email_password_edit_form_test.rb +117 -0
  131. data/test/unit/helpers/auth_helper_test.rb +4 -0
  132. data/test/unit/helpers/credentials/email_helper_test.rb +4 -0
  133. data/test/unit/helpers/credentials/open_id_helper_test.rb +4 -0
  134. data/test/unit/helpers/credentials_helper_test.rb +4 -0
  135. data/test/unit/helpers/email_auth_helper_test.rb +4 -0
  136. data/test/unit/helpers/email_signup_helper_test.rb +4 -0
  137. data/test/unit/helpers/open_id_auth_helper_test.rb +4 -0
  138. data/test/unit/helpers/open_id_signup_helper_test.rb +4 -0
  139. data/test/unit/helpers/password_auth_helper_test.rb +4 -0
  140. data/test/unit/helpers/password_signup_helper_test.rb +4 -0
  141. data/test/unit/helpers/signup_helper_test.rb +4 -0
  142. data/test/unit/notice_formatter_test.rb +153 -0
  143. data/test/unit/open_id_credential_test.rb +108 -0
  144. data/test/unit/open_id_login_form_test.rb +57 -0
  145. data/test/unit/session_test.rb +53 -0
  146. data/test/unit/token_util_test.rb +51 -0
  147. data/test/unit/user_test.rb +177 -0
  148. metadata +220 -0
data/public/robots.txt ADDED
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,365 @@
1
+
2
+ /* generic */
3
+
4
+ *
5
+ {
6
+ margin: 0;
7
+ padding: 0;
8
+ }
9
+
10
+ body
11
+ {
12
+ width: 100%;
13
+ background-color: #F0F0F0;
14
+ }
15
+
16
+ a
17
+ {
18
+ color: #0066CC;
19
+ text-decoration: none;
20
+ }
21
+
22
+ a:hover
23
+ {
24
+ text-decoration: underline;
25
+ }
26
+
27
+ a img
28
+ {
29
+ border-width: 0;
30
+ }
31
+
32
+ /* head */
33
+
34
+ #head-outer
35
+ {
36
+ position: relative;
37
+ width: 100%;
38
+ min-width: 700px;
39
+ height: 120px;
40
+ background-color: #000000;
41
+ background-image: url(/images/logo-back.png);
42
+ background-repeat: repeat-x;
43
+ }
44
+
45
+ #head-inner
46
+ {
47
+ }
48
+
49
+ #head-logo
50
+ {
51
+ position: relative;
52
+ width: 350px;
53
+ }
54
+ #head-logo img
55
+ {
56
+ display: block;
57
+ }
58
+
59
+ #head-navi
60
+ {
61
+ position: absolute;
62
+ top: 95px;
63
+ right: 10px;
64
+ font-size: 13px;
65
+ line-height: 20px;
66
+ color: #CCCCCC;
67
+ }
68
+ #head-navi a
69
+ {
70
+ color: #99CCFF;
71
+ }
72
+
73
+ #head-ad
74
+ {
75
+ position: absolute;
76
+ width: 470px;
77
+ height: 62px;
78
+ top: 25px;
79
+ right: 20px;
80
+ }
81
+
82
+ /* body */
83
+
84
+ #body-outer-with-background,
85
+ #body-outer-without-background
86
+ {
87
+ position: relative;
88
+ width: 100%;
89
+ min-width: 700px;
90
+ }
91
+
92
+ #body-outer-with-background
93
+ {
94
+ background-image: url(../images/side-column-back.png);
95
+ background-repeat: repeat-y;
96
+ background-position: right;
97
+ }
98
+
99
+ #body-inner
100
+ {
101
+ }
102
+
103
+ #content-outer
104
+ {
105
+ }
106
+
107
+ #content-inner
108
+ {
109
+ padding: 10px;
110
+ }
111
+
112
+ #content-column-outer
113
+ {
114
+ margin: 0px 200px 0px 0px;
115
+ }
116
+
117
+ #content-column-inner
118
+ {
119
+ padding: 10px;
120
+ }
121
+
122
+ #side-column-outer
123
+ {
124
+ width: 200px;
125
+ min-height: 400px;
126
+ }
127
+
128
+ #side-column-inner
129
+ {
130
+ padding: 10px;
131
+ }
132
+
133
+ /* foot */
134
+
135
+ #foot-outer
136
+ {
137
+ width: 100%;
138
+ min-width: 700px;
139
+ border-width: 1px 0px 0px 0px;
140
+ border-style: solid;
141
+ border-color: #D0D0D0;
142
+ }
143
+
144
+ #foot-inner
145
+ {
146
+ padding: 20px;
147
+ }
148
+
149
+ #foot-powerd
150
+ {
151
+ float: right;
152
+ font-size: 90%;
153
+ font-weight: bold;
154
+ color: #999999;
155
+ }
156
+ #foot-powerd a
157
+ {
158
+ color: #333333;
159
+ }
160
+
161
+ #foot-github
162
+ {
163
+ font-size: 95%;
164
+ }
165
+
166
+ #foot-services
167
+ {
168
+ font-size: 90%;
169
+ color: #999999;
170
+ }
171
+ #foot-services a
172
+ {
173
+ color: #333333;
174
+ }
175
+
176
+ /* topic path */
177
+
178
+ #topic-path
179
+ {
180
+ padding: 0.1em 0.4em;
181
+ background-color: #E0E0E0;
182
+ color: #999999;
183
+ font-size: 90%;
184
+ }
185
+
186
+ #topic-path a
187
+ {
188
+ }
189
+
190
+ #topic-path em
191
+ {
192
+ color: #666666;
193
+ font-weight: bold;
194
+ font-style: normal;
195
+ }
196
+
197
+ /* for debug */
198
+
199
+ div.debug
200
+ {
201
+ margin-top: 1em;
202
+ background-color: #FFF0F0;
203
+ }
204
+
205
+ /* table.list */
206
+
207
+ table.list
208
+ {
209
+ border-collapse: collapse;
210
+ }
211
+
212
+ table.list thead tr th
213
+ {
214
+ padding: 0.4em;
215
+ border-width: 1px;
216
+ border-style: solid;
217
+ border-color: #F0F0F0;
218
+ color: #CCCCCC;
219
+ background-color: #333333;
220
+ }
221
+
222
+ table.list tbody tr
223
+ {
224
+ border-width: 1px;
225
+ border-style: solid;
226
+ border-color: #F0F0F0;
227
+ }
228
+
229
+ table.list tbody tr td
230
+ {
231
+ padding: 0.2em 0.4em;
232
+ border-width: 0;
233
+ }
234
+
235
+ table.list tbody tr.even td
236
+ {
237
+ background-color: #E0E0E0;
238
+ }
239
+
240
+ table.list tbody tr.odd td
241
+ {
242
+ background-color: #D0D0D0;
243
+ }
244
+
245
+ /* table.energies */
246
+
247
+ table.energies img
248
+ {
249
+ vertical-align: text-top;
250
+ }
251
+
252
+ table.energies thead tr th
253
+ {
254
+ font-size: 70%;
255
+ }
256
+
257
+ table.energies tbody tr td
258
+ {
259
+ font-size: 80%;
260
+ }
261
+
262
+ table.energies tfoot td
263
+ {
264
+ color: #999999;
265
+ text-align: right;
266
+ }
267
+
268
+ /* table.events */
269
+
270
+ table.events img
271
+ {
272
+ vertical-align: text-top;
273
+ }
274
+
275
+ table.events thead tr th
276
+ {
277
+ font-size: 70%;
278
+ }
279
+
280
+ table.events tbody tr td
281
+ {
282
+ font-size: 80%;
283
+ }
284
+
285
+ table.events tfoot td
286
+ {
287
+ color: #999999;
288
+ text-align: right;
289
+ }
290
+
291
+ /* battery */
292
+
293
+ div.battery-cell
294
+ {
295
+ margin: 0;
296
+ padding: 4px 7px 4px 5px;
297
+ width: 100px;
298
+ height: 13px;
299
+ background-image: url(/images/battery/cell.png);
300
+ background-repeat: no-repeat;
301
+ }
302
+
303
+ div.battery-level
304
+ {
305
+ margin: 0;
306
+ padding: 0;
307
+ width: 100px;
308
+ height: 13px;
309
+ }
310
+
311
+ div.battery-high,
312
+ div.battery-middle,
313
+ div.battery-low,
314
+ div.battery-empty
315
+ {
316
+ margin: 0;
317
+ padding: 0;
318
+ height: 13px;
319
+ background-repeat: repeat-x;
320
+ }
321
+
322
+ div.battery-high
323
+ {
324
+ background-image: url(/images/battery/level-green.png);
325
+ }
326
+
327
+ div.battery-middle
328
+ {
329
+ background-image: url(/images/battery/level-orange.png);
330
+ }
331
+
332
+ div.battery-low
333
+ {
334
+ background-image: url(/images/battery/level-yellow.png);
335
+ }
336
+
337
+ div.battery-empty
338
+ {
339
+ background-image: url(/images/battery/level-red.png);
340
+ }
341
+
342
+ /* signup-progress */
343
+ /* FIXME: 別ファイルに分離 */
344
+
345
+ ol#email-signup-progress
346
+ {
347
+ }
348
+
349
+ ol#email-signup-progress li
350
+ {
351
+ display: inline;
352
+ border-style: solid;
353
+ border-width: 1px;
354
+ border-color: black;
355
+ }
356
+
357
+ ol#email-signup-progress li.active
358
+ {
359
+ font-weight: bold;
360
+ }
361
+
362
+ ol#email-signup-progress li.inactive
363
+ {
364
+ font-weight: normal;
365
+ }
@@ -0,0 +1,22 @@
1
+
2
+ #dialog
3
+ {
4
+ margin: 100px auto;
5
+ padding: 15px;
6
+ width: 500px;
7
+ border-width: 1px;
8
+ border-style: solid;
9
+ border-color: #CCCCCC;
10
+ }
11
+ #dialog h1
12
+ {
13
+ margin: 0 0 0.4em 0;
14
+ color: #666666;
15
+ font-size: 130%;
16
+ font-weight: bold;
17
+ }
18
+ .message
19
+ {
20
+ color: #999999;
21
+ font-size: 90%;
22
+ }
@@ -0,0 +1,114 @@
1
+
2
+ h1
3
+ {
4
+ background-image: url(/images/h1-back.png);
5
+ background-repeat: repeat-x;
6
+ background-position: left center;
7
+ }
8
+ h1 span
9
+ {
10
+ padding-right: 0.2em;
11
+ background-color: #F0F0F0;
12
+ }
13
+
14
+ h2
15
+ {
16
+ background-image: url(/images/h1-back.png);
17
+ background-repeat: repeat-x;
18
+ background-position: left center;
19
+ }
20
+ h2 span
21
+ {
22
+ padding-right: 0.2em;
23
+ background-color: #F0F0F0;
24
+ }
25
+
26
+ /* side-column */
27
+
28
+ #side-column-inner h1
29
+ {
30
+ margin-bottom: 8px;
31
+ color: #666666;
32
+ font-size: 16px;
33
+ font-weight: bold;
34
+ }
35
+
36
+ #side-column-inner hr
37
+ {
38
+ height: 1px;
39
+ margin: 8px 0px;
40
+ border: none;
41
+ background-color: #CCCCCC;
42
+ }
43
+
44
+ #signup-link
45
+ {
46
+ font-size: 22px;
47
+ font-weight: bold;
48
+ text-align: center;
49
+ }
50
+ #signup-free
51
+ {
52
+ margin-bottom: 10px;
53
+ font-size: 12px;
54
+ text-align: center;
55
+ color: #990000;
56
+ }
57
+
58
+ #openid-sites
59
+ {
60
+ font-size: 12px;
61
+ line-height: 18px;
62
+ }
63
+ #openid-sites img
64
+ {
65
+ vertical-align: text-bottom;
66
+ }
67
+
68
+ #side-column-inner form input.openid,
69
+ #side-column-inner form input.openid-with-desc,
70
+ #side-column-inner form input.email,
71
+ #side-column-inner form input.email-with-desc,
72
+ #side-column-inner form input.password,
73
+ #side-column-inner form input.password-with-desc
74
+ {
75
+ width: 160px; /* width:200 - (padding:20 + padding:18 + border:2)*/
76
+ height: 20px;
77
+ margin-bottom: 4px;
78
+ padding-left: 18px;
79
+ border-width: 1px;
80
+ border-style: solid;
81
+ border-color: #666666;
82
+ background-repeat: no-repeat;
83
+ background-position: 1px;
84
+ }
85
+
86
+ #side-column-inner form input.openid
87
+ {
88
+ background-image: url(/images/icons/openid.png);
89
+ }
90
+
91
+ #side-column-inner form input.openid-with-desc
92
+ {
93
+ background-image: url(/images/icons/openid-with-desc.png);
94
+ }
95
+
96
+ #side-column-inner form input.email
97
+ {
98
+ background-image: url(/images/icons/fam/email.png);
99
+ }
100
+
101
+ #side-column-inner form input.email-with-desc
102
+ {
103
+ background-image: url(/images/icons/fam/email-with-desc.png);
104
+ }
105
+
106
+ #side-column-inner form input.password
107
+ {
108
+ background-image: url(/images/icons/fam/key.png);
109
+ }
110
+
111
+ #side-column-inner form input.password-with-desc
112
+ {
113
+ background-image: url(/images/icons/fam/key-with-desc.png);
114
+ }
data/rails/init.rb ADDED
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ # initialize
3
+ plugin_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
+
5
+ Dir.glob(File.join(plugin_root, 'lib', '*.rb')).each do |f|
6
+ require(f)
7
+ end
8
+
9
+ config.gem "ruby-openid", :lib => 'openid'
10
+ config.gem "okkez-open_id_authentication", :lib => 'open_id_authentication'
11
+ #config.gem "open_id_authentication"
12
+ config.gem "validates_email_format_of"
13
+ config.gem "locale", :version => ">= 2.0.4"
14
+ config.gem "locale_rails", :version => ">= 2.0.4"
15
+ config.gem "gettext", :version => ">= 2.0.4"
16
+ config.gem "gettext_activerecord", :version => ">= 2.0.4"
17
+ config.gem "gettext_rails", :version => ">= 2.0.4"
18
+ config.gem "nayutaya-active-form", :lib => "active_form"
19
+
20
+ # FIXME: これで正しいのかもう少し考える
21
+ config.action_mailer.raise_delivery_errors = true
22
+ config.action_mailer.delivery_method = :smtp
23
+ config.action_mailer.smtp_settings = YAML.load_file(Rails.root + "config/smtp.yml")
24
+
@@ -0,0 +1,102 @@
1
+
2
+ require 'test_helper'
3
+
4
+ class Auth::EmailControllerTest < ActionController::TestCase
5
+ def setup
6
+ @login_form = EmailLoginForm.new
7
+ end
8
+
9
+ test "routes" do
10
+ base = {:controller => "auth/email"}
11
+
12
+ assert_routing("/auth/email", base.merge(:action => "index"))
13
+ assert_routing("/auth/email/login", base.merge(:action => "login"))
14
+ end
15
+
16
+ test "GET index" do
17
+ session_login(users(:yuya))
18
+
19
+ get :index
20
+
21
+ assert_response(:success)
22
+ assert_template("index")
23
+ assert_flash_empty
24
+ assert_not_logged_in
25
+
26
+ assert_equal(
27
+ EmailLoginForm.new.attributes,
28
+ assigns(:login_form).attributes)
29
+ end
30
+
31
+ test "POST login" do
32
+ session_login(users(:shinya))
33
+
34
+ time = Time.local(2010, 1, 1)
35
+ @login_form.attributes = {
36
+ :email => email_credentials(:yuya_gmail).email,
37
+ :password => "yuya_gmail",
38
+ }
39
+ assert_equal(true, @login_form.valid?)
40
+
41
+ Kagemusha::DateTime.at(time) {
42
+ post :login, :login_form => @login_form.attributes
43
+ }
44
+
45
+ assert_response(:redirect)
46
+ assert_redirected_to(:controller => "/auth", :action => "logged_in")
47
+ assert_flash_empty
48
+ assert_logged_in(users(:yuya))
49
+
50
+ assert_equal(
51
+ @login_form.attributes,
52
+ assigns(:login_form).attributes)
53
+
54
+ assert_equal(
55
+ email_credentials(:yuya_gmail),
56
+ assigns(:email_credential))
57
+ assert_equal(time, assigns(:email_credential).loggedin_at)
58
+ end
59
+
60
+ test "POST login, failed, inactive credential" do
61
+ session_login(users(:shinya))
62
+
63
+ @login_form.attributes = {
64
+ :email => email_credentials(:yuya_nayutaya).email,
65
+ :password => "yuya_nayutaya",
66
+ }
67
+ assert_equal(true, @login_form.valid?)
68
+
69
+ post :login, :login_form => @login_form.attributes
70
+
71
+ assert_response(:success)
72
+ assert_template("index")
73
+ assert_flash_error
74
+ assert_not_logged_in
75
+
76
+ assert_equal(nil, assigns(:login_form).password)
77
+ assert_equal(nil, assigns(:email_credential))
78
+ end
79
+
80
+ test "POST login, invalid form" do
81
+ session_login(users(:shinya))
82
+
83
+ assert_equal(false, @login_form.valid?)
84
+
85
+ post :login, :login_form => @login_form.attributes
86
+
87
+ assert_response(:success)
88
+ assert_template("index")
89
+ assert_flash_error
90
+ assert_not_logged_in
91
+
92
+ assert_equal(nil, assigns(:login_form).password)
93
+ assert_equal(nil, assigns(:email_credential))
94
+ end
95
+
96
+ test "GET login, abnormal, method not allowed" do
97
+ get :login
98
+
99
+ assert_response(405)
100
+ assert_template(nil)
101
+ end
102
+ end
@@ -0,0 +1,76 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+
5
+ class Auth::OpenIdControllerTest < ActionController::TestCase
6
+ def setup
7
+ @shinya_example = open_id_credentials(:shinya_example)
8
+ end
9
+
10
+ test "routes" do
11
+ base = {:controller => "auth/open_id"}
12
+
13
+ assert_routing("/auth/open_id", base.merge(:action => "index"))
14
+ assert_routing("/auth/open_id/login", base.merge(:action => "login"))
15
+ end
16
+
17
+ test "GET index" do
18
+ session_login(users(:yuya))
19
+
20
+ get :index
21
+
22
+ assert_response(:success)
23
+ assert_template("index")
24
+ assert_flash_empty
25
+ assert_not_logged_in
26
+ end
27
+
28
+ test "POST login, successful with registered identity_url" do
29
+ musha = Kagemusha.new(Auth::OpenIdController::Result)
30
+ musha.def(:successful?) { true }
31
+ musha.swap{
32
+ post :login, :openid_url => @shinya_example.identity_url
33
+ }
34
+ assert_response(:redirect)
35
+ assert_redirected_to('/')
36
+ assert_equal('ログインしました。', @response.flash[:notice])
37
+ end
38
+
39
+ test "POST login, successful with unregistered identity_url" do
40
+ musha = Kagemusha.new(Auth::OpenIdController::Result)
41
+ musha.def(:successful?) { true }
42
+ musha.swap{
43
+ post :login, :openid_url => 'http://example.jp/yuya'
44
+ }
45
+ assert_response(:redirect)
46
+ assert_redirected_to(:controller => 'signup/open_id', :action => 'index')
47
+ assert_equal('OpenID がまだ登録されていません。', @response.flash[:notice])
48
+ end
49
+
50
+ [
51
+ [:missing, 'OpenID サーバが見つかりませんでした。'],
52
+ [:invalid, 'OpenID が不正です。'],
53
+ [:canceled, 'OpenID の検証がキャンセルされました。'],
54
+ [:failed, 'OpenID の検証が失敗しました。'],
55
+ ].each do |status, message|
56
+ test "POST login, #{status}" do
57
+ musha = Kagemusha.new(Auth::OpenIdController::Result)
58
+ musha.def(:successful?) { false }
59
+ musha.def(:message) { message }
60
+ musha.swap {
61
+ post :login, :openid_url => @shinya_example.identity_url
62
+ }
63
+ assert_response(:redirect)
64
+ assert_redirected_to('/')
65
+ assert_equal(message, @response.flash[:error])
66
+ end
67
+ end
68
+
69
+ test "GET login, abnormal, method not allowed" do
70
+ get :login
71
+
72
+ assert_response(405)
73
+ assert_template(nil)
74
+ end
75
+
76
+ end