removing more ticket-stuff; update all unit-tests

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-19 19:42:50 +01:00
parent 60f1db5caf
commit 26510f0745
63 changed files with 537 additions and 1579 deletions

View File

@@ -1,6 +1,9 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Database\Database;
use Froxlor\Api\Commands\Admins;
/**
* @covers ApiCommand
* @covers ApiParameter
@@ -29,7 +32,6 @@ class AdminsTest extends TestCase
'email_imap' => 1,
'email_pop3' => 0,
'ftps' => 15,
'tickets' => 15,
'mysqls' => 15,
'sendpassword' => 0,
'phpenabled' => 1,

View File

@@ -1,11 +1,16 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Settings;
use Froxlor\Database\Database;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\CustomerBackups;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers CustomerBackups
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\CustomerBackups
*/
class CustomerBackupsTest extends TestCase
{
@@ -13,7 +18,7 @@ class CustomerBackupsTest extends TestCase
public function testAdminCustomerBackupsNotEnabled()
{
global $admin_userdata;
Settings::Set('system.backupenabled', 0, true);
// get customer
@@ -27,15 +32,16 @@ class CustomerBackupsTest extends TestCase
}
/**
*
* @depends testAdminCustomerBackupsNotEnabled
*/
public function testAdminCustomerBackupsExtrasHidden()
{
global $admin_userdata;
Settings::Set('system.backupenabled', 1, true);
Settings::Set('panel.customer_hide_options', 'extras', true);
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -47,14 +53,15 @@ class CustomerBackupsTest extends TestCase
}
/**
*
* @depends testAdminCustomerBackupsExtrasHidden
*/
public function testAdminCustomerBackupsExtrasBackupHidden()
{
global $admin_userdata;
Settings::Set('panel.customer_hide_options', 'extras.backup', true);
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -64,23 +71,24 @@ class CustomerBackupsTest extends TestCase
$this->expectExceptionMessage("You cannot access this resource");
CustomerBackups::getLocal($customer_userdata)->add();
}
/**
*
* @depends testAdminCustomerBackupsExtrasBackupHidden
*/
public function testCustomerCustomerBackupsAdd()
{
global $admin_userdata;
Settings::Set('panel.customer_hide_options', '', true);
Database::query("TRUNCATE TABLE `panel_tasks`;");
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'path' => '/my-backup',
'backup_dbs' => 2,
@@ -96,6 +104,7 @@ class CustomerBackupsTest extends TestCase
}
/**
*
* @depends testCustomerCustomerBackupsAdd
*/
public function testCustomerCustomerBackupsAddPathNotDocroot()
@@ -138,7 +147,7 @@ class CustomerBackupsTest extends TestCase
public function testAdminCustomerBackupsListing()
{
global $admin_userdata;
$json_result = CustomerBackups::getLocal($admin_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['count']);
@@ -154,13 +163,13 @@ class CustomerBackupsTest extends TestCase
public function testCustomerCustomerBackupsDelete()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'backup_job_entry' => 1
];
@@ -176,13 +185,13 @@ class CustomerBackupsTest extends TestCase
public function testCustomerCustomerBackupsDeleteNotFound()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'backup_job_entry' => 1337
];

View File

