TT#28472 cert file per Collection.pm instance

+ fix api-cert-auth.t
+ fix api-balanceintervals.t "parallel" timing tests

Change-Id: I458e01b9ae45f8500b1fa689c1ac191c303ffa28
changes/20/17920/2
Rene Krenn 7 years ago
parent 148b119824
commit bf9b84419e

@ -28,7 +28,7 @@ use NGCP::Panel::Utils::DateTime qw();
#use NGCP::Panel::Utils::ProfilePackages qw(); #since it depends on Utils::Subscribers and thus Sipwise::Base, importin it causes segfault when creating threads.. #use NGCP::Panel::Utils::ProfilePackages qw(); #since it depends on Utils::Subscribers and thus Sipwise::Base, importin it causes segfault when creating threads..
my $is_local_env = 0; my $is_local_env = 0;
my $disable_parallel_catchup = 1; my $disable_parallel_catchup = 0;
my $disable_hourly_intervals = 1; my $disable_hourly_intervals = 1;
#my $enable_profile_packages = NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; #my $enable_profile_packages = NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES;
#my $enable_profile_packages = 1; #my $enable_profile_packages = 1;
@ -1008,7 +1008,7 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
#is($intervals_b->{total_count},scalar (grep { $_->{contact_id} == $custcontact9->{id} } values %customer_map),"check total count of thread b results"); #is($intervals_b->{total_count},scalar (grep { $_->{contact_id} == $custcontact9->{id} } values %customer_map),"check total count of thread b results");
#is($intervals_c->{total_count},3,"check total count of thread c results"); #is($intervals_c->{total_count},3,"check total count of thread c results");
ok($t2 - $t1 < $delta_serialized,'expected delay to assume only required contracts were locked and requests were performed in parallel') if !$disable_parallel_catchup; ok(($t2 - $t1) < $delta_serialized,'expected delay to assume only required contracts were locked and requests were performed in parallel') if !$disable_parallel_catchup;
} else { } else {
diag('allow_delay_commit not set, skipping ...'); diag('allow_delay_commit not set, skipping ...');
@ -1059,7 +1059,7 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
#is($intervals_b->{total_count},scalar (grep { $_->{contact_id} == $custcontact9->{id} } values %customer_map),"check total count of thread b results"); #is($intervals_b->{total_count},scalar (grep { $_->{contact_id} == $custcontact9->{id} } values %customer_map),"check total count of thread b results");
#is($intervals_c->{total_count},3,"check total count of thread c results"); #is($intervals_c->{total_count},3,"check total count of thread c results");
ok($t2 - $t1 < $delta_serialized,'expected delay to assume only required contracts were locked and requests were performed in parallel') if !$disable_parallel_catchup; ok(($t2 - $t1) < $delta_serialized,'expected delay to assume only required contracts were locked and requests were performed in parallel') if !$disable_parallel_catchup;
} else { } else {
@ -1141,7 +1141,7 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
is($got_asc->[$i]->{lock},4,"check if subscriber is locked now"); is($got_asc->[$i]->{lock},4,"check if subscriber is locked now");
} }
ok($t2 - $t1 < $delta_serialized,'expected delay to assume only required contracts were locked and requests were performed in parallel') if !$disable_parallel_catchup; ok(($t2 - $t1) < $delta_serialized,'expected delay to assume only required contracts were locked and requests were performed in parallel') if !$disable_parallel_catchup;
$t1 = time; $t1 = time;
$t_a = threads->create(\&_fetch_preferences_worker,$delay,'id','asc',$custcontact2); $t_a = threads->create(\&_fetch_preferences_worker,$delay,'id','asc',$custcontact2);
@ -1236,7 +1236,7 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
for (my $i = 0; $i < 2*3; $i++) { for (my $i = 0; $i < 2*3; $i++) {
is($got_asc->[$i]->{lock},4,"check if subscriber is locked now"); is($got_asc->[$i]->{lock},4,"check if subscriber is locked now");
} }
ok($t2 - $t1 < $delta_serialized,'expected delay to assume only required contracts were locked and requests were performed in parallel') if !$disable_parallel_catchup; ok(($t2 - $t1) < $delta_serialized,'expected delay to assume only required contracts were locked and requests were performed in parallel') if !$disable_parallel_catchup;
$t1 = time; $t1 = time;
$t_a = threads->create(\&_fetch_subscribers_worker,$delay,'id','asc',$custcontact2); $t_a = threads->create(\&_fetch_subscribers_worker,$delay,'id','asc',$custcontact2);

