Skip to content
Snippets Groups Projects
Commit 4d6f447f authored by Stan Hu's avatar Stan Hu
Browse files

Merge branch 'ssh-host-key-indifferent' into 'master'

Allow SshHostKey.find_by to accept string keys

See merge request gitlab-org/gitlab-ce!24903
parents fe76bb29 3dadb1f8
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ def as_json(*)
self.reactive_cache_lifetime = 10.minutes
def self.find_by(opts = {})
opts = HashWithIndifferentAccess.new(opts)
return nil unless opts.key?(:id)
project_id, url = opts[:id].split(':', 2)
......
......@@ -56,6 +56,29 @@ def stub_ssh_keyscan(args, status: true, stdout: "", stderr: "")
end
end
describe '.find_by' do
let(:project) { create(:project) }
let(:url) { 'ssh://invalid.invalid:2222' }
let(:finding_id) { [project.id, url].join(':') }
it 'accepts a string key' do
result = described_class.find_by('id' => finding_id)
expect(result).to be_a(described_class)
expect(result.project).to eq(project)
expect(result.url.to_s).to eq(url)
end
it 'accepts a symbol key' do
result = described_class.find_by(id: finding_id)
expect(result).to be_a(described_class)
expect(result.project).to eq(project)
expect(result.url.to_s).to eq(url)
end
end
describe '#fingerprints', :use_clean_rails_memory_store_caching do
it 'returns an array of indexed fingerprints when the cache is filled' do
stub_reactive_cache(ssh_host_key, known_hosts: known_hosts)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment