authpwn_rails 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.travis.yml +7 -2
  2. data/VERSION +1 -1
  3. data/app/models/credentials/password.rb +16 -8
  4. data/app/models/credentials/token.rb +8 -0
  5. data/app/models/tokens/email_verification.rb +3 -0
  6. data/app/models/tokens/password_reset.rb +5 -2
  7. data/app/models/tokens/session_uid.rb +54 -0
  8. data/authpwn_rails.gemspec +8 -2
  9. data/lib/authpwn_rails.rb +3 -2
  10. data/lib/authpwn_rails/current_user.rb +1 -10
  11. data/lib/authpwn_rails/engine.rb +2 -2
  12. data/lib/authpwn_rails/expires.rb +23 -0
  13. data/lib/authpwn_rails/generators/all_generator.rb +9 -4
  14. data/lib/authpwn_rails/generators/templates/credential.rb +1 -1
  15. data/lib/authpwn_rails/generators/templates/credentials.yml +16 -0
  16. data/lib/authpwn_rails/generators/templates/initializer.rb +18 -0
  17. data/lib/authpwn_rails/generators/templates/session/forbidden.html.erb +1 -1
  18. data/lib/authpwn_rails/generators/templates/session/home.html.erb +1 -1
  19. data/lib/authpwn_rails/generators/templates/session/new.html.erb +3 -3
  20. data/lib/authpwn_rails/generators/templates/session/welcome.html.erb +1 -1
  21. data/lib/authpwn_rails/generators/templates/session_controller.rb +13 -4
  22. data/lib/authpwn_rails/generators/templates/session_controller_test.rb +12 -2
  23. data/lib/authpwn_rails/generators/templates/session_mailer.rb +3 -3
  24. data/lib/authpwn_rails/generators/templates/session_mailer/email_verification_email.html.erb +3 -3
  25. data/lib/authpwn_rails/generators/templates/session_mailer/reset_password_email.html.erb +3 -3
  26. data/lib/authpwn_rails/generators/templates/session_mailer_test.rb +4 -4
  27. data/lib/authpwn_rails/routes.rb +4 -4
  28. data/lib/authpwn_rails/session.rb +31 -8
  29. data/lib/authpwn_rails/session_controller.rb +27 -18
  30. data/lib/authpwn_rails/test_extensions.rb +16 -6
  31. data/lib/authpwn_rails/user_model.rb +10 -10
  32. data/test/cookie_controller_test.rb +165 -16
  33. data/test/credentials/email_verification_token_test.rb +11 -11
  34. data/test/credentials/password_credential_test.rb +31 -12
  35. data/test/credentials/session_uid_token_test.rb +98 -0
  36. data/test/credentials/token_crendential_test.rb +46 -12
  37. data/test/helpers/db_setup.rb +6 -5
  38. data/test/helpers/routes.rb +5 -2
  39. data/test/initializer_test.rb +18 -0
  40. data/test/session_controller_api_test.rb +127 -53
  41. data/test/test_extensions_test.rb +41 -0
  42. data/test/test_helper.rb +3 -0
  43. data/test/user_test.rb +11 -10
  44. metadata +9 -3
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class TestExtensionsTest < ActionController::TestCase
4
+ def setup
5
+ @user = users(:john)
6
+ @token = credentials(:john_session_token)
7
+ end
8
+
9
+ test 'session_current_user for no user' do
10
+ assert_nil session_current_user
11
+ end
12
+
13
+ test 'session_current_user with valid suid' do
14
+ request.session[:authpwn_suid] = @token.suid
15
+ assert_equal @user, session_current_user
16
+ end
17
+
18
+ test 'set_session_current_user reuses existing token' do
19
+ assert_no_difference 'Credential.count' do
20
+ set_session_current_user @user
21
+ end
22
+ assert_equal @token.suid, request.session[:authpwn_suid]
23
+ end
24
+
25
+ test 'set_session_current_user creates token if necessary' do
26
+ @token.destroy
27
+ assert_difference 'Credential.count', 1 do
28
+ set_session_current_user @user
29
+ end
30
+ assert_equal @user, session_current_user
31
+ end
32
+
33
+ test 'set_session_current_user to nil' do
34
+ request.session[:authpwn_suid] = @token.suid
35
+ assert_no_difference 'Credential.count' do
36
+ set_session_current_user nil
37
+ end
38
+ assert_nil request.session[:authpwn_suid]
39
+ end
40
+ end
41
+
data/test/test_helper.rb CHANGED
@@ -21,3 +21,6 @@ require 'helpers/autoload_path.rb'
21
21
  require 'helpers/db_setup.rb'
22
22
  require 'helpers/fbgraph.rb'
23
23
  require 'helpers/routes.rb'
24
+
25
+ # Simulate Rails' initializer loading.
26
+ require 'authpwn_rails/generators/templates/initializer.rb'
data/test/user_test.rb CHANGED
@@ -1,29 +1,29 @@
1
1
  require File.expand_path('../test_helper', __FILE__)
