Skip to content
Snippets Groups Projects
Commit 032c4661 authored by Matthias Käppler's avatar Matthias Käppler :two:
Browse files

Merge branch 'add-terminating-newline-to-ssh-and-gpg-key-list-response' into 'master'

Add terminating newline to /:username.keys and /:username.gpg

See merge request !90973
parents f5711451 8a2a06e6
No related branches found
No related tags found
1 merge request!90973Add terminating newline to /:username.keys and /:username.gpg
Pipeline #573633680 passed
......@@ -58,7 +58,9 @@ def show
# Get all keys of a user(params[:username]) in a text format
# Helpful for sysadmins to put in respective servers
def ssh_keys
render plain: user.all_ssh_keys.join("\n")
keys = user.all_ssh_keys.join("\n")
keys << "\n" unless keys.empty?
render plain: keys
end
def activity
......@@ -74,7 +76,9 @@ def activity
# Get all gpg keys of a user(params[:username]) in a text format
def gpg_keys
render plain: user.gpg_keys.select(&:verified?).map(&:key).join("\n")
keys = user.gpg_keys.filter_map { |gpg_key| gpg_key.key if gpg_key.verified? }.join("\n")
keys << "\n" unless keys.empty?
render plain: keys
end
def groups
......
......@@ -236,14 +236,14 @@
let!(:deploy_key) { create(:deploy_key, user: user) }
shared_examples_for 'renders all public keys' do
it 'renders all non-deploy keys separated with a new line with text/plain content type without the comment key' do
it 'renders all non-deploy keys terminated with a new line with text/plain content type without the comment key' do
get "/#{user.username}.keys"
expect(response).to be_successful
expect(response.media_type).to eq("text/plain")
expect(response.body).not_to eq('')
expect(response.body).to eq(user.all_ssh_keys.join("\n"))
expect(response.body).to eq(user.all_ssh_keys.map { |key| key + "\n" }.join)
expect(response.body).to include(key.key.sub(' dummy@gitlab.com', ''))
expect(response.body).to include(another_key.key.sub(' dummy@gitlab.com', ''))
......@@ -308,7 +308,7 @@
let!(:another_gpg_key) { create(:another_gpg_key, user: user.reload) }
shared_examples_for 'renders all verified GPG keys' do
it 'renders all verified keys separated with a new line with text/plain content type' do
it 'renders all verified keys terminated with a new line with text/plain content type' do
get "/#{user.username}.gpg"
expect(response).to be_successful
......@@ -316,7 +316,7 @@
expect(response.media_type).to eq("text/plain")
expect(response.body).not_to eq('')
expect(response.body).to eq(user.gpg_keys.select(&:verified?).map(&:key).join("\n"))
expect(response.body).to eq(user.gpg_keys.filter_map { |gpg_key| gpg_key.key + "\n" if gpg_key.verified? }.join)
expect(response.body).to include(gpg_key.key)
expect(response.body).to include(another_gpg_key.key)
......
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