| Server IP : 162.144.4.212 / Your IP : 216.73.216.50 Web Server : Apache System : Linux gator2125.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 User : cozeellc ( 2980) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/PUC/t/DataStore/ |
Upload File : |
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use Test::More;
use Test::Exception;
use JSON;
use PUC::Collector;
## no critic (ProhibitConstantPragma)
use constant CLASS => 'PUC::Collector::DataStore';
use constant KEY_FILE => $FindBin::Bin
. '/../../../testdata/etc/collector/puc_datastore_api_key';
use constant POST_DATA => {
domain => {
name => 'example.com',
type => 'main',
},
server => {
hostname => 'dev.hostgator.com',
},
username => 'hgfedcba',
webApp => {
name => 'wordpress',
version => '1.2.3',
},
};
use constant DATASTORE_API_PATH => '/v1/report/installed/webapp';
use constant SWAGGER_PATH => '/v1/report/installed/webapp';
## use critic
use_ok CLASS;
my $app_config;
subtest 'Get PUC::Collector config' => sub {
my $bindir = $FindBin::Bin . '/../..';
my $debug = $ENV{TEST_VERBOSE} || 0;
my $dryrun = 1;
my $dataroot = $FindBin::Bin . '/../../../testdata/';
lives_ok {
$app_config = PUC::Collector::parse_config(
bindir => $bindir,
debug => $debug,
dryrun => $dryrun,
dataroot => $dataroot,
datastore_base_url => 'dryrun://localhost',
);
}
'Lives through parsing PUC::Collector config';
$app_config->{datastore_config}->{key_file} = KEY_FILE;
};
my $datastore;
my $result;
lives_ok {
$datastore = CLASS->new( %{ $app_config->{datastore_config} } );
$result = $datastore->send_data( ${ \SWAGGER_PATH }, encode_json(POST_DATA) );
}
'Lives through request';
is_deeply {
map { $_ => 1 } keys %{ decode_json( $result->{content} ) }
},
{ map { $_ => 1 } CLASS->SWAGGER_WEBAPP_KEYS },
'Required keys were transmitted';
like $result->{request_data}->{headers}->{Accept}, qr/json/i,
'Accept header specifies json';
like $result->{request_data}->{headers}->{'X-API-Key'}, qr/INSECURE/i,
'X-API-Key header specifies test key';
like $result->{url}, qr/\Q${\SWAGGER_PATH}\E/x,
'url matches endpoint';
done_testing;