@ -7,13 +7,10 @@ use Test::More;
use File::Temp qw/tempfile/; use File::Temp qw/tempfile/;
use Test::Collection; use Test::Collection;
my $certpath = '/tmp/apicert.pem';
my $uri = $ENV{CATALYST_SERVER} || ('https://'.hostfqdn.':4443'); my $uri = $ENV{CATALYST_SERVER} || ('https://'.hostfqdn.':4443');
#docker: CATALYST_SERVER=https://10.15.20.104:1443 perl t/api-rest/api-cert-auth.t #docker: CATALYST_SERVER=https://10.15.20.104:1443 perl t/api-rest/api-cert-auth.t
-f $certpath && unlink $certpath;
my ($invalid_ssl_client_cert, $valid_ssl_client_cert) = _download_certs($uri); my ($invalid_ssl_client_cert, $valid_ssl_client_cert) = _download_certs($uri);
my ($ua, $res); my ($ua, $res);
@ -57,10 +54,12 @@ sub _download_certs {
-f $invalid_cert && unlink $invalid_cert; -f $invalid_cert && unlink $invalid_cert;
-f $valid_cert && unlink $valid_cert; -f $valid_cert && unlink $valid_cert;
$ua = Test::Collection->new()->ua();
rename $certpath, $invalid_cert; my $coll = Test::Collection->new();
$ua = Test::Collection->new()->ua(); rename $coll->ssl_cert, $invalid_cert;
rename $certpath, $valid_cert; $coll->clear_cert;
rename $coll->ssl_cert, $valid_cert;
return ($invalid_cert, $valid_cert); return ($invalid_cert, $valid_cert);
} }

@ -20,14 +20,14 @@ use File::Slurp qw/write_file/;
use Storable; use Storable;
use Carp qw(cluck longmess shortmess); use Carp qw(cluck longmess shortmess);
use IO::Uncompress::Unzip; use IO::Uncompress::Unzip;
use File::Temp qw();
has 'crt_path' => ( has 'ssl_cert' => (
is => 'ro', is => 'ro',
isa => 'Str', isa => 'Str',
lazy => 1, lazy => 1,
default => sub {'/tmp/apicert.pem';}, builder => 'init_ssl_cert',
); );
has 'data_cache_file' => ( has 'data_cache_file' => (
is => 'ro', is => 'ro',
isa => 'Str', isa => 'Str',
@ -251,6 +251,10 @@ sub init_catalyst_config{
} }
sub init_ua { sub init_ua {
my $self = shift; my $self = shift;
return $self->_create_ua(1);
}
sub _create_ua {
my ($self,$init_cert) = @_;
my $ua = LWP::UserAgent->new; my $ua = LWP::UserAgent->new;
my $uri = $self->base_uri; my $uri = $self->base_uri;
$uri =~ s/^https?:\/\///; $uri =~ s/^https?:\/\///;
@ -260,14 +264,17 @@ sub init_ua {
verify_hostname => 0, verify_hostname => 0,
SSL_verify_mode => 0, SSL_verify_mode => 0,
); );
if($role eq "default" || $role eq "admin" || $role eq "reseller") { if($init_cert and ($role eq "default" || $role eq "admin" || $role eq "reseller")) {
$self->init_ssl_cert($ua); $ua->ssl_opts(
SSL_cert_file => $self->ssl_cert,
SSL_key_file => $self->ssl_cert,
);
} }
return $ua; return $ua;
} }
sub init_ssl_cert { sub init_ssl_cert {
my ($self, $ua) = @_; my ($self, $ua) = @_;
unless(-f $self->crt_path) { $ua = $self->_create_ua(0) unless $ua;
my $res = $ua->post( my $res = $ua->post(
$self->base_uri . '/api/admincerts/', $self->base_uri . '/api/admincerts/',
Content_Type => 'application/json', Content_Type => 'application/json',
@ -294,14 +301,16 @@ sub init_ssl_cert {
unless($data) { unless($data) {
die "failed to find PEM file in client certificate zip file\n"; die "failed to find PEM file in client certificate zip file\n";
} }
open my $fh, ">:raw", $self->crt_path or die "failed to open " . $self->crt_path . ": $!\n"; my ($tmpfh,$tmpfilename) = File::Temp::tempfile('apicert_XXXX', DIR => '/tmp', SUFFIX => '.pem', UNLINK => 0);
print $fh $data; print $tmpfh $data;
close $fh; close $tmpfh;
return $tmpfilename;
} }
$ua->ssl_opts( sub clear_cert {
SSL_cert_file => $self->crt_path, my $self = shift;
SSL_key_file => $self->crt_path, delete $self->{ua};
); delete $self->{ssl_cert};
return $self;
} }
sub runas { sub runas {
my $self = shift; my $self = shift;

Loading…
Cancel
Save