signinable 2.0.11 → 2.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -4
- data/app/models/signin.rb +12 -2
- data/config/routes.rb +2 -0
- data/db/migrate/20140103165607_create_signins.rb +7 -5
- data/db/migrate/20180530131006_add_custom_data_to_sigins.rb +5 -5
- data/lib/signinable/engine.rb +4 -9
- data/lib/signinable/model_additions.rb +77 -51
- data/lib/signinable/version.rb +3 -1
- data/lib/signinable.rb +3 -1
- data/spec/dummy/Rakefile +3 -1
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/bin/bundle +3 -1
- data/spec/dummy/bin/rails +3 -1
- data/spec/dummy/bin/rake +2 -0
- data/spec/dummy/config/application.rb +5 -20
- data/spec/dummy/config/boot.rb +5 -3
- data/spec/dummy/config/environment.rb +3 -1
- data/spec/dummy/config/environments/development.rb +4 -2
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +4 -2
- data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +1 -0
- data/spec/dummy/config/initializers/mime_types.rb +1 -0
- data/spec/dummy/config/initializers/secret_token.rb +2 -0
- data/spec/dummy/config/initializers/session_store.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140103165606_create_users.rb +3 -1
- data/spec/dummy/db/schema.rb +23 -24
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +427 -0
- data/spec/dummy/log/test.log +8192 -0
- data/spec/factories/signins.rb +8 -0
- data/spec/factories/users.rb +7 -0
- data/spec/models/signin_spec.rb +25 -23
- data/spec/models/user_spec.rb +71 -72
- data/spec/rails_helper.rb +20 -0
- data/spec/spec_helper.rb +11 -12
- data/spec/support/utilities.rb +2 -0
- metadata +39 -14
- data/spec/factories/signin.rb +0 -8
- data/spec/factories/user.rb +0 -7
data/spec/models/signin_spec.rb
CHANGED
@@ -1,49 +1,51 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
2
4
|
|
3
5
|
describe Signin do
|
4
|
-
it
|
5
|
-
signin =
|
6
|
-
signin.
|
6
|
+
it 'has a valid factory' do
|
7
|
+
signin = build(:signin)
|
8
|
+
expect(signin).to be_valid
|
7
9
|
end
|
8
10
|
|
9
|
-
context
|
10
|
-
it
|
11
|
-
signin =
|
11
|
+
context 'is invalid without' do
|
12
|
+
it 'a token' do
|
13
|
+
signin = create(:signin)
|
12
14
|
signin.token = nil
|
13
|
-
signin.
|
15
|
+
expect(signin).to_not be_valid
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
17
|
-
|
18
|
+
it 'an ip' do
|
19
|
+
expect(build(:signin, ip: nil)).to_not be_valid
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
it
|
22
|
-
signin =
|
23
|
-
signin.token.
|
23
|
+
it 'should generate token on create' do
|
24
|
+
signin = create(:signin, token: nil)
|
25
|
+
expect(signin.token).to_not be_nil
|
24
26
|
end
|
25
27
|
|
26
|
-
context
|
27
|
-
it
|
28
|
-
|
28
|
+
context 'not valid with' do
|
29
|
+
it 'wrong ip' do
|
30
|
+
expect(build(:signin, ip: '123')).to_not be_valid
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
it
|
34
|
+
it 'should expire' do
|
33
35
|
Timecop.freeze
|
34
36
|
expiration_time = Time.zone.now + 1.hour
|
35
|
-
signin =
|
37
|
+
signin = create(:signin, expiration_time: expiration_time)
|
36
38
|
Timecop.travel(expiration_time)
|
37
|
-
signin.
|
39
|
+
expect(signin).to be_expired
|
38
40
|
Timecop.return
|
39
41
|
end
|
40
42
|
|
41
|
-
describe
|
42
|
-
it
|
43
|
+
describe '.expire!' do
|
44
|
+
it 'should set expiration_time to now' do
|
43
45
|
Timecop.freeze
|
44
|
-
signin =
|
46
|
+
signin = create(:signin, expiration_time: (Time.zone.now + 1.hour))
|
45
47
|
signin.expire!
|
46
|
-
signin.
|
48
|
+
expect(signin).to be_expired
|
47
49
|
Timecop.return
|
48
50
|
end
|
49
51
|
end
|
data/spec/models/user_spec.rb
CHANGED
@@ -1,131 +1,130 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
2
4
|
|
3
5
|
describe User do
|
6
|
+
let(:credentials) { ['127.0.0.1', 'user_agent'] }
|
7
|
+
let(:other_credentials) { ['127.0.0.2', 'user_agent2'] }
|
8
|
+
let(:user) { create(:user) }
|
9
|
+
|
4
10
|
before :each do
|
5
11
|
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
12
|
end
|
13
13
|
|
14
14
|
after :each do
|
15
15
|
Timecop.return
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
expect
|
21
|
-
sign_in_user(
|
22
|
-
|
18
|
+
describe '.signin' do
|
19
|
+
it 'should create Signin' do
|
20
|
+
expect do
|
21
|
+
sign_in_user(user, credentials)
|
22
|
+
end.to change(Signin, :count).by(1)
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
signin = sign_in_user(
|
27
|
-
signin.expiration_time.to_i.
|
25
|
+
it 'should set expiration_time' do
|
26
|
+
signin = sign_in_user(user, credentials)
|
27
|
+
expect(signin.expiration_time.to_i).to eq((Time.zone.now + User.signin_expiration).to_i)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
31
|
-
User.signin_expiration
|
32
|
-
signin = sign_in_user(
|
33
|
-
signin.expiration_time.
|
30
|
+
it 'should not set expiration_time' do
|
31
|
+
allow(User).to receive(:signin_expiration).and_return(0)
|
32
|
+
signin = sign_in_user(user, credentials)
|
33
|
+
expect(signin.expiration_time).to be_nil
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
38
|
-
it
|
39
|
-
signin = sign_in_user(
|
40
|
-
sign_out_user(signin,
|
41
|
-
signin.reload
|
42
|
-
signin.should be_expired
|
37
|
+
describe '.signout' do
|
38
|
+
it 'should expire signin' do
|
39
|
+
signin = sign_in_user(user, credentials)
|
40
|
+
sign_out_user(signin, credentials)
|
41
|
+
expect(signin.reload).to be_expired
|
43
42
|
end
|
44
43
|
|
45
|
-
context
|
46
|
-
%
|
44
|
+
context 'should be allowed with' do
|
45
|
+
%i[ip user_agent].each do |c|
|
47
46
|
it "changed #{c} if not restricted" do
|
48
|
-
signin = sign_in_user(
|
49
|
-
sign_out_user(signin,
|
47
|
+
signin = sign_in_user(user, credentials)
|
48
|
+
expect(sign_out_user(signin, credentials)).to be_truthy
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
context
|
55
|
-
%
|
53
|
+
context 'should not be allowed with' do
|
54
|
+
%i[ip user_agent].each do |c|
|
56
55
|
it "changed #{c} if restricted" do
|
57
|
-
User.signin_restrictions
|
58
|
-
signin = sign_in_user(
|
59
|
-
sign_out_user(signin,
|
56
|
+
allow(User).to receive(:signin_restrictions).and_return([c])
|
57
|
+
signin = sign_in_user(user, credentials)
|
58
|
+
expect(sign_out_user(signin, other_credentials)).to be_nil
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
|
-
describe
|
66
|
-
context
|
67
|
-
it
|
68
|
-
signin = sign_in_user(
|
64
|
+
describe '#authenticate_with_token' do
|
65
|
+
context 'expiration_time' do
|
66
|
+
it 'should be changed after authentication' do
|
67
|
+
signin = sign_in_user(user, credentials)
|
69
68
|
old_time = signin.expiration_time
|
70
69
|
new_time = signin.expiration_time - 1.hour
|
71
70
|
Timecop.travel(new_time)
|
72
|
-
User.authenticate_with_token(signin.token,
|
71
|
+
User.authenticate_with_token(signin.token, *credentials)
|
73
72
|
signin.reload
|
74
|
-
signin.expiration_time.to_i.
|
73
|
+
expect(signin.expiration_time.to_i).to eq((new_time + User.signin_expiration).to_i)
|
75
74
|
end
|
76
75
|
|
77
|
-
it
|
78
|
-
User.signin_expiration
|
79
|
-
signin = sign_in_user(
|
76
|
+
it 'should not be changed after authentication' do
|
77
|
+
allow(User).to receive(:signin_expiration).and_return(0)
|
78
|
+
signin = sign_in_user(user, credentials)
|
80
79
|
old_time = signin.expiration_time
|
81
80
|
Timecop.travel(Time.zone.now + 1.hour)
|
82
|
-
User.authenticate_with_token(signin.token,
|
81
|
+
User.authenticate_with_token(signin.token, *credentials)
|
83
82
|
signin.reload
|
84
|
-
signin.expiration_time.to_i.
|
83
|
+
expect(signin.expiration_time.to_i).to eq(old_time.to_i)
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
88
|
-
context
|
89
|
-
it
|
90
|
-
signin1 = sign_in_user(
|
91
|
-
signin2 = sign_in_user(
|
92
|
-
User.authenticate_with_token(signin1.token,
|
93
|
-
User.authenticate_with_token(signin2.token,
|
87
|
+
context 'should allow signin with' do
|
88
|
+
it 'not last token if simultaneous is permitted' do
|
89
|
+
signin1 = sign_in_user(user, credentials)
|
90
|
+
signin2 = sign_in_user(user, credentials)
|
91
|
+
expect(User.authenticate_with_token(signin1.token, *credentials)).to eq(user)
|
92
|
+
expect(User.authenticate_with_token(signin2.token, *credentials)).to eq(user)
|
94
93
|
end
|
95
94
|
|
96
|
-
it
|
97
|
-
signin = sign_in_user(
|
98
|
-
User.authenticate_with_token(signin.token,
|
95
|
+
it 'valid token' do
|
96
|
+
signin = sign_in_user(user, credentials)
|
97
|
+
expect(User.authenticate_with_token(signin.token, *credentials)).to eq(user)
|
99
98
|
end
|
100
99
|
|
101
|
-
%
|
100
|
+
%i[ip user_agent].each do |c|
|
102
101
|
it "changed #{c} if not restricted" do
|
103
|
-
signin = sign_in_user(
|
104
|
-
User.authenticate_with_token(signin.token,
|
102
|
+
signin = sign_in_user(user, credentials)
|
103
|
+
expect(User.authenticate_with_token(signin.token, *other_credentials)).to eq(user)
|
105
104
|
end
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
109
|
-
context
|
110
|
-
it
|
111
|
-
User.
|
112
|
-
signin1 = sign_in_user(
|
113
|
-
signin2 = sign_in_user(
|
114
|
-
User.authenticate_with_token(signin1.token,
|
115
|
-
User.authenticate_with_token(signin2.token,
|
108
|
+
context 'should not allow signin with' do
|
109
|
+
it 'not last token if simultaneous not permitted' do
|
110
|
+
allow(User).to receive(:simultaneous_signings).and_return(false)
|
111
|
+
signin1 = sign_in_user(user, credentials)
|
112
|
+
signin2 = sign_in_user(user, credentials)
|
113
|
+
expect(User.authenticate_with_token(signin1.token, *credentials)).to be_nil
|
114
|
+
expect(User.authenticate_with_token(signin2.token, *credentials)).to eq(user)
|
116
115
|
end
|
117
116
|
|
118
|
-
it
|
119
|
-
signin = sign_in_user(
|
120
|
-
|
121
|
-
User.authenticate_with_token(signin.token,
|
117
|
+
it 'expired token' do
|
118
|
+
signin = sign_in_user(user, credentials)
|
119
|
+
user.signout(signin.token, *credentials)
|
120
|
+
expect(User.authenticate_with_token(signin.token, *credentials)).to be_nil
|
122
121
|
end
|
123
122
|
|
124
|
-
%
|
123
|
+
%i[ip user_agent].each do |c|
|
125
124
|
it "changed #{c} if restricted" do
|
126
|
-
User.signin_restrictions
|
127
|
-
signin = sign_in_user(
|
128
|
-
User.authenticate_with_token(signin.token,
|
125
|
+
allow(User).to receive(:signin_restrictions).and_return([c])
|
126
|
+
signin = sign_in_user(user, credentials)
|
127
|
+
expect(User.authenticate_with_token(signin.token, *other_credentials)).to be_nil
|
129
128
|
end
|
130
129
|
end
|
131
130
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ENV['RAILS_ENV'] ||= 'test'
|
4
|
+
|
5
|
+
require File.expand_path('dummy/config/environment', __dir__)
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
require 'rspec/rails'
|
9
|
+
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.use_transactional_fixtures = true
|
14
|
+
|
15
|
+
config.infer_spec_type_from_file_location!
|
16
|
+
|
17
|
+
config.filter_rails_from_backtrace!
|
18
|
+
|
19
|
+
config.include FactoryBot::Syntax::Methods
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require '
|
5
|
-
require 'rspec/autorun'
|
6
|
-
require 'factory_girl_rails'
|
3
|
+
require 'factory_bot_rails'
|
4
|
+
require 'pry'
|
7
5
|
require 'timecop'
|
8
6
|
|
9
|
-
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.expect_with :rspec do |expectations|
|
9
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
+
config.mock_with :rspec do |mocks|
|
13
|
+
mocks.verify_partial_doubles = true
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
config.mock_with :rspec
|
15
|
-
config.use_transactional_fixtures = false
|
16
|
-
config.infer_base_class_for_anonymous_controllers = false
|
17
|
-
config.order = 'random'
|
16
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
18
17
|
end
|
data/spec/support/utilities.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: signinable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Novozhenets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,16 +16,30 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: factory_bot_rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: sqlite3
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
@@ -67,7 +81,7 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: timecop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -121,21 +135,27 @@ files:
|
|
121
135
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
122
136
|
- spec/dummy/config/locales/en.yml
|
123
137
|
- spec/dummy/config/routes.rb
|
138
|
+
- spec/dummy/db/development.sqlite3
|
124
139
|
- spec/dummy/db/migrate/20140103165606_create_users.rb
|
125
140
|
- spec/dummy/db/schema.rb
|
141
|
+
- spec/dummy/db/test.sqlite3
|
142
|
+
- spec/dummy/log/development.log
|
143
|
+
- spec/dummy/log/test.log
|
126
144
|
- spec/dummy/public/404.html
|
127
145
|
- spec/dummy/public/422.html
|
128
146
|
- spec/dummy/public/500.html
|
129
147
|
- spec/dummy/public/favicon.ico
|
130
|
-
- spec/factories/
|
131
|
-
- spec/factories/
|
148
|
+
- spec/factories/signins.rb
|
149
|
+
- spec/factories/users.rb
|
132
150
|
- spec/models/signin_spec.rb
|
133
151
|
- spec/models/user_spec.rb
|
152
|
+
- spec/rails_helper.rb
|
134
153
|
- spec/spec_helper.rb
|
135
154
|
- spec/support/utilities.rb
|
136
155
|
homepage: https://github.com/novozhenets/signinable
|
137
156
|
licenses: []
|
138
|
-
metadata:
|
157
|
+
metadata:
|
158
|
+
rubygems_mfa_required: 'true'
|
139
159
|
post_install_message:
|
140
160
|
rdoc_options: []
|
141
161
|
require_paths:
|
@@ -144,20 +164,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
164
|
requirements:
|
145
165
|
- - ">="
|
146
166
|
- !ruby/object:Gem::Version
|
147
|
-
version: '
|
167
|
+
version: '2.5'
|
148
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
169
|
requirements:
|
150
170
|
- - ">="
|
151
171
|
- !ruby/object:Gem::Version
|
152
172
|
version: '0'
|
153
173
|
requirements: []
|
154
|
-
rubygems_version: 3.1.
|
174
|
+
rubygems_version: 3.1.6
|
155
175
|
signing_key:
|
156
176
|
specification_version: 4
|
157
177
|
summary: Token based signin
|
158
178
|
test_files:
|
159
179
|
- spec/dummy/config.ru
|
160
180
|
- spec/dummy/README.rdoc
|
181
|
+
- spec/dummy/db/test.sqlite3
|
182
|
+
- spec/dummy/db/development.sqlite3
|
161
183
|
- spec/dummy/db/migrate/20140103165606_create_users.rb
|
162
184
|
- spec/dummy/db/schema.rb
|
163
185
|
- spec/dummy/config/environment.rb
|
@@ -185,9 +207,12 @@ test_files:
|
|
185
207
|
- spec/dummy/public/favicon.ico
|
186
208
|
- spec/dummy/public/404.html
|
187
209
|
- spec/dummy/public/422.html
|
210
|
+
- spec/dummy/log/test.log
|
211
|
+
- spec/dummy/log/development.log
|
212
|
+
- spec/rails_helper.rb
|
188
213
|
- spec/support/utilities.rb
|
189
|
-
- spec/factories/
|
190
|
-
- spec/factories/
|
214
|
+
- spec/factories/users.rb
|
215
|
+
- spec/factories/signins.rb
|
191
216
|
- spec/spec_helper.rb
|
192
217
|
- spec/models/signin_spec.rb
|
193
218
|
- spec/models/user_spec.rb
|
data/spec/factories/signin.rb
DELETED