@@ -277,6 +277,128 @@ def new_request(method=nil)
277277 end
278278 end
279279 end
280+
281+ describe "for proxy" do
282+ before do
283+ Chef ::Config [ :http_proxy ] = "http://proxy.example.com:3128"
284+ Chef ::Config [ :https_proxy ] = "http://sproxy.example.com:3129"
285+ Chef ::Config [ :http_proxy_user ] = nil
286+ Chef ::Config [ :https_proxy_pass ] = nil
287+ Chef ::Config [ :https_proxy_user ] = nil
288+ Chef ::Config [ :https_proxy_pass ] = nil
289+ Chef ::Config [ :no_proxy ] = nil
290+ end
291+
292+ after do
293+ Chef ::Config [ :http_proxy ] = nil
294+ Chef ::Config [ :https_proxy ] = nil
295+ Chef ::Config [ :http_proxy_user ] = nil
296+ Chef ::Config [ :https_proxy_pass ] = nil
297+ Chef ::Config [ :https_proxy_user ] = nil
298+ Chef ::Config [ :https_proxy_pass ] = nil
299+ Chef ::Config [ :no_proxy ] = nil
300+ end
301+
302+ describe "with :no_proxy nil" do
303+ it "configures the proxy address and port when using http scheme" do
304+ http_client = new_request . http_client
305+ http_client . proxy? . should == true
306+ http_client . proxy_address . should == "proxy.example.com"
307+ http_client . proxy_port . should == 3128
308+ http_client . proxy_user . should be_nil
309+ http_client . proxy_pass . should be_nil
310+ end
311+
312+ it "configures the proxy address and port when using https scheme" do
313+ @url . scheme = "https"
314+ http_client = new_request . http_client
315+ http_client . proxy? . should == true
316+ http_client . proxy_address . should == "sproxy.example.com"
317+ http_client . proxy_port . should == 3129
318+ http_client . proxy_user . should be_nil
319+ http_client . proxy_pass . should be_nil
320+ end
321+ end
322+
323+ describe "with :no_proxy set" do
324+ before do
325+ Chef ::Config [ :no_proxy ] = "10.*,*.example.com"
326+ end
327+
328+ it "does not configure the proxy address and port when using http scheme" do
329+ http_client = new_request . http_client
330+ http_client . proxy? . should == false
331+ http_client . proxy_address . should be_nil
332+ http_client . proxy_port . should be_nil
333+ http_client . proxy_user . should be_nil
334+ http_client . proxy_pass . should be_nil
335+ end
336+
337+ it "does not configure the proxy address and port when using https scheme" do
338+ @url . scheme = "https"
339+ http_client = new_request . http_client
340+ http_client . proxy? . should == false
341+ http_client . proxy_address . should be_nil
342+ http_client . proxy_port . should be_nil
343+ http_client . proxy_user . should be_nil
344+ http_client . proxy_pass . should be_nil
345+ end
346+ end
347+
348+ describe "with :http_proxy_user and :http_proxy_pass set" do
349+ before do
350+ Chef ::Config [ :http_proxy_user ] = "homie"
351+ Chef ::Config [ :http_proxy_pass ] = "theclown"
352+ end
353+
354+ after do
355+ Chef ::Config [ :http_proxy_user ] = nil
356+ Chef ::Config [ :http_proxy_pass ] = nil
357+ end
358+
359+ it "configures the proxy user and pass when using http scheme" do
360+ http_client = new_request . http_client
361+ http_client . proxy? . should == true
362+ http_client . proxy_user . should == "homie"
363+ http_client . proxy_pass . should == "theclown"
364+ end
365+
366+ it "does not configure the proxy user and pass when using https scheme" do
367+ @url . scheme = "https"
368+ http_client = new_request . http_client
369+ http_client . proxy? . should == true
370+ http_client . proxy_user . should be_nil
371+ http_client . proxy_pass . should be_nil
372+ end
373+ end
374+
375+ describe "with :https_proxy_user and :https_proxy_pass set" do
376+ before do
377+ Chef ::Config [ :https_proxy_user ] = "homie"
378+ Chef ::Config [ :https_proxy_pass ] = "theclown"
379+ end
380+
381+ after do
382+ Chef ::Config [ :https_proxy_user ] = nil
383+ Chef ::Config [ :https_proxy_pass ] = nil
384+ end
385+
386+ it "does not configure the proxy user and pass when using http scheme" do
387+ http_client = new_request . http_client
388+ http_client . proxy? . should == true
389+ http_client . proxy_user . should be_nil
390+ http_client . proxy_pass . should be_nil
391+ end
392+
393+ it "configures the proxy user and pass when using https scheme" do
394+ @url . scheme = "https"
395+ http_client = new_request . http_client
396+ http_client . proxy? . should == true
397+ http_client . proxy_user . should == "homie"
398+ http_client . proxy_pass . should == "theclown"
399+ end
400+ end
401+ end
280402 end
281403
282404end
0 commit comments