@@ -1,10 +1,15 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\Certificates;
/**
* @covers ApiCommand
* @covers ApiParameter
* @covers Certificates
*
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\Certificates
*/
class CertificatesTest extends TestCase
{
@@ -12,7 +17,7 @@ class CertificatesTest extends TestCase
public function testAdminCertificatesAdd()
{
global $admin_userdata;
$certdata = $this->generateKey();
$json_result = Certificates::getLocal($admin_userdata, array(
'domainname' => 'test2.local',
@@ -32,7 +37,7 @@ class CertificatesTest extends TestCase
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$certdata = $this->generateKey();
$this->expectExceptionCode(406);
$this->expectExceptionMessage("Domain 'test2.local' already has a certificate. Did you mean to call update?");
@@ -51,7 +56,7 @@ class CertificatesTest extends TestCase
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$certdata = $this->generateKey();
$json_result = Certificates::getLocal($customer_userdata, array(
'domainname' => 'mysub2.test2.local',
@@ -65,7 +70,7 @@ class CertificatesTest extends TestCase
public function testAdminCertificatesList()
{
global $admin_userdata;
$json_result = Certificates::getLocal($admin_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(2, $result['count']);
@@ -80,7 +85,7 @@ class CertificatesTest extends TestCase
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$json_result = Certificates::getLocal($reseller_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(2, $result['count']);
@@ -89,7 +94,7 @@ class CertificatesTest extends TestCase
public function testCustomerCertificatesList()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -103,7 +108,7 @@ class CertificatesTest extends TestCase
public function testAdminCertificatesUpdate()
{
global $admin_userdata;
$certdata = $this->generateKey();
$json_result = Certificates::getLocal($admin_userdata, array(
'domainname' => 'test2.local',
@@ -123,7 +128,7 @@ class CertificatesTest extends TestCase
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$certdata = $this->generateKey();
$json_result = Certificates::getLocal($customer_userdata, array(
'domainname' => 'mysub2.test2.local',
@@ -136,12 +141,13 @@ class CertificatesTest extends TestCase
}
/**
*
* @depends testAdminCertificatesUpdate
*/
public function testCustomerCertificatesDelete()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -165,28 +171,28 @@ class CertificatesTest extends TestCase
"commonName" => "test2.local",
"emailAddress" => "team@froxlor.org"
);
// generate key pair
$privkey = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA
));
// generate csr
$csr = openssl_csr_new($dn, $privkey, array(
'digest_alg' => 'sha256'
));
// generate self-signed certificate
$sscert = openssl_csr_sign($csr, null, $privkey, 365, array(
'digest_alg' => 'sha256'
));
// export
openssl_csr_export($csr, $csrout);
openssl_x509_export($sscert, $certout);
openssl_pkey_export($privkey, $pkeyout, null);
return array(
'cert' => $certout,
'key' => $pkeyout

View File

@@ -1,9 +1,14 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\Cronjobs;
/**
* @covers ApiCommand
* @covers ApiParameter
*
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers Cronjobs
*/
class CronjobsTest extends TestCase
@@ -17,7 +22,7 @@ class CronjobsTest extends TestCase
$this->assertTrue(isset($result['list'][0]['module']));
$this->assertTrue(isset($result['list'][0]['cronfile']));
}
public function testCustomerCronjobsListNotAllowed()
{
global $admin_userdata;
@@ -30,7 +35,7 @@ class CronjobsTest extends TestCase
$this->expectExceptionMessage("Not allowed to execute given command.");
Cronjobs::getLocal($customer_userdata)->listing();
}
public function testAdminCronjobsAdd()
{
global $admin_userdata;
@@ -45,9 +50,11 @@ class CronjobsTest extends TestCase
global $admin_userdata;
$this->expectExceptionCode(404);
$this->expectExceptionMessage("cronjob with id #999 could not be found");
Cronjobs::getLocal($admin_userdata, array('id' => 999))->get();
Cronjobs::getLocal($admin_userdata, array(
'id' => 999
))->get();
}
public function testCustomerCronjobsGetNotAllowed()
{
global $admin_userdata;
@@ -58,9 +65,11 @@ class CronjobsTest extends TestCase
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
Cronjobs::getLocal($customer_userdata, array('id' => 1))->get();
Cronjobs::getLocal($customer_userdata, array(
'id' => 1
))->get();
}
public function testAdminCronjobsEdit()
{
global $admin_userdata;

View File

@@ -1,12 +1,17 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Settings;
use Froxlor\Database\Database;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers Customers
* @covers Admins
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\Customers
* @covers \Froxlor\Api\Commands\Admins
*/
class CustomersTest extends TestCase
{
@@ -14,7 +19,7 @@ class CustomersTest extends TestCase
public function testAdminCustomersAdd()
{
global $admin_userdata;
$data = [
'new_loginname' => 'test1',
'email' => 'team@froxlor.org',
@@ -31,7 +36,6 @@ class CustomersTest extends TestCase
'email_imap' => 1,
'email_pop3' => 0,
'ftps' => 15,
'tickets' => 15,
'mysqls' => 15,
'createstdsubdomain' => 1,
'new_customer_password' => 'h0lYmo1y',
@@ -45,7 +49,7 @@ class CustomersTest extends TestCase
1
)
];
$json_result = Customers::getLocal($admin_userdata, $data)->add();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['customerid']);
@@ -58,14 +62,14 @@ class CustomersTest extends TestCase
public function testAdminCustomersAddEmptyMail()
{
global $admin_userdata;
$data = [
'new_loginname' => 'test2',
'email' => ' ',
'firstname' => 'Test2',
'name' => 'Testman2'
];
$this->expectExceptionMessage('Requested parameter "email" is empty where it should not be for "Customers:add"');
Customers::getLocal($admin_userdata, $data)->add();
}
@@ -73,14 +77,14 @@ class CustomersTest extends TestCase
public function testAdminCustomersAddInvalidMail()
{
global $admin_userdata;
$data = [
'new_loginname' => 'test2',
'email' => 'test.froxlor.org',
'firstname' => 'Test2',
'name' => 'Testman2'
];
$this->expectExceptionMessage("Email-address test.froxlor.org contains invalid characters or is incomplete");
Customers::getLocal($admin_userdata, $data)->add();
}
@@ -92,7 +96,7 @@ class CustomersTest extends TestCase
public function testAdminCustomersList()
{
global $admin_userdata;
$json_result = Customers::getLocal($admin_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['count']);
@@ -128,10 +132,10 @@ class CustomersTest extends TestCase
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
$json_result = Customers::getLocal($customer_userdata)->listing();
}
@@ -147,12 +151,12 @@ class CustomersTest extends TestCase
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$json_result = Customers::getLocal($customer_userdata, array(
'id' => $customer_userdata['customerid']
))->get();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['customerid']);
$this->assertEquals('team@froxlor.org', $result['email']);
$this->assertEquals(1337, $result['customernumber']);
@@ -183,10 +187,10 @@ class CustomersTest extends TestCase
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectException(Exception::class);
$this->expectExceptionCode(401);
Customers::getLocal($customer_userdata, array(
'id' => 2
))->get();
@@ -204,13 +208,13 @@ class CustomersTest extends TestCase
'id' => 1,
'deactivated' => 1
))->update();
// get customer and check results
$json_result = Customers::getLocal($admin_userdata, array(
'id' => 1
))->get();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['customerid']);
$this->assertEquals(1, $result['deactivated']);
// standard-subdomains will be removed on deactivation
@@ -229,11 +233,11 @@ class CustomersTest extends TestCase
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectException(Exception::class);
$this->expectExceptionCode(406);
$this->expectExceptionMessage("Account suspended");
Customers::getLocal($customer_userdata, array(
'id' => $customer_userdata['customerid']
))->get();
@@ -246,32 +250,32 @@ class CustomersTest extends TestCase
public function testCustomerCustomersUpdate()
{
global $admin_userdata;
// reactivate customer
// get customer
Customers::getLocal($admin_userdata, array(
'id' => 1,
'deactivated' => 0
))->update();
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
Customers::getLocal($customer_userdata, array(
'id' => $customer_userdata['customerid'],
'def_language' => 'English',
'theme' => 'Froxlor',
'new_customer_password' => 'h0lYmo1y2'
))->update();
$json_result = Customers::getLocal($customer_userdata, array(
'id' => $customer_userdata['customerid']
))->get();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('Froxlor', $result['theme']);
$this->assertEquals('English', $result['def_language']);
}
@@ -289,7 +293,7 @@ class CustomersTest extends TestCase
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$this->expectExceptionMessage("You cannot allocate more resources than you own for yourself.");
// add new customer
$data = [
@@ -371,7 +375,7 @@ class CustomersTest extends TestCase
global $admin_userdata;
$testadmin_userdata = $admin_userdata;
$testadmin_userdata['adminsession'] = 0;
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
Customers::getLocal($testadmin_userdata, array(
@@ -384,7 +388,7 @@ class CustomersTest extends TestCase
global $admin_userdata;
$testadmin_userdata = $admin_userdata;
$testadmin_userdata['change_serversettings'] = 0;
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
Customers::getLocal($testadmin_userdata, array(
@@ -412,7 +416,7 @@ class CustomersTest extends TestCase
'adminid' => 2
))->move();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(2, $result['adminid']);
}
@@ -423,7 +427,7 @@ class CustomersTest extends TestCase
public function testAdminCustomersAddLoginnameIsSystemaccount()
{
global $admin_userdata;
$data = [
'new_loginname' => 'web1',
'email' => 'team@froxlor.org',
@@ -439,7 +443,6 @@ class CustomersTest extends TestCase
'email_imap' => 1,
'email_pop3' => 0,
'ftps' => 15,
'tickets' => 15,
'mysqls' => 15,
'createstdsubdomain' => 1,
'new_customer_password' => 'h0lYmo1y',
@@ -453,7 +456,7 @@ class CustomersTest extends TestCase
1
)
];
$this->expectExceptionMessage('You cannot create accounts which are similar to system accounts (as for example begin with "web"). Please enter another account name.');
Customers::getLocal($admin_userdata, $data)->add();
}
@@ -465,10 +468,9 @@ class CustomersTest extends TestCase
public function testAdminCustomersAddAutoLoginname()
{
global $admin_userdata;
Settings::Set('system.lastaccountnumber', 0, true);
Settings::Set('ticket.enabled', 0, true);
$data = [
'new_loginname' => '',
'email' => 'team@froxlor.org',
@@ -479,7 +481,7 @@ class CustomersTest extends TestCase
'perlenabled' => 2,
'dnsenabled' => 4
];
$json_result = Customers::getLocal($admin_userdata, $data)->add();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('web1', $result['loginname']);
@@ -493,7 +495,7 @@ class CustomersTest extends TestCase
public function testAdminCustomersAddLoginnameExists()
{
global $admin_userdata;
$data = [
'new_loginname' => 'test1',
'email' => 'team@froxlor.org',
@@ -501,7 +503,7 @@ class CustomersTest extends TestCase
'name' => 'Testman2',
'customernumber' => 1339
];
$this->expectExceptionMessage('Loginname test1 already exists');
Customers::getLocal($admin_userdata, $data)->add();
}
@@ -513,7 +515,7 @@ class CustomersTest extends TestCase
public function testAdminCustomersAddLoginnameInvalid()
{
global $admin_userdata;
$data = [
'new_loginname' => 'user-',
'email' => 'team@froxlor.org',
@@ -521,7 +523,7 @@ class CustomersTest extends TestCase
'name' => 'Testman2',
'customernumber' => 1339
];
$this->expectExceptionMessage('Loginname "user-" contains illegal characters.');
Customers::getLocal($admin_userdata, $data)->add();
}
@@ -533,7 +535,7 @@ class CustomersTest extends TestCase
public function testAdminCustomersAddLoginnameInvalid2()
{
global $admin_userdata;
$data = [
'new_loginname' => 'useruseruseruseruseruserX',
'email' => 'team@froxlor.org',
@@ -541,7 +543,7 @@ class CustomersTest extends TestCase
'name' => 'Testman2',
'customernumber' => 1339
];
$this->expectExceptionMessage('Loginname contains too many characters. Only ' . (14 - strlen(Settings::Get('customer.mysqlprefix'))) . ' characters are allowed.');
Customers::getLocal($admin_userdata, $data)->add();
}

View File

@@ -1,12 +1,16 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Settings;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\DomainZones;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers SubDomains
* @covers DomainZones
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\SubDomains
* @covers \Froxlor\Api\Commands\DomainZones
*/
class DomainZonesTest extends TestCase
{
@@ -14,15 +18,15 @@ class DomainZonesTest extends TestCase
public function testCustomerDomainZonesGet()
{
global $admin_userdata;
Settings::Set('system.dnsenabled', 1, true);
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local'
];
@@ -33,18 +37,19 @@ class DomainZonesTest extends TestCase
}
/**
*
* @depends testCustomerDomainZonesGet
*/
public function testCustomerDomainZonesGetNoSubdomains()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'mysub2.test2.local'
];
@@ -52,14 +57,14 @@ class DomainZonesTest extends TestCase
$this->expectExceptionMessage("DNS zones can only be generated for the main domain, not for subdomains");
DomainZones::getLocal($customer_userdata, $data)->get();
}
public function testAdminDomainZonesListing()
{
global $admin_userdata;
$this->expectExceptionCode(303);
DomainZones::getLocal($admin_userdata)->listing();
}
public function testAdminDomainZonesUpdate()
{
global $admin_userdata;
@@ -68,6 +73,7 @@ class DomainZonesTest extends TestCase
}
/**
*
* @depends testCustomerDomainZonesGet
*/
public function testCustomerDomainZonesAddA()
@@ -79,7 +85,7 @@ class DomainZonesTest extends TestCase
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local',
'record' => 'www2',
@@ -99,68 +105,71 @@ class DomainZonesTest extends TestCase
$this->assertTrue($found);
$this->assertEquals('www2 18000 IN A 127.0.0.1', $entry);
}
/**
*
* @depends testCustomerDomainZonesAddA
*/
public function testCustomerDomainZonesAddAInvalid()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local',
'record' => 'www3',
'type' => 'A',
'content' => 'a.b.c.d',
'ttl' => -1
'ttl' => - 1
];
$this->expectExceptionMessage("No valid IP address for A-record given");
DomainZones::getLocal($customer_userdata, $data)->add();
}
/**
*
* @depends testCustomerDomainZonesAddA
*/
public function testCustomerDomainZonesAddADuplicate()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local',
'record' => 'www2',
'type' => 'A',
'content' => '127.0.0.1',
'ttl' => -1
'ttl' => - 1
];
$this->expectExceptionMessage("Record already exists");
DomainZones::getLocal($customer_userdata, $data)->add();
}
/**
*
* @depends testCustomerDomainZonesGet
*/
public function testCustomerDomainZonesAddAAAA()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local',
'record' => 'www3',
@@ -180,31 +189,32 @@ class DomainZonesTest extends TestCase
$this->assertTrue($found);
$this->assertEquals('www3 18000 IN AAAA ::1', $entry);
}
/**
*
* @depends testCustomerDomainZonesAddA
*/
public function testCustomerDomainZonesAddAAAAInvalid()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local',
'record' => 'www4',
'type' => 'AAAA',
'content' => 'z:z123.123',
'ttl' => -1
'ttl' => - 1
];
$this->expectExceptionMessage("No valid IP address for AAAA-record given");
DomainZones::getLocal($customer_userdata, $data)->add();
}
public function testAdminDomainZonesAddMX()
{
global $admin_userdata;
@@ -221,7 +231,7 @@ class DomainZonesTest extends TestCase
$this->assertTrue(count($result) > 1);
$found = false;
foreach ($result as $entry) {
if (substr($entry, strlen('mail.example.com.') * -1) == 'mail.example.com.') {
if (substr($entry, strlen('mail.example.com.') * - 1) == 'mail.example.com.') {
$found = true;
break;
}
@@ -229,14 +239,15 @@ class DomainZonesTest extends TestCase
$this->assertTrue($found);
$this->assertEquals('@ 18000 IN MX 10 mail.example.com.', $entry);
}
/**
*
* @depends testAdminDomainZonesAddMX
*/
public function testAdminDomainZonesAddMXNoPrio()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => '',
@@ -248,12 +259,13 @@ class DomainZonesTest extends TestCase
}
/**
*
* @depends testAdminDomainZonesAddMX
*/
public function testAdminDomainZonesAddMXInvalid()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => '',
@@ -264,11 +276,11 @@ class DomainZonesTest extends TestCase
$this->expectExceptionMessage("The MX content value must be a valid domain-name");
DomainZones::getLocal($admin_userdata, $data)->add();
}
public function testAdminDomainZonesAddCname()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => 'db',
@@ -280,7 +292,7 @@ class DomainZonesTest extends TestCase
$this->assertTrue(count($result) > 1);
$found = false;
foreach ($result as $entry) {
if (substr($entry, strlen('db.example.com.') * -1) == 'db.example.com.') {
if (substr($entry, strlen('db.example.com.') * - 1) == 'db.example.com.') {
$found = true;
break;
}
@@ -288,11 +300,11 @@ class DomainZonesTest extends TestCase
$this->assertTrue($found);
$this->assertEquals('db 18000 IN CNAME db.example.com.', $entry);
}
public function testAdminDomainZonesAddCnameLocal()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => 'db',
@@ -304,7 +316,7 @@ class DomainZonesTest extends TestCase
$this->assertTrue(count($result) > 1);
$found = false;
foreach ($result as $entry) {
if (substr($entry, strlen('db2.test2.local.') * -1) == 'db2.test2.local.') {
if (substr($entry, strlen('db2.test2.local.') * - 1) == 'db2.test2.local.') {
$found = true;
break;
}
@@ -312,14 +324,15 @@ class DomainZonesTest extends TestCase
$this->assertTrue($found);
$this->assertEquals('db 18000 IN CNAME db2.test2.local.', $entry);
}
/**
*
* @depends testAdminDomainZonesAddCname
*/
public function testAdminDomainZonesAddCnameInvalid()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => '',
@@ -329,8 +342,9 @@ class DomainZonesTest extends TestCase
$this->expectExceptionMessage("Invalid domain-name for CNAME record");
DomainZones::getLocal($admin_userdata, $data)->add();
}
/**
*
* @depends testAdminDomainZonesAddCname
*/
public function testAdminDomainZonesAddCnameUnderscore()
@@ -348,7 +362,7 @@ class DomainZonesTest extends TestCase
$this->assertTrue(count($result) > 1);
$found = false;
foreach ($result as $entry) {
if (substr($entry, strlen('test._domainkey.myhost.tld.') * -1) == 'test._domainkey.myhost.tld.') {
if (substr($entry, strlen('test._domainkey.myhost.tld.') * - 1) == 'test._domainkey.myhost.tld.') {
$found = true;
break;
}
@@ -360,7 +374,7 @@ class DomainZonesTest extends TestCase
public function testAdminDomainZonesAddNS()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => '',
@@ -372,7 +386,7 @@ class DomainZonesTest extends TestCase
$this->assertTrue(count($result) > 1);
$found = false;
foreach ($result as $entry) {
if (substr($entry, strlen('ns.example.com.') * -1) == 'ns.example.com.') {
if (substr($entry, strlen('ns.example.com.') * - 1) == 'ns.example.com.') {
$found = true;
break;
}
@@ -384,7 +398,7 @@ class DomainZonesTest extends TestCase
public function testAdminDomainZonesAddNsInvalid()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => '',
@@ -394,11 +408,11 @@ class DomainZonesTest extends TestCase
$this->expectExceptionMessage("Invalid domain-name for NS record");
DomainZones::getLocal($admin_userdata, $data)->add();
}
public function testAdminDomainZonesAddTXT()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => '_test1',
@@ -418,11 +432,11 @@ class DomainZonesTest extends TestCase
$this->assertTrue($found);
$this->assertEquals('_test1 18000 IN TXT aw yeah', $entry);
}
public function testAdminDomainZonesAddSRV()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => '_test2',
@@ -443,11 +457,11 @@ class DomainZonesTest extends TestCase
$this->assertTrue($found);
$this->assertEquals('_test2 18000 IN SRV 50 2 1 srv.example.com.', $entry);
}
public function testAdminDomainZonesAddSrvInvalid()
{
global $admin_userdata;
$data = [
'domainname' => 'test2.local',
'record' => '_test2',
@@ -458,7 +472,7 @@ class DomainZonesTest extends TestCase
$this->expectExceptionMessage("Invalid SRV content, must contain of fields weight, port and target, e.g.: 5 5060 sipserver.example.com.");
DomainZones::getLocal($admin_userdata, $data)->add();
}
public function testCustomerDomainZonesDelete()
{
global $admin_userdata;
@@ -468,7 +482,7 @@ class DomainZonesTest extends TestCase
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local',
'entry_id' => 1
@@ -478,17 +492,17 @@ class DomainZonesTest extends TestCase
$this->assertTrue($result['data']);
$this->assertEquals(200, $result['status']);
}
public function testCustomerDomainZonesDeleteUnmodified()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local',
'entry_id' => 1337

View File

@@ -1,11 +1,17 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Settings;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\Domains;
/**
* @covers ApiCommand
* @covers ApiParameter
* @covers SubDomains
* @covers Domains
*
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\Domains
* @covers \Froxlor\Api\Commands\SubDomains
*/
class DomainsTest extends TestCase
{
@@ -28,6 +34,7 @@ class DomainsTest extends TestCase
}
/**
*
* @depends testAdminDomainsAdd
*/
public function testAdminDomainsList()
@@ -40,6 +47,7 @@ class DomainsTest extends TestCase
}
/**
*
* @depends testAdminDomainsAdd
*/
public function testResellerDomainsList()
@@ -95,7 +103,7 @@ class DomainsTest extends TestCase
'customerid' => 1,
'ipandport' => 4,
'isemaildomain' => 1,
'subcanemaildomain' => 2
'subcanemaildomain' => 2
];
$json_result = Domains::getLocal($reseller_userdata, $data)->add();
$result = json_decode($json_result, true)['data'];
@@ -137,6 +145,7 @@ class DomainsTest extends TestCase
}
/**
*
* @depends testAdminDomainsAdd
*/
public function testAdminDomainsUpdate()
@@ -152,6 +161,7 @@ class DomainsTest extends TestCase
}
/**
*
* @depends testAdminDomainsUpdate
*/
public function testAdminDomainsMoveButUnknownCustomer()
@@ -185,7 +195,7 @@ class DomainsTest extends TestCase
];
$json_result = Customers::getLocal($admin_userdata, $data)->add();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test.local',
'customerid' => $customer_userdata['customerid']
@@ -197,6 +207,7 @@ class DomainsTest extends TestCase
}
/**
*
* @depends testAdminDomainsMove
*/
public function testAdminDomainsDelete()
@@ -209,7 +220,7 @@ class DomainsTest extends TestCase
$json_result = Domains::getLocal($admin_userdata, $data)->delete();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test.local', $result['domain']);
// remove customer again
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test3'

