diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-05-12 00:33:26 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-05-12 01:31:15 +0200 |
commit | 8413ed947577a37c79ceebfc827acd37494d1a37 (patch) | |
tree | d0de6294ed93ad2c9e2d191bd5d2f2d399e485e1 /tests/lib/Accounts | |
parent | 1e271e9f76a5378d719e699c828a530c95ece336 (diff) | |
download | nextcloud-server-8413ed947577a37c79ceebfc827acd37494d1a37.tar.gz nextcloud-server-8413ed947577a37c79ceebfc827acd37494d1a37.zip |
allow to set valid scopes only in AccountProperty
the auto-fallback to v2-local is removed as well to react on wrong input
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests/lib/Accounts')
-rw-r--r-- | tests/lib/Accounts/AccountManagerTest.php | 20 | ||||
-rw-r--r-- | tests/lib/Accounts/AccountPropertyTest.php | 12 |
2 files changed, 25 insertions, 7 deletions
diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php index 687ae29ff7b..1da128ae124 100644 --- a/tests/lib/Accounts/AccountManagerTest.php +++ b/tests/lib/Accounts/AccountManagerTest.php @@ -213,8 +213,8 @@ class AccountManagerTest extends TestCase { // SCOPE_PRIVATE is not allowed for display name and email IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Display Name', 'scope' => IAccountManager::SCOPE_PRIVATE], IAccountManager::PROPERTY_EMAIL => ['value' => 'test@example.org', 'scope' => IAccountManager::SCOPE_PRIVATE], - IAccountManager::PROPERTY_TWITTER => ['value' => '@sometwitter', 'scope' => 'invalid'], - IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => ''], + IAccountManager::PROPERTY_TWITTER => ['value' => '@sometwitter', 'scope' => IAccountManager::SCOPE_LOCAL], + IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => IAccountManager::SCOPE_LOCAL], ], [ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Display Name', 'scope' => IAccountManager::SCOPE_LOCAL], @@ -222,9 +222,23 @@ class AccountManagerTest extends TestCase { IAccountManager::PROPERTY_TWITTER => ['value' => '@sometwitter', 'scope' => IAccountManager::SCOPE_LOCAL], IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => IAccountManager::SCOPE_LOCAL], ], - // don't throw but fall back false, false, ], + // illegal scope values + [ + [ + IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => IAccountManager::SCOPE_FEDERATED], + IAccountManager::PROPERTY_ADDRESS => ['value' => 'some street', 'scope' => IAccountManager::SCOPE_LOCAL], + IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://example.org', 'scope' => IAccountManager::SCOPE_PRIVATE], + ], + [ + IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => ''], + IAccountManager::PROPERTY_ADDRESS => ['value' => 'some street', 'scope' => 'v2-invalid'], + IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://example.org', 'scope' => 'invalid'], + ], + [], + true, true + ], // invalid or unsupported scope values throw an exception when passing $throwOnData=true [ [IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Display Name', 'scope' => IAccountManager::SCOPE_PUBLISHED]], diff --git a/tests/lib/Accounts/AccountPropertyTest.php b/tests/lib/Accounts/AccountPropertyTest.php index f99abc21f83..84059bbc35d 100644 --- a/tests/lib/Accounts/AccountPropertyTest.php +++ b/tests/lib/Accounts/AccountPropertyTest.php @@ -80,16 +80,20 @@ class AccountPropertyTest extends TestCase { [IAccountManager::VISIBILITY_PRIVATE, IAccountManager::SCOPE_LOCAL], [IAccountManager::VISIBILITY_CONTACTS_ONLY, IAccountManager::SCOPE_FEDERATED], [IAccountManager::VISIBILITY_PUBLIC, IAccountManager::SCOPE_PUBLISHED], - // fallback - ['', IAccountManager::SCOPE_LOCAL], - ['unknown', IAccountManager::SCOPE_LOCAL], + // invalid values + ['', null], + ['unknown', null], + ['v2-unknown', null], ]; } /** * @dataProvider scopesProvider */ - public function testSetScopeMapping($storedScope, $returnedScope) { + public function testSetScopeMapping(string $storedScope, ?string $returnedScope) { + if ($returnedScope === null) { + $this->expectException(\InvalidArgumentException::class); + } $accountProperty = new AccountProperty( IAccountManager::PROPERTY_WEBSITE, 'https://example.com', |