Commit 718ea942 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve test cases description in token-related specs

parent 636b038e
......@@ -15,8 +15,6 @@ module TokenAuthenticatableStrategies
end
token_authenticatable
rescue ActiveRecord::StatementInvalid
nil
end
def ensure_token(instance)
......@@ -38,8 +36,8 @@ module TokenAuthenticatableStrategies
end
def get_token(instance)
raw_token = instance.read_attribute(encrypted_field)
token = Gitlab::CryptoHelper.aes256_gcm_decrypt(raw_token)
encrypted_token = instance.read_attribute(encrypted_field)
token = Gitlab::CryptoHelper.aes256_gcm_decrypt(encrypted_token)
token || (fallback_strategy.get_token(instance) if fallback?)
end
......@@ -61,7 +59,7 @@ module TokenAuthenticatableStrategies
def token_set?(instance)
raw_token = instance.read_attribute(encrypted_field)
raw_token ||= (instance.read_attribute(token_field) if fallback?)
raw_token ||= (fallback_strategy.get_token(instance) if fallback?)
raw_token.present?
end
......
......@@ -13,7 +13,7 @@ module Gitlab
self.table_name = 'ci_runners'
self.inheritance_column = :_type_disabled
def runners_token=(value)
def token=(value)
self.token_encrypted =
::Gitlab::CryptoHelper.aes256_gcm_encrypt(value)
end
......
......@@ -771,13 +771,13 @@ describe Ci::Build do
context 'hide runners token' do
let(:data) { "new #{project.runners_token} data"}
it { is_expected.to match(/^new [x]+ data$/) }
it { is_expected.to match(/^new x+ data$/) }
end
context 'hide build token' do
let(:data) { "new #{build.token} data"}
it { is_expected.to match(/^new [x]+ data$/) }
it { is_expected.to match(/^new x+ data$/) }
end
end
......
......@@ -14,7 +14,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
describe '#find_token_authenticatable' do
it 'finds a relevant resource by encrypted value' do
it 'finds the encrypted resource by cleartext' do
allow(model).to receive(:find_by)
.with('some_field_encrypted' => encrypted)
.and_return('encrypted resource')
......@@ -23,8 +23,8 @@ describe TokenAuthenticatableStrategies::Encrypted do
.to eq 'encrypted resource'
end
it 'uses fallback strategy when token can not be found' do
allow_any_instance_of(TokenAuthenticatableStrategies::Insecure)
it 'uses fallback strategy when encrypted token cannot be found' do
allow(subject.send(:fallback_strategy))
.to receive(:find_token_authenticatable)
.and_return('plaintext resource')
......@@ -38,7 +38,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
describe '#get_token' do
it 'decrypts a token when encrypted token is present' do
it 'returns decrypted token when an encrypted token is present' do
allow(instance).to receive(:read_attribute)
.with('some_field_encrypted')
.and_return(encrypted)
......@@ -46,7 +46,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
expect(subject.get_token(instance)).to eq 'my-value'
end
it 'reads a plaintext token when encrypted token is not present' do
it 'returns the plaintext token when encrypted token is not present' do
allow(instance).to receive(:read_attribute)
.with('some_field_encrypted')
.and_return(nil)
......@@ -60,7 +60,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
describe '#set_token' do
it 'writes encrypted token to a model instance and returns it' do
it 'writes encrypted token and removes plaintext token and returns it' do
expect(instance).to receive(:[]=)
.with('some_field_encrypted', encrypted)
expect(instance).to receive(:[]=)
......
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