public function testURIParsing()
 {
     $uri = new PhutilURI('http://*****:*****@host:99/path/?query=value#fragment');
     $this->assertEqual('http', $uri->getProtocol(), pht('protocol'));
     $this->assertEqual('user', $uri->getUser(), pht('user'));
     $this->assertEqual('pass', $uri->getPass(), pht('password'));
     $this->assertEqual('host', $uri->getDomain(), pht('domain'));
     $this->assertEqual('99', $uri->getPort(), pht('port'));
     $this->assertEqual('/path/', $uri->getPath(), pht('path'));
     $this->assertEqual(array('query' => 'value'), $uri->getQueryParams(), 'query params');
     $this->assertEqual('fragment', $uri->getFragment(), pht('fragment'));
     $this->assertEqual('http://*****:*****@host:99/path/?query=value#fragment', (string) $uri, 'uri');
     $uri = new PhutilURI('ssh://git@example.com/example/example.git');
     $this->assertEqual('ssh', $uri->getProtocol(), pht('protocol'));
     $this->assertEqual('git', $uri->getUser(), pht('user'));
     $this->assertEqual('', $uri->getPass(), pht('password'));
     $this->assertEqual('example.com', $uri->getDomain(), pht('domain'));
     $this->assertEqual('', $uri->getPort(), 'port');
     $this->assertEqual('/example/example.git', $uri->getPath(), pht('path'));
     $this->assertEqual(array(), $uri->getQueryParams(), pht('query parameters'));
     $this->assertEqual('', $uri->getFragment(), pht('fragment'));
     $this->assertEqual('ssh://git@example.com/example/example.git', (string) $uri, 'uri');
     $uri = new PhutilURI('http://0@domain.com/');
     $this->assertEqual('0', $uri->getUser());
     $this->assertEqual('http://0@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://*****:*****@domain.com/');
     $this->assertEqual('0', $uri->getUser());
     $this->assertEqual('0', $uri->getPass());
     $this->assertEqual('http://*****:*****@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://%20:%20@domain.com/');
     $this->assertEqual(' ', $uri->getUser());
     $this->assertEqual(' ', $uri->getPass());
     $this->assertEqual('http://%20:%20@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://%40:%40@domain.com/');
     $this->assertEqual('@', $uri->getUser());
     $this->assertEqual('@', $uri->getPass());
     $this->assertEqual('http://%40:%40@domain.com/', (string) $uri);
     // These tests are covering cases where cURL and parse_url() behavior
     // may differ in potentially dangerous ways. See T6755 for discussion.
     // In general, we defuse these attacks by emitting URIs which escape
     // special characters so that they are interpreted unambiguously by
     // cURL in the same way that parse_url() interpreted them.
     $uri = new PhutilURI('http://*****:*****@evil.com?@good.com');
     $this->assertEqual('u', $uri->getUser());
     $this->assertEqual('p', $uri->getPass());
     $this->assertEqual('evil.com', $uri->getDomain());
     $this->assertEqual('http://*****:*****@evil.com?%40good.com=', (string) $uri);
     $uri = new PhutilURI('http://good.com#u:p@evil.com/');
     $this->assertEqual('good.com#u', $uri->getUser());
     $this->assertEqual('p', $uri->getPass());
     $this->assertEqual('evil.com', $uri->getDomain());
     $this->assertEqual('http://good.com%23u:p@evil.com/', (string) $uri);
     $uri = new PhutilURI('http://good.com?u:p@evil.com/');
     $this->assertEqual('', $uri->getUser());
     $this->assertEqual('', $uri->getPass());
     $this->assertEqual('good.com', $uri->getDomain());
     $this->assertEqual('http://good.com?u%3Ap%40evil.com%2F=', (string) $uri);
 }