View File

@@ -1,15 +1,22 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Settings;
use Froxlor\Database\Database;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\Emails;
use Froxlor\Api\Commands\EmailForwarders;
use Froxlor\Api\Commands\EmailAccounts;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers Emails
* @covers EmailForwarders
* @covers EmailAccounts
* @covers Customers
* @covers Admins
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\Emails
* @covers \Froxlor\Api\Commands\EmailForwarders
* @covers \Froxlor\Api\Commands\EmailAccounts
* @covers \Froxlor\Api\Commands\Customers
* @covers \Froxlor\Api\Commands\Admins
*/
class MailsTest extends TestCase
{

View File

@@ -1,10 +1,15 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\DirOptions;
/**
* @covers ApiCommand
* @covers ApiParameter
* @covers DirOptions
*
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\DirOptions
*/
class DirOptionsTest extends TestCase
{

View File

@@ -1,10 +1,15 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\DirProtections;
/**
* @covers ApiCommand
* @covers ApiParameter
* @covers DirProtections
*
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\DirProtections
*/
class DirProtectionsTest extends TestCase
{
@@ -12,13 +17,13 @@ class DirProtectionsTest extends TestCase
public function testCustomerDirProtectionsAdd()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'path' => '/test',
'username' => 'testing',
@@ -30,17 +35,17 @@ class DirProtectionsTest extends TestCase
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['path']);
$this->assertEquals('test1', $result['authname']);
}
public function testCustomerDirProtectionsAddSameUserPath()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'path' => '/test',
'username' => 'testing',
@@ -50,11 +55,11 @@ class DirProtectionsTest extends TestCase
$this->expectExceptionMessage("Combination of username and path already exists");
DirProtections::getLocal($customer_userdata, $data)->add();
}
public function testCustomerDirProtectionsAddPasswordEqualsUsername()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -70,8 +75,9 @@ class DirProtectionsTest extends TestCase
$this->expectExceptionMessage("The password should not be the same as the username.");
DirProtections::getLocal($customer_userdata, $data)->add();
}
/**
*
* @depends testCustomerDirProtectionsAdd
*/
public function testAdminDirProtectionsGet()
@@ -91,8 +97,9 @@ class DirProtectionsTest extends TestCase
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['path']);
$this->assertEquals('test1', $result['authname']);
}
/**
*
* @depends testCustomerDirProtectionsAdd
*/
public function testResellerDirProtectionsGet()
@@ -117,21 +124,24 @@ class DirProtectionsTest extends TestCase
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['path']);
$this->assertEquals('test1', $result['authname']);
}
/**
*
* @depends testCustomerDirProtectionsAdd
*/
public function testCustomerDirProtectionsUpdate()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$json_result = DirProtections::getLocal($customer_userdata, array('id' => 1))->get();
$json_result = DirProtections::getLocal($customer_userdata, array(
'id' => 1
))->get();
$data_old = json_decode($json_result, true)['data'];
$data = [
@@ -145,14 +155,15 @@ class DirProtectionsTest extends TestCase
$this->assertTrue($data_old['authname'] != $result['authname']);
$this->assertEquals('test1337', $result['authname']);
}
/**
*
* @depends testCustomerDirProtectionsAdd
*/
public function testCustomerDirProtectionsList()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -165,21 +176,24 @@ class DirProtectionsTest extends TestCase
$this->assertEquals('test1', $result['list'][0]['username']);
$this->assertEquals('testing', $result['list'][1]['username']);
}
/**
*
* @depends testCustomerDirProtectionsList
*/
public function testCustomerDirProtectionsDelete()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
DirProtections::getLocal($customer_userdata, array('username' => 'testing'))->delete();
DirProtections::getLocal($customer_userdata, array(
'username' => 'testing'
))->delete();
$json_result = DirProtections::getLocal($customer_userdata)->listing();
$result = json_decode($json_result, true)['data'];

