BigW Consortium Gitlab

gpg_keys_spec.rb 1.62 KB
Newer Older
1 2
require 'rails_helper'

3
feature 'Profile > GPG Keys' do
Alexis Reigel committed
4
  let(:user) { create(:user, email: GpgHelpers::User2.emails.first) }
5 6 7 8 9 10 11 12 13 14 15

  before do
    login_as(user)
  end

  describe 'User adds a key' do
    before do
      visit profile_gpg_keys_path
    end

    scenario 'saves the new key' do
Alexis Reigel committed
16
      fill_in('Key', with: GpgHelpers::User2.public_key)
17 18
      click_button('Add key')

Alexis Reigel committed
19 20 21
      expect(page).to have_content('bette.cartwright@example.com Verified')
      expect(page).to have_content('bette.cartwright@example.net Unverified')
      expect(page).to have_content(GpgHelpers::User2.fingerprint)
22 23 24
    end
  end

Alexis Reigel committed
25 26
  scenario 'User sees their key' do
    create(:gpg_key, user: user, key: GpgHelpers::User2.public_key)
27 28
    visit profile_gpg_keys_path

Alexis Reigel committed
29 30 31
    expect(page).to have_content('bette.cartwright@example.com Verified')
    expect(page).to have_content('bette.cartwright@example.net Unverified')
    expect(page).to have_content(GpgHelpers::User2.fingerprint)
32 33 34
  end

  scenario 'User removes a key via the key index' do
Alexis Reigel committed
35
    create(:gpg_key, user: user, key: GpgHelpers::User2.public_key)
36 37 38 39 40 41
    visit profile_gpg_keys_path

    click_link('Remove')

    expect(page).to have_content('Your GPG keys (0)')
  end
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

  scenario 'User revokes a key via the key index' do
    gpg_key = create :gpg_key, user: user, key: GpgHelpers::User2.public_key
    gpg_signature = create :gpg_signature, gpg_key: gpg_key, valid_signature: true

    visit profile_gpg_keys_path

    click_link('Revoke')

    expect(page).to have_content('Your GPG keys (0)')

    expect(gpg_signature.reload).to have_attributes(
      valid_signature: false,
      gpg_key: nil
    )
  end
58
end