signinable 1.1.2 → 2.0.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +2 -6
  3. data/Rakefile +7 -12
  4. data/{lib/generators/signinable/templates → app/models}/signin.rb +0 -0
  5. data/config/routes.rb +2 -0
  6. data/{lib/generators/signinable/templates/create_signins.rb → db/migrate/20140103165607_create_signins.rb} +0 -0
  7. data/lib/signinable.rb +1 -0
  8. data/lib/signinable/engine.rb +18 -0
  9. data/lib/signinable/version.rb +1 -1
  10. data/spec/dummy/README.rdoc +28 -0
  11. data/spec/dummy/Rakefile +6 -0
  12. data/spec/dummy/app/models/user.rb +3 -0
  13. data/spec/dummy/bin/bundle +3 -0
  14. data/spec/dummy/bin/rails +4 -0
  15. data/spec/dummy/bin/rake +4 -0
  16. data/spec/dummy/config.ru +4 -0
  17. data/spec/dummy/config/application.rb +28 -0
  18. data/spec/dummy/config/boot.rb +5 -0
  19. data/spec/dummy/config/database.yml +25 -0
  20. data/spec/dummy/config/environment.rb +5 -0
  21. data/spec/dummy/config/environments/development.rb +29 -0
  22. data/spec/dummy/config/environments/production.rb +80 -0
  23. data/spec/dummy/config/environments/test.rb +36 -0
  24. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  25. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  26. data/spec/dummy/config/initializers/inflections.rb +16 -0
  27. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  28. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  29. data/spec/dummy/config/initializers/session_store.rb +3 -0
  30. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  31. data/spec/dummy/config/locales/en.yml +23 -0
  32. data/spec/dummy/config/routes.rb +56 -0
  33. data/spec/dummy/db/migrate/20140103165606_create_users.rb +11 -0
  34. data/spec/dummy/db/schema.rb +35 -0
  35. data/spec/dummy/db/test.sqlite3 +0 -0
  36. data/spec/dummy/log/development.log +128 -0
  37. data/spec/dummy/log/test.log +1180 -0
  38. data/spec/dummy/public/404.html +58 -0
  39. data/spec/dummy/public/422.html +58 -0
  40. data/spec/dummy/public/500.html +57 -0
  41. data/spec/dummy/public/favicon.ico +0 -0
  42. data/spec/factories/signin.rb +8 -0
  43. data/spec/factories/user.rb +7 -0
  44. data/spec/models/signin_spec.rb +50 -0
  45. data/spec/models/user_spec.rb +133 -0
  46. data/spec/spec_helper.rb +18 -0
  47. data/spec/support/utilities.rb +8 -0
  48. metadata +82 -6
  49. data/lib/generators/signinable/USEGA +0 -6
  50. data/lib/generators/signinable/signinable_generator.rb +0 -15
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,8 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :signin do
5
+ ip "127.0.0.1"
6
+ signinable
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :user, :aliases => [:signinable] do
5
+ name "test"
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Signin do
4
+ it "has a valid factory" do
5
+ signin = FactoryGirl.build(:signin)
6
+ signin.should be_valid
7
+ end
8
+
9
+ context "is invalid without" do
10
+ it "a token" do
11
+ signin = FactoryGirl.create(:signin)
12
+ signin.token = nil
13
+ signin.should_not be_valid
14
+ end
15
+
16
+ it "an ip" do
17
+ FactoryGirl.build(:signin, ip: nil).should_not be_valid
18
+ end
19
+ end
20
+
21
+ it "should generate token on create" do
22
+ signin = FactoryGirl.create(:signin, token: nil)
23
+ signin.token.should_not be_nil
24
+ end
25
+
26
+ context "not valid with" do
27
+ it "wrong ip" do
28
+ FactoryGirl.build(:signin, ip: "123").should_not be_valid
29
+ end
30
+ end
31
+
32
+ it "should expire" do
33
+ Timecop.freeze
34
+ expiration_time = Time.zone.now + 1.hour
35
+ signin = FactoryGirl.create(:signin, expiration_time: expiration_time)
36
+ Timecop.travel(expiration_time)
37
+ signin.should be_expired
38
+ Timecop.return
39
+ end
40
+
41
+ describe ".expire!" do
42
+ it "should set expiration_time to now" do
43
+ Timecop.freeze
44
+ signin = FactoryGirl.create(:signin, expiration_time: (Time.zone.now + 1.hour))
45
+ signin.expire!
46
+ signin.should be_expired
47
+ Timecop.return
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe User do
4
+ before :each do
5
+ Timecop.freeze
6
+ User.signin_expiration = 2.hours
7
+ User.signin_simultaneous = true
8
+ User.signin_restrictions = []
9
+ @user = FactoryGirl.create(:user)
10
+ @credentials = ['127.0.0.1', 'user_agent']
11
+ @other_credentials = ['127.0.0.2', 'user_agent2']
12
+ end
13
+
14
+ after :each do
15
+ Timecop.return
16
+ end
17
+
18
+ describe ".signin" do
19
+ it "should create Signin" do
20
+ expect {
21
+ sign_in_user(@user, @credentials)
22
+ }.to change(Signin, :count).by(1)
23
+ end
24
+
25
+ it "should set expiration_time" do
26
+ signin = sign_in_user(@user, @credentials)
27
+ signin.expiration_time.to_i.should eq((Time.zone.now + User.signin_expiration).to_i)
28
+ end
29
+
30
+ it "should not set expiration_time" do
31
+ User.signin_expiration = 0
32
+ signin = sign_in_user(@user, @credentials)
33
+ signin.expiration_time.should be_nil
34
+ end
35
+ end
36
+
37
+ describe ".signout" do
38
+ it "should expire signin" do
39
+ signin = sign_in_user(@user, @credentials)
40
+ sign_out_user(signin, @credentials)
41
+ signin.reload
42
+ signin.should be_expired
43
+ end
44
+
45
+ context "should be allowed with" do
46
+ %w{ip user_agent}.each do |c|
47
+ it "changed #{c} if not restricted" do
48
+ signin = sign_in_user(@user, @credentials)
49
+ sign_out_user(signin, @credentials).should be_true
50
+ end
51
+ end
52
+ end
53
+
54
+ context "should not be allowed with" do
55
+ %w{ip user_agent}.each do |c|
56
+ it "changed #{c} if restricted" do
57
+ User.signin_restrictions = [c]
58
+ signin = sign_in_user(@user, @credentials)
59
+ sign_out_user(signin, @other_credentials).should be_nil
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "#authenticate_with_token" do
66
+ context "expiration_time" do
67
+ it "should be changed after authentication" do
68
+ signin = sign_in_user(@user, @credentials)
69
+ old_time = signin.expiration_time
70
+ new_time = signin.expiration_time - 1.hour
71
+ Timecop.travel(new_time)
72
+ User.authenticate_with_token(signin.token, *@credentials)
73
+ signin.reload
74
+ signin.expiration_time.to_i.should eq((new_time + User.signin_expiration).to_i)
75
+ end
76
+
77
+ it "should not be changed after authentication" do
78
+ User.signin_expiration = 0
79
+ signin = sign_in_user(@user, @credentials)
80
+ old_time = signin.expiration_time
81
+ Timecop.travel(Time.zone.now + 1.hour)
82
+ User.authenticate_with_token(signin.token, *@credentials)
83
+ signin.reload
84
+ signin.expiration_time.to_i.should eq(old_time.to_i)
85
+ end
86
+ end
87
+
88
+ context "should allow signin with" do
89
+ it "not last token if simultaneous is permitted" do
90
+ signin1 = sign_in_user(@user, @credentials)
91
+ signin2 = sign_in_user(@user, @credentials)
92
+ User.authenticate_with_token(signin1.token, *@credentials).should eq(@user)
93
+ User.authenticate_with_token(signin2.token, *@credentials).should eq(@user)
94
+ end
95
+
96
+ it "valid token" do
97
+ signin = sign_in_user(@user, @credentials)
98
+ User.authenticate_with_token(signin.token, *@credentials).should eq(@user)
99
+ end
100
+
101
+ %w{ip user_agent}.each do |c|
102
+ it "changed #{c} if not restricted" do
103
+ signin = sign_in_user(@user, @credentials)
104
+ User.authenticate_with_token(signin.token, *@other_credentials).should eq(@user)
105
+ end
106
+ end
107
+ end
108
+
109
+ context "should not allow signin with" do
110
+ it "not last token if simultaneous not permitted" do
111
+ User.signin_simultaneous = false
112
+ signin1 = sign_in_user(@user, @credentials)
113
+ signin2 = sign_in_user(@user, @credentials)
114
+ User.authenticate_with_token(signin1.token, *@credentials).should be_nil
115
+ User.authenticate_with_token(signin2.token, *@credentials).should eq(@user)
116
+ end
117
+
118
+ it "expired token" do
119
+ signin = sign_in_user(@user, @credentials)
120
+ @user.signout(signin.token, *@credentials)
121
+ User.authenticate_with_token(signin.token, *@credentials).should be_nil
122
+ end
123
+
124
+ %w{ip user_agent}.each do |c|
125
+ it "changed #{c} if restricted" do
126
+ User.signin_restrictions = [c]
127
+ signin = sign_in_user(@user, @credentials)
128
+ User.authenticate_with_token(signin.token, *@other_credentials).should be_nil
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,18 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require File.expand_path('../dummy/config/environment', __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+ require 'factory_girl_rails'
7
+ require 'timecop'
8
+
9
+ Rails.backtrace_cleaner.remove_silencers!
10
+
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ RSpec.configure do |config|
14
+ config.mock_with :rspec
15
+ config.use_transactional_fixtures = false
16
+ config.infer_base_class_for_anonymous_controllers = false
17
+ config.order = 'random'
18
+ end
@@ -0,0 +1,8 @@
1
+ def sign_in_user(user, credentials)
2
+ token = user.signin(*credentials, 'referer')
3
+ Signin.find_by_token(token)
4
+ end
5
+
6
+ def sign_out_user(signin, credentials)
7
+ signin.signinable.signout(signin.token, *credentials)
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: signinable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Novozhenets
@@ -90,13 +90,51 @@ files:
90
90
  - MIT-LICENSE
91
91
  - README.rdoc
92
92
  - Rakefile
93
- - lib/generators/signinable/USEGA
94
- - lib/generators/signinable/signinable_generator.rb
95
- - lib/generators/signinable/templates/create_signins.rb
96
- - lib/generators/signinable/templates/signin.rb
93
+ - app/models/signin.rb
94
+ - config/routes.rb
95
+ - db/migrate/20140103165607_create_signins.rb
97
96
  - lib/signinable.rb
97
+ - lib/signinable/engine.rb
98
98
  - lib/signinable/model_additions.rb
99
99
  - lib/signinable/version.rb
100
+ - spec/dummy/README.rdoc
101
+ - spec/dummy/Rakefile
102
+ - spec/dummy/app/models/user.rb
103
+ - spec/dummy/bin/bundle
104
+ - spec/dummy/bin/rails
105
+ - spec/dummy/bin/rake
106
+ - spec/dummy/config.ru
107
+ - spec/dummy/config/application.rb
108
+ - spec/dummy/config/boot.rb
109
+ - spec/dummy/config/database.yml
110
+ - spec/dummy/config/environment.rb
111
+ - spec/dummy/config/environments/development.rb
112
+ - spec/dummy/config/environments/production.rb
113
+ - spec/dummy/config/environments/test.rb
114
+ - spec/dummy/config/initializers/backtrace_silencers.rb
115
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
116
+ - spec/dummy/config/initializers/inflections.rb
117
+ - spec/dummy/config/initializers/mime_types.rb
118
+ - spec/dummy/config/initializers/secret_token.rb
119
+ - spec/dummy/config/initializers/session_store.rb
120
+ - spec/dummy/config/initializers/wrap_parameters.rb
121
+ - spec/dummy/config/locales/en.yml
122
+ - spec/dummy/config/routes.rb
123
+ - spec/dummy/db/migrate/20140103165606_create_users.rb
124
+ - spec/dummy/db/schema.rb
125
+ - spec/dummy/db/test.sqlite3
126
+ - spec/dummy/log/development.log
127
+ - spec/dummy/log/test.log
128
+ - spec/dummy/public/404.html
129
+ - spec/dummy/public/422.html
130
+ - spec/dummy/public/500.html
131
+ - spec/dummy/public/favicon.ico
132
+ - spec/factories/signin.rb
133
+ - spec/factories/user.rb
134
+ - spec/models/signin_spec.rb
135
+ - spec/models/user_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/support/utilities.rb
100
138
  homepage: https://github.com/novozhenets/signinable
101
139
  licenses: []
102
140
  metadata: {}
@@ -120,4 +158,42 @@ rubygems_version: 2.2.0
120
158
  signing_key:
121
159
  specification_version: 4
122
160
  summary: Token based signin
123
- test_files: []
161
+ test_files:
162
+ - spec/dummy/app/models/user.rb
163
+ - spec/dummy/bin/bundle
164
+ - spec/dummy/bin/rails
165
+ - spec/dummy/bin/rake
166
+ - spec/dummy/config/application.rb
167
+ - spec/dummy/config/boot.rb
168
+ - spec/dummy/config/database.yml
169
+ - spec/dummy/config/environment.rb
170
+ - spec/dummy/config/environments/development.rb
171
+ - spec/dummy/config/environments/production.rb
172
+ - spec/dummy/config/environments/test.rb
173
+ - spec/dummy/config/initializers/backtrace_silencers.rb
174
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
175
+ - spec/dummy/config/initializers/inflections.rb
176
+ - spec/dummy/config/initializers/mime_types.rb
177
+ - spec/dummy/config/initializers/secret_token.rb
178
+ - spec/dummy/config/initializers/session_store.rb
179
+ - spec/dummy/config/initializers/wrap_parameters.rb
180
+ - spec/dummy/config/locales/en.yml
181
+ - spec/dummy/config/routes.rb
182
+ - spec/dummy/config.ru
183
+ - spec/dummy/db/migrate/20140103165606_create_users.rb
184
+ - spec/dummy/db/schema.rb
185
+ - spec/dummy/db/test.sqlite3
186
+ - spec/dummy/log/development.log
187
+ - spec/dummy/log/test.log
188
+ - spec/dummy/public/404.html
189
+ - spec/dummy/public/422.html
190
+ - spec/dummy/public/500.html
191
+ - spec/dummy/public/favicon.ico
192
+ - spec/dummy/Rakefile
193
+ - spec/dummy/README.rdoc
194
+ - spec/factories/signin.rb
195
+ - spec/factories/user.rb
196
+ - spec/models/signin_spec.rb
197
+ - spec/models/user_spec.rb
198
+ - spec/spec_helper.rb
199
+ - spec/support/utilities.rb