signinable 2.0.13 → 2.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -77,10 +77,18 @@ describe User do
77
77
  end
78
78
 
79
79
  describe '#signout' do
80
+ it 'ignores expired signin' do
81
+ sign_in_user(user, credentials)
82
+ signin = user.last_signin
83
+ Timecop.travel(signin.expiration_time) do
84
+ expect(sign_out_user(user, credentials)).to be_falsey
85
+ end
86
+ end
87
+
80
88
  it 'should expire signin' do
81
89
  sign_in_user(user, credentials)
82
90
  signin = user.last_signin
83
- sign_out_user(signin, credentials)
91
+ sign_out_user(user, credentials)
84
92
  expect(signin.reload).to be_expired
85
93
  end
86
94
 
@@ -88,8 +96,7 @@ describe User do
88
96
  %i[ip user_agent].each do |c|
89
97
  it "allows signout when #{c} changes" do
90
98
  sign_in_user(user, credentials)
91
- signin = user.last_signin
92
- expect(sign_out_user(signin, credentials)).to be_truthy
99
+ expect(sign_out_user(user, credentials)).to be_truthy
93
100
  end
94
101
  end
95
102
  end
@@ -99,8 +106,7 @@ describe User do
99
106
  it "forbids signout when #{c} changes" do
100
107
  allow(described_class).to receive(:signin_restrictions).and_return([c])
101
108
  sign_in_user(user, credentials)
102
- signin = user.last_signin
103
- expect(sign_out_user(signin, other_credentials)).to be_nil
109
+ expect(sign_out_user(user, other_credentials)).to be_nil
104
110
  end
105
111
  end
106
112
  end
@@ -148,10 +154,19 @@ describe User do
148
154
  sign_in_user(user, credentials)
149
155
  end
150
156
 
157
+ it 'returns nil if user not found' do
158
+ allow(described_class).to receive(:find_by).and_return(nil)
159
+ expect(described_class.authenticate_with_token(user.jwt, *credentials)).to be_nil
160
+ end
161
+
151
162
  it 'returns user' do
152
163
  expect(described_class.authenticate_with_token(user.jwt, *credentials)).to eq(user)
153
164
  end
154
165
 
166
+ it 'returns jwt with user' do
167
+ expect(described_class.authenticate_with_token(user.jwt, *credentials).jwt).to eq(user.jwt)
168
+ end
169
+
155
170
  it 'does not update refresh token' do
156
171
  allow(described_class).to receive(:refresh_jwt)
157
172
  described_class.authenticate_with_token(user.jwt, *credentials)
@@ -4,6 +4,6 @@ def sign_in_user(user, credentials)
4
4
  user.signin(*credentials, 'referer')
5
5
  end
6
6
 
7
- def sign_out_user(signin, credentials)
8
- signin.signinable.signout(signin.token, *credentials)
7
+ def sign_out_user(user, credentials)
8
+ user.signout(user.jwt, *credentials)
9
9
  end
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.13
4
+ version: 2.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Novozhenets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-15 00:00:00.000000000 Z
11
+ date: 2022-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt