Commit c60cb393 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'bvl-deploy-token' into 'master'

Fix deploy tokens without `expire_at` crashes

Closes #49904

See merge request gitlab-org/gitlab-ce!20992
parents 367e7520 a6268d30
...@@ -30,7 +30,7 @@ class DeployToken < ActiveRecord::Base ...@@ -30,7 +30,7 @@ class DeployToken < ActiveRecord::Base
end end
def active? def active?
!revoked && expires_at > Date.today !revoked && !expired?
end end
def scopes def scopes
...@@ -63,6 +63,12 @@ class DeployToken < ActiveRecord::Base ...@@ -63,6 +63,12 @@ class DeployToken < ActiveRecord::Base
private private
def expired?
return false unless expires_at
expires_at < Date.today
end
def ensure_at_least_one_scope def ensure_at_least_one_scope
errors.add(:base, "Scopes can't be blank") unless read_repository || read_registry errors.add(:base, "Scopes can't be blank") unless read_repository || read_registry
end end
......
...@@ -74,6 +74,14 @@ describe DeployToken do ...@@ -74,6 +74,14 @@ describe DeployToken do
expect(deploy_token.active?).to be_falsy expect(deploy_token.active?).to be_falsy
end end
end end
context "when it hasn't been revoked and has no expiry" do
let(:deploy_token) { create(:deploy_token, expires_at: nil) }
it 'should return true' do
expect(deploy_token.active?).to be_truthy
end
end
end end
describe '#username' do describe '#username' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment