Commit cfee95d0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #8340 from cirosantilli/multi-ruby-install-v2

Web edit and HTTPS push work if multiple Rubies installed v2
parents a4e98f0e 533f4cdf
...@@ -92,5 +92,7 @@ module Gitlab ...@@ -92,5 +92,7 @@ module Gitlab
redis_config_hash[:namespace] = 'cache:gitlab' redis_config_hash[:namespace] = 'cache:gitlab'
config.cache_store = :redis_store, redis_config_hash config.cache_store = :redis_store, redis_config_hash
ENV['GITLAB_PATH_OUTSIDE_HOOK'] = ENV['PATH']
end end
end end
...@@ -307,7 +307,7 @@ test: ...@@ -307,7 +307,7 @@ test:
enabled: true enabled: true
gitlab: gitlab:
host: localhost host: localhost
port: 80 port: 3001
# When you run tests we clone and setup gitlab-shell # When you run tests we clone and setup gitlab-shell
# In order to setup it correctly you need to specify # In order to setup it correctly you need to specify
......
# Be sure to restart your server when you modify this file. Gitlab::Shell.setup_secret_token
require 'securerandom'
# Your secret key for verifying the gitlab_shell.
secret_file = Rails.root.join('.gitlab_shell_secret')
gitlab_shell_symlink = File.join(Gitlab.config.gitlab_shell.path, '.gitlab_shell_secret')
unless File.exist? secret_file
# Generate a new token of 16 random hexadecimal characters and store it in secret_file.
token = SecureRandom.hex(16)
File.write(secret_file, token)
end
if File.exist?(Gitlab.config.gitlab_shell.path) && !File.exist?(gitlab_shell_symlink)
FileUtils.symlink(secret_file, gitlab_shell_symlink)
end
\ No newline at end of file
...@@ -11,20 +11,18 @@ Feature: Project Forked Merge Requests ...@@ -11,20 +11,18 @@ Feature: Project Forked Merge Requests
And I submit the merge request And I submit the merge request
Then I should see merge request "Merge Request On Forked Project" Then I should see merge request "Merge Request On Forked Project"
# TODO: Improve it so it does not fail randomly @javascript
# Scenario: I can edit a forked merge request
#@javascript Given I visit project "Forked Shop" merge requests page
#Scenario: I can edit a forked merge request And I click link "New Merge Request"
#Given I visit project "Forked Shop" merge requests page And I fill out a "Merge Request On Forked Project" merge request
#And I click link "New Merge Request" And I submit the merge request
#And I fill out a "Merge Request On Forked Project" merge request And I should see merge request "Merge Request On Forked Project"
#And I submit the merge request And I click link edit "Merge Request On Forked Project"
#And I should see merge request "Merge Request On Forked Project" Then I see the edit page prefilled for "Merge Request On Forked Project"
#And I click link edit "Merge Request On Forked Project" And I update the merge request title
#Then I see the edit page prefilled for "Merge Request On Forked Project" And I save the merge request
#And I update the merge request title Then I should see the edited merge request
#And I save the merge request
#Then I should see the edited merge request
@javascript @javascript
Scenario: I cannot submit an invalid merge request Scenario: I cannot submit an invalid merge request
......
require 'securerandom'
module Gitlab module Gitlab
class Shell class Shell
class AccessDenied < StandardError; end class AccessDenied < StandardError; end
...@@ -13,6 +15,25 @@ module Gitlab ...@@ -13,6 +15,25 @@ module Gitlab
@version_required ||= File.read(Rails.root. @version_required ||= File.read(Rails.root.
join('GITLAB_SHELL_VERSION')).strip join('GITLAB_SHELL_VERSION')).strip
end end
# Be sure to restart your server when you modify this method.
def setup_secret_token
secret_file = Rails.root.join('.gitlab_shell_secret')
gitlab_shell_symlink = File.join(Gitlab.config.gitlab_shell.path,
'.gitlab_shell_secret')
unless File.exist? secret_file
# Generate a new token of 16 random hexadecimal characters
# and store it in secret_file.
token = SecureRandom.hex(16)
File.write(secret_file, token)
end
if File.exist?(Gitlab.config.gitlab_shell.path) &&
!File.exist?(gitlab_shell_symlink)
FileUtils.symlink(secret_file, gitlab_shell_symlink)
end
end
end end
# Init new repository # Init new repository
......
...@@ -22,10 +22,14 @@ namespace :gitlab do ...@@ -22,10 +22,14 @@ namespace :gitlab do
# Make sure we're on the right tag # Make sure we're on the right tag
Dir.chdir(target_dir) do Dir.chdir(target_dir) do
# Allows to change the origin URL to the fork
# when developing gitlab-shell.
sh(*%W(git remote set-url origin #{args.repo}))
# First try to checkout without fetching # First try to checkout without fetching
# to avoid stalling tests if the Internet is down. # to avoid stalling tests if the Internet is down.
reset = "git reset --hard $(git describe #{args.tag} || git describe origin/#{args.tag})" reset = "(rev=\"$(git describe #{args.tag} || git describe \"origin/#{args.tag}\")\" && git reset --hard \"$rev\")"
sh "#{reset} || git fetch origin && #{reset}" sh "#{reset} || (git fetch --tags origin && #{reset})"
config = { config = {
user: user, user: user,
...@@ -37,7 +41,7 @@ namespace :gitlab do ...@@ -37,7 +41,7 @@ namespace :gitlab do
bin: %x{which redis-cli}.chomp, bin: %x{which redis-cli}.chomp,
namespace: "resque:gitlab" namespace: "resque:gitlab"
}.stringify_keys, }.stringify_keys,
log_level: "INFO", log_level: Rails.env.test? ? 'DEBUG' : 'INFO',
audit_usernames: false audit_usernames: false
}.stringify_keys }.stringify_keys
...@@ -66,6 +70,8 @@ namespace :gitlab do ...@@ -66,6 +70,8 @@ namespace :gitlab do
File.open(File.join(home_dir, ".ssh", "environment"), "w+") do |f| File.open(File.join(home_dir, ".ssh", "environment"), "w+") do |f|
f.puts "PATH=#{ENV['PATH']}" f.puts "PATH=#{ENV['PATH']}"
end end
Gitlab::Shell.setup_secret_token
end end
desc "GITLAB | Setup gitlab-shell" desc "GITLAB | Setup gitlab-shell"
......
require 'rspec/mocks' require 'rspec/mocks'
require 'webrick'
module TestEnv module TestEnv
extend self extend self
...@@ -24,8 +25,6 @@ module TestEnv ...@@ -24,8 +25,6 @@ module TestEnv
disable_mailer if opts[:mailer] == false disable_mailer if opts[:mailer] == false
# Clean /tmp/tests # Clean /tmp/tests
tmp_test_path = Rails.root.join('tmp', 'tests')
if File.directory?(tmp_test_path) if File.directory?(tmp_test_path)
Dir.entries(tmp_test_path).each do |entry| Dir.entries(tmp_test_path).each do |entry|
unless ['.', '..', 'gitlab-shell', factory_repo_name].include?(entry) unless ['.', '..', 'gitlab-shell', factory_repo_name].include?(entry)
...@@ -39,6 +38,8 @@ module TestEnv ...@@ -39,6 +38,8 @@ module TestEnv
# Setup GitLab shell for test instance # Setup GitLab shell for test instance
setup_gitlab_shell setup_gitlab_shell
setup_internal_api_mock
# Create repository for FactoryGirl.create(:project) # Create repository for FactoryGirl.create(:project)
setup_factory_repo setup_factory_repo
end end
...@@ -108,4 +109,52 @@ module TestEnv ...@@ -108,4 +109,52 @@ module TestEnv
def factory_repo_name def factory_repo_name
'gitlab-test' 'gitlab-test'
end end
def tmp_test_path
Rails.root.join('tmp', 'tests')
end
def internal_api_mock_pid_path
File.join(tmp_test_path, 'internal_api_mock.pid')
end
# This mock server exists because during testing GitLab is not served
# on any port, but gitlab-shell needs to ask the GitLab internal API
# if it is OK to push to repositories. This can happen during blob web
# edit tests. The server always replies yes: this should not modify affect
# web interface tests.
def setup_internal_api_mock
begin
server = WEBrick::HTTPServer.new(
BindAddress: '0.0.0.0',
Port: Gitlab.config.gitlab.port,
AccessLog: [],
Logger: WEBrick::Log.new('/dev/null')
)
rescue => ex
ex.message.prepend('could not start mock server on configured port. ')
raise ex
end
fork do
trap(:INT) { server.shutdown }
server.mount_proc('/') do |_req, res|
res.status = 200
res.body = 'true'
end
WEBrick::Daemon.start do
File.write(internal_api_mock_pid_path, Process.pid)
end
server.start
end
# Ideally this should be called from `config.after(:suite)`,
# but on Spinach when user hits Ctrl+C the server does not get killed
# if the hook is set up with `Spinach.hooks.after_run`.
at_exit do
# The file should exist on normal operation,
# but certain errors can lead to it not existing.
if File.exists?(internal_api_mock_pid_path)
Process.kill(:INT, File.read(internal_api_mock_pid_path).to_i)
end
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