View File

@@ -1,9 +1,13 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Froxlor;
/**
*
* @covers Froxlor
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Froxlor
*/
class FroxlorTest extends TestCase
{

View File

@@ -1,12 +1,17 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\Ftps;
/**
* @covers ApiCommand
* @covers ApiParameter
* @covers Ftps
* @covers Customers
* @covers Admins
*
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\Admins
* @covers \Froxlor\Api\Commands\Customers
* @covers \Froxlor\Api\Commands\Ftps
*/
class FtpsTest extends TestCase
{
@@ -19,7 +24,7 @@ class FtpsTest extends TestCase
'id' => 1
))->get();
$result = json_decode($json_result, true)['data'];
// should be the ftp user of the first added customr 'test1'
$this->assertEquals('test1', $result['username']);
}
@@ -39,30 +44,30 @@ class FtpsTest extends TestCase
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test1', $result['username']);
}
public function testCustomerFtpsGetId()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$json_result = Ftps::getLocal($customer_userdata, array(
'id' => 1
))->get();
$result = json_decode($json_result, true)['data'];
// should be the ftp user of the first added customr 'test1'
$this->assertEquals('test1', $result['username']);
}
public function testCustomerFtpsGetOtherId()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'id' => 1
@@ -75,11 +80,11 @@ class FtpsTest extends TestCase
'id' => 10
))->get();
}
public function testAdminFtpsList()
{
global $admin_userdata;
$json_result = Ftps::getLocal($admin_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(2, $result['count']);
@@ -88,13 +93,15 @@ class FtpsTest extends TestCase
public function testAdminFtpsListSpecificCustomer()
{
global $admin_userdata;
$json_result = Ftps::getLocal($admin_userdata, array('loginname' => 'test1'))->listing();
$json_result = Ftps::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['count']);
$this->assertEquals('test1', $result['list'][0]['username']);
}
public function testResellerFtpsList()
{
global $admin_userdata;
@@ -109,7 +116,7 @@ class FtpsTest extends TestCase
$this->assertEquals(1, $result['count']);
$this->assertEquals('test1', $result['list'][0]['username']);
}
public function testCustomerFtpsList()
{
global $admin_userdata;
@@ -123,17 +130,17 @@ class FtpsTest extends TestCase
$this->assertEquals(1, $result['count']);
$this->assertEquals('test1', $result['list'][0]['username']);
}
public function testCustomerFtpsAdd()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'ftp_password' => 'h4xXx0r',
'path' => '/',
@@ -148,13 +155,13 @@ class FtpsTest extends TestCase
public function testCustomerFtpsAddNoMoreResources()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];#
$customer_userdata = json_decode($json_result, true)['data']; //
$customer_userdata['ftps_used'] = 100;
$this->expectExceptionCode(406);
@@ -172,7 +179,7 @@ class FtpsTest extends TestCase
'ftp_description' => 'testing',
'sendinfomail' => 1
];
$this->expectExceptionCode(406);
$this->expectExceptionMessage('Requested parameter "loginname" is empty where it should not be for "Customers:get"');
$json_result = Ftps::getLocal($admin_userdata, $data)->add();
@@ -181,13 +188,13 @@ class FtpsTest extends TestCase
public function testCustomerFtpsEdit()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'username' => 'test1ftp1',
'ftp_password' => 'h4xXx0r2',
@@ -196,10 +203,10 @@ class FtpsTest extends TestCase
];
$json_result = Ftps::getLocal($customer_userdata, $data)->update();
$result = json_decode($json_result, true)['data'];
$this->assertEquals($customer_userdata['documentroot'].'subfolder/', $result['homedir']);
$this->assertEquals($customer_userdata['documentroot'] . 'subfolder/', $result['homedir']);
$this->assertEquals('testing2', $result['description']);
}
public function testAdminFtpsEdit()
{
global $admin_userdata;
@@ -217,20 +224,20 @@ class FtpsTest extends TestCase
];
$json_result = Ftps::getLocal($admin_userdata, $data)->update();
$result = json_decode($json_result, true)['data'];
$this->assertEquals($customer_userdata['documentroot'].'anotherfolder/', $result['homedir']);
$this->assertEquals($customer_userdata['documentroot'] . 'anotherfolder/', $result['homedir']);
$this->assertEquals('testing3', $result['description']);
}
public function testAdminFtpsAdd()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'customerid' => $customer_userdata['customerid'],
'ftp_password' => 'h4xXx0r',
@@ -242,11 +249,11 @@ class FtpsTest extends TestCase
$result = json_decode($json_result, true)['data'];
$this->assertEquals($customer_userdata['documentroot'], $result['homedir']);
}
public function testCustomerFtpsDelete()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -259,7 +266,7 @@ class FtpsTest extends TestCase
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test1ftp1', $result['username']);
}
public function testAdminFtpsDelete()
{
global $admin_userdata;

View File

@@ -1,9 +1,13 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Froxlor;
/**
*
* @covers ApiParameter
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Froxlor
*/
class ApiParameterTest extends TestCase
{

View File

@@ -1,8 +1,12 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Database\Database;
use Froxlor\Api\FroxlorRPC;
/**
* @covers FroxlorRPC
*
* @covers \Froxlor\Api\FroxlorRPC
*/
class FroxlorRpcTest extends TestCase
{
@@ -84,7 +88,9 @@ class FroxlorRpcTest extends TestCase
'apikey' => 'test',
'secret' => 'test'
],
'body' => ['command' => 'Froxlor']
'body' => [
'command' => 'Froxlor'
]
));
}
@@ -97,7 +103,9 @@ class FroxlorRpcTest extends TestCase
'apikey' => 'test',
'secret' => 'test'
],
'body' => ['command' => 'SomeModule.cmd']
'body' => [
'command' => 'SomeModule.cmd'
]
));
}
@@ -108,7 +116,9 @@ class FroxlorRpcTest extends TestCase
'apikey' => 'test',
'secret' => 'test'
],
'body' => ['command' => 'Froxlor.listFunctions']
'body' => [
'command' => 'Froxlor.listFunctions'
]
));
$this->assertEquals('Froxlor', $result['command']['class']);
$this->assertEquals('listFunctions', $result['command']['method']);

