Skip to content

Commit

Permalink
removed promptAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
hirak committed Apr 25, 2016
1 parent 5805497 commit e270932
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 192 deletions.
6 changes: 0 additions & 6 deletions src/GitHubRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ public function getURL()
parent::getURL()
);
}

public function promptAuth(HttpGetResponse $res, IO\IOInterface $io)
{
$util = new \Composer\Util\GitHub($io, $this->config, null);
$this->promptAuthWithUtil(404, $util, $res, $io);
}
}
9 changes: 0 additions & 9 deletions src/GitLabRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,4 @@ public function __construct($origin, $url, IO\IOInterface $io)
$this->username = $this->password = null;
}
}

/**
* @codeCoverageIgnore
*/
public function promptAuth(HttpGetResponse $res, IO\IOInterface $io)
{
$util = new \Composer\Util\GitLab($io, $this->config, null);
$this->promptAuthWithUtil(401, $util, $res, $io);
}
}
55 changes: 0 additions & 55 deletions src/HttpGetRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,61 +234,6 @@ public function setConfig(CConfig $config)
$this->config = $config;
}

public function promptAuth(HttpGetResponse $res, IO\IOInterface $io)
{
$httpCode = $res->info['http_code'];
// 404s are only handled for github
if (404 === $httpCode) {
return false;
}

// fail if the console is not interactive
if (!$io->isInteractive() && ($httpCode === 401 || $httpCode === 403)) {
$message = "The '{$this->getURL()}' URL required authentication.\nYou must be using the interactive console to authenticate";
throw new Downloader\TransportException($message, $httpCode);
}

// fail if we already have auth
if ($io->hasAuthentication($this->origin)) {
throw new Downloader\TransportException("Invalid credentials for '{$this->getURL()}', aborting.", $httpCode);
}

$io->overwrite(" Authentication required (<info>$this->host</info>):");
$username = $io->ask(' Username: ');
$password = $io->askAndHideAnswer(' Password: ');
$io->setAuthentication($this->origin, $username, $password);
return true;
}

/**
* @internal
* @param int $privateCode 404|403
* @param Composer\Util\GitHub|Composer\Util\GitLab $util
* @param HttpGetResponse $res
* @param IO\IOInterface $io
* @throws Composer\Downloader\TransportException
* @return bool
*/
public function promptAuthWithUtil($privateCode, $util, HttpGetResponse $res, IO\IOInterface $io)
{
$httpCode = $res->info['http_code'];
$message = "\nCould not fetch {$this->getURL()}, enter your $this->origin credentials ";
if ($privateCode === $httpCode) {
$message .= 'to access private repos';
} else {
$message .= 'to go over the API rate limit';
}
if ($util->authorizeOAuth($this->origin)) {
return true;
}
if ($io->isInteractive() &&
$util->authorizeOAuthInteractively($this->origin, $message)) {
return true;
}

throw new Downloader\TransportException("Could not authenticate against $this->origin", $httpCode);
}

/**
* @return string
*/
Expand Down
52 changes: 0 additions & 52 deletions tests/unit/GitHubRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,56 +40,4 @@ public function testProcessRFSOption()
));
self::assertEquals('abcdef', $req->query['access_token']);
}

/**
* @expectedException Composer\Downloader\TransportException
*/
public function testPromptAuth()
{
$io = $this->prophesize('Composer\IO\NullIO');
$req = new GitHubRequest(
'github.com',
'https://github.com/',
$io->reveal()
);
$req->setConfig(new CConfig);

$res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 400));
$req->promptAuth($res, $io->reveal());
}

public function testPromptAuthWith404()
{
$io = $this->prophesize('Composer\IO\NullIO')
->hasAuthentication(Argument::any())
->willReturn(false)
->getObjectProphecy()
->isInteractive()
->willReturn(true)
->getObjectProphecy()
->reveal();
$req = new GitHubRequest(
'github.com',
'https://github.com/',
$io
);
$util = $this->prophesize('Composer\Util\GitHub')
->authorizeOAuth('github.com')
->willReturn(true)
->getObjectProphecy()
->reveal();

$res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 404));
self::assertTrue($req->promptAuthWithUtil(404, $util, $res, $io));

$util = $this->prophesize('Composer\Util\GitHub')
->authorizeOAuth('github.com')
->willReturn(false)
->getObjectProphecy()
->authorizeOAuthInteractively('github.com', Argument::any())
->willReturn(true)
->getObjectProphecy()
->reveal();
self::assertTrue($req->promptAuthWithUtil(404, $util, $res, $io));
}
}
70 changes: 0 additions & 70 deletions tests/unit/HttpGetRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,74 +165,4 @@ public function testSetConfig()
);
self::assertNull($req->setConfig(new CConfig));
}

public function testPromptAuth()
{
$res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 400));
$io = $this->prophesize('Composer\IO\NullIO')
->isInteractive()
->willReturn(true)
->getObjectProphecy()
->hasAuthentication('packagist.org')
->willReturn(false)
->getObjectProphecy()
->overwrite(Argument::any())
->willReturn(false)
->getObjectProphecy()
->ask(Argument::any())
->willReturn('user')
->getObjectProphecy()
->askAndHideAnswer(Argument::any())
->willReturn('pass')
->getObjectProphecy()
->setAuthentication('packagist.org', 'user', 'pass')
->willReturn(null)
->getObjectProphecy()
->reveal();

$req = new HttpGetRequest(
'packagist.org',
'https://packagist.org/packages.json',
$io
);
$req->promptAuth($res, $io);
}

/**
* @expectedException Composer\Downloader\TransportException
*/
public function testPromptAuth403()
{
$res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 403));
$io = $this->prophesize('Composer\IO\NullIO')->reveal();

$req = new HttpGetRequest('packagist.org', 'https://packagist.org/packages.json', $io);
$req->promptAuth($res, $io);
}

/**
* @expectedException Composer\Downloader\TransportException
*/
public function testPromptAuthInvalidCred()
{
$res = new HttpGetResponse(CURLE_OK, '', array('http_code' => 400));
$io = $this->prophesize('Composer\IO\NullIO')
->isInteractive()
->willReturn(true)
->getObjectProphecy()
->hasAuthentication('packagist.org')
->willReturn(true)
->getObjectProphecy()
->getAuthentication('packagist.org')
->willReturn(array('username' => 'user', 'password' => 'pass'))
->getObjectProphecy()
->reveal();

$req = new HttpGetRequest(
'packagist.org',
'https://packagist.org/packages.json',
$io
);
$req->promptAuth($res, $io);
}
}

0 comments on commit e270932

Please sign in to comment.