Neo4j-Driver
view release on metacpan or search on metacpan
t/net-tiny.t view on Meta::CPAN
headers => {
'content-type' => 'text/plain',
},
};
is $m->fetch_all(), $msg, 'fetch_all';
is $m->http_header->{content_type}, '', 'content_type empty';
is $m->http_header->{status}, '', 'status empty';
is $m->http_reason(), $msg, 'reason message';
};
subtest 'response jolt ndjson' => sub {
plan 4;
my @jolt = qw( {"header":{"fields":["0"]}} {"data":[1]} {"data":[2]} );
$m->{response} = {
content => ( join '', map { "$_\n" } @jolt ),
headers => { 'content-type' => 'application/vnd.neo4j.jolt' },
};
is $m->fetch_event(), qq<{"header":{"fields":["0"]}}\n>, 'fetch_event 0';
is $m->fetch_event(), qq<{"data":[1]}\n>, 'fetch_event 1';
is $m->fetch_event(), qq<{"data":[2]}\n>, 'fetch_event 2';
is $m->fetch_event(), qq<>, 'fetch_event 3 empty';
};
subtest 'response jolt json-seq' => sub {
plan 3;
my @jolt = qw( {"header":{"fields":["0"]}} {"info":{}} );
$m->{response} = {
content => ( "\x{1e}" . join "\n\x{1e}", @jolt ),
headers => { 'content-type' => 'application/vnd.neo4j.jolt-v2+json-seq' },
};
is $m->fetch_event(), qq<{"header":{"fields":["0"]}}\n>, 'fetch_event 0';
is $m->fetch_event(), qq<{"info":{}}>, 'fetch_event 1';
is $m->fetch_event(), qq<>, 'fetch_event 2 empty';
};
subtest 'auth variations' => sub {
plan 4;
my $clone = $base->clone;
$clone->userinfo($userinfo);
my $config;
$config = { uri => $base, auth => { scheme => 'basic', principal => "\xc4\x80" } };
$m = Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
like $m->uri(), qr|//%C3%84%C2%80:@|i, 'latin1 userid after utf8::encode';
$config = { uri => $base, auth => { scheme => 'basic', credentials => "\x{100}" } };
$m = Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
like $m->uri(), qr|//:%C4%80@|i, 'uri with utf8 passwd';
$config = { uri => $base };
$m = Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
is $m->uri(), 'http://net.test/', 'uri no auth';
$config = { uri => $base, auth => { scheme => 'blackmagic' } };
like dies {
Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
}, qr/\bBasic Auth/i, 'new custom auth croaks';
};
subtest 'tls' => sub {
skip_all "(IO::Socket::SSL unavailable)" unless eval 'require IO::Socket::SSL; 1';
skip_all "(Net::SSLeay unavailable)" unless eval 'require Net::SSLeay; 1';
plan 8;
my $config;
try_ok {
$config = { uri => URI->new('https://e.net.test/'), encrypted => 1 };
$m = Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
} 'encrypted https';
like $m->uri(), qr|^https://e|i, 'encrypted https uri';
try_ok {
$config = { uri => URI->new('https://d.net.test/'), encrypted => undef };
$m = Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
} 'https';
like $m->uri(), qr|^https://d|i, 'https uri';
my $ca_file = eval { ({ IO::Socket::SSL::default_ca() })->{SSL_ca_file} };
SKIP: {
skip "(default CA file unavailable)", 4 unless $ca_file;
try_ok {
$config = { uri => URI->new('https://c.net.test/'), trust_ca => $ca_file };
$m = Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
} 'https trust_ca lives';
like $m->uri(), qr|^https://c|i, 'https trust_ca uri';
is $m->{http}->SSL_options->{SSL_ca_file}, $ca_file, 'https trust_ca';
ok $m->{http}->verify_SSL, 'https verify_SSL';
}
};
subtest 'tls config errors' => sub {
plan 2;
my $config;
like dies {
$config = { uri => $base, encrypted => 1 };
Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
}, qr/\bHTTP does not support encrypted communication\b/i, 'no encrypted http';
SKIP: {
skip "(IO::Socket::SSL unavailable)", 1 unless eval 'require IO::Socket::SSL; 1';
skip "(Net::SSLeay unavailable)", 1 unless eval 'require Net::SSLeay; 1';
like dies {
$config = { uri => URI->new('https://net.test/'), encrypted => 0 };
Neo4j::Driver::Net::HTTP::Tiny->new( new_driver_config $config );
}, qr/\bHTTPS does not support unencrypted communication\b/i, 'no unencrypted https';
}
};
done_testing;
( run in 1.234 second using v1.01-cache-2.11-cpan-39bf76dae61 )