Navigation Menu

Skip to content

Commit

Permalink
[rubygems/rubygems] Remove unnecessary DIR constant
Browse files Browse the repository at this point in the history
We have `__dir__` which is the same thing.

rubygems/rubygems@f89776427f
  • Loading branch information
deivid-rodriguez authored and hsbt committed May 7, 2020
1 parent 1ede0c1 commit 427eb2b
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions test/rubygems/test_gem_remote_fetcher.rb
Expand Up @@ -78,8 +78,6 @@ class TestGemRemoteFetcher < Gem::TestCase

PROXY_DATA = SERVER_DATA.gsub(/0.4.11/, '0.4.2')

DIR = File.expand_path(File.dirname(__FILE__))

# Generated via:
# x = OpenSSL::PKey::DH.new(2048) # wait a while...
# x.to_s => pem
Expand Down Expand Up @@ -890,7 +888,7 @@ def test_yaml_error_on_size

def test_ssl_connection
ssl_server = start_ssl_server
temp_ca_cert = File.join(DIR, 'ca_cert.pem')
temp_ca_cert = File.join(__dir__, 'ca_cert.pem')
with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher|
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end
Expand All @@ -901,8 +899,8 @@ def test_ssl_client_cert_auth_connection
:SSLVerifyClient =>
OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT})

temp_ca_cert = File.join(DIR, 'ca_cert.pem')
temp_client_cert = File.join(DIR, 'client.pem')
temp_ca_cert = File.join(__dir__, 'ca_cert.pem')
temp_client_cert = File.join(__dir__, 'client.pem')

with_configured_fetcher(
":ssl_ca_cert: #{temp_ca_cert}\n" +
Expand All @@ -916,8 +914,8 @@ def test_do_not_allow_invalid_client_cert_auth_connection
:SSLVerifyClient =>
OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT})

temp_ca_cert = File.join(DIR, 'ca_cert.pem')
temp_client_cert = File.join(DIR, 'invalid_client.pem')
temp_ca_cert = File.join(__dir__, 'ca_cert.pem')
temp_client_cert = File.join(__dir__, 'invalid_client.pem')

with_configured_fetcher(
":ssl_ca_cert: #{temp_ca_cert}\n" +
Expand Down Expand Up @@ -946,7 +944,7 @@ def test_ssl_connection_allow_verify_none

def test_do_not_follow_insecure_redirect
ssl_server = start_ssl_server
temp_ca_cert = File.join(DIR, 'ca_cert.pem')
temp_ca_cert = File.join(__dir__, 'ca_cert.pem')
expected_error_message =
"redirecting to non-https resource: #{@server_uri} (https://localhost:#{ssl_server.config[:Port]}/insecure_redirect?to=#{@server_uri})"

Expand Down Expand Up @@ -1055,16 +1053,14 @@ def proxy_server_port
@proxy_server[:server].config[:Port]
end

DIR = File.expand_path(File.dirname(__FILE__))

def start_ssl_server(config = {})
null_logger = NilLog.new
server = WEBrick::HTTPServer.new({
:Port => 0,
:Logger => null_logger,
:AccessLog => [],
:SSLEnable => true,
:SSLCACertificateFile => File.join(DIR, 'ca_cert.pem'),
:SSLCACertificateFile => File.join(__dir__, 'ca_cert.pem'),
:SSLCertificate => cert('ssl_cert.pem'),
:SSLPrivateKey => key('ssl_key.pem'),
:SSLVerifyClient => nil,
Expand Down Expand Up @@ -1145,11 +1141,11 @@ def start_server(data)
end

def cert(filename)
OpenSSL::X509::Certificate.new(File.read(File.join(DIR, filename)))
OpenSSL::X509::Certificate.new(File.read(File.join(__dir__, filename)))
end

def key(filename)
OpenSSL::PKey::RSA.new(File.read(File.join(DIR, filename)))
OpenSSL::PKey::RSA.new(File.read(File.join(__dir__, filename)))
end

end if defined?(OpenSSL::SSL)

0 comments on commit 427eb2b

Please sign in to comment.