Commit fe4b5c98 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix token encrypted strategy when migrating data

parent 0f5073d9
...@@ -19,11 +19,17 @@ module TokenAuthenticatableStrategies ...@@ -19,11 +19,17 @@ module TokenAuthenticatableStrategies
.find_by(encrypted_field => encrypted_value) .find_by(encrypted_field => encrypted_value)
end end
if migrating? || fallback? if fallback? || migrating?
token_authenticatable ||= fallback_strategy token_authenticatable ||= fallback_strategy
.find_token_authenticatable(token) .find_token_authenticatable(token)
end end
if migrating?
encrypted_value = Gitlab::CryptoHelper.aes256_gcm_encrypt(token)
token_authenticatable ||= relation(unscoped)
.find_by(encrypted_field => encrypted_value)
end
token_authenticatable token_authenticatable
end end
......
...@@ -66,9 +66,26 @@ describe TokenAuthenticatableStrategies::Encrypted do ...@@ -66,9 +66,26 @@ describe TokenAuthenticatableStrategies::Encrypted do
.with('some_field' => 'my-value') .with('some_field' => 'my-value')
.and_return(nil) .and_return(nil)
allow(model).to receive(:find_by)
.with('some_field_encrypted' => encrypted)
.and_return(nil)
expect(subject.find_token_authenticatable('my-value')) expect(subject.find_token_authenticatable('my-value'))
.to be_nil .to be_nil
end end
it 'finds by encrypted value if cleartext is not present' do
allow(model).to receive(:find_by)
.with('some_field' => 'my-value')
.and_return(nil)
allow(model).to receive(:find_by)
.with('some_field_encrypted' => encrypted)
.and_return('encrypted resource')
expect(subject.find_token_authenticatable('my-value'))
.to eq 'encrypted resource'
end
end end
end end
......
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