1
0
Fork 0
composer/tests/Composer/Test/Util/AuthHelperTest.php

535 lines
16 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Util;
use Composer\IO\IOInterface;
use Composer\Test\TestCase;
use Composer\Util\AuthHelper;
use Composer\Util\Bitbucket;
/**
* @author Michael Chekin <mchekin@gmail.com>
*/
class AuthHelperTest extends TestCase
{
2021-10-27 14:18:46 +00:00
/** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
private $io;
2021-10-27 14:18:46 +00:00
/** @var \Composer\Config&\PHPUnit\Framework\MockObject\MockObject */
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
private $config;
2021-10-27 14:18:46 +00:00
/** @var AuthHelper */
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
private $authHelper;
2021-12-08 16:03:05 +00:00
protected function setUp(): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$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
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$headers = array(
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$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
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$headers = array(
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$origin = 'http://example.org';
$url = 'file://' . __FILE__;
$auth = array(
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'bearer',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$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
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$headers = array(
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$origin = 'github.com';
$url = 'https://api.github.com/';
$auth = array(
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'x-oauth-basic',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$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
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$headers = array(
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$origin = 'gitlab.com';
$url = 'https://api.gitlab.com/';
$auth = array(
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'oauth2',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$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)
);
}
2022-02-21 12:42:28 +00:00
public function gitlabPrivateTokenProvider(): array
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
return array(
array('private-token'),
array('gitlab-ci-token'),
);
}
/**
* @dataProvider gitlabPrivateTokenProvider
*
* @param string $password
*/
2022-02-22 15:47:09 +00:00
public function testAddAuthenticationHeaderWithGitlabPrivateToken(string $password): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$headers = array(
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$origin = 'gitlab.com';
$url = 'https://api.gitlab.com/';
$auth = array(
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => $password,
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$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
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$headers = array(
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$origin = 'bitbucket.org';
$url = 'https://bitbucket.org/site/oauth2/authorize';
$auth = array(
'username' => 'x-token-auth',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$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)
);
}
2022-02-21 12:42:28 +00:00
public function bitbucketPublicUrlProvider(): array
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
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'),
);
}
/**
* @dataProvider bitbucketPublicUrlProvider
*
* @param string $url
*/
2022-02-22 15:47:09 +00:00
public function testAddAuthenticationHeaderWithBitbucketPublicUrl(string $url): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$headers = array(
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$origin = 'bitbucket.org';
$auth = array(
'username' => 'x-token-auth',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$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)
);
}
2022-02-21 12:42:28 +00:00
public function basicHttpAuthenticationProvider(): array
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
return array(
array(
Bitbucket::OAUTH2_ACCESS_TOKEN_URL,
'bitbucket.org',
array(
'username' => 'x-token-auth',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
),
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
),
array(
'https://some-api.url.com',
'some-api.url.com',
array(
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
),
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
),
array(
'https://gitlab.com',
'gitlab.com',
array(
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
),
),
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
}
/**
* @dataProvider basicHttpAuthenticationProvider
*
2021-10-27 14:18:46 +00:00
* @param string $url
* @param string $origin
* @param array<string, string|null> $auth
*
* @phpstan-param array{username: string|null, password: string|null} $auth
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
*/
2022-02-22 15:47:09 +00:00
public function testAddAuthenticationHeaderWithBasicHttpAuthentication(string $url, string $origin, array $auth): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$headers = array(
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$this->expectsAuthentication($origin, $auth);
$this->config->expects($this->once())
->method('get')
->with('gitlab-domains')
->willReturn(array($origin));
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$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)
);
}
/**
* @dataProvider bitbucketPublicUrlProvider
*
* @param string $url
*/
2022-02-22 15:47:09 +00:00
public function testIsPublicBitBucketDownloadWithBitbucketPublicUrl(string $url): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$this->assertTrue($this->authHelper->isPublicBitBucketDownload($url));
}
public function testIsPublicBitBucketDownloadWithNonBitbucketPublicUrl(): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
2020-11-22 13:48:56 +00:00
$this->assertFalse(
$this->authHelper->isPublicBitBucketDownload(
'https://bitbucket.org/site/oauth2/authorize'
)
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
}
public function testStoreAuthAutomatically(): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$origin = 'github.com';
$storeAuth = true;
$auth = array(
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
2021-10-27 14:18:46 +00:00
/** @var \Composer\Config\ConfigSourceInterface&\PHPUnit\Framework\MockObject\MockObject $configSource */
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$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')
2022-02-22 21:10:52 +00:00
->with('http-basic.'.$origin, $auth);
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$this->authHelper->storeAuth($origin, $storeAuth);
}
public function testStoreAuthWithPromptYesAnswer(): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$origin = 'github.com';
$storeAuth = 'prompt';
$auth = array(
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
);
$answer = 'y';
$configSourceName = 'https://api.gitlab.com/source';
2021-10-27 14:18:46 +00:00
/** @var \Composer\Config\ConfigSourceInterface&\PHPUnit\Framework\MockObject\MockObject $configSource */
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$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'
)
2022-02-21 12:42:28 +00:00
->willReturnCallback(function ($question, $validator, $attempts, $default) use ($answer): string {
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$validator($answer);
return $answer;
});
$this->io->expects($this->once())
->method('getAuthentication')
->with($origin)
->willReturn($auth);
$configSource->expects($this->once())
->method('addConfigSetting')
2022-02-22 21:10:52 +00:00
->with('http-basic.'.$origin, $auth);
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$this->authHelper->storeAuth($origin, $storeAuth);
}
public function testStoreAuthWithPromptNoAnswer(): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$origin = 'github.com';
$storeAuth = 'prompt';
$answer = 'n';
$configSourceName = 'https://api.gitlab.com/source';
2021-10-27 14:18:46 +00:00
/** @var \Composer\Config\ConfigSourceInterface&\PHPUnit\Framework\MockObject\MockObject $configSource */
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$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'
)
2022-02-21 12:42:28 +00:00
->willReturnCallback(function ($question, $validator, $attempts, $default) use ($answer): string {
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$validator($answer);
return $answer;
});
$this->authHelper->storeAuth($origin, $storeAuth);
}
public function testStoreAuthWithPromptInvalidAnswer(): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
2021-12-09 19:55:26 +00:00
self::expectException('RuntimeException');
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$origin = 'github.com';
$storeAuth = 'prompt';
$answer = 'invalid';
$configSourceName = 'https://api.gitlab.com/source';
2021-10-27 14:18:46 +00:00
/** @var \Composer\Config\ConfigSourceInterface&\PHPUnit\Framework\MockObject\MockObject $configSource */
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$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'
)
2022-02-21 12:42:28 +00:00
->willReturnCallback(function ($question, $validator, $attempts, $default) use ($answer): string {
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
$validator($answer);
return $answer;
});
$this->authHelper->storeAuth($origin, $storeAuth);
}
/**
2021-10-27 14:18:46 +00:00
* @param string $origin
* @param array<string, string|null> $auth
*
* @return void
*
* @phpstan-param array{username: string|null, password: string|null} $auth
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
*/
2022-02-22 15:47:09 +00:00
private function expectsAuthentication(string $origin, array $auth): void
Add Util\AuthHelper unit test coverage (#8863) * Add AuthHelper::addAuthenticationHeader() test on missing authentication credentials. * Add AuthHelper::addAuthenticationHeader() test on bearer password. * Add AuthHelper::addAuthenticationHeader() test on Github token. * Add AuthHelper::addAuthenticationHeader() test on Gitlab Oauth token. * Add $authenticationDisplayMessage write expectation to AuthHelper::addAuthenticationHeader() tests. * Add AuthHelper::addAuthenticationHeader() test on Gitlab private token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket Oauth token. * Add AuthHelper::addAuthenticationHeader() test on Bitbucket public urls. * Add AuthHelper::addAuthenticationHeader() test on Basic Http Authentication. * Add AuthHelper::isPublicBitBucketDownload() tests. * Rename AuthHelperTest $credentials variable to $auth. * Add AuthHelper::storeAuth() test for auto-store option. * Add AuthHelper::storeAuth() test for user prompt and y(es) answer. * Add AuthHelper::storeAuth() test for user prompt and n(o) answer. * Add AuthHelper::storeAuth() test for user prompt with invalid answer. * Add AuthHelper::promptAuthIfNeeded() test for Github authentication failure. - add GitHub hard dependency mock (new GitHub(...) mock) * Run AuthHelper::promptAuthIfNeeded() tests only with PHP > 5.3 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP >= 5.4 * Run AuthHelper::promptAuthIfNeeded() tests only with PHP 5.4 * Exclude PHPStan analyses of '../tests/Composer/Test/Util/Mocks/*' * Exclude AuthHelper::promptAuthIfNeeded() tests from current pull request. * Extract repetitive AuthHelperTest authentication expectation into a method.
2020-05-04 07:48:23 +00:00
{
$this->io->expects($this->once())
->method('hasAuthentication')
->with($origin)
->willReturn(true);
$this->io->expects($this->once())
->method('getAuthentication')
->with($origin)
->willReturn($auth);
}
}