Commit 5a7f8cb5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add readability improvements to registry auth specs

parent a222486c
...@@ -6,14 +6,15 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do ...@@ -6,14 +6,15 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do
let(:current_params) { {} } let(:current_params) { {} }
let(:rsa_key) { OpenSSL::PKey::RSA.generate(512) } let(:rsa_key) { OpenSSL::PKey::RSA.generate(512) }
let(:payload) { JWT.decode(subject[:token], rsa_key).first } let(:payload) { JWT.decode(subject[:token], rsa_key).first }
let(:authentication_abilities) do let(:authentication_abilities) do
[ [:read_container_image, :create_container_image]
:read_container_image,
:create_container_image
]
end end
subject { described_class.new(current_project, current_user, current_params).execute(authentication_abilities: authentication_abilities) } subject do
described_class.new(current_project, current_user, current_params)
.execute(authentication_abilities: authentication_abilities)
end
before do before do
allow(Gitlab.config.registry).to receive_messages(enabled: true, issuer: 'rspec', key: nil) allow(Gitlab.config.registry).to receive_messages(enabled: true, issuer: 'rspec', key: nil)
...@@ -40,13 +41,11 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do ...@@ -40,13 +41,11 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do
end end
end end
shared_examples 'a accessible' do shared_examples 'an accessible' do
let(:access) do let(:access) do
[{ [{ 'type' => 'repository',
'type' => 'repository',
'name' => project.path_with_namespace, 'name' => project.path_with_namespace,
'actions' => actions, 'actions' => actions }]
}]
end end
it_behaves_like 'a valid token' it_behaves_like 'a valid token'
...@@ -59,19 +58,19 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do ...@@ -59,19 +58,19 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do
end end
shared_examples 'a pullable' do shared_examples 'a pullable' do
it_behaves_like 'a accessible' do it_behaves_like 'an accessible' do
let(:actions) { ['pull'] } let(:actions) { ['pull'] }
end end
end end
shared_examples 'a pushable' do shared_examples 'a pushable' do
it_behaves_like 'a accessible' do it_behaves_like 'an accessible' do
let(:actions) { ['push'] } let(:actions) { ['push'] }
end end
end end
shared_examples 'a pullable and pushable' do shared_examples 'a pullable and pushable' do
it_behaves_like 'a accessible' do it_behaves_like 'an accessible' do
let(:actions) { %w(pull push) } let(:actions) { %w(pull push) }
end end
end end
...@@ -87,7 +86,7 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do ...@@ -87,7 +86,7 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do
subject { { token: token } } subject { { token: token } }
it_behaves_like 'a accessible' do it_behaves_like 'an accessible' do
let(:actions) { ['*'] } let(:actions) { ['*'] }
end end
end end
...@@ -198,11 +197,9 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do ...@@ -198,11 +197,9 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do
context 'build authorized as user' do context 'build authorized as user' do
let(:current_project) { create(:empty_project) } let(:current_project) { create(:empty_project) }
let(:current_user) { create(:user) } let(:current_user) { create(:user) }
let(:authentication_abilities) do let(:authentication_abilities) do
[ [:build_read_container_image, :build_create_container_image]
:build_read_container_image,
:build_create_container_image
]
end end
before do before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment