summaryrefslogtreecommitdiffstats
path: root/tests/lib/User
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-04-12 10:29:28 +0200
committerJoas Schilling <coding@schilljs.com>2017-04-18 14:29:34 +0200
commita3922bbcdc04d13c4e9614e0a29506c2fc8c7989 (patch)
tree53e719877d12b186d1ebe20145d58975da80c280 /tests/lib/User
parentb072d2c49d6f61c2b55abf12e04bdf2166dbd4f4 (diff)
downloadnextcloud-server-a3922bbcdc04d13c4e9614e0a29506c2fc8c7989.tar.gz
nextcloud-server-a3922bbcdc04d13c4e9614e0a29506c2fc8c7989.zip
Better validation of allowed user names
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests/lib/User')
-rw-r--r--tests/lib/User/ManagerTest.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php
index 123271bcc8f..671b2ac57c1 100644
--- a/tests/lib/User/ManagerTest.php
+++ b/tests/lib/User/ManagerTest.php
@@ -256,6 +256,49 @@ class ManagerTest extends TestCase {
$this->assertEquals('foo3', array_shift($result)->getUID());
}
+ public function dataCreateUserInvalid() {
+ return [
+ ['te?st', 'foo', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ["te\tst", '', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ["te\nst", '', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ["te\rst", '', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ["te\0st", '', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ["te\x0Bst", '', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ["te\xe2st", '', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ["te\x80st", '', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ["te\x8bst", '', 'Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
+ ['', 'foo', 'A valid username must be provided'],
+ [' ', 'foo', 'A valid username must be provided'],
+ [' test', 'foo', 'Username contains whitespace at the beginning or at the end'],
+ ['test ', 'foo', 'Username contains whitespace at the beginning or at the end'],
+ ['.', 'foo', 'Username must not consist of dots only'],
+ ['..', 'foo', 'Username must not consist of dots only'],
+ ['.test', '', 'A valid password must be provided'],
+ ['test', '', 'A valid password must be provided'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataCreateUserInvalid
+ */
+ public function testCreateUserInvalid($uid, $password, $exception) {
+
+ $this->setExpectedException(\Exception::class, $exception);
+
+ $manager = new \OC\User\Manager($this->config);
+ $manager->createUser($uid, $password);
+
+ }
+
public function testCreateUserSingleBackendNotExists() {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend