diff --git a/t/integration/complete.t b/t/integration/complete.t index 0a6f96fba..2ffbbe1df 100644 --- a/t/integration/complete.t +++ b/t/integration/complete.t @@ -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/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; +}