View File

@@ -1,10 +1,15 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\IpsAndPorts;
/**
* @covers ApiCommand
* @covers ApiParameter
* @covers IpsAndPorts
*
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\IpsAndPorts
*/
class IpsAndPortsTest extends TestCase
{
@@ -44,8 +49,9 @@ class IpsAndPortsTest extends TestCase
$this->assertEquals(3, $result['id']);
$this->assertEquals(80, $result['port']);
}
/**
*
* @depends testAdminIpsAndPortsAdd
*/
public function testAdminIpsAndPortsAddExists()
@@ -57,7 +63,7 @@ class IpsAndPortsTest extends TestCase
];
IpsAndPorts::getLocal($admin_userdata, $data)->add();
}
public function testAdminIpsAndPortsAddIpv6()
{
global $admin_userdata;
@@ -70,16 +76,19 @@ class IpsAndPortsTest extends TestCase
$this->assertEquals(4, $result['id']);
$this->assertEquals('/var/www/html/', $result['docroot']);
}
public function testAdminIpsAndPortsGetNotFound()
{
global $admin_userdata;
$this->expectExceptionCode(404);
$this->expectExceptionMessage("IP/port with id #999 could not be found");
IpsAndPorts::getLocal($admin_userdata, array('id' => 999))->get();
IpsAndPorts::getLocal($admin_userdata, array(
'id' => 999
))->get();
}
/**
*
* @depends testAdminIpsAndPortsAdd
*/
public function testResellerIpsAndPortsList()
@@ -88,7 +97,9 @@ class IpsAndPortsTest extends TestCase
// update reseller to allow ip access to ip id #3
$json_result = Admins::getLocal($admin_userdata, array(
'loginname' => 'reseller',
'ipaddress' => array(3)
'ipaddress' => array(
3
)
))->update();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
@@ -97,8 +108,9 @@ class IpsAndPortsTest extends TestCase
$this->assertEquals(1, $result['count']);
$this->assertEquals('82.149.225.47', $result['list'][0]['ip']);
}
/**
*
* @depends testResellerIpsAndPortsList
*/
public function testResellerIpsAndPortsGet()
@@ -110,12 +122,15 @@ class IpsAndPortsTest extends TestCase
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$json_result = IpsAndPorts::getLocal($reseller_userdata, array('id' => 3))->get();
$json_result = IpsAndPorts::getLocal($reseller_userdata, array(
'id' => 3
))->get();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('82.149.225.47', $result['ip']);
}
/**
*
* @depends testResellerIpsAndPortsList
*/
public function testResellerIpsAndPortsGetRestrictedNotOwned()
@@ -129,9 +144,11 @@ class IpsAndPortsTest extends TestCase
$reseller_userdata['adminsession'] = 1;
$this->expectExceptionCode(405);
$this->expectExceptionMessage("You cannot access this resource");
IpsAndPorts::getLocal($reseller_userdata, array('id' => 1))->get();
IpsAndPorts::getLocal($reseller_userdata, array(
'id' => 1
))->get();
}
public function testResellerIpsAndPortsAdd()
{
global $admin_userdata;
@@ -159,9 +176,11 @@ class IpsAndPortsTest extends TestCase
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
IpsAndPorts::getLocal($customer_userdata, array('id' => 1))->get();
IpsAndPorts::getLocal($customer_userdata, array(
'id' => 1
))->get();
}
public function testAdminIpsAndPortsEdit()
{
global $admin_userdata;
@@ -221,7 +240,7 @@ class IpsAndPortsTest extends TestCase
$this->expectExceptionMessage("You cannot change the last system IP, either create another new IP/Port combination for the system IP or change the system IP.");
$json_result = IpsAndPorts::getLocal($admin_userdata, $data)->update();
}
public function testResellerIpsAndPortsEditNoDuplicate()
{
global $admin_userdata;
@@ -237,7 +256,7 @@ class IpsAndPortsTest extends TestCase
$this->expectExceptionMessage("This IP/Port combination already exists.");
IpsAndPorts::getLocal($reseller_userdata, $data)->update();
}
public function testAdminIpsAndPortsDeleteCantDeleteDefaultIp()
{
global $admin_userdata;
@@ -247,7 +266,7 @@ class IpsAndPortsTest extends TestCase
$this->expectExceptionMessage("You cannot delete the default IP/Port combination, please make another IP/Port combination default for before deleting this IP/Port combination.");
IpsAndPorts::getLocal($admin_userdata, $data)->delete();
}
public function testAdminIpsAndPortsDelete()
{
global $admin_userdata;
@@ -258,7 +277,7 @@ class IpsAndPortsTest extends TestCase
$result = json_decode($json_result, true)['data'];
$this->assertEquals('82.149.225.47', $result['ip']);
}
public function testResellerIpsAndPortsDeleteNotAllowed()
{
global $admin_userdata;

View File

@@ -1,13 +1,17 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\Mysqls;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers Mysqls
* @covers Customers
* @covers Admins
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\Mysqls
* @covers \Froxlor\Api\Commands\Customers
* @covers \Froxlor\Api\Commands\Admins
*/
class MysqlsTest extends TestCase
{
@@ -15,13 +19,13 @@ class MysqlsTest extends TestCase
public function testCustomerMysqlsAdd()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'mysql_password' => generatePassword(),
'description' => 'testdb',
@@ -32,24 +36,26 @@ class MysqlsTest extends TestCase
$this->assertEquals('testdb', $result['description']);
$this->assertEquals(0, $result['dbserver']);
}
/**
*
* @depends testCustomerMysqlsAdd
*/
public function testAdminMysqlsGet()
{
global $admin_userdata;
$json_result = Mysqls::getLocal($admin_userdata, array(
'dbname' => 'test1sql1'
))->get();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test1sql1', $result['databasename']);
$this->assertEquals('testdb', $result['description']);
}
/**
*
* @depends testCustomerMysqlsAdd
*/
public function testResellerMysqlsGet()
@@ -68,17 +74,17 @@ class MysqlsTest extends TestCase
$this->assertEquals('test1sql1', $result['databasename']);
$this->assertEquals('testdb', $result['description']);
}
public function testCustomerMysqlsGetUnknown()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'dbname' => 'test1sql5'
];
@@ -86,19 +92,15 @@ class MysqlsTest extends TestCase
$this->expectExceptionMessage("MySQL database with dbname 'test1sql5' could not be found");
Mysqls::getLocal($customer_userdata, $data)->get();
}
/**
*
* @depends testCustomerMysqlsAdd
*/
public function testAdminMysqlsUpdate()
{
global $admin_userdata;
$json_result = Mysqls::getLocal($admin_userdata, array(
'dbname' => 'test1sql1'
))->get();
$old_db = json_decode($json_result, true)['data'];
$data = [
'dbname' => 'test1sql1',
'mysql_password' => generatePassword(),
@@ -109,14 +111,15 @@ class MysqlsTest extends TestCase
$result = json_decode($json_result, true)['data'];
$this->assertEquals('testdb-upd', $result['description']);
}
/**
*
* @depends testCustomerMysqlsAdd
*/
public function testCustomerMysqlsList()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -128,20 +131,21 @@ class MysqlsTest extends TestCase
$this->assertEquals(1, $result['count']);
$this->assertEquals('test1sql1', $result['list'][0]['databasename']);
}
/**
*
* @depends testCustomerMysqlsList
*/
public function testCustomerMysqlsDelete()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'dbname' => 'test1sql1'
];

