Commit edd3080c authored by Vijay Hawoldar's avatar Vijay Hawoldar

Allow internal snippet git operations if web

When internal api operations are for snippets
it should be allowed if the protocol is web so that we
can keep the snippet repos updated regardless of the feature
flag status
parent 4dc3a316
---
title: Resolve Snippet update error with version flag disabled
merge_request: 28815
author:
type: fixed
...@@ -108,7 +108,7 @@ module API ...@@ -108,7 +108,7 @@ module API
# check_ip - optional, only in EE version, may limit access to # check_ip - optional, only in EE version, may limit access to
# group resources based on its IP restrictions # group resources based on its IP restrictions
post "/allowed" do post "/allowed" do
if repo_type.snippet? && Feature.disabled?(:version_snippets, actor.user) if repo_type.snippet? && params[:protocol] != 'web' && Feature.disabled?(:version_snippets, actor.user)
break response_with_status(code: 401, success: false, message: 'Snippet git access is disabled.') break response_with_status(code: 401, success: false, message: 'Snippet git access is disabled.')
end end
......
...@@ -335,6 +335,27 @@ describe API::Internal::Base do ...@@ -335,6 +335,27 @@ describe API::Internal::Base do
end end
end end
shared_examples 'snippet success' do
it 'responds with success' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['status']).to be_truthy
end
end
shared_examples 'snippets with web protocol' do
it_behaves_like 'snippet success'
context 'with disabled version flag' do
before do
stub_feature_flags(version_snippets: false)
end
it_behaves_like 'snippet success'
end
end
context 'git push with personal snippet' do context 'git push with personal snippet' do
subject { push(key, personal_snippet, env: env.to_json, changes: snippet_changes) } subject { push(key, personal_snippet, env: env.to_json, changes: snippet_changes) }
...@@ -349,14 +370,21 @@ describe API::Internal::Base do ...@@ -349,14 +370,21 @@ describe API::Internal::Base do
end end
it_behaves_like 'snippets with disabled feature flag' it_behaves_like 'snippets with disabled feature flag'
it_behaves_like 'snippets with web protocol' do
subject { push(key, personal_snippet, 'web', env: env.to_json, changes: snippet_changes) }
end
it_behaves_like 'sets hook env' do it_behaves_like 'sets hook env' do
let(:gl_repository) { Gitlab::GlRepository::SNIPPET.identifier_for_container(personal_snippet) } let(:gl_repository) { Gitlab::GlRepository::SNIPPET.identifier_for_container(personal_snippet) }
end end
end end
context 'git pull with personal snippet' do context 'git pull with personal snippet' do
subject { pull(key, personal_snippet) }
it 'responds with success' do it 'responds with success' do
pull(key, personal_snippet) subject
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response["status"]).to be_truthy expect(json_response["status"]).to be_truthy
...@@ -365,8 +393,10 @@ describe API::Internal::Base do ...@@ -365,8 +393,10 @@ describe API::Internal::Base do
expect(user.reload.last_activity_on).to eql(Date.today) expect(user.reload.last_activity_on).to eql(Date.today)
end end
it_behaves_like 'snippets with disabled feature flag' do it_behaves_like 'snippets with disabled feature flag'
subject { pull(key, personal_snippet) }
it_behaves_like 'snippets with web protocol' do
subject { pull(key, personal_snippet, 'web') }
end end
end end
...@@ -384,6 +414,11 @@ describe API::Internal::Base do ...@@ -384,6 +414,11 @@ describe API::Internal::Base do
end end
it_behaves_like 'snippets with disabled feature flag' it_behaves_like 'snippets with disabled feature flag'
it_behaves_like 'snippets with web protocol' do
subject { push(key, project_snippet, 'web', env: env.to_json, changes: snippet_changes) }
end
it_behaves_like 'sets hook env' do it_behaves_like 'sets hook env' do
let(:gl_repository) { Gitlab::GlRepository::SNIPPET.identifier_for_container(project_snippet) } let(:gl_repository) { Gitlab::GlRepository::SNIPPET.identifier_for_container(project_snippet) }
end end
...@@ -403,6 +438,10 @@ describe API::Internal::Base do ...@@ -403,6 +438,10 @@ describe API::Internal::Base do
it_behaves_like 'snippets with disabled feature flag' do it_behaves_like 'snippets with disabled feature flag' do
subject { pull(key, project_snippet) } subject { pull(key, project_snippet) }
end end
it_behaves_like 'snippets with web protocol' do
subject { pull(key, project_snippet, 'web') }
end
end end
context "git pull" do context "git pull" 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