Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verification borks on Linux when source directory contains a space #135

Closed
gruntster opened this issue Jan 5, 2018 · 9 comments
Closed

Comments

@gruntster
Copy link
Contributor

Pact verification borks on Linux when the source directory contains a space; Windows works fine.

I'm using the following patch to workaround the issue:

diff -urN a/pact-linux-x86_64/bin/pact-provider-verifier b/pact-linux-x86_64/bin/pact-provider-verifier
--- a/pact-linux-x86_64/bin/pact-provider-verifier	2017-12-06 23:31:39.809497900 +1100
+++ b/pact-linux-x86_64/bin/pact-provider-verifier	2018-01-05 20:28:44.883002600 +1100
@@ -23,4 +23,4 @@
 unset RUBYGEMS_GEMDEPS # See https://github.com/pact-foundation/pact-mock-service-npm/issues/16
 
 # Run the actual app using the bundled Ruby interpreter, with Bundler activated.
-exec "$LIBDIR/ruby/bin/ruby" -rbundler/setup -rreadline -I$LIBDIR/app/lib "$LIBDIR/app/pact-provider-verifier.rb" "$@"
+exec "$LIBDIR/ruby/bin/ruby" -rbundler/setup -rreadline -I "$LIBDIR/app/lib" "$LIBDIR/app/pact-provider-verifier.rb" "$@"
diff -urN a/pact-linux-x86_64/lib/ruby/bin/ruby_environment b/pact-linux-x86_64/lib/ruby/bin/ruby_environment
--- a/pact-linux-x86_64/lib/ruby/bin/ruby_environment	2017-12-06 23:31:40.059663900 +1100
+++ b/pact-linux-x86_64/lib/ruby/bin/ruby_environment	2018-01-05 20:33:48.118014600 +1100
@@ -10,12 +10,12 @@
 
 echo LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH:$ROOT/lib\"
 echo SSL_CERT_FILE=\"$ROOT/lib/ca-bundle.crt\"
-echo RUBYOPT=\"-r$ROOT/lib/restore_environment\"
+echo RUBYOPT="-rrestore_environment"
 for DIR in "$ROOT"/lib/ruby/gems/*/deplibs/*/*; do
 	echo LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH:$DIR\"
 done
-echo GEM_HOME="$ROOT/lib/ruby/gems/2.2.0"
-echo GEM_PATH="$ROOT/lib/ruby/gems/2.2.0"
+echo GEM_HOME=\"$ROOT/lib/ruby/gems/2.2.0\"
+echo GEM_PATH=\"$ROOT/lib/ruby/gems/2.2.0\"
 echo RUBYLIB=\"$ROOT/lib/ruby/site_ruby/2.2.0:$ROOT/lib/ruby/site_ruby/2.2.0/x86_64-linux:$ROOT/lib/ruby/site_ruby:$ROOT/lib/ruby/vendor_ruby/2.2.0:$ROOT/lib/ruby/vendor_ruby/2.2.0/x86_64-linux:$ROOT/lib/ruby/vendor_ruby:$ROOT/lib/ruby/2.2.0:$ROOT/lib/ruby/2.2.0/x86_64-linux\"
 
 echo export ORIG_LD_LIBRARY_PATH
