Skip to content

Commit

Permalink
Beef up integration test
Browse files Browse the repository at this point in the history
case RE-948: I did the best here to be terse but understandable,
which was difficult without the QA tools. Regardless, I think
this will work.
  • Loading branch information
Thomas "Andy" Baugh authored and Andy Baugh committed Nov 15, 2024
1 parent 7753160 commit 2fa0b6a
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions t/integration/complete.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,64 @@
use lib '/usr/local/cpanel/';

use Cpanel::OS ();
use Cpanel::JSON ();
use Cpanel::SafeRun::Simple ();

use Test::More tests => 7;

use Data::Dumper;
use Test::More;
use Test::FailWarnings; # Ensures that stderr from SafeRun causes fails

is( Cpanel::OS->distro(), 'almalinux', 'System is Almalinux after upgrade.' );
is( Cpanel::OS->major(), '8', 'Verson 8 of OS.' );
is( -e '/var/log/elevate-cpanel.log', 1, 'Elevate log exists.' );
like( Cpanel::SafeRun::Simple::saferun( '/bin/sh', '-c', '/scripts/restartsrv_httpd --status' ), qr/is running as root/, 'Apache is up and accepting connections.' );
like( Cpanel::SafeRun::Simple::saferun( '/bin/sh', '-c', '/scripts/restartsrv_cpsrvd --status' ), qr/is running as root/, 'Chksrvd is up and accepting connections.' );
like( Cpanel::SafeRun::Simple::saferun( '/bin/sh', '-c', '/scripts/restartsrv_named --status' ), qr/is running as named/, 'Nameserver is up and accepting connections.' );
ok( Cpanel::SafeRun::Simple::saferun( '/bin/sh', '-c', 'pgrep elevate' ) eq '', 'No instance of elevate-cpanel currently running.' );

my $svcstatus = run_api( qw{whmapi1 servicestatus} );
ok( $svcstatus->{'result'}, "whmapi1 servicestatus call works" );
if( ref $svcstatus->{'data'}{'service'} eq 'ARRAY' ) {
foreach my $svc_info ($svcstatus->{'data'}{'service'}->@*) {
next if !$svc_info->{'enabled'};
ok( $svc_info->{'running'}, "$svc_info->{'name'} is running" );
}
}
ok( run( qw{pgrep elevate} ) eq '', 'No instance of elevate-cpanel currently running.' );

# Do some basic checks for other things
# Sadly, we don't ship anything useful for login checks, so just use curl
my $login_url = run('/usr/sbin/whmlogin');
my $content = run( qw{curl -k -L}, $login_url );
like( $content, qr/<title>WHM/, "WHM is able to be logged into" );

like( run(qw{/usr/bin/bash -c}, 'echo "SHOW DATABASES" | mysql'), qr/information_schema/, "MySQL seems OK" );

# XXX TODO randomize this, I really wish I had t/qa tools here. Also need to set allowunreg, etc. ;_;
note "Creating an account for testing...";
run_api( qw{whmapi1 set_tewaksetting value=1}, "key=$_" ) for qw{allowunregistereddomains allowremotedomains};
my $user = run_api( qw{whmapi1 createacct domain=azurediamond.test user=azurediamond pass=H4nt3r2_Als0_B1FF_R00LZ} );
$login_url = run_api(qw{whmapi1 create_user_session user=azurediamond service=cpaneld})->{'url'};
$content = run( qw{curl -k -L}, $login_url );
note "Waiting on taskqueue...";
run(qw{/usr/local/cpanel/3rdparty/bin/servers_queue run});
like( $content, qr/<title>cPanel/, "cPanel is able to be logged into with newly created user" );

# XXX TODO Delete the account. Possibly should be done in an END block but meh.
# VM will get whacked after pipeline runs, so *for now* this should be fine to not do.

done_testing();

# Less typing, it all needs the chomp
sub run {
my $out = Cpanel::SafeRun::Simple::saferun(@_);
chomp $out;
return $out;
}

# Returns HASHREF. For "script only opts" like --user, etc., use `--` to separate after API args.
sub run_api {
my ($api, @call_args) = @_;
my $out = {};
{
local $@;
$out = eval { Cpanel::JSON::Load(run( "/usr/local/cpanel/bin/$api", '--output=json', @call_args )) };
warn $@ if $@;
}
return $out;
}

0 comments on commit 2fa0b6a

Please sign in to comment.