File: proxy.t

package info (click to toggle)
libmojolicious-perl 9.31%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,260 kB
  • sloc: perl: 10,139; makefile: 31; javascript: 1
file content (48 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use Mojo::Base -strict;

use Test::More;
use Mojo::UserAgent::Proxy;

# Proxy detection
subtest 'Proxy detection with uppercase variable names' => sub {
  my $proxy = Mojo::UserAgent::Proxy->new;
  local $ENV{HTTP_PROXY}  = 'http://127.0.0.1';
  local $ENV{HTTPS_PROXY} = 'http://127.0.0.1:8080';
  local $ENV{NO_PROXY}    = 'mojolicious.org';
  $proxy->detect;
  is $proxy->http,  'http://127.0.0.1',      'right proxy';
  is $proxy->https, 'http://127.0.0.1:8080', 'right proxy';
  $proxy->http(undef);
  $proxy->https(undef);
  is $proxy->http,  undef, 'right proxy';
  is $proxy->https, undef, 'right proxy';
  ok !$proxy->is_needed('dummy.mojolicious.org'), 'no proxy needed';
  ok $proxy->is_needed('icious.org'),             'proxy needed';
  ok $proxy->is_needed('localhost'),              'proxy needed';
};

subtest 'Proxy detection with lowercase variable names' => sub {
  local $ENV{HTTP_PROXY};
  local $ENV{HTTPS_PROXY};
  local $ENV{NO_PROXY};

  local $ENV{http_proxy}  = 'proxy.example.com';
  local $ENV{https_proxy} = 'tunnel.example.com';
  local $ENV{no_proxy}    = 'localhost,localdomain,foo.com,example.com';

  my $proxy = Mojo::UserAgent::Proxy->new;
  $proxy->detect;
  is_deeply $proxy->not, ['localhost', 'localdomain', 'foo.com', 'example.com'], 'right list';
  is $proxy->http,  'proxy.example.com',  'right proxy';
  is $proxy->https, 'tunnel.example.com', 'right proxy';
  ok $proxy->is_needed('dummy.mojolicious.org'),  'proxy needed';
  ok $proxy->is_needed('icious.org'),             'proxy needed';
  ok !$proxy->is_needed('localhost'),             'proxy needed';
  ok !$proxy->is_needed('localhost.localdomain'), 'no proxy needed';
  ok !$proxy->is_needed('foo.com'),               'no proxy needed';
  ok !$proxy->is_needed('example.com'),           'no proxy needed';
  ok !$proxy->is_needed('www.example.com'),       'no proxy needed';
  ok $proxy->is_needed('www.example.com.com'),    'proxy needed';
};

done_testing();