diff options
Diffstat (limited to 'spec/requests/api/ci/runner/runners_post_spec.rb')
-rw-r--r-- | spec/requests/api/ci/runner/runners_post_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/requests/api/ci/runner/runners_post_spec.rb b/spec/requests/api/ci/runner/runners_post_spec.rb index 1696fe63d5d..6d222046998 100644 --- a/spec/requests/api/ci/runner/runners_post_spec.rb +++ b/spec/requests/api/ci/runner/runners_post_spec.rb @@ -11,8 +11,10 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do before do stub_feature_flags(ci_enable_live_trace: true) + stub_feature_flags(runner_registration_control: false) stub_gitlab_calls stub_application_setting(runners_registration_token: registration_token) + stub_application_setting(valid_runner_registrars: ApplicationSetting::VALID_RUNNER_REGISTRAR_TYPES) allow_any_instance_of(::Ci::Runner).to receive(:cache_attributes) end @@ -122,6 +124,33 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do expect(project.runners.recent.size).to eq(1) end end + + context 'when valid runner registrars do not include project' do + before do + stub_application_setting(valid_runner_registrars: ['group']) + end + + context 'when feature flag is enabled' do + before do + stub_feature_flags(runner_registration_control: true) + end + + it 'returns 403 error' do + request + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context 'when feature flag is disabled' do + it 'registers the runner' do + request + + expect(response).to have_gitlab_http_status(:created) + expect(::Ci::Runner.first.active).to be true + end + end + end end context 'when group token is used' do @@ -180,6 +209,33 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do expect(group.runners.recent.size).to eq(1) end end + + context 'when valid runner registrars do not include group' do + before do + stub_application_setting(valid_runner_registrars: ['project']) + end + + context 'when feature flag is enabled' do + before do + stub_feature_flags(runner_registration_control: true) + end + + it 'returns 403 error' do + request + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context 'when feature flag is disabled' do + it 'registers the runner' do + request + + expect(response).to have_gitlab_http_status(:created) + expect(::Ci::Runner.first.active).to be true + end + end + end end end |