Exemplo n.º 2
0
 public function testURIParsing()
 {
     $uri = new PhutilURI('http://*****:*****@host:99/path/?query=value#fragment');
     $this->assertEqual('http', $uri->getProtocol(), 'protocol');
     $this->assertEqual('user', $uri->getUser(), 'user');
     $this->assertEqual('pass', $uri->getPass(), 'pass');
     $this->assertEqual('host', $uri->getDomain(), 'domain');
     $this->assertEqual('99', $uri->getPort(), 'port');
     $this->assertEqual('/path/', $uri->getPath(), 'path');
     $this->assertEqual(array('query' => 'value'), $uri->getQueryParams(), 'query params');
     $this->assertEqual('fragment', $uri->getFragment(), 'fragment');
     $this->assertEqual('http://*****:*****@host:99/path/?query=value#fragment', (string) $uri, 'uri');
     $uri = new PhutilURI('ssh://git@example.com/example/example.git');
     $this->assertEqual('ssh', $uri->getProtocol(), 'protocol');
     $this->assertEqual('git', $uri->getUser(), 'user');
     $this->assertEqual('', $uri->getPass(), 'pass');
     $this->assertEqual('example.com', $uri->getDomain(), 'domain');
     $this->assertEqual('', $uri->getPort(), 'port');
     $this->assertEqual('/example/example.git', $uri->getPath(), 'path');
     $this->assertEqual(array(), $uri->getQueryParams(), 'query params');
     $this->assertEqual('', $uri->getFragment(), 'fragment');
     $this->assertEqual('ssh://git@example.com/example/example.git', (string) $uri, 'uri');
     $uri = new PhutilURI('http://0@domain.com/');
     $this->assertEqual('0', $uri->getUser());
     $this->assertEqual('http://0@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://*****:*****@domain.com/');
     $this->assertEqual('0', $uri->getUser());
     $this->assertEqual('0', $uri->getPass());
     $this->assertEqual('http://*****:*****@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://%20:%20@domain.com/');
     $this->assertEqual(' ', $uri->getUser());
     $this->assertEqual(' ', $uri->getPass());
     $this->assertEqual('http://%20:%20@domain.com/', (string) $uri);
     $uri = new PhutilURI('http://%40:%40@domain.com/');
     $this->assertEqual('@', $uri->getUser());
     $this->assertEqual('@', $uri->getPass());
     $this->assertEqual('http://%40:%40@domain.com/', (string) $uri);
 }
 private function getRemoteURIUser($raw_uri)
 {
     $uri = new PhutilURI($raw_uri);
     if ($uri->getUser()) {
         return $uri->getUser();
     }
     $git_uri = new PhutilGitURI($raw_uri);
     if (strlen($git_uri->getDomain()) && strlen($git_uri->getPath())) {
         return $git_uri->getUser();
     }
     return null;
 }
 if (!$raw_uri) {
     echo pht('...no remote URI.') . "\n";
     continue;
 }
 $uri = new PhutilURI($raw_uri);
 $proto = strtolower($uri->getProtocol());
 if ($proto == 'http' || $proto == 'https' || $proto == 'svn') {
     $username = $repository->getDetail('http-login');
     $secret = $repository->getDetail('http-pass');
     $type = PassphrasePasswordCredentialType::CREDENTIAL_TYPE;
 } else {
     $username = $repository->getDetail('ssh-login');
     if (!$username) {
         // If there's no explicit username, check for one in the URI. This is
         // possible with older repositories.
         $username = $uri->getUser();
         if (!$username) {
             // Also check for a Git/SCP-style URI.
             $git_uri = new PhutilGitURI($raw_uri);
             $username = $git_uri->getUser();
         }
     }
     $file = $repository->getDetail('ssh-keyfile');
     if ($file) {
         $secret = $file;
         $type = PassphraseSSHPrivateKeyFileCredentialType::CREDENTIAL_TYPE;
     } else {
         $secret = $repository->getDetail('ssh-key');
         $type = PassphraseSSHPrivateKeyTextCredentialType::CREDENTIAL_TYPE;
     }
 }
Exemplo n.º 5
0
 public function testGitURIParsing()
 {
     $uri = new PhutilURI('git@host.com:path/to/something');
     $this->assertEqual('ssh', $uri->getProtocol());
     $this->assertEqual('git', $uri->getUser());
     $this->assertEqual('host.com', $uri->getDomain());
     $this->assertEqual('path/to/something', $uri->getPath());
     $this->assertEqual('git@host.com:path/to/something', (string) $uri);
     $uri = new PhutilURI('host.com:path/to/something');
     $this->assertEqual('ssh', $uri->getProtocol());
     $this->assertEqual('', $uri->getUser());
     $this->assertEqual('host.com', $uri->getDomain());
     $this->assertEqual('path/to/something', $uri->getPath());
     $this->assertEqual('host.com:path/to/something', (string) $uri);
     $uri_1 = new PhutilURI('host.com:path/to/something');
     $uri_2 = new PhutilURI($uri_1);
     $this->assertEqual((string) $uri_1, (string) $uri_2);
 }