Skip to content

Commit

Permalink
Tests for user agent injection
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelruiz committed Jan 16, 2013
1 parent 892c39f commit 3b730b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion t/01-opsview-rest.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use FindBin;
use lib "$FindBin::Bin/lib";
use Opsview::REST::TestUtils;

use HTTP::Tiny;

use Test::More tests => 14;
use Test::Exception;

Expand Down Expand Up @@ -34,7 +36,11 @@ SKIP: {
is($@->reason, 'Unauthorized', '"Unauthorized" reason in exception');
ok(defined $@->message, 'Message defined in exception');

my $ops = get_opsview();
my $ops = get_opsview(undef, undef, undef, ua => HTTP::Tiny->new);
like($ops->ua->agent, qr/HTTP-Tiny/, 'Force user agent');

$ops = get_opsview();
like($ops->ua->agent, qr/Opsview-REST/, 'Default user agent');

isa_ok($ops, 'Opsview::REST', "Object created");
ok(defined $ops->headers->{'X-Opsview-Token'}, "Logged in");
Expand Down
5 changes: 4 additions & 1 deletion t/lib/Opsview/REST/TestUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ use Test::Exception;
use Test::Deep;

sub get_opsview {
my ($url, $user, $pass) = (qw( http://localhost/rest admin initial ));
my ($url, $user, $pass, %opts) =
(qw( http://localhost/rest admin initial ));

return Opsview::REST->new(
base_url => $ENV{OPSVIEW_REST_URL} || $url,
user => $ENV{OPSVIEW_REST_USER} || $user,
pass => $ENV{OPSVIEW_REST_PASS} || $pass,
%opts
);
}

Expand Down

0 comments on commit 3b730b6

Please sign in to comment.