|
75 | 75 |
|
76 | 76 | expect(services.include?(CC::PullRequests)).not_to eq(true) |
77 | 77 | end |
| 78 | + |
| 79 | + context "with proxy details" do |
| 80 | + before do |
| 81 | + @old_no_proxy = ENV["no_proxy"] |
| 82 | + @old_http_proxy = ENV["http_proxy"] |
| 83 | + ENV["no_proxy"] = "github.com" |
| 84 | + ENV["http_proxy"] = "http://127.0.0.2:42" |
| 85 | + end |
| 86 | + |
| 87 | + after do |
| 88 | + ENV["no_proxy"] = @old_no_proxy |
| 89 | + ENV["http_proxy"] = @old_http_proxy |
| 90 | + end |
| 91 | + |
| 92 | + it "uses the proxy when it should" do |
| 93 | + stub_http("http://proxied.test/my/test/url") do |env| |
| 94 | + expect(env.request.proxy).to be_instance_of(Faraday::ProxyOptions) |
| 95 | + expect(env.request.proxy.uri).to eq(URI.parse("http://127.0.0.2:42")) |
| 96 | + [200, {}, '{"ok": true, "thing": "123"}'] |
| 97 | + end |
| 98 | + |
| 99 | + response = service_post("http://proxied.test/my/test/url", { token: "1234" }.to_json, {}) do |inner_response| |
| 100 | + body = JSON.parse(inner_response.body) |
| 101 | + { thing: body["thing"] } |
| 102 | + end |
| 103 | + |
| 104 | + expect(response[:ok]).to eq(true) |
| 105 | + expect(response[:params]).to eq('{"token":"1234"}') |
| 106 | + expect(response[:endpoint_url]).to eq("http://proxied.test/my/test/url") |
| 107 | + expect(response[:status]).to eq(200) |
| 108 | + end |
| 109 | + |
| 110 | + it "respects proxy exclusions" do |
| 111 | + stub_http("http://github.com/my/test/url") do |env| |
| 112 | + expect(env.request.proxy).to be_nil |
| 113 | + [200, {}, '{"ok": true, "thing": "123"}'] |
| 114 | + end |
| 115 | + |
| 116 | + response = service_post("http://github.com/my/test/url", { token: "1234" }.to_json, {}) do |inner_response| |
| 117 | + body = JSON.parse(inner_response.body) |
| 118 | + { thing: body["thing"] } |
| 119 | + end |
| 120 | + |
| 121 | + expect(response[:ok]).to eq(true) |
| 122 | + expect(response[:params]).to eq('{"token":"1234"}') |
| 123 | + expect(response[:endpoint_url]).to eq("http://github.com/my/test/url") |
| 124 | + expect(response[:status]).to eq(200) |
| 125 | + end |
| 126 | + |
| 127 | + end |
78 | 128 | end |
0 commit comments