View File

@@ -1,14 +1,18 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\FpmDaemons;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers FpmDaemons
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\FpmDaemons
*/
class FpmDaemonsTest extends TestCase
{
private static $id = 0;
public function testAdminFpmDaemonsAdd()
@@ -27,7 +31,7 @@ class FpmDaemonsTest extends TestCase
$this->assertEquals('.php', $result['limit_extensions']);
self::$id = $result['id'];
}
public function testAdminFpmDaemonsAddUnknownPM()
{
global $admin_userdata;
@@ -41,7 +45,7 @@ class FpmDaemonsTest extends TestCase
$this->expectExceptionMessage("Unknown process manager");
FpmDaemons::getLocal($admin_userdata, $data)->add();
}
public function testAdminFpmDaemonsAddInvalidDesc()
{
// max 50. characters
@@ -56,6 +60,7 @@ class FpmDaemonsTest extends TestCase
}
/**
*
* @depends testAdminFpmDaemonsAdd
*/
public function testAdminFpmDaemonsUpdate()
@@ -67,7 +72,7 @@ class FpmDaemonsTest extends TestCase
'pm' => 'dynamic',
'max_children' => '10',
'start_servers' => '4',
'limit_extensions' => '.php .php.xml',
'limit_extensions' => '.php .php.xml'
];
$json_result = FpmDaemons::getLocal($admin_userdata, $data)->update();
$result = json_decode($json_result, true)['data'];
@@ -77,6 +82,7 @@ class FpmDaemonsTest extends TestCase
}
/**
*
* @depends testAdminFpmDaemonsUpdate
*/
public function testAdminFpmDaemonsUpdate2()
@@ -84,7 +90,7 @@ class FpmDaemonsTest extends TestCase
global $admin_userdata;
$data = [
'id' => self::$id,
'limit_extensions' => '',
'limit_extensions' => ''
];
$json_result = FpmDaemons::getLocal($admin_userdata, $data)->update();
$result = json_decode($json_result, true)['data'];
@@ -92,6 +98,7 @@ class FpmDaemonsTest extends TestCase
}
/**
*
* @depends testAdminFpmDaemonsAdd
*/
public function testAdminFpmDaemonsUpdateUnknownPM()
@@ -105,8 +112,9 @@ class FpmDaemonsTest extends TestCase
$this->expectExceptionMessage("Unknown process manager");
FpmDaemons::getLocal($admin_userdata, $data)->update();
}
/**
*
* @depends testAdminFpmDaemonsAdd
*/
public function testAdminFpmDaemonsUpdateInvalidDesc()
@@ -122,6 +130,7 @@ class FpmDaemonsTest extends TestCase
}
/**
*
* @depends testAdminFpmDaemonsUpdate
*/
public function testAdminFpmDaemonsList()
@@ -139,7 +148,9 @@ class FpmDaemonsTest extends TestCase
global $admin_userdata;
$this->expectExceptionCode(404);
$this->expectExceptionMessage("fpm-daemon with id #-1 could not be found");
FpmDaemons::getLocal($admin_userdata, array('id' => -1))->get();
FpmDaemons::getLocal($admin_userdata, array(
'id' => - 1
))->get();
}
public function testCustomerFpmDaemonsAdd()
@@ -154,7 +165,7 @@ class FpmDaemonsTest extends TestCase
$this->expectExceptionMessage("Not allowed to execute given command.");
FpmDaemons::getLocal($customer_userdata)->add();
}
public function testCustomerFpmDaemonsGet()
{
global $admin_userdata;
@@ -208,6 +219,7 @@ class FpmDaemonsTest extends TestCase
}
/**
*
* @depends testAdminFpmDaemonsList
*/
public function testAdminFpmDaemonsDelete()
@@ -224,6 +236,7 @@ class FpmDaemonsTest extends TestCase
}
/**
*
* @depends testAdminFpmDaemonsDelete
*/
public function testAdminFpmDaemonsDeleteDefaultConfig()

