Skip to content

Commit

Permalink
Add acceptance tests for new :net_http_connect_on_start allowed values
Browse files Browse the repository at this point in the history
  • Loading branch information
rzane committed May 22, 2022
1 parent de69d99 commit fecb72c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/acceptance/net_http/net_http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ class TestMarshalingInWebMockNetHTTP
}
end

it "should connect to the server on start when allowlisted", net_connect: true do
WebMock.disable_net_connect!(allow: "www.google.com", net_http_connect_on_start: "www.google.com")
@http.start {|conn|
cert = OpenSSL::X509::Certificate.new conn.peer_cert
expect(cert).to be_a(OpenSSL::X509::Certificate)
}
end

it "should not connect to the server on start when not allowlisted", net_connect: true do
WebMock.disable_net_connect!(allow: "www.google.com", net_http_connect_on_start: "www.yahoo.com")
@http.start {|conn|
expect(conn.peer_cert).to be_nil
}
end

it "should connect to the server if the URI matches an regex", net_connect: true do
WebMock.disable_net_connect!(allow: /google.com/)
Net::HTTP.get('www.google.com','/')
Expand Down Expand Up @@ -282,6 +297,13 @@ class TestMarshalingInWebMockNetHTTP
it_should_behave_like "Net::HTTP"
end

describe "when net_http_connect_on_start is a specific host" do
before(:each) do
WebMock.allow_net_connect!(net_http_connect_on_start: "localhost")
end
it_should_behave_like "Net::HTTP"
end

describe 'after_request callback support', net_connect: true do
let(:expected_body_regex) { /hello world/ }

Expand Down

0 comments on commit fecb72c

Please sign in to comment.