Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 1,021 Lines • ▼ Show 20 Lines | public function testUserResponse(): void | ||||
$this->assertFalse($result['statusInfo']['enableDomains']); | $this->assertFalse($result['statusInfo']['enableDomains']); | ||||
$this->assertFalse($result['statusInfo']['enableWallets']); | $this->assertFalse($result['statusInfo']['enableWallets']); | ||||
$this->assertFalse($result['statusInfo']['enableUsers']); | $this->assertFalse($result['statusInfo']['enableUsers']); | ||||
$this->assertSame([], $result['statusInfo']['betaSKUs']); | $this->assertSame([], $result['statusInfo']['betaSKUs']); | ||||
} | } | ||||
/** | /** | ||||
* List of alias validation cases for testValidateEmail() | * List of email address validation cases for testValidateEmail() | ||||
* | * | ||||
* @return array Arguments for testValidateEmail() | * @return array Arguments for testValidateEmail() | ||||
*/ | */ | ||||
public function dataValidateEmail(): array | public function dataValidateEmail(): array | ||||
{ | { | ||||
$this->refreshApplication(); | $this->refreshApplication(); | ||||
$public_domains = Domain::getPublicDomains(); | $public_domains = Domain::getPublicDomains(); | ||||
$domain = reset($public_domains); | $domain = reset($public_domains); | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
return [ | return [ | ||||
// Invalid format | // Invalid format | ||||
["$domain", $john, true, 'The specified alias is invalid.'], | ["$domain", $john, 'The specified email is invalid.'], | ||||
[".@$domain", $john, true, 'The specified alias is invalid.'], | [".@$domain", $john, 'The specified email is invalid.'], | ||||
["test123456@localhost", $john, true, 'The specified domain is invalid.'], | ["test123456@localhost", $john, 'The specified domain is invalid.'], | ||||
["test123456@unknown-domain.org", $john, true, 'The specified domain is invalid.'], | ["test123456@unknown-domain.org", $john, 'The specified domain is invalid.'], | ||||
["$domain", $john, false, 'The specified email is invalid.'], | ["$domain", $john, 'The specified email is invalid.'], | ||||
[".@$domain", $john, false, 'The specified email is invalid.'], | [".@$domain", $john, 'The specified email is invalid.'], | ||||
// forbidden local part on public domains | // forbidden local part on public domains | ||||
["admin@$domain", $john, true, 'The specified alias is not available.'], | ["admin@$domain", $john, 'The specified email is not available.'], | ||||
["administrator@$domain", $john, true, 'The specified alias is not available.'], | ["administrator@$domain", $john, 'The specified email is not available.'], | ||||
// forbidden (other user's domain) | // forbidden (other user's domain) | ||||
["testtest@kolab.org", $user, true, 'The specified domain is not available.'], | ["testtest@kolab.org", $user, 'The specified domain is not available.'], | ||||
// existing alias of other user, to be a user email | // existing alias of other user, to be a user email | ||||
["jack.daniels@kolab.org", $john, false, 'The specified email is not available.'], | ["jack.daniels@kolab.org", $john, 'The specified email is not available.'], | ||||
// valid (user domain) | |||||
["admin@kolab.org", $john, null], | |||||
// valid (public domain) | |||||
["test.test@$domain", $john, null], | |||||
]; | |||||
} | |||||
/** | |||||
* User email address validation. | |||||
* | |||||
* Note: Technically these include unit tests, but let's keep it here for now. | |||||
* FIXME: Shall we do a http request for each case? | |||||
* | |||||
* @dataProvider dataValidateEmail | |||||
*/ | |||||
public function testValidateEmail($email, $user, $expected_result): void | |||||
{ | |||||
$result = UsersController::validateEmail($email, $user); | |||||
$this->assertSame($expected_result, $result); | |||||
} | |||||
/** | |||||
* List of alias validation cases for testValidateAlias() | |||||
* | |||||
* @return array Arguments for testValidateAlias() | |||||
*/ | |||||
public function dataValidateAlias(): array | |||||
{ | |||||
$this->refreshApplication(); | |||||
$public_domains = Domain::getPublicDomains(); | |||||
$domain = reset($public_domains); | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | |||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | |||||
return [ | |||||
// Invalid format | |||||
["$domain", $john, 'The specified alias is invalid.'], | |||||
[".@$domain", $john, 'The specified alias is invalid.'], | |||||
["test123456@localhost", $john, 'The specified domain is invalid.'], | |||||
["test123456@unknown-domain.org", $john, 'The specified domain is invalid.'], | |||||
["$domain", $john, 'The specified alias is invalid.'], | |||||
[".@$domain", $john, 'The specified alias is invalid.'], | |||||
// forbidden local part on public domains | |||||
["admin@$domain", $john, 'The specified alias is not available.'], | |||||
["administrator@$domain", $john, 'The specified alias is not available.'], | |||||
// forbidden (other user's domain) | |||||
["testtest@kolab.org", $user, 'The specified domain is not available.'], | |||||
// existing alias of other user, to be an alias, user in the same group account | // existing alias of other user, to be an alias, user in the same group account | ||||
["jack.daniels@kolab.org", $john, true, null], | ["jack.daniels@kolab.org", $john, null], | ||||
// existing user | // existing user | ||||
["jack@kolab.org", $john, true, 'The specified alias is not available.'], | ["jack@kolab.org", $john, 'The specified alias is not available.'], | ||||
// valid (user domain) | // valid (user domain) | ||||
["admin@kolab.org", $john, true, null], | ["admin@kolab.org", $john, null], | ||||
// valid (public domain) | // valid (public domain) | ||||
["test.test@$domain", $john, true, null], | ["test.test@$domain", $john, null], | ||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* User email/alias validation. | * User email alias validation. | ||||
* | * | ||||
* Note: Technically these include unit tests, but let's keep it here for now. | * Note: Technically these include unit tests, but let's keep it here for now. | ||||
* FIXME: Shall we do a http request for each case? | * FIXME: Shall we do a http request for each case? | ||||
* | * | ||||
* @dataProvider dataValidateEmail | * @dataProvider dataValidateAlias | ||||
*/ | */ | ||||
public function testValidateEmail($alias, $user, $is_alias, $expected_result): void | public function testValidateAlias($alias, $user, $expected_result): void | ||||
{ | { | ||||
$args = [$alias, $user, $is_alias]; | $result = UsersController::validateAlias($alias, $user); | ||||
$result = $this->invokeMethod(new UsersController(), 'validateEmail', $args); | |||||
$this->assertSame($expected_result, $result); | $this->assertSame($expected_result, $result); | ||||
} | } | ||||
/** | /** | ||||
* User email/alias validation - more cases. | * User alias validation - more cases. | ||||
* | * | ||||
* Note: Technically these include unit tests, but let's keep it here for now. | * Note: Technically these include unit tests, but let's keep it here for now. | ||||
* FIXME: Shall we do a http request for each case? | * FIXME: Shall we do a http request for each case? | ||||
*/ | */ | ||||
public function testValidateEmail2(): void | public function testValidateAlias2(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$deleted_priv = $this->getTestUser('deleted@kolab.org'); | $deleted_priv = $this->getTestUser('deleted@kolab.org'); | ||||
$deleted_priv->setAliases(['deleted-alias@kolab.org']); | $deleted_priv->setAliases(['deleted-alias@kolab.org']); | ||||
$deleted_priv->delete(); | $deleted_priv->delete(); | ||||
$deleted_pub = $this->getTestUser('deleted@kolabnow.com'); | $deleted_pub = $this->getTestUser('deleted@kolabnow.com'); | ||||
$deleted_pub->setAliases(['deleted-alias@kolabnow.com']); | $deleted_pub->setAliases(['deleted-alias@kolabnow.com']); | ||||
$deleted_pub->delete(); | $deleted_pub->delete(); | ||||
// An alias that was a user email before is allowed, but only for custom domains | // An alias that was a user email before is allowed, but only for custom domains | ||||
$result = UsersController::validateEmail('deleted@kolab.org', $john, true); | $result = UsersController::validateAlias('deleted@kolab.org', $john); | ||||
$this->assertSame(null, $result); | $this->assertSame(null, $result); | ||||
$result = UsersController::validateEmail('deleted-alias@kolab.org', $john, true); | $result = UsersController::validateAlias('deleted-alias@kolab.org', $john); | ||||
$this->assertSame(null, $result); | $this->assertSame(null, $result); | ||||
$result = UsersController::validateEmail('deleted@kolabnow.com', $john, true); | $result = UsersController::validateAlias('deleted@kolabnow.com', $john); | ||||
$this->assertSame('The specified alias is not available.', $result); | $this->assertSame('The specified alias is not available.', $result); | ||||
$result = UsersController::validateEmail('deleted-alias@kolabnow.com', $john, true); | $result = UsersController::validateAlias('deleted-alias@kolabnow.com', $john); | ||||
$this->assertSame('The specified alias is not available.', $result); | $this->assertSame('The specified alias is not available.', $result); | ||||
} | } | ||||
} | } |