View File

@@ -1,14 +1,19 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Settings;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\PhpSettings;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers PhpSettings
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\PhpSettings
*/
class PhpSettingsText extends TestCase
{
private static $id = 0;
public function testAdminPhpSettingsList()
@@ -47,7 +52,7 @@ class PhpSettingsText extends TestCase
$this->assertEquals('60s', $result['fpm_reqterm']);
self::$id = $result['id'];
}
public function testAdminPhpSettingsGet()
{
global $admin_userdata;
@@ -65,9 +70,11 @@ class PhpSettingsText extends TestCase
global $admin_userdata;
$this->expectExceptionCode(404);
$this->expectExceptionMessage("php-config with id #999 could not be found");
PhpSettings::getLocal($admin_userdata, array('id' => 999))->get();
PhpSettings::getLocal($admin_userdata, array(
'id' => 999
))->get();
}
public function testCustomerPhpSettingsGetNotAllowed()
{
global $admin_userdata;
@@ -78,6 +85,8 @@ class PhpSettingsText extends TestCase
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
PhpSettings::getLocal($customer_userdata, array('id' => 1))->get();
PhpSettings::getLocal($customer_userdata, array(
'id' => 1
))->get();
}
}

View File

@@ -1,13 +1,18 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\SubDomains;
/**
* @covers ApiCommand
* @covers ApiParameter
* @covers SubDomains
* @covers Domains
* @covers Customers
* @covers Admins
*
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\SubDomains
* @covers \Froxlor\Api\Commands\Domains
* @covers \Froxlor\Api\Commands\Customers
* @covers \Froxlor\Api\Commands\Admins
*/
class SubDomainsTest extends TestCase
{
@@ -15,13 +20,13 @@ class SubDomainsTest extends TestCase
public function testCustomerSubDomainsAdd()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'subdomain' => 'mysub',
'domain' => 'test2.local'
@@ -40,7 +45,7 @@ class SubDomainsTest extends TestCase
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$data = [
'subdomain' => 'mysub2',
'domain' => 'test2.local',
@@ -54,13 +59,13 @@ class SubDomainsTest extends TestCase
public function testCustomerSubDomainsAddNoPunycode()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'subdomain' => 'xn--asd',
'domain' => 'unknown.froxlor.org'
@@ -72,13 +77,13 @@ class SubDomainsTest extends TestCase
public function testCustomerSubDomainsAddMainDomainUnknown()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'subdomain' => 'wohoo',
'domain' => 'unknown.froxlor.org'
@@ -90,13 +95,13 @@ class SubDomainsTest extends TestCase
public function testCustomerSubDomainsAddInvalidDomain()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'subdomain' => '#+?',
'domain' => 'unknown.froxlor.org'
@@ -106,18 +111,13 @@ class SubDomainsTest extends TestCase
}
/**
*
* @depends testCustomerSubDomainsAdd
*/
public function testAdminSubDomainsGet()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'mysub.test2.local'
];
@@ -128,18 +128,13 @@ class SubDomainsTest extends TestCase
}
/**
*
* @depends testCustomerSubDomainsAdd
*/
public function testAdminSubDomainsGetMainDomain()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domainname' => 'test2.local'
];
@@ -150,6 +145,7 @@ class SubDomainsTest extends TestCase
}
/**
*
* @depends testCustomerSubDomainsAdd
*/
public function testAdminSubDomainsUpdate()
@@ -172,6 +168,7 @@ class SubDomainsTest extends TestCase
}
/**
*
* @depends testAdminSubDomainsUpdate
*/
public function testCustomerSubDomainsUpdate()
@@ -185,7 +182,7 @@ class SubDomainsTest extends TestCase
$data = [
'domainname' => 'mysub.test2.local',
'url' => 'https://www.froxlor.org/',
'isemaildomain' => 0,
'isemaildomain' => 0
];
$json_result = SubDomains::getLocal($customer_userdata, $data)->update();
$result = json_decode($json_result, true)['data'];
@@ -195,7 +192,7 @@ class SubDomainsTest extends TestCase
public function testCustomerSubDomainsList()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
@@ -231,6 +228,7 @@ class SubDomainsTest extends TestCase
}
/**
*
* @depends testCustomerSubDomainsList
*/
public function testCustomerSubDomainsDelete()

View File

@@ -1,13 +1,17 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\Database\Database;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\Traffic;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers Traffic
* @covers Customers
* @covers Admins
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\Traffic
* @covers \Froxlor\Api\Commands\Customers
* @covers \Froxlor\Api\Commands\Admins
*/
class TrafficTest extends TestCase
{

View File

@@ -53,7 +53,6 @@ Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DISKSPACE . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DISKSPACE_ADMINS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_TRAFFIC . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_TRAFFIC_ADMINS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_TICKETS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_TASKS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_SESSIONS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_LOG . "`;");
@@ -87,8 +86,6 @@ Database::query("INSERT INTO `" . TABLE_PANEL_ADMINS . "` SET
`email_forwarders` = -1,
`email_quota` = -1,
`ftps` = -1,
`tickets` = -1,
`tickets_see_all` = 1,
`subdomains` = -1,
`traffic` = -1048576,
`ip` = -1