diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-08 06:08:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-08 06:08:19 +0300 |
commit | bf293d47937b3332462689c3fecc868706553f3a (patch) | |
tree | 47f0f1063aa27e4529c23068537ce45d6adb4cf0 /spec/models | |
parent | 356e3c444dc8fab920d3547461b6ae721c5eb50f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/token_authenticatable_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/personal_access_token_spec.rb | 30 |
2 files changed, 10 insertions, 22 deletions
diff --git a/spec/models/concerns/token_authenticatable_spec.rb b/spec/models/concerns/token_authenticatable_spec.rb index 7367577914c..70123eaac26 100644 --- a/spec/models/concerns/token_authenticatable_spec.rb +++ b/spec/models/concerns/token_authenticatable_spec.rb @@ -130,7 +130,7 @@ RSpec.describe PersonalAccessToken, 'TokenAuthenticatable' do let(:token_digest) { Gitlab::CryptoHelper.sha256(token_value) } let(:user) { create(:user) } let(:personal_access_token) do - described_class.new(name: 'test-pat-01', user_id: user.id, scopes: [:api], token_digest: token_digest) + described_class.new(name: 'test-pat-01', user_id: user.id, scopes: [:api], token_digest: token_digest, expires_at: 30.days.from_now) end before do diff --git a/spec/models/personal_access_token_spec.rb b/spec/models/personal_access_token_spec.rb index 5ba9597a519..8e86518912c 100644 --- a/spec/models/personal_access_token_spec.rb +++ b/spec/models/personal_access_token_spec.rb @@ -259,6 +259,13 @@ RSpec.describe PersonalAccessToken, feature_category: :system_access do context 'validates expires_at' do let(:max_expiration_date) { described_class::MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS.days.from_now } + it "can't be blank" do + personal_access_token.expires_at = nil + + expect(personal_access_token).not_to be_valid + expect(personal_access_token.errors[:expires_at].first).to eq("can't be blank") + end + context 'when expires_in is less than MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS days' do it 'is valid' do personal_access_token.expires_at = max_expiration_date - 1.day @@ -285,11 +292,10 @@ RSpec.describe PersonalAccessToken, feature_category: :system_access do let_it_be(:not_revoked_nil_token) { create(:personal_access_token, revoked: nil) } let_it_be(:expired_token) { create(:personal_access_token, :expired) } let_it_be(:not_expired_token) { create(:personal_access_token) } - let_it_be(:never_expires_token) { create(:personal_access_token, expires_at: nil) } - it 'includes non-revoked and non-expired tokens' do + it 'includes non-revoked tokens' do expect(described_class.active) - .to match_array([not_revoked_false_token, not_revoked_nil_token, not_expired_token, never_expires_token]) + .to match_array([not_revoked_false_token, not_revoked_nil_token, not_expired_token]) end end @@ -414,22 +420,4 @@ RSpec.describe PersonalAccessToken, feature_category: :system_access do end end end - - describe '#expires_at=' do - let(:personal_access_token) { described_class.new } - - context 'expires_at set to empty value' do - [nil, ""].each do |expires_in_value| - it 'defaults to PersonalAccessToken::MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS' do - personal_access_token.expires_at = expires_in_value - - freeze_time do - expect(personal_access_token.expires_at).to eq( - PersonalAccessToken::MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS.days.from_now.to_date - ) - end - end - end - end - end end |