API-CPanel
view release on metacpan or search on metacpan
t/01-test.t view on Meta::CPAN
#!/usr/bin/perl -w
use strict;
use warnings;
use lib qw( ./lib );
use Data::Dumper;
our $ONLINE;
BEGIN {
#$ENV{auth_user} = 'restest';
#$ENV{auth_passwd} = '123';
#$ENV{host} = '192.168.123.1';
$ONLINE = $ENV{auth_user} && $ENV{auth_passwd} && $ENV{host};
}
my $manipulate_user = 'zsezse';
use Test::More tests => $ONLINE ? 61 : 61;
my $test_host = $ENV{host} || '127.0.0.1';
ok(1, 'Test OK');
use_ok('API::CPanel');
$a = 'refs';
is( refs( undef ), '', $a);
is( refs( {} ), 'HASH', $a );
is( refs( [] ), 'ARRAY', $a );
is( refs( sub {} ), 'CODE', $a );
is( refs( \$a ), 'SCALAR', $a );
$a = 'is_success';
ok(! is_success(), $a);
ok(! is_success( { error => {}, data => {} } ), $a);
ok(! is_success( { data => {} } ), $a);
ok(! is_success( { } ), $a);
ok( is_success( { status => 1 } ), $a);
$a = 'filter_hash';
is_deeply( API::CPanel::filter_hash( { }, [ ]), {}, $a );
is_deeply( API::CPanel::filter_hash( { aaa => 555, bbb => 111 }, [ 'aaa' ]), { aaa => 555 }, $a );
is_deeply( API::CPanel::filter_hash( { aaa => 555, bbb => 111 }, [ ]), { }, $a );
is_deeply( API::CPanel::filter_hash( { }, [ 'aaa' ]), { }, $a );
$a = 'mk_query_string';
is( API::CPanel::mk_query_string( { } ), '', $a );
is( API::CPanel::mk_query_string( '' ), '', $a );
is( API::CPanel::mk_query_string( undef ), '', $a );
is( API::CPanel::mk_query_string( { aaa => 111, bbb => 222 } ), 'aaa=111&bbb=222', $a );
is( API::CPanel::mk_query_string( { bbb => 222, aaa => 111 } ), 'aaa=111&bbb=222', $a );
is( API::CPanel::mk_query_string( [ ] ), '', $a );
is( API::CPanel::mk_query_string( { dddd => 'dfdf' } ), 'dddd=dfdf', $a );
my $kill_start_end_slashes_test = {
'////aaa////' => 'aaa',
'bbb////' => 'bbb',
'////ccc' => 'ccc',
'' => '',
};
for (keys %$kill_start_end_slashes_test) {
is(
API::CPanel::kill_start_end_slashes ($_),
$kill_start_end_slashes_test->{$_},
'kill_start_end_slashes'
);
}
$a = 'mk_full_query_string';
is( API::CPanel::mk_full_query_string( {
host => $test_host,
} ),
'',
$a
);
is( API::CPanel::mk_full_query_string( {
host => $test_host,
allow_http => 1,
path => 'xml-api',
} ),
'',
$a
);
is( API::CPanel::mk_full_query_string( {
host => $test_host,
allow_http => 1,
param1 => 'val1',
param2 => 'val2',
func => 'test',
} ),
"http://$test_host:2087/xml-api/test?param1=val1¶m2=val2",
$a
);
t/01-test.t view on Meta::CPAN
<setsiteip>
<result>
<status>1</status>
<statusmsg></statusmsg>
</result>
</setsiteip>
THEEND
$result = API::CPanel::Domain::change_site_ip(
{
%correct_params,
ip => '192.168.123.150',
user => $manipulate_user,
}
);
is( $result, 1, 'API::CPanel::Domain::change_site_ip');
$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<setsiteip>
<result>
<status>1</status>
<statusmsg></statusmsg>
</result>
</setsiteip>
THEEND
$result = API::CPanel::Domain::change_site_ip(
{
%correct_params,
ip => $main_shared_ip,
user => $manipulate_user,
}
);
is( $result, 1, 'API::CPanel::Domain::change_site_ip to main_shared_ip');
$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<delip>
<delip>
<status>1</status>
<statusmsg>eth0:4 is now down, 192.168.123.150 has been removed</statusmsg>
</delip>
</delip>
THEEND
$result = API::CPanel::Ip::remove(
{
%correct_params,
ip => '192.168.123.150',
}
);
is( $result, 1, 'API::CPanel::Ip::remove');
$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<removeacct>
<result>
<rawout>Running pre removal script (/scripts/prekillacct)......DoneCollecting Domain Name and IP...User: zseasd
Domain: zse1.ru
...DoneKilling all processes owned by user......DoneCleaning passwd,shadow,group......DoneRemoving User from Group..........DoneRemoving Web Logs......DoneRemoving Bandwidth Files......DoneRemoving Crontab......DoneRemoving Virtual Hosts...Removed zs...
Removed Entry from httpd.conf
...DoneRemoving MySQL databases and users......DoneRemoving PostgreSQL databases and users......DoneRemoving System User......DoneRemoving Group......DoneRemoving DNS Entries...zse1.ru => deleted from www.
...DoneRemoving Email Setup...Removing /etc/valiases/zse1.ru
...DoneRemoving mailman lists......DoneUpdating Databases......DoneRemoving Counter Data......DoneAdding ip back to the ip address pool...System has 2 free ips.
...DoneRemoving users cPanel Databases & Updating......DoneReloading Services......DoneRemoving mail and service configs...
...DoneSending Contacts......DoneUpdating internal databases...Updating ftp passwords for zseasd
Purging ftp user zseasd
Ftp password files updated.
Ftp vhost passwords synced
...DoneRunning post removal scripts (/scripts/legacypostkillacct, /scripts/postkillacct)......DoneAccount Removal Complete!!!...zseasd account removed...Done</rawout>
<status>1</status>
<statusmsg>zseasd account removed</statusmsg>
</result>
</removeacct>
THEEND
$result = API::CPanel::User::delete(
{
%correct_params,
user => $manipulate_user,
}
);
is( $result, 1, 'API::CPanel::User::delete');
$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<removeacct>
<result>
<rawout></rawout>
<status>0</status>
<statusmsg>Warning!.. system user zseasd does not exist!
</statusmsg>
</result>
</removeacct>
THEEND
$result = API::CPanel::User::delete(
{
%correct_params,
user => $manipulate_user,
}
);
is( $result, '', 'API::CPanel::User::delete repeat');
#diag Dumper( $result );
# Mysql òåñòû
$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<?xml version="1.0" ?>
<cpanelresult>
<module>Mysql</module>
<func>adduser</func>
<type>event</type>
<source>internal</source>
<apiversion>1</apiversion>
<data>
<result></result>
</data>
<event>
<result>1</result>
</event>
</cpanelresult>
THEEND
$result = API::CPanel::Mysql::adduser(
{
%correct_params,
do_as_user => 'zsezse5',
username => 'test13',
password => 'test13pass',
}
);
is( $result, 1, 'API::CPanel::Mysql::adduser');
$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<?xml version="1.0" ?>
<cpanelresult>
<module>Mysql</module>
<func>adddb</func>
<type>event</type>
<source>internal</source>
<apiversion>1</apiversion>
<data>
<result></result>
</data>
<event>
<result>1</result>
</event>
</cpanelresult>
THEEND
$result = API::CPanel::Mysql::adddb(
{
%correct_params,
do_as_user => 'zsezse5',
dbname => 'default',
}
);
is( $result, 1, 'API::CPanel::Mysql::adddb');
$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<?xml version="1.0" ?>
<cpanelresult>
<module>Mysql</module>
<func>adduserdb</func>
<type>event</type>
<source>internal</source>
<apiversion>1</apiversion>
<data>
<result></result>
</data>
<event>
<result>1</result>
</event>
</cpanelresult>
THEEND
$result = API::CPanel::Mysql::grant_perms(
{
%correct_params,
do_as_user => 'zsezse5',
dbname => 'zsezse5_default',
dbuser => 'zsezse5_test13',
perms_list => 'all',
}
);
is( $result, 1, 'API::CPanel::Mysql::grant_perms');
$API::CPanel::FAKE_ANSWER = ! $ONLINE ? <<THEEND : undef;
<?xml version="1.0" ?>
<cpanelresult>
<apiversion>2</apiversion>
<data>
<reason>
aaaaa.asdasd.ru was successfully parked on top of aaaaa.x
</reason>
<result>1</result>
</data>
<event>
<result>1</result>
</event>
<func>addaddondomain</func>
<module>AddonDomain</module>
</cpanelresult>
THEEND
my $addondomain = 'ssssss.ru';
my $subdomain = 'ssssss';
$result = API::CPanel::Domain::add_addon_domain(
{
%correct_params,
do_as_user => 'zsezse5',
dir => "public_html/$addondomain",
newdomain => $addondomain,
pass => 'asdsadasdsad',
subdomain => $subdomain,
}
);
is( $result->{data}->{result}, 1 , 'API::CPanel::Domain::add_addon_domain');
( run in 0.938 second using v1.01-cache-2.11-cpan-39bf76dae61 )