Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show All 28 Lines | public function setUp(): void | ||||
$this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | ||||
$this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | $this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | ||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $this->deleteTestUser('john2.doe2@kolab.org'); | ||||
$this->deleteTestUser('deleted@kolab.org'); | $this->deleteTestUser('deleted@kolab.org'); | ||||
$this->deleteTestUser('deleted@kolabnow.com'); | $this->deleteTestUser('deleted@kolabnow.com'); | ||||
$this->deleteTestDomain('userscontroller.com'); | $this->deleteTestDomain('userscontroller.com'); | ||||
$this->deleteTestGroup('group-test@kolabnow.com'); | $this->deleteTestGroup('group-test@kolabnow.com'); | ||||
$this->deleteTestGroup('group-test@kolab.org'); | $this->deleteTestGroup('group-test@kolab.org'); | ||||
$this->deleteTestSharedFolder('folder-test@kolabnow.com'); | |||||
$this->deleteTestResource('resource-test@kolabnow.com'); | |||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | $wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | ||||
$wallet->save(); | $wallet->save(); | ||||
$user->status |= User::STATUS_IMAP_READY; | $user->status |= User::STATUS_IMAP_READY; | ||||
$user->save(); | $user->save(); | ||||
Show All 10 Lines | public function tearDown(): void | ||||
$this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | ||||
$this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | $this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | ||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $this->deleteTestUser('john2.doe2@kolab.org'); | ||||
$this->deleteTestUser('deleted@kolab.org'); | $this->deleteTestUser('deleted@kolab.org'); | ||||
$this->deleteTestUser('deleted@kolabnow.com'); | $this->deleteTestUser('deleted@kolabnow.com'); | ||||
$this->deleteTestDomain('userscontroller.com'); | $this->deleteTestDomain('userscontroller.com'); | ||||
$this->deleteTestGroup('group-test@kolabnow.com'); | $this->deleteTestGroup('group-test@kolabnow.com'); | ||||
$this->deleteTestGroup('group-test@kolab.org'); | $this->deleteTestGroup('group-test@kolab.org'); | ||||
$this->deleteTestSharedFolder('folder-test@kolabnow.com'); | |||||
$this->deleteTestResource('resource-test@kolabnow.com'); | |||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | $wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | ||||
$wallet->save(); | $wallet->save(); | ||||
$user->settings()->whereIn('key', ['greylist_enabled'])->delete(); | $user->settings()->whereIn('key', ['greylist_enabled'])->delete(); | ||||
$user->status |= User::STATUS_IMAP_READY; | $user->status |= User::STATUS_IMAP_READY; | ||||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | public function testShow(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertEquals($userA->id, $json['id']); | $this->assertEquals($userA->id, $json['id']); | ||||
$this->assertEquals($userA->email, $json['email']); | $this->assertEquals($userA->email, $json['email']); | ||||
$this->assertTrue(is_array($json['statusInfo'])); | $this->assertTrue(is_array($json['statusInfo'])); | ||||
$this->assertTrue(is_array($json['settings'])); | $this->assertTrue(is_array($json['settings'])); | ||||
$this->assertTrue(is_array($json['aliases'])); | |||||
$this->assertTrue($json['config']['greylist_enabled']); | $this->assertTrue($json['config']['greylist_enabled']); | ||||
$this->assertSame([], $json['skus']); | $this->assertSame([], $json['skus']); | ||||
$this->assertSame([], $json['aliases']); | |||||
// Values below are tested by Unit tests | // Values below are tested by Unit tests | ||||
$this->assertArrayHasKey('isDeleted', $json); | $this->assertArrayHasKey('isDeleted', $json); | ||||
$this->assertArrayHasKey('isDegraded', $json); | $this->assertArrayHasKey('isDegraded', $json); | ||||
$this->assertArrayHasKey('isAccountDegraded', $json); | $this->assertArrayHasKey('isAccountDegraded', $json); | ||||
$this->assertArrayHasKey('isSuspended', $json); | $this->assertArrayHasKey('isSuspended', $json); | ||||
$this->assertArrayHasKey('isActive', $json); | $this->assertArrayHasKey('isActive', $json); | ||||
$this->assertArrayHasKey('isLdapReady', $json); | $this->assertArrayHasKey('isLdapReady', $json); | ||||
$this->assertArrayHasKey('isImapReady', $json); | $this->assertArrayHasKey('isImapReady', $json); | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$ned = $this->getTestUser('ned@kolab.org'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
// Test unauthorized access to a profile of other user | // Test unauthorized access to a profile of other user | ||||
$response = $this->actingAs($jack)->get("/api/v4/users/{$userA->id}"); | $response = $this->actingAs($jack)->get("/api/v4/users/{$userA->id}"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Test authorized access to a profile of other user | // Test authorized access to a profile of other user | ||||
// Ned: Additional account controller | // Ned: Additional account controller | ||||
$response = $this->actingAs($ned)->get("/api/v4/users/{$john->id}"); | $response = $this->actingAs($ned)->get("/api/v4/users/{$john->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | |||||
$this->assertSame(['john.doe@kolab.org'], $json['aliases']); | |||||
$response = $this->actingAs($ned)->get("/api/v4/users/{$jack->id}"); | $response = $this->actingAs($ned)->get("/api/v4/users/{$jack->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
// John: Account owner | // John: Account owner | ||||
$response = $this->actingAs($john)->get("/api/v4/users/{$jack->id}"); | $response = $this->actingAs($john)->get("/api/v4/users/{$jack->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$response = $this->actingAs($john)->get("/api/v4/users/{$ned->id}"); | $response = $this->actingAs($john)->get("/api/v4/users/{$ned->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
Show All 10 Lines | public function testShow(): void | ||||
$this->assertSame(5, $json['skus'][$storage_sku->id]['count']); | $this->assertSame(5, $json['skus'][$storage_sku->id]['count']); | ||||
$this->assertSame([0,0,0,0,0], $json['skus'][$storage_sku->id]['costs']); | $this->assertSame([0,0,0,0,0], $json['skus'][$storage_sku->id]['costs']); | ||||
$this->assertSame(1, $json['skus'][$groupware_sku->id]['count']); | $this->assertSame(1, $json['skus'][$groupware_sku->id]['count']); | ||||
$this->assertSame([490], $json['skus'][$groupware_sku->id]['costs']); | $this->assertSame([490], $json['skus'][$groupware_sku->id]['costs']); | ||||
$this->assertSame(1, $json['skus'][$mailbox_sku->id]['count']); | $this->assertSame(1, $json['skus'][$mailbox_sku->id]['count']); | ||||
$this->assertSame([500], $json['skus'][$mailbox_sku->id]['costs']); | $this->assertSame([500], $json['skus'][$mailbox_sku->id]['costs']); | ||||
$this->assertSame(1, $json['skus'][$secondfactor_sku->id]['count']); | $this->assertSame(1, $json['skus'][$secondfactor_sku->id]['count']); | ||||
$this->assertSame([0], $json['skus'][$secondfactor_sku->id]['costs']); | $this->assertSame([0], $json['skus'][$secondfactor_sku->id]['costs']); | ||||
$this->assertSame([], $json['aliases']); | |||||
} | } | ||||
/** | /** | ||||
* Test fetching user status (GET /api/v4/users/<user-id>/status) | * Test fetching user status (GET /api/v4/users/<user-id>/status) | ||||
* and forcing setup process update (?refresh=1) | * and forcing setup process update (?refresh=1) | ||||
* | * | ||||
* @group imap | * @group imap | ||||
* @group dns | * @group dns | ||||
▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | public function testStore(): void | ||||
$this->assertSame("User created successfully.", $json['message']); | $this->assertSame("User created successfully.", $json['message']); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$user = User::where('email', 'john2.doe2@kolab.org')->first(); | $user = User::where('email', 'john2.doe2@kolab.org')->first(); | ||||
$this->assertInstanceOf(User::class, $user); | $this->assertInstanceOf(User::class, $user); | ||||
$this->assertSame('John2', $user->getSetting('first_name')); | $this->assertSame('John2', $user->getSetting('first_name')); | ||||
$this->assertSame('Doe2', $user->getSetting('last_name')); | $this->assertSame('Doe2', $user->getSetting('last_name')); | ||||
$this->assertSame('TestOrg', $user->getSetting('organization')); | $this->assertSame('TestOrg', $user->getSetting('organization')); | ||||
/** @var array<int, \App\UserAlias> $aliases */ | |||||
$aliases = $user->aliases()->orderBy('alias')->get(); | $aliases = $user->aliases()->orderBy('alias')->get(); | ||||
$this->assertCount(2, $aliases); | $this->assertCount(2, $aliases); | ||||
$this->assertSame('deleted@kolab.org', $aliases[0]->alias); | $this->assertSame('deleted@kolab.org', $aliases[0]->alias); | ||||
$this->assertSame('useralias1@kolab.org', $aliases[1]->alias); | $this->assertSame('useralias1@kolab.org', $aliases[1]->alias); | ||||
// Assert the new user entitlements | // Assert the new user entitlements | ||||
$this->assertEntitlements($user, ['groupware', 'mailbox', | $this->assertEntitlements($user, ['groupware', 'mailbox', | ||||
'storage', 'storage', 'storage', 'storage', 'storage']); | 'storage', 'storage', 'storage', 'storage', 'storage']); | ||||
// Assert the wallet to which the new user should be assigned to | // Assert the wallet to which the new user should be assigned to | ||||
▲ Show 20 Lines • Show All 448 Lines • ▼ Show 20 Lines | public function testUserResponse(): void | ||||
$wallet->setSettings(['mollie_id' => null, 'stripe_id' => null]); | $wallet->setSettings(['mollie_id' => null, 'stripe_id' => null]); | ||||
$result = $this->invokeMethod(new UsersController(), 'userResponse', [$user]); | $result = $this->invokeMethod(new UsersController(), 'userResponse', [$user]); | ||||
$this->assertEquals($user->id, $result['id']); | $this->assertEquals($user->id, $result['id']); | ||||
$this->assertEquals($user->email, $result['email']); | $this->assertEquals($user->email, $result['email']); | ||||
$this->assertEquals($user->status, $result['status']); | $this->assertEquals($user->status, $result['status']); | ||||
$this->assertTrue(is_array($result['statusInfo'])); | $this->assertTrue(is_array($result['statusInfo'])); | ||||
$this->assertTrue(is_array($result['aliases'])); | |||||
$this->assertCount(1, $result['aliases']); | |||||
$this->assertSame('john.doe@kolab.org', $result['aliases'][0]); | |||||
$this->assertTrue(is_array($result['settings'])); | $this->assertTrue(is_array($result['settings'])); | ||||
$this->assertSame('US', $result['settings']['country']); | $this->assertSame('US', $result['settings']['country']); | ||||
$this->assertSame('USD', $result['settings']['currency']); | $this->assertSame('USD', $result['settings']['currency']); | ||||
$this->assertTrue(is_array($result['accounts'])); | $this->assertTrue(is_array($result['accounts'])); | ||||
$this->assertTrue(is_array($result['wallets'])); | $this->assertTrue(is_array($result['wallets'])); | ||||
$this->assertCount(0, $result['accounts']); | $this->assertCount(0, $result['accounts']); | ||||
$this->assertCount(1, $result['wallets']); | $this->assertCount(1, $result['wallets']); | ||||
▲ Show 20 Lines • Show All 53 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->assertFalse($result['statusInfo']['enableSettings']); | $this->assertFalse($result['statusInfo']['enableSettings']); | ||||
} | } | ||||
/** | /** | ||||
* List of email address validation cases for testValidateEmail() | * User email address validation. | ||||
* | * | ||||
* @return array Arguments for testValidateEmail() | * Note: Technically these include unit tests, but let's keep it here for now. | ||||
* FIXME: Shall we do a http request for each case? | |||||
*/ | */ | ||||
public function dataValidateEmail(): array | public function testValidateEmail(): void | ||||
{ | { | ||||
$this->refreshApplication(); | Queue::fake(); | ||||
$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'); | ||||
$folder = $this->getTestSharedFolder('folder-event@kolab.org'); | |||||
$folder->setAliases(['folder-alias1@kolab.org']); | |||||
$folder_del = $this->getTestSharedFolder('folder-test@kolabnow.com'); | |||||
$folder_del->setAliases(['folder-alias2@kolabnow.com']); | |||||
$folder_del->delete(); | |||||
$pub_group = $this->getTestGroup('group-test@kolabnow.com'); | |||||
$pub_group->delete(); | |||||
$priv_group = $this->getTestGroup('group-test@kolab.org'); | |||||
$resource = $this->getTestResource('resource-test@kolabnow.com'); | |||||
$resource->delete(); | |||||
$cases = [ | |||||
// valid (user domain) | |||||
["admin@kolab.org", $john, null], | |||||
// valid (public domain) | |||||
["test.test@$domain", $john, null], | |||||
return [ | |||||
// Invalid format | // Invalid format | ||||
["$domain", $john, 'The specified email is invalid.'], | ["$domain", $john, 'The specified email is invalid.'], | ||||
[".@$domain", $john, 'The specified email is invalid.'], | [".@$domain", $john, 'The specified email is invalid.'], | ||||
["test123456@localhost", $john, 'The specified domain is invalid.'], | ["test123456@localhost", $john, 'The specified domain is invalid.'], | ||||
["test123456@unknown-domain.org", $john, 'The specified domain is invalid.'], | ["test123456@unknown-domain.org", $john, 'The specified domain is invalid.'], | ||||
["$domain", $john, 'The specified email is invalid.'], | ["$domain", $john, 'The specified email is invalid.'], | ||||
[".@$domain", $john, '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, 'The specified email is not available.'], | ["admin@$domain", $john, 'The specified email is not available.'], | ||||
["administrator@$domain", $john, 'The specified email 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, '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 | ||||
["jack.daniels@kolab.org", $john, 'The specified email is not available.'], | ["jack.daniels@kolab.org", $john, 'The specified email is not available.'], | ||||
// valid (user domain) | // An existing shared folder or folder alias | ||||
["admin@kolab.org", $john, null], | ["folder-event@kolab.org", $john, 'The specified email is not available.'], | ||||
["folder-alias1@kolab.org", $john, 'The specified email is not available.'], | |||||
// valid (public domain) | // A soft-deleted shared folder or folder alias | ||||
["test.test@$domain", $john, null], | ["folder-test@kolabnow.com", $john, 'The specified email is not available.'], | ||||
["folder-alias2@kolabnow.com", $john, 'The specified email is not available.'], | |||||
// A group | |||||
["group-test@kolab.org", $john, 'The specified email is not available.'], | |||||
// A soft-deleted group | |||||
["group-test@kolabnow.com", $john, 'The specified email is not available.'], | |||||
// A resource | |||||
["resource-test1@kolab.org", $john, 'The specified email is not available.'], | |||||
// A soft-deleted resource | |||||
["resource-test@kolabnow.com", $john, 'The specified email is not available.'], | |||||
]; | ]; | ||||
} | |||||
/** | foreach ($cases as $idx => $case) { | ||||
* User email address validation. | list($email, $user, $expected) = $case; | ||||
* | |||||
* Note: Technically these include unit tests, but let's keep it here for now. | $deleted = null; | ||||
* FIXME: Shall we do a http request for each case? | $result = UsersController::validateEmail($email, $user, $deleted); | ||||
* | |||||
* @dataProvider dataValidateEmail | $this->assertSame($expected, $result, "Case {$email}"); | ||||
*/ | $this->assertNull($deleted, "Case {$email}"); | ||||
public function testValidateEmail($email, $user, $expected_result): void | } | ||||
{ | |||||
$result = UsersController::validateEmail($email, $user); | |||||
$this->assertSame($expected_result, $result); | |||||
} | } | ||||
/** | /** | ||||
* User email validation - tests for $deleted argument | * User email validation - tests for $deleted argument | ||||
* | * | ||||
* 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? | ||||
*/ | */ | ||||
Show All 13 Lines | public function testValidateEmailDeleted(): void | ||||
$result = UsersController::validateEmail('deleted@kolabnow.com', $john, $deleted); | $result = UsersController::validateEmail('deleted@kolabnow.com', $john, $deleted); | ||||
$this->assertSame('The specified email is not available.', $result); | $this->assertSame('The specified email is not available.', $result); | ||||
$this->assertSame(null, $deleted); | $this->assertSame(null, $deleted); | ||||
$result = UsersController::validateEmail('jack@kolab.org', $john, $deleted); | $result = UsersController::validateEmail('jack@kolab.org', $john, $deleted); | ||||
$this->assertSame('The specified email is not available.', $result); | $this->assertSame('The specified email is not available.', $result); | ||||
$this->assertSame(null, $deleted); | $this->assertSame(null, $deleted); | ||||
} | |||||
/** | |||||
* User email validation - tests for an address being a group email address | |||||
* | |||||
* Note: Technically these include unit tests, but let's keep it here for now. | |||||
* FIXME: Shall we do a http request for each case? | |||||
*/ | |||||
public function testValidateEmailGroup(): void | |||||
{ | |||||
Queue::fake(); | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$pub_group = $this->getTestGroup('group-test@kolabnow.com'); | $pub_group = $this->getTestGroup('group-test@kolabnow.com'); | ||||
$priv_group = $this->getTestGroup('group-test@kolab.org'); | $priv_group = $this->getTestGroup('group-test@kolab.org'); | ||||
// A group in a public domain, existing | // A group in a public domain, existing | ||||
$result = UsersController::validateEmail($pub_group->email, $john, $deleted); | $result = UsersController::validateEmail($pub_group->email, $john, $deleted); | ||||
$this->assertSame('The specified email is not available.', $result); | $this->assertSame('The specified email is not available.', $result); | ||||
$this->assertNull($deleted); | $this->assertNull($deleted); | ||||
Show All 10 Lines | public function testValidateEmailDeleted(): void | ||||
$this->assertNull($deleted); | $this->assertNull($deleted); | ||||
$priv_group->delete(); | $priv_group->delete(); | ||||
// A group in a private domain, deleted | // A group in a private domain, deleted | ||||
$result = UsersController::validateEmail($priv_group->email, $john, $deleted); | $result = UsersController::validateEmail($priv_group->email, $john, $deleted); | ||||
$this->assertSame(null, $result); | $this->assertSame(null, $result); | ||||
$this->assertSame($priv_group->id, $deleted->id); | $this->assertSame($priv_group->id, $deleted->id); | ||||
// TODO: Test the same with a resource and shared folder | |||||
} | } | ||||
/** | /** | ||||
* List of alias validation cases for testValidateAlias() | * User email alias validation. | ||||
* | * | ||||
* @return array Arguments for testValidateAlias() | * Note: Technically these include unit tests, but let's keep it here for now. | ||||
* FIXME: Shall we do a http request for each case? | |||||
*/ | */ | ||||
public function dataValidateAlias(): array | public function testValidateAlias(): void | ||||
{ | { | ||||
$this->refreshApplication(); | Queue::fake(); | ||||
$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'); | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$deleted_priv = $this->getTestUser('deleted@kolab.org'); | |||||
$deleted_priv->setAliases(['deleted-alias@kolab.org']); | |||||
$deleted_priv->delete(); | |||||
$deleted_pub = $this->getTestUser('deleted@kolabnow.com'); | |||||
$deleted_pub->setAliases(['deleted-alias@kolabnow.com']); | |||||
$deleted_pub->delete(); | |||||
$folder = $this->getTestSharedFolder('folder-event@kolab.org'); | |||||
$folder->setAliases(['folder-alias1@kolab.org']); | |||||
$folder_del = $this->getTestSharedFolder('folder-test@kolabnow.com'); | |||||
$folder_del->setAliases(['folder-alias2@kolabnow.com']); | |||||
$folder_del->delete(); | |||||
$group_priv = $this->getTestGroup('group-test@kolab.org'); | |||||
$group = $this->getTestGroup('group-test@kolabnow.com'); | |||||
$group->delete(); | |||||
$resource = $this->getTestResource('resource-test@kolabnow.com'); | |||||
$resource->delete(); | |||||
return [ | $cases = [ | ||||
// Invalid format | // Invalid format | ||||
["$domain", $john, 'The specified alias is invalid.'], | ["$domain", $john, 'The specified alias is invalid.'], | ||||
[".@$domain", $john, 'The specified alias is invalid.'], | [".@$domain", $john, 'The specified alias is invalid.'], | ||||
["test123456@localhost", $john, 'The specified domain is invalid.'], | ["test123456@localhost", $john, 'The specified domain is invalid.'], | ||||
["test123456@unknown-domain.org", $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.'], | ||||
[".@$domain", $john, 'The specified alias is invalid.'], | [".@$domain", $john, 'The specified alias is invalid.'], | ||||
Show All 11 Lines | public function testValidateAlias(): void | ||||
// existing user | // existing user | ||||
["jack@kolab.org", $john, '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, null], | ["admin@kolab.org", $john, null], | ||||
// valid (public domain) | // valid (public domain) | ||||
["test.test@$domain", $john, null], | ["test.test@$domain", $john, null], | ||||
]; | |||||
} | |||||
/** | |||||
* User email alias 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 dataValidateAlias | |||||
*/ | |||||
public function testValidateAlias($alias, $user, $expected_result): void | |||||
{ | |||||
$result = UsersController::validateAlias($alias, $user); | |||||
$this->assertSame($expected_result, $result); | |||||
} | |||||
/** | |||||
* User alias validation - more cases. | |||||
* | |||||
* Note: Technically these include unit tests, but let's keep it here for now. | |||||
* FIXME: Shall we do a http request for each case? | |||||
*/ | |||||
public function testValidateAlias2(): void | |||||
{ | |||||
Queue::fake(); | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | |||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | |||||
$deleted_priv = $this->getTestUser('deleted@kolab.org'); | |||||
$deleted_priv->setAliases(['deleted-alias@kolab.org']); | |||||
$deleted_priv->delete(); | |||||
$deleted_pub = $this->getTestUser('deleted@kolabnow.com'); | |||||
$deleted_pub->setAliases(['deleted-alias@kolabnow.com']); | |||||
$deleted_pub->delete(); | |||||
$group = $this->getTestGroup('group-test@kolabnow.com'); | |||||
// 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::validateAlias('deleted@kolab.org', $john); | ["deleted@kolab.org", $john, null], | ||||
$this->assertSame(null, $result); | ["deleted-alias@kolab.org", $john, null], | ||||
["deleted@kolabnow.com", $john, 'The specified alias is not available.'], | |||||
["deleted-alias@kolabnow.com", $john, 'The specified alias is not available.'], | |||||
// An existing shared folder or folder alias | |||||
["folder-event@kolab.org", $john, 'The specified alias is not available.'], | |||||
["folder-alias1@kolab.org", $john, null], | |||||
// A soft-deleted shared folder or folder alias | |||||
["folder-test@kolabnow.com", $john, 'The specified alias is not available.'], | |||||
["folder-alias2@kolabnow.com", $john, 'The specified alias is not available.'], | |||||
// A group with the same email address exists | |||||
["group-test@kolab.org", $john, 'The specified alias is not available.'], | |||||
$result = UsersController::validateAlias('deleted-alias@kolab.org', $john); | // A soft-deleted group | ||||
$this->assertSame(null, $result); | ["group-test@kolabnow.com", $john, 'The specified alias is not available.'], | ||||
$result = UsersController::validateAlias('deleted@kolabnow.com', $john); | // A resource | ||||
$this->assertSame('The specified alias is not available.', $result); | ["resource-test1@kolab.org", $john, 'The specified alias is not available.'], | ||||
$result = UsersController::validateAlias('deleted-alias@kolabnow.com', $john); | // A soft-deleted resource | ||||
$this->assertSame('The specified alias is not available.', $result); | ["resource-test@kolabnow.com", $john, 'The specified alias is not available.'], | ||||
]; | |||||
// A grpoup with the same email address exists | foreach ($cases as $idx => $case) { | ||||
$result = UsersController::validateAlias($group->email, $john); | list($alias, $user, $expected) = $case; | ||||
$this->assertSame('The specified alias is not available.', $result); | $result = UsersController::validateAlias($alias, $user); | ||||
$this->assertSame($expected, $result, "Case {$alias}"); | |||||
} | |||||
} | } | ||||
} | } |