Skip to content

Commit 9304901

Browse files
authored
Merge pull request #68 from abashurov/master
Ensure tests can be passed with the 'Very strong' password policy
2 parents aa10351 + 30f5ea8 commit 9304901

File tree

10 files changed

+113
-36
lines changed

10 files changed

+113
-36
lines changed

tests/CustomerTest.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\KeyLimitChecker;
6+
use PleskXTest\Utility\PasswordProvider;
7+
58
class CustomerTest extends TestCase
69
{
7-
private $_customerProperties = [
8-
'cname' => 'Plesk',
9-
'pname' => 'John Smith',
10-
'login' => 'john-unit-test',
11-
'passwd' => 'simple-password',
12-
'email' => 'john@smith.com',
13-
'external-id' => 'link:12345',
14-
'description' => 'Good guy',
15-
];
10+
private $_customerProperties;
11+
12+
public function setUp()
13+
{
14+
$this->_customerProperties = [
15+
'cname' => 'Plesk',
16+
'pname' => 'John Smith',
17+
'login' => 'john-unit-test',
18+
'passwd' => PasswordProvider::STRONG_PASSWORD,
19+
'email' => 'john@smith.com',
20+
'external-id' => 'link:12345',
21+
'description' => 'Good guy',
22+
];
23+
}
1624

1725
public function testCreate()
1826
{
@@ -48,19 +56,19 @@ public function testGetAll()
4856
{
4957
$keyInfo = static::$_client->server()->getKeyInfo();
5058

51-
if ((int)$keyInfo['lim_cl'] < 2) {
59+
if (!KeyLimitChecker::checkByType($keyInfo, KeyLimitChecker::LIMIT_CLIENTS, 2)) {
5260
$this->markTestSkipped('License does not allow to create more than 1 customer.');
5361
}
5462

5563
static::$_client->customer()->create([
5664
'pname' => 'John Smith',
5765
'login' => 'customer-a',
58-
'passwd' => 'simple-password',
66+
'passwd' => PasswordProvider::STRONG_PASSWORD,
5967
]);
6068
static::$_client->customer()->create([
6169
'pname' => 'Mike Black',
6270
'login' => 'customer-b',
63-
'passwd' => 'simple-password',
71+
'passwd' => PasswordProvider::STRONG_PASSWORD,
6472
]);
6573

6674
$customersInfo = static::$_client->customer()->getAll();

tests/DatabaseTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\PasswordProvider;
6+
57
class DatabaseTest extends TestCase
68
{
79
/** @var \PleskX\Api\Struct\Webspace\Info */
@@ -35,7 +37,7 @@ public function testCreateUser()
3537
$user = $this->_createUser([
3638
'db-id' => $database->id,
3739
'login' => 'test_user1',
38-
'password' => 'setup1Q',
40+
'password' => PasswordProvider::STRONG_PASSWORD,
3941
]);
4042
static::$_client->database()->deleteUser('id', $user->id);
4143
static::$_client->database()->delete('id', $database->id);
@@ -52,12 +54,12 @@ public function testUpdateUser()
5254
$user = $this->_createUser([
5355
'db-id' => $database->id,
5456
'login' => 'test_user1',
55-
'password' => 'setup1Q',
57+
'password' => PasswordProvider::STRONG_PASSWORD,
5658
]);
5759
$updatedUser = static::$_client->database()->updateUser([
5860
'id' => $user->id,
5961
'login' => 'test_user2',
60-
'password' => 'setup2Q',
62+
'password' => PasswordProvider::STRONG_PASSWORD,
6163
]);
6264
$this->assertEquals(true, $updatedUser);
6365
static::$_client->database()->deleteUser('id', $user->id);
@@ -118,7 +120,7 @@ public function testGetUserById()
118120
$user = $this->_createUser([
119121
'db-id' => $database->id,
120122
'login' => 'test_user1',
121-
'password' => 'setup1Q',
123+
'password' => PasswordProvider::STRONG_PASSWORD,
122124
]);
123125

124126
$dbUser = static::$_client->database()->getUser('id', $user->id);
@@ -146,19 +148,19 @@ public function testGetAllUsersByDbId()
146148
$user1 = $this->_createUser([
147149
'db-id' => $db1->id,
148150
'login' => 'test_user1',
149-
'password' => 'setup1Q',
151+
'password' => PasswordProvider::STRONG_PASSWORD,
150152
]);
151153

152154
$user2 = $this->_createUser([
153155
'db-id' => $db1->id,
154156
'login' => 'test_user2',
155-
'password' => 'setup1Q',
157+
'password' => PasswordProvider::STRONG_PASSWORD,
156158
]);
157159

158160
$user3 = $this->_createUser([
159161
'db-id' => $db2->id,
160162
'login' => 'test_user3',
161-
'password' => 'setup1Q',
163+
'password' => PasswordProvider::STRONG_PASSWORD,
162164
]);
163165

164166
$dbUsers = static::$_client->database()->getAllUsers('db-id', $db1->id);
@@ -196,7 +198,7 @@ public function testDeleteUser()
196198
$user = $this->_createUser([
197199
'db-id' => $database->id,
198200
'login' => 'test_user1',
199-
'password' => 'setup1Q',
201+
'password' => PasswordProvider::STRONG_PASSWORD,
200202
]);
201203

202204
$result = static::$_client->database()->deleteUser('id', $user->id);

tests/MailTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\PasswordProvider;
6+
57
class MailTest extends TestCase
68
{
79
/** @var \PleskX\Api\Struct\Webspace\Info */
@@ -35,7 +37,7 @@ protected function setUp()
3537

3638
public function testCreate()
3739
{
38-
$mailname = static::$_client->mail()->create('test', static::$webspace->id, true, 'secret');
40+
$mailname = static::$_client->mail()->create('test', static::$webspace->id, true, PasswordProvider::STRONG_PASSWORD);
3941

4042
$this->assertIsInt($mailname->id);
4143
$this->assertGreaterThan(0, $mailname->id);

tests/ProtectedDirectoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\PasswordProvider;
6+
57
class ProtectedDirectoryTest extends TestCase
68
{
79
/** @var \PleskX\Api\Struct\Webspace\Info */
@@ -64,7 +66,7 @@ public function testAddUser()
6466
{
6567
$protectedDirectory = static::$_client->protectedDirectory()->add('/', static::$webspace->id);
6668

67-
$user = static::$_client->protectedDirectory()->addUser($protectedDirectory, 'john', 'secret');
69+
$user = static::$_client->protectedDirectory()->addUser($protectedDirectory, 'john', PasswordProvider::STRONG_PASSWORD);
6870
$this->assertGreaterThan(0, $user->id);
6971

7072
static::$_client->protectedDirectory()->delete('id', $protectedDirectory->id);
@@ -74,7 +76,7 @@ public function testDeleteUser()
7476
{
7577
$protectedDirectory = static::$_client->protectedDirectory()->add('/', static::$webspace->id);
7678

77-
$user = static::$_client->protectedDirectory()->addUser($protectedDirectory, 'john', 'secret');
79+
$user = static::$_client->protectedDirectory()->addUser($protectedDirectory, 'john', PasswordProvider::STRONG_PASSWORD);
7880
$result = static::$_client->protectedDirectory()->deleteUser('id', $user->id);
7981
$this->assertTrue($result);
8082

tests/ResellerTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\KeyLimitChecker;
6+
use PleskXTest\Utility\PasswordProvider;
7+
58
class ResellerTest extends TestCase
69
{
7-
private $_resellerProperties = [
8-
'pname' => 'John Reseller',
9-
'login' => 'reseller-unit-test',
10-
'passwd' => 'simple-password',
11-
];
10+
private $_resellerProperties;
11+
12+
public function setUp()
13+
{
14+
$this->_resellerProperties = [
15+
'pname' => 'John Reseller',
16+
'login' => 'reseller-unit-test',
17+
'passwd' => PasswordProvider::STRONG_PASSWORD,
18+
];
19+
}
1220

1321
public function testCreate()
1422
{
@@ -41,19 +49,19 @@ public function testGetAll()
4149
{
4250
$keyInfo = static::$_client->server()->getKeyInfo();
4351

44-
if ((int)$keyInfo['lim_cl'] < 2) {
52+
if (!KeyLimitChecker::checkByType($keyInfo, KeyLimitChecker::LIMIT_RESELLERS, 2)) {
4553
$this->markTestSkipped('License does not allow to create more than 1 reseller.');
4654
}
4755

4856
static::$_client->reseller()->create([
4957
'pname' => 'John Reseller',
5058
'login' => 'reseller-a',
51-
'passwd' => 'simple-password',
59+
'passwd' => PasswordProvider::STRONG_PASSWORD,
5260
]);
5361
static::$_client->reseller()->create([
5462
'pname' => 'Mike Reseller',
5563
'login' => 'reseller-b',
56-
'passwd' => 'simple-password',
64+
'passwd' => PasswordProvider::STRONG_PASSWORD,
5765
]);
5866

5967
$resellersInfo = static::$_client->reseller()->getAll();

tests/SiteTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\KeyLimitChecker;
6+
57
class SiteTest extends TestCase
68
{
79
/** @var \PleskX\Api\Struct\Webspace\Info */
@@ -19,7 +21,7 @@ protected function setUp()
1921

2022
$keyInfo = static::$_client->server()->getKeyInfo();
2123

22-
if ((int)$keyInfo['lim_dom'] < 2) {
24+
if (!KeyLimitChecker::checkByType($keyInfo, KeyLimitChecker::LIMIT_DOMAINS, 2)) {
2325
$this->markTestSkipped('License does not allow to create more than 1 domain.');
2426
}
2527
}

tests/TestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\PasswordProvider;
6+
57
abstract class TestCase extends \PHPUnit\Framework\TestCase
68
{
79
/** @var \PleskX\Api\Client */
@@ -52,15 +54,13 @@ protected static function _getIpAddress()
5254
protected static function _createWebspace()
5355
{
5456
$id = uniqid();
55-
$password = base64_encode(time());
56-
5757
$webspace = static::$_client->webspace()->create(
5858
[
5959
'name' => "test{$id}.test",
6060
'ip_address' => static::_getIpAddress(),
6161
], [
6262
'ftp_login' => "u{$id}",
63-
'ftp_password' => $password,
63+
'ftp_password' => PasswordProvider::STRONG_PASSWORD,
6464
]
6565
);
6666
self::$webspaces[] = $webspace;

tests/Utility/KeyLimitChecker.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace PleskXTest\Utility;
4+
5+
class KeyLimitChecker
6+
{
7+
const LIMIT_CLIENTS = 'limit_clients';
8+
const LIMIT_RESELLERS = 'limit_resellers';
9+
const LIMIT_DOMAINS = 'limit_domains';
10+
11+
/**
12+
* Checks whether limit is within the required constraint
13+
*
14+
* @param (string|int)[] $keyInfo Structure returned by the getKeyInfo call
15+
* @param string $type Type of the object that should be checked
16+
* @param int $minimalRequirement Minimal value that should satisfy the limit
17+
* @return bool if license satisfies set limits
18+
*/
19+
public static function checkByType(array $keyInfo, $type, $minimalRequirement)
20+
{
21+
$field = null;
22+
switch ($type) {
23+
case self::LIMIT_CLIENTS:
24+
if (intval($keyInfo['can-manage-customers']) === 0) {
25+
return false;
26+
}
27+
$field = 'lim_cl';
28+
break;
29+
case self::LIMIT_RESELLERS:
30+
if (intval($keyInfo['can-manage-resellers']) === 0) {
31+
return false;
32+
}
33+
$field = 'lim_cl';
34+
break;
35+
case self::LIMIT_DOMAINS:
36+
$field = 'lim_dom';
37+
break;
38+
default:
39+
return false;
40+
}
41+
return intval($keyInfo[$field]) === -1 || intval($keyInfo[$field]) > $minimalRequirement;
42+
}
43+
}

tests/Utility/PasswordProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace PleskXTest\Utility;
4+
5+
class PasswordProvider
6+
{
7+
const STRONG_PASSWORD = 'test-PWD*1@42!13#';
8+
}

tests/WebspaceTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\PasswordProvider;
6+
57
class WebspaceTest extends TestCase
68
{
79
public function testGetPermissionDescriptor()
@@ -96,7 +98,7 @@ public function testRequestCreateWebspace()
9698
],
9799
[
98100
'name' => 'ftp_password',
99-
'value' => 'test-PWD*1',
101+
'value' => PasswordProvider::STRONG_PASSWORD,
100102
],
101103
],
102104
'ip_address' => static::_getIpAddress(),

0 commit comments

Comments
 (0)