Commit c8fa78af authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'deploy-token-policy-actor-deactivated' into 'master'

Implement `deactivated?` for deploy tokens

See merge request gitlab-org/gitlab!47698
parents 81fdc3f0 4b03c83a
......@@ -54,6 +54,10 @@ class DeployToken < ApplicationRecord
!revoked && !expired?
end
def deactivated?
!active?
end
def scopes
AVAILABLE_SCOPES.select { |token_scope| read_attribute(token_scope) }
end
......
......@@ -124,6 +124,39 @@ RSpec.describe DeployToken do
end
end
# override the default PolicyActor implementation that always returns false
describe "#deactivated?" do
context "when it has been revoked" do
it 'returns true' do
deploy_token.revoke!
expect(deploy_token.deactivated?).to be_truthy
end
end
context "when it hasn't been revoked and is not expired" do
it 'returns false' do
expect(deploy_token.deactivated?).to be_falsy
end
end
context "when it hasn't been revoked and is expired" do
it 'returns false' do
deploy_token.update_attribute(:expires_at, Date.today - 5.days)
expect(deploy_token.deactivated?).to be_truthy
end
end
context "when it hasn't been revoked and has no expiry" do
let(:deploy_token) { create(:deploy_token, expires_at: nil) }
it 'returns false' do
expect(deploy_token.deactivated?).to be_falsy
end
end
end
describe '#username' do
context 'persisted records' do
it 'returns a default username if none is set' 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