Changeset View
Changeset View
Standalone View
Standalone View
src/utils/__tests__/PhutilUtilsTestCase.php
Show First 20 Lines • Show All 602 Lines • ▼ Show 20 Lines | final class PhutilUtilsTestCase extends PhutilTestCase { | ||||
public function testCensorCredentials() { | public function testCensorCredentials() { | ||||
$cases = array( | $cases = array( | ||||
'' => '', | '' => '', | ||||
'abc' => 'abc', | 'abc' => 'abc', | ||||
// NOTE: We're liberal about censoring here, since we can't tell | // NOTE: We're liberal about censoring here, since we can't tell | ||||
// if this is a truncated password at the end of an input string | // if this is a truncated password at the end of an input string | ||||
// or a domain name. The version with a "/" isn't censored. | // or a domain name. The version with a "/" isn't censored. | ||||
'http://example.com' => 'http://xxxxx', | 'http://example.com' => 'http://********', | ||||
'http://example.com/' => 'http://example.com/', | 'http://example.com/' => 'http://example.com/', | ||||
'http://username@example.com' => 'http://xxxxx@example.com', | 'http://username@example.com' => 'http://********@example.com', | ||||
'http://user:pass@example.com' => 'http://xxxxx@example.com', | 'http://user:pass@example.com' => 'http://********@example.com', | ||||
// We censor these because they might be truncated credentials at the end | // We censor these because they might be truncated credentials at the end | ||||
// of the string. | // of the string. | ||||
'http://user' => 'http://xxxxx', | 'http://user' => 'http://********', | ||||
"http://user\n" => "http://xxxxx\n", | "http://user\n" => "http://********\n", | ||||
'svn+ssh://user:pass@example.com' => 'svn+ssh://xxxxx@example.com', | 'svn+ssh://user:pass@example.com' => 'svn+ssh://********@example.com', | ||||
); | ); | ||||
foreach ($cases as $input => $expect) { | foreach ($cases as $input => $expect) { | ||||
$this->assertEqual( | $this->assertEqual( | ||||
$expect, | $expect, | ||||
phutil_censor_credentials($input), | phutil_censor_credentials($input), | ||||
pht('Credential censoring for: %s', $input)); | pht('Credential censoring for: %s', $input)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 257 Lines • Show Last 20 Lines |