Allow users to update their OpenPGP pubkey
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -14,6 +14,7 @@ RSpec.describe 'Account settings', type: :feature do
|
||||
.with("invalid password").and_return(false)
|
||||
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
|
||||
.with("valid password").and_return(true)
|
||||
allow_any_instance_of(User).to receive(:pgp_pubkey).and_return(nil)
|
||||
end
|
||||
|
||||
scenario 'fails with invalid password' do
|
||||
@@ -55,4 +56,44 @@ RSpec.describe 'Account settings', type: :feature do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature "Update OpenPGP key" do
|
||||
let(:invalid_key) { File.read("#{Rails.root}/spec/fixtures/files/pgp_key_invalid.asc") }
|
||||
let(:valid_key_alice) { File.read("#{Rails.root}/spec/fixtures/files/pgp_key_valid_alice.asc") }
|
||||
let(:fingerprint_alice) { "EB85BB5FA33A75E15E944E63F231550C4F47E38E" }
|
||||
|
||||
before do
|
||||
login_as user, :scope => :user
|
||||
allow_any_instance_of(User).to receive(:ldap_entry).and_return({
|
||||
uid: user.cn, ou: user.ou, display_name: nil, pgp_key: nil
|
||||
})
|
||||
end
|
||||
|
||||
scenario 'rejects an invalid key' do
|
||||
expect(UserManager::UpdatePgpKey).not_to receive(:call)
|
||||
|
||||
visit setting_path(:account)
|
||||
fill_in 'Public key', with: invalid_key
|
||||
click_button "Save"
|
||||
|
||||
expect(current_url).to eq(setting_url(:account))
|
||||
within ".error-msg" do
|
||||
expect(page).to have_content("This is not a valid armored PGP public key block")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'stores a valid key' do
|
||||
expect(UserManager::UpdatePgpKey).to receive(:call)
|
||||
.with(user: user).and_return(true)
|
||||
|
||||
visit setting_path(:account)
|
||||
fill_in 'Public key', with: valid_key_alice
|
||||
click_button "Save"
|
||||
|
||||
expect(current_url).to eq(setting_url(:account))
|
||||
within ".flash-msg" do
|
||||
expect(page).to have_content("Settings saved")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ RSpec.describe 'Profile settings', type: :feature do
|
||||
allow(user).to receive(:display_name).and_return("Mark")
|
||||
allow_any_instance_of(User).to receive(:dn).and_return("cn=mwahlberg,ou=kosmos.org,cn=users,dc=kosmos,dc=org")
|
||||
allow_any_instance_of(User).to receive(:ldap_entry).and_return({
|
||||
uid: user.cn, ou: user.ou, display_name: "Mark"
|
||||
uid: user.cn, ou: user.ou, display_name: "Mark", pgp_key: nil
|
||||
})
|
||||
allow_any_instance_of(User).to receive(:avatar).and_return(avatar_base64)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user