do not create empty userid when attribute does not have allowed chars
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
1953a11dfa
commit
8607992e85
|
@ -579,7 +579,19 @@ class Access extends LDAPUtility implements IUserTools {
|
||||||
} else {
|
} else {
|
||||||
$username = $uuid;
|
$username = $uuid;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$intName = $this->sanitizeUsername($username);
|
$intName = $this->sanitizeUsername($username);
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
\OC::$server->getLogger()->logException($e, [
|
||||||
|
'app' => 'user_ldap',
|
||||||
|
'level' => Util::WARN,
|
||||||
|
]);
|
||||||
|
// we don't attempt to set a username here. We can go for
|
||||||
|
// for an alternativ 4 digit random number as we would append
|
||||||
|
// otherwise, however it's likely not enough space in bigger
|
||||||
|
// setups, and most importantly: this is not intended.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$intName = $ldapName;
|
$intName = $ldapName;
|
||||||
}
|
}
|
||||||
|
@ -1291,7 +1303,7 @@ class Access extends LDAPUtility implements IUserTools {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool|mixed|string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function sanitizeUsername($name) {
|
public function sanitizeUsername($name) {
|
||||||
if($this->connection->ldapIgnoreNamingRules) {
|
if($this->connection->ldapIgnoreNamingRules) {
|
||||||
|
@ -1300,7 +1312,7 @@ class Access extends LDAPUtility implements IUserTools {
|
||||||
|
|
||||||
// Transliteration
|
// Transliteration
|
||||||
// latin characters to ASCII
|
// latin characters to ASCII
|
||||||
$name = iconv('UTF-8', 'ASCII//TRANSLIT', $name);
|
$name = iconv('UTF-8', 'ASCII//TRANSLIT', trim($name));
|
||||||
|
|
||||||
// Replacements
|
// Replacements
|
||||||
$name = str_replace(' ', '_', $name);
|
$name = str_replace(' ', '_', $name);
|
||||||
|
@ -1308,6 +1320,10 @@ class Access extends LDAPUtility implements IUserTools {
|
||||||
// Every remaining disallowed characters will be removed
|
// Every remaining disallowed characters will be removed
|
||||||
$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
|
$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
|
||||||
|
|
||||||
|
if($name === '') {
|
||||||
|
throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
|
||||||
|
}
|
||||||
|
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -632,5 +632,33 @@ class AccessTest extends TestCase {
|
||||||
$this->assertSame($expected, $list);
|
$this->assertSame($expected, $list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function intUsernameProvider() {
|
||||||
|
return [
|
||||||
|
['alice', 'alice'],
|
||||||
|
['b/ob', 'bob'],
|
||||||
|
['charly🐬', 'charly'],
|
||||||
|
['debo rah', 'debo_rah'],
|
||||||
|
['epost@poste.test', 'epost@poste.test'],
|
||||||
|
['fränk', 'frank'],
|
||||||
|
[' gerda ', 'gerda'],
|
||||||
|
['🕱🐵🐘🐑', null]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider intUsernameProvider
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
* @param $expected
|
||||||
|
*/
|
||||||
|
public function testSanitizeUsername($name, $expected) {
|
||||||
|
if($expected === null) {
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
}
|
||||||
|
$sanitizedName = $this->access->sanitizeUsername($name);
|
||||||
|
$this->assertSame($expected, $sanitizedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue