BigW Consortium Gitlab

keys_spec.rb 1.24 KB
Newer Older
1 2
require 'spec_helper'

3
describe API::Keys do
4 5 6 7 8 9 10 11 12
  let(:user)  { create(:user) }
  let(:admin) { create(:admin) }
  let(:key)   { create(:key, user: user) }
  let(:email)   { create(:email, user: user) }

  describe 'GET /keys/:uid' do
    before { admin }

    context 'when unauthenticated' do
13
      it 'returns authentication error' do
14
        get api("/keys/#{key.id}")
15
        expect(response).to have_http_status(401)
16 17 18 19
      end
    end

    context 'when authenticated' do
20
      it 'returns 404 for non-existing key' do
21
        get api('/keys/999999', admin)
22
        expect(response).to have_http_status(404)
23 24 25
        expect(json_response['message']).to eq('404 Not found')
      end

26
      it 'returns single ssh key with user information' do
27 28 29
        user.keys << key
        user.save
        get api("/keys/#{key.id}", admin)
30
        expect(response).to have_http_status(200)
31 32 33 34
        expect(json_response['title']).to eq(key.title)
        expect(json_response['user']['id']).to eq(user.id)
        expect(json_response['user']['username']).to eq(user.username)
      end
35 36 37 38 39 40

      it "does not include the user's `is_admin` flag" do
        get api("/keys/#{key.id}", admin)

        expect(json_response['user']['is_admin']).to be_nil
      end
41 42 43
    end
  end
end