Clustericious
view release on metacpan or search on metacpan
lib/Clustericious/Client.pm view on Meta::CPAN
use Carp qw( carp );
use Mojo::Util qw( monkey_patch );
# ABSTRACT: Construct command line and perl clients for RESTful services.
our $VERSION = '1.29'; # VERSION
has server_url => '';
has [qw(tx res userinfo ua )];
has _remote => ''; # Access via remote()
has _cache => sub { + {} }; # cache of credentials
sub client
{
carp "Clustericious::Client->client is deprecated (use ua instead)";
shift->ua(@_);
}
sub import
{
my($class) = @_;
lib/Clustericious/Client.pm view on Meta::CPAN
my $tx = $self->ua->build_tx($method, $url, $headers, $body);
$tx = $self->ua->start($tx);
my $res = $tx->res;
$self->res($res);
$self->tx($tx);
my $auth_header;
if (($tx->res->code||0) == 401 && ($auth_header = $tx->res->headers->www_authenticate)
&& !$url->userinfo && ($self->_has_auth || $self->_can_auth)) {
DEBUG "received code 401, trying again with credentials";
my ($realm) = $auth_header =~ /realm=(.*)$/i;
my $host = $url->host;
$self->login( $self->_has_auth ? () : $self->_get_user_pw($host,$realm) );
return $self->_doit($meta ? $meta : (), @_);
}
if ($res->is_success) {
TRACE "Got response : ".$res->to_string;
my $content_type = $res->headers->content_type || do {
WARN "No content-type from "._sanitize_url($url);
t/clustericious_plugin_plugauth.t view on Meta::CPAN
plan tests => 3;
my $url = $cluster->url->clone;
$url->userinfo('foo:bar');
$url->path('/private');
$t->get_ok($url)
->status_is(503)
->content_is('auth server down');
};
subtest 'non VIP host making request, authentication credentials are ok and user is authorized' => sub {
plan tests => 3;
my $url = $cluster->url->clone;
$url->userinfo('foo:bar');
local $status = {
trusted => 0,
auth => 1,
authz => 1,
};
$url->path('/private');
$t->get_ok($url)
->status_is(200)
->content_is('this is private');
};
subtest "host is trusted, credentials wouldn't check out, but users is authorized" => sub {
plan tests => 3;
my $url = $cluster->url->clone;
$url->userinfo('foo:bar');
local $status = {
trusted => 1,
auth => 0,
authz => 1,
};
$url->path('/private');
$t->get_ok($url)
->status_is(200)
->content_is('this is private');
};
subtest 'non VIP host making request with bad credentials, user is authorized' => sub {
plan tests => 3;
my $url = $cluster->url->clone;
$url->userinfo('foo:bar');
local $status = {
trusted => 0,
auth => undef,
authz => 1,
};
$url->path('/private');
$t->get_ok($url)
->status_is(503)
->content_is('auth server down');
};
subtest 'non VIP host making request with good credentials, authz server is DOWN' => sub {
plan tests => 3;
my $url = $cluster->url->clone;
$url->userinfo('foo:bar');
local $status = {
trusted => 0,
auth => 1,
authz => undef,
};
$url->path('/private');
$t->get_ok($url)
->status_is(503)
->content_is('auth server down');
};
subtest 'non VIP host making request with good credentials, but user is not authorized' => sub {
plan tests => 3;
my $url = $cluster->url->clone;
$url->userinfo('foo:bar');
local $status = {
trusted => 0,
auth => 1,
authz => 0,
};
$url->path('/private');
$t->get_ok($url)
->status_is(403)
->content_is('unauthorized');
};
subtest 'non VIP host making request with bad credentials, but user IS authorized' => sub {
plan tests => 3;
my $url = $cluster->url->clone;
$url->userinfo('foo:bar');
local $status = {
trusted => 0,
auth => 0,
authz => 1,
};
( run in 0.232 second using v1.01-cache-2.11-cpan-4d50c553e7e )