Commit e2615734 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'pl-spec-services-auth-container-authentication-perf' into 'master'

Speed up container registry authentication service specs

See merge request gitlab-org/gitlab!45593
parents d48526fb a4e1a599
...@@ -135,7 +135,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -135,7 +135,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
describe '#full_access_token' do describe '#full_access_token' do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:token) { described_class.full_access_token(project.full_path) } let(:token) { described_class.full_access_token(project.full_path) }
subject { { token: token } } subject { { token: token } }
...@@ -148,7 +148,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -148,7 +148,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
describe '#pull_access_token' do describe '#pull_access_token' do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:token) { described_class.pull_access_token(project.full_path) } let(:token) { described_class.pull_access_token(project.full_path) }
subject { { token: token } } subject { { token: token } }
...@@ -161,7 +161,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -161,7 +161,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'user authorization' do context 'user authorization' do
let(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
context 'for registry catalog' do context 'for registry catalog' do
let(:current_params) do let(:current_params) do
...@@ -175,14 +175,14 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -175,14 +175,14 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for private project' do context 'for private project' do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
context 'allow to use scope-less authentication' do context 'allow to use scope-less authentication' do
it_behaves_like 'a valid token' it_behaves_like 'a valid token'
end end
context 'allow developer to push images' do context 'allow developer to push images' do
before do before_all do
project.add_developer(current_user) project.add_developer(current_user)
end end
...@@ -195,7 +195,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -195,7 +195,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow developer to delete images' do context 'disallow developer to delete images' do
before do before_all do
project.add_developer(current_user) project.add_developer(current_user)
end end
...@@ -222,7 +222,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -222,7 +222,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow developer to delete images since registry 2.7' do context 'disallow developer to delete images since registry 2.7' do
before do before_all do
project.add_developer(current_user) project.add_developer(current_user)
end end
...@@ -235,7 +235,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -235,7 +235,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'allow reporter to pull images' do context 'allow reporter to pull images' do
before do before_all do
project.add_reporter(current_user) project.add_reporter(current_user)
end end
...@@ -250,7 +250,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -250,7 +250,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow reporter to delete images' do context 'disallow reporter to delete images' do
before do before_all do
project.add_reporter(current_user) project.add_reporter(current_user)
end end
...@@ -263,7 +263,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -263,7 +263,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow reporter to delete images since registry 2.7' do context 'disallow reporter to delete images since registry 2.7' do
before do before_all do
project.add_reporter(current_user) project.add_reporter(current_user)
end end
...@@ -276,7 +276,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -276,7 +276,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'return a least of privileges' do context 'return a least of privileges' do
before do before_all do
project.add_reporter(current_user) project.add_reporter(current_user)
end end
...@@ -289,7 +289,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -289,7 +289,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow guest to pull or push images' do context 'disallow guest to pull or push images' do
before do before_all do
project.add_guest(current_user) project.add_guest(current_user)
end end
...@@ -302,7 +302,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -302,7 +302,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow guest to delete images' do context 'disallow guest to delete images' do
before do before_all do
project.add_guest(current_user) project.add_guest(current_user)
end end
...@@ -315,7 +315,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -315,7 +315,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow guest to delete images since registry 2.7' do context 'disallow guest to delete images since registry 2.7' do
before do before_all do
project.add_guest(current_user) project.add_guest(current_user)
end end
...@@ -329,7 +329,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -329,7 +329,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for public project' do context 'for public project' do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
context 'allow anyone to pull images' do context 'allow anyone to pull images' do
let(:current_params) do let(:current_params) do
...@@ -378,7 +378,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -378,7 +378,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for internal project' do context 'for internal project' do
let(:project) { create(:project, :internal) } let_it_be(:project) { create(:project, :internal) }
context 'for internal user' do context 'for internal user' do
context 'allow anyone to pull images' do context 'allow anyone to pull images' do
...@@ -420,7 +420,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -420,7 +420,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
context 'for external user' do context 'for external user' do
context 'disallow anyone to pull or push images' do context 'disallow anyone to pull or push images' do
let(:current_user) { create(:user, external: true) } let_it_be(:current_user) { create(:user, external: true) }
let(:current_params) do let(:current_params) do
{ scopes: ["repository:#{project.full_path}:pull,push"] } { scopes: ["repository:#{project.full_path}:pull,push"] }
end end
...@@ -430,7 +430,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -430,7 +430,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow anyone to delete images' do context 'disallow anyone to delete images' do
let(:current_user) { create(:user, external: true) } let_it_be(:current_user) { create(:user, external: true) }
let(:current_params) do let(:current_params) do
{ scopes: ["repository:#{project.full_path}:*"] } { scopes: ["repository:#{project.full_path}:*"] }
end end
...@@ -440,7 +440,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -440,7 +440,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'disallow anyone to delete images since registry 2.7' do context 'disallow anyone to delete images since registry 2.7' do
let(:current_user) { create(:user, external: true) } let_it_be(:current_user) { create(:user, external: true) }
let(:current_params) do let(:current_params) do
{ scopes: ["repository:#{project.full_path}:delete"] } { scopes: ["repository:#{project.full_path}:delete"] }
end end
...@@ -453,14 +453,14 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -453,14 +453,14 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'delete authorized as maintainer' do context 'delete authorized as maintainer' do
let(:current_project) { create(:project) } let_it_be(:current_project) { create(:project) }
let(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
let(:authentication_abilities) do let(:authentication_abilities) do
[:admin_container_image] [:admin_container_image]
end end
before do before_all do
current_project.add_maintainer(current_user) current_project.add_maintainer(current_user)
end end
...@@ -488,14 +488,14 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -488,14 +488,14 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'build authorized as user' do context 'build authorized as user' do
let(:current_project) { create(:project) } let_it_be(:current_project) { create(:project) }
let(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
let(:authentication_abilities) do let(:authentication_abilities) do
[:build_read_container_image, :build_create_container_image, :build_destroy_container_image] [:build_read_container_image, :build_create_container_image, :build_destroy_container_image]
end end
before do before_all do
current_project.add_developer(current_user) current_project.add_developer(current_user)
end end
...@@ -550,7 +550,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -550,7 +550,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'allow for public' do context 'allow for public' do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
it_behaves_like 'not a container repository factory' it_behaves_like 'not a container repository factory'
...@@ -563,7 +563,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -563,7 +563,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'when you are member' do context 'when you are member' do
before do before_all do
project.add_developer(current_user) project.add_developer(current_user)
end end
...@@ -572,7 +572,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -572,7 +572,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'when you are owner' do context 'when you are owner' do
let(:project) { create(:project, namespace: current_user.namespace) } let_it_be(:project) { create(:project, namespace: current_user.namespace) }
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
it_behaves_like 'not a container repository factory' it_behaves_like 'not a container repository factory'
...@@ -580,12 +580,12 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -580,12 +580,12 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for private' do context 'for private' do
let(:project) { create(:project, :private) } let_it_be(:project) { create(:project, :private) }
it_behaves_like 'pullable for being team member' it_behaves_like 'pullable for being team member'
context 'when you are admin' do context 'when you are admin' do
let(:current_user) { create(:admin) } let_it_be(:current_user) { create(:admin) }
context 'when you are not member' do context 'when you are not member' do
it_behaves_like 'an inaccessible' it_behaves_like 'an inaccessible'
...@@ -593,7 +593,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -593,7 +593,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'when you are member' do context 'when you are member' do
before do before_all do
project.add_developer(current_user) project.add_developer(current_user)
end end
...@@ -602,7 +602,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -602,7 +602,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'when you are owner' do context 'when you are owner' do
let(:project) { create(:project, namespace: current_user.namespace) } let_it_be(:project) { create(:project, namespace: current_user.namespace) }
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
it_behaves_like 'not a container repository factory' it_behaves_like 'not a container repository factory'
...@@ -618,9 +618,9 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -618,9 +618,9 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
context 'disallow for all' do context 'disallow for all' do
context 'when you are member' do context 'when you are member' do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
before do before_all do
project.add_developer(current_user) project.add_developer(current_user)
end end
...@@ -629,7 +629,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -629,7 +629,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'when you are owner' do context 'when you are owner' do
let(:project) { create(:project, :public, namespace: current_user.namespace) } let_it_be(:project) { create(:project, :public, namespace: current_user.namespace) }
it_behaves_like 'an inaccessible' it_behaves_like 'an inaccessible'
it_behaves_like 'not a container repository factory' it_behaves_like 'not a container repository factory'
...@@ -639,7 +639,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -639,7 +639,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for project without container registry' do context 'for project without container registry' do
let(:project) { create(:project, :public, container_registry_enabled: false) } let_it_be(:project) { create(:project, :public, container_registry_enabled: false) }
before do before do
project.update(container_registry_enabled: false) project.update(container_registry_enabled: false)
...@@ -656,7 +656,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -656,7 +656,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for project that disables repository' do context 'for project that disables repository' do
let(:project) { create(:project, :public, :repository_disabled) } let_it_be(:project) { create(:project, :public, :repository_disabled) }
context 'disallow when pulling' do context 'disallow when pulling' do
let(:current_params) do let(:current_params) do
...@@ -670,8 +670,8 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -670,8 +670,8 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'registry catalog browsing authorized as admin' do context 'registry catalog browsing authorized as admin' do
let(:current_user) { create(:user, :admin) } let_it_be(:current_user) { create(:user, :admin) }
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
let(:current_params) do let(:current_params) do
{ scopes: ["registry:catalog:*"] } { scopes: ["registry:catalog:*"] }
...@@ -681,8 +681,8 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -681,8 +681,8 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'support for multiple scopes' do context 'support for multiple scopes' do
let(:internal_project) { create(:project, :internal) } let_it_be(:internal_project) { create(:project, :internal) }
let(:private_project) { create(:project, :private) } let_it_be(:private_project) { create(:project, :private) }
let(:current_params) do let(:current_params) do
{ {
...@@ -694,7 +694,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -694,7 +694,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'user has access to all projects' do context 'user has access to all projects' do
let(:current_user) { create(:user, :admin) } let_it_be(:current_user) { create(:user, :admin) }
it_behaves_like 'a browsable' do it_behaves_like 'a browsable' do
let(:access) do let(:access) do
...@@ -711,7 +711,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -711,7 +711,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'user only has access to internal project' do context 'user only has access to internal project' do
let(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
it_behaves_like 'a browsable' do it_behaves_like 'a browsable' do
let(:access) do let(:access) do
...@@ -747,7 +747,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -747,7 +747,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for private project' do context 'for private project' do
let(:project) { create(:project, :private) } let_it_be(:project) { create(:project, :private) }
let(:current_params) do let(:current_params) do
{ scopes: ["repository:#{project.full_path}:pull"] } { scopes: ["repository:#{project.full_path}:pull"] }
...@@ -757,7 +757,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -757,7 +757,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for public project' do context 'for public project' do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
context 'when pulling and pushing' do context 'when pulling and pushing' do
let(:current_params) do let(:current_params) do
...@@ -806,7 +806,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -806,7 +806,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for public project' do context 'for public project' do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
...@@ -824,7 +824,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -824,7 +824,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for internal project' do context 'for internal project' do
let(:project) { create(:project, :internal) } let_it_be(:project) { create(:project, :internal) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
...@@ -842,7 +842,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -842,7 +842,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for private project' do context 'for private project' do
let(:project) { create(:project, :private) } let_it_be(:project) { create(:project, :private) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
...@@ -880,7 +880,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -880,7 +880,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for public project' do context 'for public project' do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
...@@ -890,7 +890,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -890,7 +890,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for internal project' do context 'for internal project' do
let(:project) { create(:project, :internal) } let_it_be(:project) { create(:project, :internal) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'an inaccessible' it_behaves_like 'an inaccessible'
...@@ -900,7 +900,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -900,7 +900,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for private project' do context 'for private project' do
let(:project) { create(:project, :internal) } let_it_be(:project) { create(:project, :internal) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'an inaccessible' it_behaves_like 'an inaccessible'
...@@ -918,10 +918,10 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -918,10 +918,10 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'when deploy token is not related to the project' do context 'when deploy token is not related to the project' do
let(:current_user) { create(:deploy_token, read_registry: false) } let_it_be(:current_user) { create(:deploy_token, read_registry: false) }
context 'for public project' do context 'for public project' do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
...@@ -929,7 +929,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -929,7 +929,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for internal project' do context 'for internal project' do
let(:project) { create(:project, :internal) } let_it_be(:project) { create(:project, :internal) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'an inaccessible' it_behaves_like 'an inaccessible'
...@@ -937,7 +937,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -937,7 +937,7 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'for private project' do context 'for private project' do
let(:project) { create(:project, :internal) } let_it_be(:project) { create(:project, :internal) }
context 'when pulling' do context 'when pulling' do
it_behaves_like 'an inaccessible' it_behaves_like 'an inaccessible'
...@@ -949,19 +949,19 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -949,19 +949,19 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
let(:current_user) { create(:deploy_token, :revoked, projects: [project]) } let(:current_user) { create(:deploy_token, :revoked, projects: [project]) }
context 'for public project' do context 'for public project' do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
it_behaves_like 'a pullable' it_behaves_like 'a pullable'
end end
context 'for internal project' do context 'for internal project' do
let(:project) { create(:project, :internal) } let_it_be(:project) { create(:project, :internal) }
it_behaves_like 'an inaccessible' it_behaves_like 'an inaccessible'
end end
context 'for private project' do context 'for private project' do
let(:project) { create(:project, :internal) } let_it_be(:project) { create(:project, :internal) }
it_behaves_like 'an inaccessible' it_behaves_like 'an inaccessible'
end end
...@@ -969,14 +969,13 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do ...@@ -969,14 +969,13 @@ RSpec.describe Auth::ContainerRegistryAuthenticationService do
end end
context 'user authorization' do context 'user authorization' do
let(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
context 'with multiple scopes' do context 'with multiple scopes' do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:project2) { create }
context 'allow developer to push images' do context 'allow developer to push images' do
before do before_all do
project.add_developer(current_user) project.add_developer(current_user)
end end
......
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