Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Composer\Test\Util; use Composer\IO\IOInterface; use Composer\Test\TestC..
Decoded Output download
<?php
namespace Composer\Test\Util; use Composer\IO\IOInterface; use Composer\Test\TestCase; use Composer\Util\AuthHelper; use Composer\Util\Bitbucket; class AuthHelperTest extends TestCase { private $io; private $config; private $authHelper; protected function setUp() : void { $this->io = $this->getMockBuilder("Composer\IO\IOInterface")->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder("Composer\Config")->getMock(); $this->authHelper = new AuthHelper($this->io, $this->config); } public function testAddAuthenticationHeaderWithoutAuthCredentials() : void { $headers = array("Accept-Encoding: gzip", "Connection: close"); $origin = "http://example.org"; $url = "file://" . __FILE__; $this->io->expects($this->once())->method("hasAuthentication")->with($origin)->willReturn(false); $this->assertSame($headers, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testAddAuthenticationHeaderWithBearerPassword() : void { $headers = array("Accept-Encoding: gzip", "Connection: close"); $origin = "http://example.org"; $url = "file://" . __FILE__; $auth = array("username" => "my_username", "password" => "bearer"); $this->expectsAuthentication($origin, $auth); $expectedHeaders = array_merge($headers, array("Authorization: Bearer " . $auth["username"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testAddAuthenticationHeaderWithGithubToken() : void { $headers = array("Accept-Encoding: gzip", "Connection: close"); $origin = "github.com"; $url = "https://api.github.com/"; $auth = array("username" => "my_username", "password" => "x-oauth-basic"); $this->expectsAuthentication($origin, $auth); $this->io->expects($this->once())->method("writeError")->with("Using GitHub token authentication", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("Authorization: token " . $auth["username"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testAddAuthenticationHeaderWithGitlabOathToken() : void { $headers = array("Accept-Encoding: gzip", "Connection: close"); $origin = "gitlab.com"; $url = "https://api.gitlab.com/"; $auth = array("username" => "my_username", "password" => "oauth2"); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("get")->with("gitlab-domains")->willReturn(array($origin)); $this->io->expects($this->once())->method("writeError")->with("Using GitLab OAuth token authentication", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("Authorization: Bearer " . $auth["username"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public static function gitlabPrivateTokenProvider() : array { return array(array("private-token"), array("gitlab-ci-token")); } public function testAddAuthenticationHeaderWithGitlabPrivateToken(string $password) : void { $headers = array("Accept-Encoding: gzip", "Connection: close"); $origin = "gitlab.com"; $url = "https://api.gitlab.com/"; $auth = array("username" => "my_username", "password" => $password); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("get")->with("gitlab-domains")->willReturn(array($origin)); $this->io->expects($this->once())->method("writeError")->with("Using GitLab private token authentication", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("PRIVATE-TOKEN: " . $auth["username"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testAddAuthenticationHeaderWithBitbucketOathToken() : void { $headers = array("Accept-Encoding: gzip", "Connection: close"); $origin = "bitbucket.org"; $url = "https://bitbucket.org/site/oauth2/authorize"; $auth = array("username" => "x-token-auth", "password" => "my_password"); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("get")->with("gitlab-domains")->willReturn(array()); $this->io->expects($this->once())->method("writeError")->with("Using Bitbucket OAuth token authentication", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("Authorization: Bearer " . $auth["password"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public static function bitbucketPublicUrlProvider() : array { return array(array("https://bitbucket.org/user/repo/downloads/whatever"), array("https://bbuseruploads.s3.amazonaws.com/9421ee72-638e-43a9-82ea-39cfaae2bfaa/downloads/b87c59d9-54f3-4922-b711-d89059ec3bcf")); } public function testAddAuthenticationHeaderWithBitbucketPublicUrl(string $url) : void { $headers = array("Accept-Encoding: gzip", "Connection: close"); $origin = "bitbucket.org"; $auth = array("username" => "x-token-auth", "password" => "my_password"); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("get")->with("gitlab-domains")->willReturn(array()); $this->assertSame($headers, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public static function basicHttpAuthenticationProvider() : array { return array(array(Bitbucket::OAUTH2_ACCESS_TOKEN_URL, "bitbucket.org", array("username" => "x-token-auth", "password" => "my_password")), array("https://some-api.url.com", "some-api.url.com", array("username" => "my_username", "password" => "my_password")), array("https://gitlab.com", "gitlab.com", array("username" => "my_username", "password" => "my_password"))); } public function testAddAuthenticationHeaderWithBasicHttpAuthentication(string $url, string $origin, array $auth) : void { $headers = array("Accept-Encoding: gzip", "Connection: close"); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("get")->with("gitlab-domains")->willReturn(array($origin)); $this->io->expects($this->once())->method("writeError")->with("Using HTTP basic authentication with username "" . $auth["username"] . """, true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("Authorization: Basic " . base64_encode($auth["username"] . ":" . $auth["password"]))); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testIsPublicBitBucketDownloadWithBitbucketPublicUrl(string $url) : void { $this->assertTrue($this->authHelper->isPublicBitBucketDownload($url)); } public function testIsPublicBitBucketDownloadWithNonBitbucketPublicUrl() : void { $this->assertFalse($this->authHelper->isPublicBitBucketDownload("https://bitbucket.org/site/oauth2/authorize")); } public function testStoreAuthAutomatically() : void { $origin = "github.com"; $storeAuth = true; $auth = array("username" => "my_username", "password" => "my_password"); $configSource = $this->getMockBuilder("Composer\Config\ConfigSourceInterface")->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method("getAuthConfigSource")->willReturn($configSource); $this->io->expects($this->once())->method("getAuthentication")->with($origin)->willReturn($auth); $configSource->expects($this->once())->method("addConfigSetting")->with("http-basic." . $origin, $auth); $this->authHelper->storeAuth($origin, $storeAuth); } public function testStoreAuthWithPromptYesAnswer() : void { $origin = "github.com"; $storeAuth = "prompt"; $auth = array("username" => "my_username", "password" => "my_password"); $answer = "y"; $configSourceName = "https://api.gitlab.com/source"; $configSource = $this->getMockBuilder("Composer\Config\ConfigSourceInterface")->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method("getAuthConfigSource")->willReturn($configSource); $configSource->expects($this->once())->method("getName")->willReturn($configSourceName); $this->io->expects($this->once())->method("askAndValidate")->with("Do you want to store credentials for " . $origin . " in " . $configSourceName . " ? [Yn] ", $this->anything(), null, "y")->willReturnCallback(static function ($question, $validator, $attempts, $default) use($answer) : string { $validator($answer); return $answer; }); $this->io->expects($this->once())->method("getAuthentication")->with($origin)->willReturn($auth); $configSource->expects($this->once())->method("addConfigSetting")->with("http-basic." . $origin, $auth); $this->authHelper->storeAuth($origin, $storeAuth); } public function testStoreAuthWithPromptNoAnswer() : void { $origin = "github.com"; $storeAuth = "prompt"; $answer = "n"; $configSourceName = "https://api.gitlab.com/source"; $configSource = $this->getMockBuilder("Composer\Config\ConfigSourceInterface")->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method("getAuthConfigSource")->willReturn($configSource); $configSource->expects($this->once())->method("getName")->willReturn($configSourceName); $this->io->expects($this->once())->method("askAndValidate")->with("Do you want to store credentials for " . $origin . " in " . $configSourceName . " ? [Yn] ", $this->anything(), null, "y")->willReturnCallback(static function ($question, $validator, $attempts, $default) use($answer) : string { $validator($answer); return $answer; }); $this->authHelper->storeAuth($origin, $storeAuth); } public function testStoreAuthWithPromptInvalidAnswer() : void { self::expectException("RuntimeException"); $origin = "github.com"; $storeAuth = "prompt"; $answer = "invalid"; $configSourceName = "https://api.gitlab.com/source"; $configSource = $this->getMockBuilder("Composer\Config\ConfigSourceInterface")->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method("getAuthConfigSource")->willReturn($configSource); $configSource->expects($this->once())->method("getName")->willReturn($configSourceName); $this->io->expects($this->once())->method("askAndValidate")->with("Do you want to store credentials for " . $origin . " in " . $configSourceName . " ? [Yn] ", $this->anything(), null, "y")->willReturnCallback(static function ($question, $validator, $attempts, $default) use($answer) : string { $validator($answer); return $answer; }); $this->authHelper->storeAuth($origin, $storeAuth); } public function testPromptAuthIfNeededGitLabNoAuthChange() : void { self::expectException("Composer\Downloader\TransportException"); $origin = "gitlab.com"; $this->io->method("hasAuthentication")->with($origin)->willReturn(true); $this->io->method("getAuthentication")->with($origin)->willReturn(array("username" => "gitlab-user", "password" => "gitlab-password")); $this->io->expects($this->once())->method("setAuthentication")->with("gitlab.com", "gitlab-user", "gitlab-password"); $this->config->method("get")->willReturnMap(array(array("github-domains", 0, array()), array("gitlab-domains", 0, array("gitlab.com")), array("gitlab-token", 0, array("gitlab.com" => array("username" => "gitlab-user", "token" => "gitlab-password"))))); $this->authHelper->promptAuthIfNeeded("https://gitlab.com/acme/archive.zip", $origin, 404, "GitLab requires authentication and it was not provided"); } public function testPromptAuthIfNeededMultipleBitbucketDownloads() : void { $origin = "bitbucket.org"; $expectedResult = array("retry" => true, "storeAuth" => false); $authConfig = array("bitbucket.org" => array("access-token" => "bitbucket_access_token", "access-token-expiration" => time() + 1800)); $this->config->method("get")->willReturnMap(array(array("github-domains", 0, array()), array("gitlab-domains", 0, array()), array("bitbucket-oauth", 0, $authConfig), array("github-domains", 0, array()), array("gitlab-domains", 0, array()))); $this->io->expects($this->exactly(2))->method("hasAuthentication")->with($origin)->willReturn(true); $getAuthenticationReturnValues = array(array("username" => "bitbucket_client_id", "password" => "bitbucket_client_secret"), array("username" => "x-token-auth", "password" => "bitbucket_access_token")); $this->io->expects($this->exactly(2))->method("getAuthentication")->willReturnCallback(function ($repositoryName) use(&$getAuthenticationReturnValues) { return array_shift($getAuthenticationReturnValues); }); $this->io->expects($this->once())->method("setAuthentication")->with($origin, "x-token-auth", "bitbucket_access_token"); $result1 = $this->authHelper->promptAuthIfNeeded("https://bitbucket.org/workspace/repo1/get/hash1.zip", $origin, 401, "HTTP/2 401 "); $result2 = $this->authHelper->promptAuthIfNeeded("https://bitbucket.org/workspace/repo2/get/hash2.zip", $origin, 401, "HTTP/2 401 "); $this->assertSame($expectedResult, $result1); $this->assertSame($expectedResult, $result2); } private function expectsAuthentication(string $origin, array $auth) : void { $this->io->expects($this->once())->method("hasAuthentication")->with($origin)->willReturn(true); $this->io->expects($this->once())->method("getAuthentication")->with($origin)->willReturn($auth); } } ?>
Did this file decode correctly?
Original Code
<?php
namespace Composer\Test\Util; use Composer\IO\IOInterface; use Composer\Test\TestCase; use Composer\Util\AuthHelper; use Composer\Util\Bitbucket; class AuthHelperTest extends TestCase { private $io; private $config; private $authHelper; protected function setUp() : void { $this->io = $this->getMockBuilder("\103\157\x6d\160\157\x73\145\x72\134\111\x4f\134\x49\x4f\111\x6e\x74\x65\162\x66\141\x63\145")->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder("\x43\157\155\x70\157\163\145\162\134\x43\157\x6e\x66\151\x67")->getMock(); $this->authHelper = new AuthHelper($this->io, $this->config); } public function testAddAuthenticationHeaderWithoutAuthCredentials() : void { $headers = array("\x41\x63\x63\x65\x70\164\55\105\156\x63\x6f\x64\x69\x6e\147\x3a\x20\x67\x7a\x69\160", "\x43\157\156\x6e\x65\143\x74\x69\x6f\156\x3a\x20\143\154\x6f\x73\x65"); $origin = "\150\164\x74\160\x3a\57\x2f\x65\170\x61\155\160\154\145\x2e\157\162\147"; $url = "\146\151\154\145\x3a\x2f\57" . __FILE__; $this->io->expects($this->once())->method("\x68\x61\x73\101\x75\x74\x68\145\x6e\x74\x69\x63\141\x74\x69\x6f\x6e")->with($origin)->willReturn(false); $this->assertSame($headers, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testAddAuthenticationHeaderWithBearerPassword() : void { $headers = array("\x41\x63\x63\145\160\x74\55\105\156\143\x6f\x64\151\156\147\72\40\147\172\x69\x70", "\x43\157\156\x6e\145\x63\x74\151\157\x6e\x3a\40\x63\154\157\163\x65"); $origin = "\150\164\164\160\x3a\57\x2f\x65\x78\x61\155\x70\x6c\x65\x2e\157\x72\x67"; $url = "\x66\x69\x6c\145\x3a\57\57" . __FILE__; $auth = array("\x75\163\145\162\x6e\141\x6d\145" => "\155\171\137\x75\x73\x65\x72\156\141\155\145", "\x70\x61\x73\163\x77\x6f\x72\144" => "\142\x65\141\162\145\162"); $this->expectsAuthentication($origin, $auth); $expectedHeaders = array_merge($headers, array("\101\165\x74\150\157\162\x69\x7a\141\164\x69\x6f\156\72\x20\102\145\x61\x72\x65\x72\x20" . $auth["\165\163\x65\162\156\141\155\x65"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testAddAuthenticationHeaderWithGithubToken() : void { $headers = array("\101\x63\x63\x65\160\x74\55\105\156\x63\157\x64\151\156\147\72\40\147\172\151\x70", "\x43\157\156\x6e\x65\x63\164\151\x6f\156\x3a\40\143\x6c\x6f\163\145"); $origin = "\x67\x69\x74\150\x75\142\x2e\x63\x6f\155"; $url = "\150\164\x74\x70\x73\x3a\57\x2f\141\x70\151\x2e\x67\x69\x74\x68\165\x62\x2e\143\157\155\57"; $auth = array("\165\x73\145\x72\x6e\141\155\145" => "\x6d\171\137\165\163\145\162\x6e\141\155\145", "\x70\x61\163\x73\x77\157\x72\x64" => "\170\x2d\157\141\x75\164\x68\55\x62\x61\x73\151\x63"); $this->expectsAuthentication($origin, $auth); $this->io->expects($this->once())->method("\x77\162\151\164\145\105\162\x72\157\x72")->with("\x55\163\151\x6e\x67\40\107\x69\164\x48\165\142\40\164\157\x6b\145\156\40\141\165\164\150\145\x6e\164\151\143\x61\x74\x69\x6f\156", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("\101\x75\x74\x68\x6f\x72\x69\x7a\x61\x74\x69\x6f\x6e\x3a\40\164\x6f\153\x65\x6e\40" . $auth["\x75\x73\x65\x72\156\x61\155\x65"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testAddAuthenticationHeaderWithGitlabOathToken() : void { $headers = array("\101\x63\x63\145\x70\x74\x2d\x45\156\x63\x6f\x64\x69\156\147\x3a\x20\x67\x7a\x69\160", "\103\x6f\x6e\x6e\145\143\x74\x69\157\156\x3a\40\143\x6c\157\x73\145"); $origin = "\x67\x69\x74\154\x61\x62\x2e\143\x6f\x6d"; $url = "\x68\x74\164\160\163\72\57\57\x61\x70\151\56\147\x69\164\154\141\142\x2e\x63\157\x6d\x2f"; $auth = array("\165\x73\x65\162\156\141\x6d\x65" => "\x6d\x79\137\165\x73\x65\162\156\x61\155\145", "\x70\141\x73\x73\x77\157\x72\144" => "\x6f\141\x75\x74\150\62"); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("\x67\x65\x74")->with("\147\151\x74\x6c\141\142\x2d\x64\x6f\x6d\x61\151\x6e\x73")->willReturn(array($origin)); $this->io->expects($this->once())->method("\x77\162\151\164\145\105\x72\162\x6f\162")->with("\125\x73\x69\x6e\147\x20\x47\x69\164\x4c\x61\142\x20\117\x41\x75\x74\150\40\x74\x6f\x6b\145\x6e\x20\x61\x75\x74\150\145\156\x74\x69\143\x61\164\151\x6f\156", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("\x41\165\164\150\157\x72\x69\x7a\x61\164\x69\157\156\72\x20\102\x65\141\x72\x65\162\40" . $auth["\165\x73\145\x72\156\x61\x6d\145"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public static function gitlabPrivateTokenProvider() : array { return array(array("\x70\162\151\x76\141\164\x65\x2d\164\x6f\x6b\x65\156"), array("\147\x69\164\154\141\142\x2d\143\151\55\164\x6f\153\145\x6e")); } public function testAddAuthenticationHeaderWithGitlabPrivateToken(string $password) : void { $headers = array("\x41\143\143\145\160\164\x2d\x45\x6e\143\157\144\151\x6e\x67\72\x20\x67\x7a\151\x70", "\103\x6f\156\x6e\145\x63\x74\x69\157\156\x3a\x20\x63\154\x6f\163\145"); $origin = "\147\151\164\154\x61\x62\56\x63\157\x6d"; $url = "\x68\164\x74\x70\163\72\57\57\x61\x70\x69\56\147\151\164\154\141\142\56\143\x6f\155\57"; $auth = array("\x75\x73\x65\x72\156\141\155\x65" => "\155\x79\x5f\165\163\145\x72\156\141\155\x65", "\x70\141\163\163\167\x6f\162\x64" => $password); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("\x67\x65\164")->with("\x67\x69\x74\x6c\141\142\55\144\x6f\155\141\x69\x6e\163")->willReturn(array($origin)); $this->io->expects($this->once())->method("\167\162\151\x74\145\105\x72\x72\157\x72")->with("\x55\x73\151\156\x67\40\107\151\x74\114\141\142\x20\x70\x72\151\x76\x61\164\x65\40\x74\157\153\145\x6e\x20\x61\x75\x74\150\x65\x6e\164\151\x63\141\x74\x69\157\156", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("\x50\x52\111\x56\101\x54\x45\x2d\x54\x4f\x4b\105\x4e\72\40" . $auth["\x75\163\x65\x72\156\141\155\x65"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testAddAuthenticationHeaderWithBitbucketOathToken() : void { $headers = array("\x41\x63\x63\145\x70\164\55\105\156\143\x6f\x64\x69\156\x67\x3a\40\x67\x7a\151\x70", "\103\157\156\x6e\x65\x63\x74\151\157\156\72\40\x63\x6c\x6f\163\145"); $origin = "\x62\151\164\x62\x75\x63\153\145\164\56\157\x72\x67"; $url = "\150\x74\164\160\x73\72\x2f\x2f\142\151\164\142\165\143\x6b\x65\164\x2e\157\162\x67\x2f\163\151\164\145\57\157\x61\165\164\x68\62\57\141\x75\x74\x68\157\x72\151\172\x65"; $auth = array("\x75\163\145\x72\156\141\155\x65" => "\170\55\164\157\x6b\145\156\x2d\x61\x75\x74\150", "\x70\141\163\x73\167\x6f\x72\x64" => "\x6d\171\x5f\x70\x61\163\x73\x77\157\162\x64"); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("\x67\145\x74")->with("\147\x69\x74\x6c\x61\142\55\x64\157\155\x61\x69\x6e\163")->willReturn(array()); $this->io->expects($this->once())->method("\167\x72\x69\x74\x65\105\x72\162\157\x72")->with("\125\163\x69\x6e\x67\40\102\151\x74\x62\165\143\153\x65\x74\x20\117\x41\165\164\x68\x20\164\x6f\153\145\156\40\x61\x75\x74\x68\x65\156\x74\151\x63\141\164\x69\x6f\x6e", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("\101\165\x74\150\157\x72\x69\x7a\141\x74\x69\157\x6e\72\x20\x42\x65\x61\162\x65\x72\x20" . $auth["\160\x61\x73\163\x77\157\x72\x64"])); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public static function bitbucketPublicUrlProvider() : array { return array(array("\150\164\164\160\163\72\57\x2f\x62\151\164\142\x75\143\x6b\x65\x74\56\x6f\162\x67\57\x75\163\145\162\x2f\162\x65\x70\157\57\144\x6f\167\156\154\157\141\144\163\x2f\x77\150\x61\164\x65\x76\145\162"), array("\150\x74\x74\160\163\x3a\57\x2f\x62\142\165\163\145\x72\165\160\x6c\x6f\x61\x64\163\x2e\x73\x33\x2e\141\155\x61\172\157\156\141\x77\x73\x2e\x63\157\155\x2f\71\64\x32\x31\145\x65\x37\62\55\66\x33\70\x65\55\x34\x33\x61\71\x2d\70\x32\145\141\x2d\63\x39\x63\146\141\141\145\62\x62\146\141\141\57\x64\157\167\x6e\x6c\157\x61\x64\163\57\142\70\x37\143\x35\71\144\71\55\65\x34\x66\63\55\64\71\62\x32\x2d\142\67\x31\x31\x2d\x64\70\x39\x30\x35\71\145\x63\x33\x62\143\146")); } public function testAddAuthenticationHeaderWithBitbucketPublicUrl(string $url) : void { $headers = array("\x41\143\143\145\x70\x74\x2d\105\x6e\143\157\144\x69\156\x67\72\x20\x67\x7a\151\x70", "\103\157\156\156\x65\x63\x74\151\157\x6e\72\x20\143\154\157\163\x65"); $origin = "\x62\x69\x74\142\165\x63\x6b\x65\164\56\157\162\147"; $auth = array("\165\x73\x65\162\156\x61\155\x65" => "\170\x2d\x74\x6f\x6b\x65\x6e\x2d\141\165\164\150", "\160\x61\x73\163\x77\x6f\x72\x64" => "\x6d\x79\x5f\160\x61\x73\x73\167\x6f\162\144"); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("\147\145\x74")->with("\x67\x69\x74\154\141\x62\55\x64\157\155\141\x69\156\163")->willReturn(array()); $this->assertSame($headers, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public static function basicHttpAuthenticationProvider() : array { return array(array(Bitbucket::OAUTH2_ACCESS_TOKEN_URL, "\x62\151\164\142\x75\143\153\x65\164\x2e\x6f\x72\x67", array("\x75\163\x65\162\156\x61\x6d\x65" => "\170\55\164\x6f\x6b\145\x6e\x2d\141\165\164\x68", "\160\141\x73\163\167\x6f\x72\144" => "\x6d\171\x5f\160\141\x73\x73\167\157\x72\144")), array("\x68\164\164\x70\163\x3a\57\57\x73\x6f\155\145\x2d\141\x70\x69\x2e\165\x72\x6c\56\x63\x6f\155", "\x73\x6f\155\x65\x2d\141\160\x69\56\165\162\154\56\x63\157\x6d", array("\165\163\145\162\x6e\141\155\x65" => "\x6d\x79\137\x75\x73\145\x72\156\141\x6d\145", "\160\141\x73\x73\167\x6f\x72\144" => "\x6d\171\x5f\160\x61\x73\163\x77\x6f\x72\144")), array("\150\x74\x74\160\163\x3a\57\57\147\151\x74\154\x61\142\x2e\143\157\x6d", "\147\x69\x74\154\141\142\56\x63\157\x6d", array("\x75\x73\x65\162\x6e\x61\155\145" => "\155\171\137\165\163\145\162\156\x61\155\x65", "\160\141\x73\163\x77\157\162\x64" => "\155\171\137\160\141\x73\x73\167\x6f\162\144"))); } public function testAddAuthenticationHeaderWithBasicHttpAuthentication(string $url, string $origin, array $auth) : void { $headers = array("\101\143\143\x65\160\164\55\x45\156\143\157\144\x69\x6e\x67\x3a\x20\147\172\151\x70", "\x43\x6f\x6e\156\145\x63\x74\151\157\156\x3a\x20\x63\154\157\163\x65"); $this->expectsAuthentication($origin, $auth); $this->config->expects($this->once())->method("\x67\145\x74")->with("\147\151\x74\x6c\141\x62\x2d\144\157\x6d\141\x69\156\163")->willReturn(array($origin)); $this->io->expects($this->once())->method("\167\162\x69\x74\x65\105\x72\x72\157\162")->with("\x55\163\x69\156\x67\40\110\124\124\120\40\142\141\x73\x69\x63\40\x61\165\x74\x68\145\156\x74\x69\143\x61\x74\x69\x6f\156\x20\167\151\x74\150\40\165\x73\145\x72\156\x61\155\145\x20\42" . $auth["\165\x73\145\x72\156\x61\155\x65"] . "\x22", true, IOInterface::DEBUG); $expectedHeaders = array_merge($headers, array("\101\165\x74\x68\157\162\151\172\x61\164\151\x6f\156\72\40\x42\141\x73\151\x63\x20" . base64_encode($auth["\165\x73\x65\x72\x6e\x61\x6d\145"] . "\72" . $auth["\x70\x61\x73\163\x77\157\162\144"]))); $this->assertSame($expectedHeaders, $this->authHelper->addAuthenticationHeader($headers, $origin, $url)); } public function testIsPublicBitBucketDownloadWithBitbucketPublicUrl(string $url) : void { $this->assertTrue($this->authHelper->isPublicBitBucketDownload($url)); } public function testIsPublicBitBucketDownloadWithNonBitbucketPublicUrl() : void { $this->assertFalse($this->authHelper->isPublicBitBucketDownload("\x68\164\x74\x70\x73\x3a\x2f\x2f\x62\151\164\142\x75\x63\x6b\145\x74\56\157\162\147\57\x73\151\164\145\57\x6f\x61\x75\x74\x68\62\x2f\141\x75\x74\x68\x6f\x72\151\x7a\145")); } public function testStoreAuthAutomatically() : void { $origin = "\x67\x69\x74\x68\x75\142\x2e\x63\157\x6d"; $storeAuth = true; $auth = array("\165\163\x65\x72\156\141\155\145" => "\x6d\171\137\x75\x73\x65\x72\x6e\x61\x6d\145", "\160\141\x73\163\x77\x6f\x72\x64" => "\155\171\137\x70\141\x73\163\x77\x6f\x72\144"); $configSource = $this->getMockBuilder("\103\157\x6d\160\x6f\163\x65\162\134\x43\x6f\156\x66\x69\147\x5c\103\x6f\156\x66\x69\x67\123\157\165\162\x63\x65\x49\x6e\x74\145\x72\146\141\x63\x65")->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method("\147\145\x74\101\165\164\150\x43\157\156\x66\151\x67\123\x6f\x75\x72\143\x65")->willReturn($configSource); $this->io->expects($this->once())->method("\147\145\x74\101\165\164\150\x65\x6e\164\x69\143\x61\x74\151\157\156")->with($origin)->willReturn($auth); $configSource->expects($this->once())->method("\x61\x64\x64\x43\x6f\x6e\x66\151\147\x53\x65\x74\164\151\156\x67")->with("\x68\x74\x74\160\55\142\x61\163\151\143\x2e" . $origin, $auth); $this->authHelper->storeAuth($origin, $storeAuth); } public function testStoreAuthWithPromptYesAnswer() : void { $origin = "\x67\151\x74\x68\165\142\56\143\x6f\x6d"; $storeAuth = "\160\162\x6f\x6d\160\x74"; $auth = array("\x75\x73\145\162\x6e\x61\155\145" => "\155\171\137\165\163\145\162\156\141\x6d\145", "\160\x61\163\x73\x77\x6f\162\144" => "\x6d\171\137\x70\141\163\163\x77\157\x72\144"); $answer = "\171"; $configSourceName = "\150\164\164\x70\163\72\x2f\x2f\x61\x70\151\56\147\151\x74\x6c\141\x62\x2e\x63\157\x6d\57\163\157\165\162\143\x65"; $configSource = $this->getMockBuilder("\103\157\x6d\x70\157\x73\x65\162\x5c\103\157\x6e\x66\151\x67\x5c\x43\157\156\146\151\x67\x53\157\x75\x72\x63\x65\x49\156\164\145\162\x66\141\143\145")->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method("\147\145\164\x41\x75\164\x68\x43\157\156\x66\x69\147\x53\157\x75\x72\143\145")->willReturn($configSource); $configSource->expects($this->once())->method("\x67\x65\164\116\x61\155\x65")->willReturn($configSourceName); $this->io->expects($this->once())->method("\141\163\x6b\101\x6e\x64\x56\141\154\151\x64\x61\x74\145")->with("\104\x6f\40\171\157\x75\40\x77\141\156\x74\40\164\x6f\40\x73\164\157\x72\145\x20\x63\x72\145\144\145\156\164\x69\141\154\163\x20\146\157\162\40" . $origin . "\40\151\156\x20" . $configSourceName . "\x20\x3f\x20\x5b\131\x6e\x5d\40", $this->anything(), null, "\x79")->willReturnCallback(static function ($question, $validator, $attempts, $default) use($answer) : string { $validator($answer); return $answer; }); $this->io->expects($this->once())->method("\147\145\x74\x41\165\x74\150\x65\x6e\x74\x69\143\141\x74\151\x6f\x6e")->with($origin)->willReturn($auth); $configSource->expects($this->once())->method("\x61\144\144\x43\x6f\x6e\146\x69\147\x53\x65\x74\164\151\156\147")->with("\x68\x74\164\160\55\x62\x61\163\151\x63\56" . $origin, $auth); $this->authHelper->storeAuth($origin, $storeAuth); } public function testStoreAuthWithPromptNoAnswer() : void { $origin = "\x67\151\x74\x68\165\142\56\x63\157\x6d"; $storeAuth = "\160\x72\x6f\155\160\164"; $answer = "\x6e"; $configSourceName = "\150\164\164\x70\x73\72\57\57\141\160\151\x2e\x67\151\x74\154\x61\142\x2e\143\x6f\x6d\57\x73\157\165\162\x63\x65"; $configSource = $this->getMockBuilder("\103\157\x6d\160\157\163\x65\x72\134\x43\157\x6e\146\x69\147\134\103\157\x6e\146\x69\147\x53\x6f\x75\x72\143\x65\111\x6e\164\x65\162\146\141\143\x65")->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method("\147\x65\x74\x41\165\164\150\x43\x6f\x6e\146\151\x67\123\157\x75\x72\x63\145")->willReturn($configSource); $configSource->expects($this->once())->method("\147\145\164\x4e\141\155\x65")->willReturn($configSourceName); $this->io->expects($this->once())->method("\x61\163\x6b\x41\156\x64\126\141\x6c\151\144\x61\164\145")->with("\104\x6f\x20\x79\x6f\165\x20\167\x61\156\164\40\164\157\40\x73\x74\x6f\x72\145\x20\x63\162\x65\x64\x65\156\164\x69\x61\x6c\x73\x20\x66\157\x72\x20" . $origin . "\40\151\x6e\x20" . $configSourceName . "\40\77\x20\133\x59\156\135\x20", $this->anything(), null, "\x79")->willReturnCallback(static function ($question, $validator, $attempts, $default) use($answer) : string { $validator($answer); return $answer; }); $this->authHelper->storeAuth($origin, $storeAuth); } public function testStoreAuthWithPromptInvalidAnswer() : void { self::expectException("\122\165\x6e\164\x69\155\x65\105\x78\143\145\x70\x74\151\157\x6e"); $origin = "\x67\x69\x74\150\x75\x62\56\143\x6f\x6d"; $storeAuth = "\x70\x72\x6f\155\x70\x74"; $answer = "\151\x6e\166\141\x6c\151\x64"; $configSourceName = "\x68\164\x74\160\x73\72\x2f\57\141\x70\x69\56\x67\x69\x74\x6c\x61\142\x2e\143\157\155\57\x73\157\165\x72\143\145"; $configSource = $this->getMockBuilder("\x43\157\x6d\160\x6f\163\x65\x72\x5c\103\157\x6e\146\x69\147\x5c\x43\157\x6e\x66\151\147\x53\157\x75\x72\x63\x65\x49\x6e\164\145\x72\x66\141\x63\145")->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method("\x67\x65\x74\x41\165\164\150\103\x6f\156\x66\151\147\x53\x6f\165\162\143\145")->willReturn($configSource); $configSource->expects($this->once())->method("\x67\145\x74\x4e\141\x6d\145")->willReturn($configSourceName); $this->io->expects($this->once())->method("\141\x73\153\x41\x6e\144\x56\x61\154\151\144\x61\x74\145")->with("\104\x6f\40\x79\157\x75\x20\167\141\156\164\40\164\157\40\x73\x74\x6f\162\x65\40\143\162\x65\x64\145\156\x74\151\141\154\163\40\146\x6f\x72\40" . $origin . "\x20\151\156\40" . $configSourceName . "\40\77\40\x5b\131\156\x5d\x20", $this->anything(), null, "\x79")->willReturnCallback(static function ($question, $validator, $attempts, $default) use($answer) : string { $validator($answer); return $answer; }); $this->authHelper->storeAuth($origin, $storeAuth); } public function testPromptAuthIfNeededGitLabNoAuthChange() : void { self::expectException("\x43\x6f\x6d\160\157\163\145\162\x5c\104\x6f\x77\156\x6c\x6f\141\144\x65\x72\x5c\124\x72\x61\156\x73\x70\157\162\x74\x45\x78\143\145\x70\164\x69\x6f\156"); $origin = "\x67\151\164\x6c\x61\142\56\x63\157\x6d"; $this->io->method("\150\141\163\x41\x75\x74\x68\x65\x6e\164\151\x63\141\x74\x69\157\156")->with($origin)->willReturn(true); $this->io->method("\147\x65\x74\x41\165\x74\150\x65\x6e\164\x69\x63\141\x74\x69\157\x6e")->with($origin)->willReturn(array("\165\x73\x65\x72\x6e\141\155\145" => "\x67\151\x74\154\x61\142\55\165\163\145\162", "\x70\x61\163\163\167\x6f\162\144" => "\x67\x69\x74\x6c\141\142\55\160\141\x73\163\x77\157\x72\144")); $this->io->expects($this->once())->method("\x73\x65\x74\101\x75\x74\150\x65\x6e\x74\x69\143\x61\x74\x69\x6f\x6e")->with("\x67\151\x74\154\x61\142\x2e\143\x6f\155", "\x67\151\x74\x6c\141\142\55\x75\x73\145\x72", "\147\x69\164\154\141\x62\55\x70\141\x73\163\167\x6f\162\x64"); $this->config->method("\147\145\164")->willReturnMap(array(array("\147\x69\x74\150\165\142\x2d\144\x6f\155\x61\151\156\163", 0, array()), array("\x67\x69\x74\154\x61\142\55\144\x6f\155\141\151\156\x73", 0, array("\147\151\164\x6c\141\x62\56\x63\157\155")), array("\147\151\x74\154\x61\x62\55\164\x6f\153\x65\156", 0, array("\147\x69\x74\154\x61\x62\x2e\x63\x6f\155" => array("\165\163\145\x72\x6e\141\x6d\x65" => "\x67\x69\164\154\x61\x62\x2d\x75\x73\x65\x72", "\x74\157\153\145\x6e" => "\x67\x69\164\x6c\141\x62\55\x70\141\x73\163\167\x6f\162\x64"))))); $this->authHelper->promptAuthIfNeeded("\150\x74\x74\160\x73\x3a\57\x2f\x67\x69\x74\154\x61\x62\x2e\143\157\x6d\x2f\x61\143\x6d\145\57\141\162\x63\150\151\166\x65\x2e\x7a\x69\160", $origin, 404, "\107\151\x74\114\x61\x62\40\162\145\x71\165\151\x72\x65\x73\40\141\x75\164\150\145\156\164\x69\x63\141\x74\x69\x6f\156\x20\141\x6e\144\40\151\164\40\167\x61\x73\40\156\x6f\164\x20\x70\x72\x6f\x76\x69\144\145\144"); } public function testPromptAuthIfNeededMultipleBitbucketDownloads() : void { $origin = "\142\x69\164\142\x75\x63\153\x65\x74\56\x6f\x72\147"; $expectedResult = array("\x72\x65\x74\x72\x79" => true, "\163\x74\157\162\145\x41\165\164\x68" => false); $authConfig = array("\142\x69\164\142\x75\x63\x6b\x65\x74\x2e\x6f\x72\x67" => array("\x61\x63\x63\x65\x73\x73\x2d\x74\157\153\145\x6e" => "\142\x69\164\x62\165\x63\153\x65\164\x5f\141\x63\x63\145\x73\x73\x5f\x74\157\153\145\x6e", "\141\143\x63\145\163\163\55\164\157\x6b\x65\x6e\55\145\x78\x70\x69\x72\141\x74\x69\x6f\156" => time() + 1800)); $this->config->method("\147\x65\164")->willReturnMap(array(array("\147\151\x74\x68\165\x62\x2d\x64\x6f\x6d\141\x69\x6e\163", 0, array()), array("\147\x69\164\154\x61\142\55\144\157\155\141\151\x6e\x73", 0, array()), array("\x62\151\x74\x62\165\143\153\x65\x74\55\157\141\165\x74\150", 0, $authConfig), array("\x67\x69\164\x68\165\x62\x2d\x64\x6f\155\141\151\156\163", 0, array()), array("\x67\151\x74\x6c\x61\x62\55\144\157\155\x61\151\x6e\163", 0, array()))); $this->io->expects($this->exactly(2))->method("\x68\141\x73\101\165\164\x68\x65\156\x74\151\143\141\x74\151\157\156")->with($origin)->willReturn(true); $getAuthenticationReturnValues = array(array("\165\x73\x65\162\156\141\155\x65" => "\142\x69\x74\x62\165\143\x6b\145\164\137\143\x6c\x69\x65\x6e\164\x5f\x69\x64", "\x70\141\x73\x73\x77\157\x72\x64" => "\142\151\x74\142\165\143\x6b\145\x74\x5f\143\154\151\x65\156\x74\x5f\163\x65\x63\162\x65\x74"), array("\165\x73\145\x72\x6e\x61\155\145" => "\170\x2d\164\x6f\153\145\156\x2d\x61\x75\164\150", "\160\x61\163\x73\x77\x6f\162\144" => "\142\151\164\x62\x75\x63\153\x65\164\137\x61\x63\x63\145\x73\x73\137\x74\157\x6b\x65\156")); $this->io->expects($this->exactly(2))->method("\147\x65\164\x41\165\164\150\x65\x6e\164\151\x63\141\164\151\157\x6e")->willReturnCallback(function ($repositoryName) use(&$getAuthenticationReturnValues) { return array_shift($getAuthenticationReturnValues); }); $this->io->expects($this->once())->method("\x73\x65\x74\101\165\164\150\x65\156\164\151\x63\141\164\151\157\156")->with($origin, "\x78\x2d\x74\157\153\145\156\55\141\165\x74\x68", "\142\151\x74\x62\x75\x63\153\x65\164\x5f\x61\x63\143\145\x73\x73\137\164\x6f\x6b\x65\x6e"); $result1 = $this->authHelper->promptAuthIfNeeded("\150\x74\164\160\x73\x3a\x2f\57\142\151\164\x62\165\143\153\145\164\56\157\162\x67\x2f\x77\x6f\x72\x6b\163\160\x61\143\x65\57\162\145\160\157\61\57\x67\145\164\57\150\141\x73\x68\x31\56\x7a\151\x70", $origin, 401, "\x48\x54\124\x50\x2f\62\x20\64\x30\x31\x20"); $result2 = $this->authHelper->promptAuthIfNeeded("\x68\x74\164\160\163\72\x2f\x2f\142\151\x74\x62\x75\143\153\x65\x74\56\x6f\162\147\x2f\x77\157\162\153\x73\160\141\x63\x65\x2f\162\x65\x70\157\x32\x2f\x67\x65\x74\57\x68\x61\x73\150\x32\56\x7a\151\x70", $origin, 401, "\110\124\124\120\x2f\62\40\x34\60\x31\40"); $this->assertSame($expectedResult, $result1); $this->assertSame($expectedResult, $result2); } private function expectsAuthentication(string $origin, array $auth) : void { $this->io->expects($this->once())->method("\150\141\x73\x41\x75\164\x68\x65\156\164\x69\x63\x61\x74\151\157\156")->with($origin)->willReturn(true); $this->io->expects($this->once())->method("\147\x65\x74\x41\165\x74\x68\145\156\164\151\x63\x61\x74\x69\157\x6e")->with($origin)->willReturn($auth); } }
Function Calls
None |
Stats
MD5 | 091177e4ec5a8c266fdc969a9b840a59 |
Eval Count | 0 |
Decode Time | 104 ms |