Commit 9a61d5f0 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'fj-fix-bug-hook-env' into 'master'

Fix bug setting hook env with personal snippets

See merge request gitlab-org/gitlab!27235
parents 45eb53bc 36ea5135
---
title: Fix bug setting hook env with personal snippets
merge_request: 27235
author:
type: fixed
...@@ -40,7 +40,7 @@ module API ...@@ -40,7 +40,7 @@ module API
# Stores some Git-specific env thread-safely # Stores some Git-specific env thread-safely
env = parse_env env = parse_env
Gitlab::Git::HookEnv.set(gl_repository, env) if project Gitlab::Git::HookEnv.set(gl_repository, env) if container
actor.update_last_used_at! actor.update_last_used_at!
access_checker = access_checker_for(actor, params[:protocol]) access_checker = access_checker_for(actor, params[:protocol])
......
...@@ -262,6 +262,8 @@ describe API::Internal::Base do ...@@ -262,6 +262,8 @@ describe API::Internal::Base do
describe "POST /internal/allowed", :clean_gitlab_redis_shared_state do describe "POST /internal/allowed", :clean_gitlab_redis_shared_state do
context "access granted" do context "access granted" do
let(:env) { {} }
around do |example| around do |example|
Timecop.freeze { example.run } Timecop.freeze { example.run }
end end
...@@ -270,30 +272,32 @@ describe API::Internal::Base do ...@@ -270,30 +272,32 @@ describe API::Internal::Base do
project.add_developer(user) project.add_developer(user)
end end
context 'with env passed as a JSON' do shared_examples 'sets hook env' do
let(:gl_repository) { Gitlab::GlRepository::WIKI.identifier_for_container(project) } context 'with env passed as a JSON' do
let(:obj_dir_relative) { './objects' }
it 'sets env in RequestStore' do let(:alt_obj_dirs_relative) { ['./alt-objects-1', './alt-objects-2'] }
obj_dir_relative = './objects' let(:env) do
alt_obj_dirs_relative = ['./alt-objects-1', './alt-objects-2'] {
GIT_OBJECT_DIRECTORY_RELATIVE: obj_dir_relative,
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE: alt_obj_dirs_relative
}
end
expect(Gitlab::Git::HookEnv).to receive(:set).with(gl_repository, { it 'sets env in RequestStore' do
'GIT_OBJECT_DIRECTORY_RELATIVE' => obj_dir_relative, expect(Gitlab::Git::HookEnv).to receive(:set).with(gl_repository, env.stringify_keys)
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE' => alt_obj_dirs_relative
})
push(key, project.wiki, env: { subject
GIT_OBJECT_DIRECTORY_RELATIVE: obj_dir_relative,
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE: alt_obj_dirs_relative
}.to_json)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end
end end
end end
context "git push with project.wiki" do context "git push with project.wiki" do
subject { push(key, project.wiki, env: env.to_json) }
it 'responds with success' do it 'responds with success' do
push(key, project.wiki) 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
...@@ -301,6 +305,10 @@ describe API::Internal::Base do ...@@ -301,6 +305,10 @@ describe API::Internal::Base do
expect(json_response["gl_repository"]).to eq("wiki-#{project.id}") expect(json_response["gl_repository"]).to eq("wiki-#{project.id}")
expect(user.reload.last_activity_on).to be_nil expect(user.reload.last_activity_on).to be_nil
end end
it_behaves_like 'sets hook env' do
let(:gl_repository) { Gitlab::GlRepository::WIKI.identifier_for_container(project) }
end
end end
context "git pull with project.wiki" do context "git pull with project.wiki" do
...@@ -328,8 +336,10 @@ describe API::Internal::Base do ...@@ -328,8 +336,10 @@ describe API::Internal::Base do
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) }
it 'responds with success' do it 'responds with success' do
push(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
...@@ -338,8 +348,9 @@ describe API::Internal::Base do ...@@ -338,8 +348,9 @@ describe API::Internal::Base do
expect(user.reload.last_activity_on).to be_nil expect(user.reload.last_activity_on).to be_nil
end end
it_behaves_like 'snippets with disabled feature flag' do it_behaves_like 'snippets with disabled feature flag'
subject { push(key, personal_snippet) } it_behaves_like 'sets hook env' do
let(:gl_repository) { Gitlab::GlRepository::SNIPPET.identifier_for_container(personal_snippet) }
end end
end end
...@@ -360,8 +371,10 @@ describe API::Internal::Base do ...@@ -360,8 +371,10 @@ describe API::Internal::Base do
end end
context 'git push with project snippet' do context 'git push with project snippet' do
subject { push(key, project_snippet, env: env.to_json) }
it 'responds with success' do it 'responds with success' do
push(key, project_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
...@@ -370,8 +383,9 @@ describe API::Internal::Base do ...@@ -370,8 +383,9 @@ describe API::Internal::Base do
expect(user.reload.last_activity_on).to be_nil expect(user.reload.last_activity_on).to be_nil
end end
it_behaves_like 'snippets with disabled feature flag' do it_behaves_like 'snippets with disabled feature flag'
subject { push(key, project_snippet) } it_behaves_like 'sets hook env' do
let(:gl_repository) { Gitlab::GlRepository::SNIPPET.identifier_for_container(project_snippet) }
end end
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