diff -urN a/pact-linux-x86_64/lib/ruby/lib/restore_environment.rb b/pact-linux-x86_64/lib/ruby/lib/restore_environment.rb
--- a/pact-linux-x86_64/lib/ruby/lib/restore_environment.rb	2017-12-06 23:31:40.140611400 +1100
+++ b/pact-linux-x86_64/lib/ruby/lib/restore_environment.rb	1970-01-01 10:00:00.000000000 +1000
@@ -1,17 +0,0 @@
-# encoding: utf-8
-# immutable: string
-
-IN_TRAVELING_RUBY = true
-
-restorable_envs = ['LD_LIBRARY_PATH', 'RUBYOPT', 'RUBYLIB'].freeze
-restorable_envs.each do |name|
-  ENV[name] = ENV["ORIG_#{name}"]
-  ENV.delete("ORIG_#{name}")
-end
-
-# We can't restore these environments now because they'll be used later.
-# We just store the original values so that the program can decide what to do.
-$OVERRIDDEN_ENVIRONMENTS = {
-  'SSL_CERT_DIR'  => ENV['OLD_SSL_CERT_DIR'],
-  'SSL_CERT_FILE' => ENV['OLD_SSL_CERT_FILE']
-}
diff -urN a/pact-linux-x86_64/lib/ruby/lib/ruby/2.2.0/restore_environment.rb b/pact-linux-x86_64/lib/ruby/lib/ruby/2.2.0/restore_environment.rb
--- a/pact-linux-x86_64/lib/ruby/lib/ruby/2.2.0/restore_environment.rb	1970-01-01 10:00:00.000000000 +1000
+++ b/pact-linux-x86_64/lib/ruby/lib/ruby/2.2.0/restore_environment.rb	2018-01-05 20:12:57.171936500 +1100
@@ -0,0 +1,17 @@
+# encoding: utf-8
+# immutable: string
+
+IN_TRAVELING_RUBY = true
+
+restorable_envs = ['LD_LIBRARY_PATH', 'RUBYOPT', 'RUBYLIB'].freeze
+restorable_envs.each do |name|
+  ENV[name] = ENV["ORIG_#{name}"]
+  ENV.delete("ORIG_#{name}")
+end
+
+# We can't restore these environments now because they'll be used later.
+# We just store the original values so that the program can decide what to do.
+$OVERRIDDEN_ENVIRONMENTS = {
+  'SSL_CERT_DIR'  => ENV['OLD_SSL_CERT_DIR'],
+  'SSL_CERT_FILE' => ENV['OLD_SSL_CERT_FILE']
+}
@neilcampbell
Copy link
Member

@gruntster Would you mind raising this issue on https://github.com/pact-foundation/pact-ruby-standalone and sending a PR to that project?

@bethesque
Copy link
Member

@gruntster I can see why you've done -I "$LIBDIR/app/lib" but how do the SSL cert changes relate to the space in the path?

@gruntster
Copy link
Contributor Author

@bethesque The patch encloses the include directory, GEM_HOME and GEM_PATH in quotes. The moving of the restore_environment.rb file is so RUBYOPT can use a relative path to avoid referencing an absolute path with a space.

There's probably a more elegant solution. I'm not that au fait with the codebase but the changes were enough to temporarily get me over the line.

@bethesque
Copy link
Member

Apart from the pact-provider-verifier file, the code you're changing comes with Travelling Ruby. It is possible that we could patch it after creating the bundle, but it will be a very hacky solution, and I'm a bit hesitant to try it. I'll have a think about whether there's another way.

Is there a reason why your path must have a space, or are you just safety proofing the code as a public service ;) ?

@gruntster
Copy link
Contributor Author

Ah, I see. Looks like the issue has been known for almost three years: phusion/traveling-ruby#38

The issue occurs on our build server when it generates a path with spaces. I can implement a hack to each of our repos to workaround the problem. I was hoping a universal fix would be possible.

@bethesque
Copy link
Member

Yeah, there's not been much movement on the project for some time. I doubt it will be fixed. Is there any way to restrict the characters in the path generation code instead?

@gruntster
Copy link
Contributor Author

Unfortunately not. We can hardcode paths in each of our CD pipelines but that hinders their portability. It's probably cleaner for us to build custom Linux NuGet packages or revert back to a custom .NET Core build of PactNet v1. I can provide a PR for building patched Linux NuGet packages so others can benefit?

@bethesque
Copy link
Member

It would be the same hack/patch, whether it's the NuGet package or the Travelling Ruby one. If we were going to do it anywhere, it would belong here, and would need to be done for all the executables (there are other scripts in the pact-provider-verifier family). I feel a bit better about it given that the solution was suggested by the Travelling Ruby maintainer. Raise an issue in the standalone repo and I'll have a look at hacking the changes in at build time.

@adamrodger
Copy link
Contributor

Closed due to age.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants