1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
# frozen_string_literal: true
RSpec.shared_examples 'Debian distributions GET request' do |status, body = nil|
and_body = body.nil? ? '' : ' and expected body'
it "returns #{status}#{and_body}" do
subject
expect(response).to have_gitlab_http_status(status)
unless body.nil?
expect(response.body).to match(body)
end
end
end
RSpec.shared_examples 'Debian distributions PUT request' do |status, body|
and_body = body.nil? ? '' : ' and expected body'
if status == :success
it 'updates distribution', :aggregate_failures do
expect(::Packages::Debian::UpdateDistributionService).to receive(:new).with(distribution, api_params.except(:codename)).and_call_original
expect { subject }
.to not_change { Packages::Debian::GroupDistribution.all.count + Packages::Debian::ProjectDistribution.all.count }
.and not_change { Packages::Debian::GroupComponent.all.count + Packages::Debian::ProjectComponent.all.count }
.and not_change { Packages::Debian::GroupArchitecture.all.count + Packages::Debian::ProjectArchitecture.all.count }
expect(response).to have_gitlab_http_status(status)
expect(response.media_type).to eq('application/json')
unless body.nil?
expect(response.body).to match(body)
end
end
else
it "returns #{status}#{and_body}", :aggregate_failures do
subject
expect(response).to have_gitlab_http_status(status)
unless body.nil?
expect(response.body).to match(body)
end
end
end
end
RSpec.shared_examples 'Debian distributions DELETE request' do |status, body|
and_body = body.nil? ? '' : ' and expected body'
if status == :success
it 'updates distribution', :aggregate_failures do
expect { subject }
.to change { Packages::Debian::GroupDistribution.all.count + Packages::Debian::ProjectDistribution.all.count }.by(-1)
.and change { Packages::Debian::GroupComponent.all.count + Packages::Debian::ProjectComponent.all.count }.by(-1)
.and change { Packages::Debian::GroupArchitecture.all.count + Packages::Debian::ProjectArchitecture.all.count }.by(-2)
expect(response).to have_gitlab_http_status(status)
expect(response.media_type).to eq('application/json')
unless body.nil?
expect(response.body).to match(body)
end
end
else
it "returns #{status}#{and_body}", :aggregate_failures do
subject
expect(response).to have_gitlab_http_status(status)
unless body.nil?
expect(response.body).to match(body)
end
end
end
end
RSpec.shared_examples 'Debian distributions POST request' do |status, body|
and_body = body.nil? ? '' : ' and expected body'
if status == :created
it 'creates distribution', :aggregate_failures do
expect(::Packages::Debian::CreateDistributionService).to receive(:new).with(container, user, api_params).and_call_original
expect { subject }
.to change { Packages::Debian::GroupDistribution.all.count + Packages::Debian::ProjectDistribution.all.count }.by(1)
.and change { Packages::Debian::GroupComponent.all.count + Packages::Debian::ProjectComponent.all.count }.by(1)
.and change { Packages::Debian::GroupArchitecture.all.count + Packages::Debian::ProjectArchitecture.all.count }.by(2)
expect(response).to have_gitlab_http_status(status)
expect(response.media_type).to eq('application/json')
unless body.nil?
expect(response.body).to match(body)
end
end
else
it "returns #{status}#{and_body}", :aggregate_failures do
subject
expect(response).to have_gitlab_http_status(status)
unless body.nil?
expect(response.body).to match(body)
end
end
end
end
RSpec.shared_examples 'Debian distributions read endpoint' do |desired_behavior, success_status, success_body|
context 'with valid container' do
using RSpec::Parameterized::TableSyntax
where(:visibility_level, :user_type, :auth_method, :expected_status, :expected_body) do
:public | :guest | :private_token | success_status | success_body
:public | :not_a_member | :private_token | success_status | success_body
:public | :anonymous | :private_token | success_status | success_body
:public | :invalid_token | :private_token | :unauthorized | nil
:private | :developer | :private_token | success_status | success_body
:private | :developer | :basic | :not_found | nil
:private | :guest | :private_token | :forbidden | nil
:private | :not_a_member | :private_token | :not_found | nil
:private | :anonymous | :private_token | :not_found | nil
:private | :invalid_token | :private_token | :unauthorized | nil
end
with_them do
include_context 'Debian repository access', params[:visibility_level], params[:user_type], params[:auth_method] do
it_behaves_like "Debian distributions #{desired_behavior} request", params[:expected_status], params[:expected_body]
end
end
end
it_behaves_like 'rejects Debian access with unknown container id', :not_found, :private_token
end
RSpec.shared_examples 'Debian distributions write endpoint' do |desired_behavior, success_status, success_body|
context 'with valid container' do
using RSpec::Parameterized::TableSyntax
where(:visibility_level, :user_type, :auth_method, :expected_status, :expected_body) do
:public | :developer | :private_token | success_status | success_body
:public | :developer | :basic | :unauthorized | nil
:public | :guest | :private_token | :forbidden | nil
:public | :not_a_member | :private_token | :forbidden | nil
:public | :anonymous | :private_token | :unauthorized | nil
:public | :invalid_token | :private_token | :unauthorized | nil
:private | :developer | :private_token | success_status | success_body
:private | :guest | :private_token | :forbidden | nil
:private | :not_a_member | :private_token | :not_found | nil
:private | :anonymous | :private_token | :not_found | nil
:private | :invalid_token | :private_token | :unauthorized | nil
end
with_them do
include_context 'Debian repository access', params[:visibility_level], params[:user_type], params[:auth_method] do
it_behaves_like "Debian distributions #{desired_behavior} request", params[:expected_status], params[:expected_body]
end
end
end
it_behaves_like 'rejects Debian access with unknown container id', :not_found, :private_token
end
RSpec.shared_examples 'Debian distributions maintainer write endpoint' do |desired_behavior, success_status, success_body|
context 'with valid container' do
using RSpec::Parameterized::TableSyntax
where(:visibility_level, :user_type, :auth_method, :expected_status, :expected_body) do
:public | :maintainer | :private_token | success_status | success_body
:public | :maintainer | :basic | :unauthorized | nil
:public | :developer | :private_token | :forbidden | nil
:public | :not_a_member | :private_token | :forbidden | nil
:public | :anonymous | :private_token | :unauthorized | nil
:public | :invalid_token | :private_token | :unauthorized | nil
:private | :maintainer | :private_token | success_status | success_body
:private | :developer | :private_token | :forbidden | nil
:private | :not_a_member | :private_token | :not_found | nil
:private | :anonymous | :private_token | :not_found | nil
:private | :invalid_token | :private_token | :unauthorized | nil
end
with_them do
include_context 'Debian repository access', params[:visibility_level], params[:user_type], params[:auth_method] do
it_behaves_like "Debian distributions #{desired_behavior} request", params[:expected_status], params[:expected_body]
end
end
end
it_behaves_like 'rejects Debian access with unknown container id', :not_found, :private_token
end
|