debian-mirror-gitlab/spec/lib/gitlab/background_migration/digest_column_spec.rb

47 lines
1.7 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-04-08 14:13:33 +05:30
describe Gitlab::BackgroundMigration::DigestColumn, schema: 20180913142237 do
2018-11-18 11:00:15 +05:30
let(:personal_access_tokens) { table(:personal_access_tokens) }
let(:users) { table(:users) }
subject { described_class.new }
describe '#perform' do
context 'token is not yet hashed' do
before do
users.create(id: 1, email: 'user@example.com', projects_limit: 10)
personal_access_tokens.create!(id: 1, user_id: 1, name: 'pat-01', token: 'token-01')
end
it 'saves token digest' do
expect { subject.perform(PersonalAccessToken, :token, :token_digest, 1, 2) }.to(
change { PersonalAccessToken.find(1).token_digest }.from(nil).to(Gitlab::CryptoHelper.sha256('token-01')))
end
it 'erases token' do
expect { subject.perform(PersonalAccessToken, :token, :token_digest, 1, 2) }.to(
2019-07-07 11:18:12 +05:30
change { PersonalAccessToken.find(1).read_attribute(:token) }.from('token-01').to(nil))
2018-11-18 11:00:15 +05:30
end
end
context 'token is already hashed' do
before do
users.create(id: 1, email: 'user@example.com', projects_limit: 10)
personal_access_tokens.create!(id: 1, user_id: 1, name: 'pat-01', token_digest: 'token-digest-01')
end
it 'does not change existing token digest' do
expect { subject.perform(PersonalAccessToken, :token, :token_digest, 1, 2) }.not_to(
change { PersonalAccessToken.find(1).token_digest })
end
it 'leaves token empty' do
expect { subject.perform(PersonalAccessToken, :token, :token_digest, 1, 2) }.not_to(
2019-07-07 11:18:12 +05:30
change { PersonalAccessToken.find(1).read_attribute(:token) }.from(nil))
2018-11-18 11:00:15 +05:30
end
end
end
end