Skip to content

Commit

Permalink
Use securerandom for generating socket path in test
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed Jan 19, 2016
1 parent d687f1d commit c21ae72
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions spec/support/mock_setup_file.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
require 'securerandom'

module MockSetupFile
def setup_mocked_config_files
setup_invoker_config
setup_osx_resolver_path
setup_linux_resolver_path
setup_socket_path
end

def remove_mocked_config_files
restore_invoker_config
restore_osx_resolver_setup
restore_linux_resolver_path
restore_socket_path
end

def safe_remove_file(file_location)
Expand Down Expand Up @@ -48,6 +52,16 @@ def setup_osx_resolver_path
safe_remove_file(Invoker::Power::OsxSetup::RESOLVER_FILE)
end

def setup_socket_path
@old_socket_path = Invoker::IPC::Server::SOCKET_PATH
socket_uuid = SecureRandom.urlsafe_base64
Invoker::IPC::Server.const_set(:SOCKET_PATH, "/tmp/invoker-#{socket_uuid}")
end

def restore_socket_path
Invoker::IPC::Server.const_set(:SOCKET_PATH, @old_socket_path)
end

def setup_linux_resolver_path
@old_linux_resolver = Invoker::Power::Distro::Base::RESOLVER_FILE
@old_socat_script = Invoker::Power::Distro::Base::SOCAT_SHELLSCRIPT
Expand Down

0 comments on commit c21ae72

Please sign in to comment.