tests fine now

This commit is contained in:
Zane C. B-H 2020-11-30 05:19:26 -06:00
parent d89fbc97e8
commit 15ca300a67
2 changed files with 36 additions and 7 deletions

View File

@ -129,12 +129,10 @@ sub new {
accessKey => 1,
};
use Data::Dumper;
#make sure all the keys required are present
foreach my $args_key ( keys( %{$args_valid_keys} ) ) {
if ( !defined( $args->{$args_key} ) ) {
die( 'The key "' . $args_key . '" is not present in the args hash ref... '.Dumper($args) );
die( 'The key "' . $args_key . '" is not present in the args hash ref' );
}
}
@ -221,7 +219,7 @@ sub signature {
# generate the timestamp if needed
# gettimeofday returns microseconds... convert to milliseconds
if ( !defined( $args->{timestmp} ) ) {
if ( !defined( $args->{timestamp} ) ) {
# gettimeofday returns microseconds... convert to milliseconds
$args->{timestamp} = gettimeofday * 1000;
@ -247,7 +245,7 @@ sub signature {
die( 'Failed to generate the signature... ' . $@ );
}
return $self;
return $sig;
}
=head1 AUTHOR

35
t/sig.t
View File

@ -4,8 +4,6 @@ use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'LogicMonitor::REST::Signature' );
}
@ -24,6 +22,7 @@ eval{
};
ok( $worked eq '0', 'init') or diag("Iinitated with missing values");
# make sure we init it
$worked=0;
eval{
$lmsig_helper=LogicMonitor::REST::Signature->new({
@ -35,3 +34,35 @@ eval{
};
ok( $worked eq '1', 'init') or diag("Failed to init the object... ".$@);
# make sure it can generate a known one, which requires a time stamp
$worked=0;
eval{
my $sig=$lmsig_helper->signature({
HTTPverb=>'GET',
path=>'/foo',
data=>'',
timestamp=>'1',
});
if ( $sig ne 'e0bb5OESDeQdMvtJy1Nr6Nju7Nd9axVXHUhMQjjA3f4=' ){
die 'Got "'.$sig.'" but was expecting "e0bb5OESDeQdMvtJy1Nr6Nju7Nd9axVXHUhMQjjA3f4="';
}
$worked=1
};
ok( $worked eq '1', 'signature 0') or diag("Failed to create the expected signature... ".$@);
# make sure it can generate a known one, which requires a time stamp
$worked=0;
eval{
my $sig=$lmsig_helper->signature({
HTTPverb=>'GET',
path=>'/foo',
data=>'',
});
if (! defined ( $sig ) ){
die( 'Got a return of undef' );
}
$worked=1
};
ok( $worked eq '1', 'signature 1') or diag("Failed to create the a signature when auto generating a timestamp... ".$@);
done_testing(5);