2
2
 
3
- class UserTest < ActiveSupport::TestCase
3
+ class UserTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  @user = User.new
6
6
  end
7
-
7
+
8
8
  test 'setup' do
9
9
  assert @user.valid?
10
10
  end
11
-
11
+
12
12
  test 'exuid generation' do
13
13
  assert @user.valid?
14
14
  assert @user.exuid
15
15
  end
16
-
16
+
17
17
  test 'exuid uniqueness' do
18
18
  @user.exuid = users(:john).exuid
19
19
  assert !@user.valid?
20
20
  end
21
-
21
+
22
22
  test 'exuid presence' do
23
23
  @user.exuid = ''
24
24
  assert !@user.valid?
25
25
  end
26
-
26
+
27
27
  test 'exuid randomness' do
28
28
  exuids = []
29
29
  1000.times do
@@ -32,20 +32,21 @@ class UserTest < ActiveSupport::TestCase
32
32
  exuids << @user.exuid
33
33
  @user.save! # Catch range errors.
34
34
  end
35
- assert_equal exuids.length, exuids.uniq.length, 'UIDs are not random enough'
35
+ assert_equal exuids.length, exuids.uniq.length,
36
+ 'UIDs are not random enough'
36
37
  end
37
-
38
+
38
39
  test 'to_param' do
39
40
  assert_equal '56789', users(:john).to_param
40
41
  end
41
-
42
+
42
43
  test 'find_by_param' do
43
44
  assert_equal users(:john), User.find_by_param(users(:john).to_param)
44
45
  assert_equal users(:jane), User.find_by_param(users(:jane).to_param)
45
46
  assert_equal nil, User.find_by_param('bogus id')
46
47
  assert_equal nil, User.find_by_param(nil)
47
48
  end
48
-
49
+
49
50
  test 'nested attributes' do
50
51
  @user = User.new :credentials_attributes => { 0 =>
51
52
  {:name => 'test@email.com', :type => 'Credentials::Password'}}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authpwn_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fbgraph_rails
@@ -196,6 +196,7 @@ files:
196
196
  - app/models/tokens/email_verification.rb
197
197
  - app/models/tokens/one_time.rb
198
198
  - app/models/tokens/password_reset.rb
199
+ - app/models/tokens/session_uid.rb
199
200
  - authpwn_rails.gemspec
200
201
  - legacy/migrate_011_to_012.rb
201
202
  - legacy/migrate_09_to_010.rb
@@ -203,12 +204,14 @@ files:
203
204
  - lib/authpwn_rails/credential_model.rb
204
205
  - lib/authpwn_rails/current_user.rb
205
206
  - lib/authpwn_rails/engine.rb
207
+ - lib/authpwn_rails/expires.rb
206
208
  - lib/authpwn_rails/facebook_session.rb
207
209
  - lib/authpwn_rails/generators/all_generator.rb
208
210
  - lib/authpwn_rails/generators/templates/001_create_users.rb
209
211
  - lib/authpwn_rails/generators/templates/003_create_credentials.rb
210
212
  - lib/authpwn_rails/generators/templates/credential.rb
211
213
  - lib/authpwn_rails/generators/templates/credentials.yml
214
+ - lib/authpwn_rails/generators/templates/initializer.rb
212
215
  - lib/authpwn_rails/generators/templates/session/forbidden.html.erb
213
216
  - lib/authpwn_rails/generators/templates/session/home.html.erb
214
217
  - lib/authpwn_rails/generators/templates/session/new.html.erb
@@ -241,6 +244,7 @@ files:
241
244
  - test/credentials/one_time_token_credential_test.rb
242
245
  - test/credentials/password_credential_test.rb
243
246
  - test/credentials/password_reset_token_test.rb
247
+ - test/credentials/session_uid_token_test.rb
244
248
  - test/credentials/token_crendential_test.rb
245
249
  - test/facebook_controller_test.rb
246
250
  - test/fixtures/bare_session/forbidden.html.erb
@@ -256,9 +260,11 @@ files:
256
260
  - test/helpers/routes.rb
257
261
  - test/helpers/view_helpers.rb
258
262
  - test/http_basic_controller_test.rb
263
+ - test/initializer_test.rb
259
264
  - test/routes_test.rb
260
265
  - test/session_controller_api_test.rb
261
266
  - test/session_mailer_api_test.rb
267
+ - test/test_extensions_test.rb
262
268
  - test/test_helper.rb
263
269
  - test/user_extensions/email_field_test.rb
264
270
  - test/user_extensions/facebook_fields_test.rb
@@ -279,7 +285,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
279
285
  version: '0'
280
286
  segments:
281
287
  - 0
282
- hash: 2906740583924378223
288
+ hash: 4464495416488992138
283
289
  required_rubygems_version: !ruby/object:Gem::Requirement
284
290
  none: false
285
291
  requirements: