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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
use strict;
use warnings;
use Test::More;
use AnyEvent::Connector;
subtest "no no_proxy", sub {
my $c = AnyEvent::Connector->new(
proxy => "http://hoge.com",
);
is $c->proxy_for("localhost", 80), "http://hoge.com";
is $c->proxy_for("127.0.0.1", 5000), "http://hoge.com";
is $c->proxy_for("foo.example.com", 22), "http://hoge.com";
is $c->proxy_for("buzz.example.com", 22), "http://hoge.com";
is $c->proxy_for("bar.quux.net",443), "http://hoge.com";
};
subtest "no_proxy domain", sub {
my $c = AnyEvent::Connector->new(
proxy => "http://hoge.com",
no_proxy => "example.com",
);
is $c->proxy_for("localhost", 80), "http://hoge.com";
is $c->proxy_for("127.0.0.1", 5000), "http://hoge.com";
is $c->proxy_for("foo.example.com", 22), undef;
is $c->proxy_for("buzz.example.com", 22), undef;
is $c->proxy_for("bar.quux.net",443), "http://hoge.com";
};
subtest "no_proxy host", sub {
my $c = AnyEvent::Connector->new(
proxy => "http://hoge.com",
no_proxy => "buzz.example.com",
);
is $c->proxy_for("localhost", 80), "http://hoge.com";
is $c->proxy_for("127.0.0.1", 5000), "http://hoge.com";
is $c->proxy_for("foo.example.com", 22), "http://hoge.com";
is $c->proxy_for("buzz.example.com", 22), undef;
is $c->proxy_for("bar.quux.net",443), "http://hoge.com";
};
subtest "no_proxy list", sub {
my $c = AnyEvent::Connector->new(
proxy => "http://hoge.com",
no_proxy => ["example.com", "localhost"],
);
is $c->proxy_for("localhost", 80), undef;
is $c->proxy_for("127.0.0.1", 5000), "http://hoge.com";
is $c->proxy_for("foo.example.com", 22), undef;
is $c->proxy_for("buzz.example.com", 22), undef;
is $c->proxy_for("bar.quux.net",443), "http://hoge.com";
};
subtest "no_proxy IPv4 address", sub {
my $c = AnyEvent::Connector->new(
proxy => "http://hoge.com",
no_proxy => "127.0.0.1",
);
is $c->proxy_for("localhost", 80), "http://hoge.com";
is $c->proxy_for("127.0.0.1", 5000), undef;
is $c->proxy_for("foo.example.com", 22), "http://hoge.com";
is $c->proxy_for("buzz.example.com", 22), "http://hoge.com";
is $c->proxy_for("bar.quux.net",443), "http://hoge.com";
};
subtest "no_proxy empty string", sub {
my $c = AnyEvent::Connector->new(
proxy => "http://hoge.com",
no_proxy => "",
);
is $c->proxy_for("localhost", 80), "http://hoge.com";
is $c->proxy_for("127.0.0.1", 5000), "http://hoge.com";
is $c->proxy_for("foo.example.com", 22), "http://hoge.com";
is $c->proxy_for("buzz.example.com", 22), "http://hoge.com";
is $c->proxy_for("bar.quux.net",443), "http://hoge.com";
};
subtest "no_proxy empty arrayref", sub {
my $c = AnyEvent::Connector->new(
proxy => "http://hoge.com",
no_proxy => [],
);
is $c->proxy_for("localhost", 80), "http://hoge.com";
is $c->proxy_for("127.0.0.1", 5000), "http://hoge.com";
is $c->proxy_for("foo.example.com", 22), "http://hoge.com";
is $c->proxy_for("buzz.example.com", 22), "http://hoge.com";
is $c->proxy_for("bar.quux.net",443), "http://hoge.com";
};
subtest "no_proxy environment should be ignored if env_proxy option is not specified", sub {
local $ENV{no_proxy} = "foo.com";
my $c = AnyEvent::Connector->new(
proxy => "http://bar.net:8080"
);
is $c->proxy_for("www.foo.com", 80), "http://bar.net:8080";
is $c->proxy_for("foo.com", 80), "http://bar.net:8080";
is $c->proxy_for("hoge.com", 5000), "http://bar.net:8080";
};
done_testing;
|