2016-09-29 09:46:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-01-03 12:48:30 +05:30
|
|
|
describe Gitlab::LfsToken do
|
2016-10-01 15:18:49 +05:30
|
|
|
describe '#token' do
|
2016-09-29 09:46:39 +05:30
|
|
|
shared_examples 'an LFS token generator' do
|
2019-01-03 12:48:30 +05:30
|
|
|
it 'returns a randomly generated token' do
|
|
|
|
token = handler.token
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
expect(token).not_to be_nil
|
|
|
|
expect(token).to be_a String
|
2019-01-03 12:48:30 +05:30
|
|
|
expect(token.length).to eq 50
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2019-01-03 12:48:30 +05:30
|
|
|
it 'returns the correct token based on the key' do
|
|
|
|
token = handler.token
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2019-01-03 12:48:30 +05:30
|
|
|
expect(handler.token).to eq(token)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-03 12:48:30 +05:30
|
|
|
context 'when the actor is a user' do
|
|
|
|
let(:actor) { create(:user) }
|
|
|
|
let(:handler) { described_class.new(actor) }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
it_behaves_like 'an LFS token generator'
|
|
|
|
|
|
|
|
it 'returns the correct username' do
|
2019-01-03 12:48:30 +05:30
|
|
|
expect(handler.actor_name).to eq(actor.username)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the correct token type' do
|
2019-01-03 12:48:30 +05:30
|
|
|
expect(handler.type).to eq(:lfs_token)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the actor is a deploy key' do
|
|
|
|
let(:actor) { create(:deploy_key) }
|
2019-01-03 12:48:30 +05:30
|
|
|
let(:handler) { described_class.new(actor) }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
it_behaves_like 'an LFS token generator'
|
|
|
|
|
|
|
|
it 'returns the correct username' do
|
2019-01-03 12:48:30 +05:30
|
|
|
expect(handler.actor_name).to eq("lfs+deploy-key-#{actor.id}")
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the correct token type' do
|
2019-01-03 12:48:30 +05:30
|
|
|
expect(handler.type).to eq(:lfs_deploy_token)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|