diff --git a/ee/lib/ee/api/internal/kubernetes.rb b/ee/lib/ee/api/internal/kubernetes.rb index d4481f325aa5032adcde60eebdd1be7c61ed107d..08bc8919105d8817aa8069c602f1d2f6afeb711b 100644 --- a/ee/lib/ee/api/internal/kubernetes.rb +++ b/ee/lib/ee/api/internal/kubernetes.rb @@ -83,6 +83,14 @@ def update_configuration(agent:, config:) forbidden!('"remote_development" licensed feature is not available') end + unless agent.unversioned_latest_workspaces_agent_config + render_api_error!( + 'The remote development workspaces config for the agent is invalid. ' \ + 'Please see https://docs.gitlab.com/user/workspace/settings/#configuration-reference', + 406 + ) + end + domain_main_class_args = { agent: agent } diff --git a/ee/spec/requests/api/internal/kubernetes_spec.rb b/ee/spec/requests/api/internal/kubernetes_spec.rb index 5905e8b9a3dd18caa69dfaefca39ca82744b3eb1..6bac5ac7de937c5112d5d842e3062337238acb21 100644 --- a/ee/spec/requests/api/internal/kubernetes_spec.rb +++ b/ee/spec/requests/api/internal/kubernetes_spec.rb @@ -145,6 +145,9 @@ def send_request(params: {}, headers: agent_token_headers) before do stub_licensed_features(remote_development: true) + # rubocop:disable RSpec/AnyInstanceOf -- It's NOT the next instance... + allow_any_instance_of(Clusters::Agent).to receive(:unversioned_latest_workspaces_agent_config).and_return(true) + # rubocop:enable RSpec/AnyInstanceOf end include_examples 'authorization' @@ -179,6 +182,22 @@ def send_request(params: {}, headers: agent_token_headers) end end + context 'when agent config not found' do + before do + # rubocop:disable RSpec/AnyInstanceOf -- It's NOT the next instance... + allow_any_instance_of(Clusters::Agent).to receive(:unversioned_latest_workspaces_agent_config).and_return(nil) + # rubocop:enable RSpec/AnyInstanceOf + end + + it 'returns service response with error 406' do + expect(RemoteDevelopment::CommonService).not_to receive(:execute) + + send_request + + expect(response).to have_gitlab_http_status(:not_acceptable) + end + end + context 'when remote_development feature is unlicensed' do before do stub_licensed_features(remote_development: false)