Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / people / storage / __tests__ / PhabricatorUserTestCase.php
bloba29dd4f20cd221a65d2ac04708c32c55146fea01
1 <?php
3 final class PhabricatorUserTestCase extends PhabricatorTestCase {
5 public function testUsernameValidation() {
6 $map = array(
7 'alincoln' => true,
8 'alincoln69' => true,
9 'hd3' => true,
10 'Alincoln' => true,
11 'a.lincoln' => true,
13 'alincoln!' => false,
14 '' => false,
16 // These are silly, but permitted.
17 '7' => true,
18 '0' => true,
19 '____' => true,
20 '-' => true,
22 // These are not permitted because they make capturing @mentions
23 // ambiguous.
24 'joe.' => false,
26 // We can never allow these because they invalidate usernames as tokens
27 // in commit messages ("Reviewers: alincoln, usgrant"), or as parameters
28 // in URIs ("/p/alincoln/", "?user=alincoln"), or make them unsafe in
29 // HTML. Theoretically we escape all the HTML/URI stuff, but these
30 // restrictions make attacks more difficult and are generally reasonable,
31 // since usernames like "<^, ,^>" don't seem very important to support.
32 '<script>' => false,
33 'a lincoln' => false,
34 ' alincoln' => false,
35 'alincoln ' => false,
36 'a,lincoln' => false,
37 'a&lincoln' => false,
38 'a/lincoln' => false,
40 "username\n" => false,
41 "user\nname" => false,
42 "\nusername" => false,
43 "username\r" => false,
44 "user\rname" => false,
45 "\rusername" => false,
48 foreach ($map as $name => $expect) {
49 $this->assertEqual(
50 $expect,
51 PhabricatorUser::validateUsername($name),
52 pht("Validity of '%s'.", $name));