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

624 lines
19 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
{
2022-08-17 12:20:07 +00:00
$headers = [
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
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
2022-08-17 12:20:07 +00:00
];
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
{
2022-08-17 12:20:07 +00:00
$headers = [
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
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
2022-08-17 12:20:07 +00:00
];
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__;
2022-08-17 12:20:07 +00:00
$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
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'bearer',
2022-08-17 12:20:07 +00:00
];
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);
2022-08-17 12:20:07 +00:00
$expectedHeaders = array_merge($headers, ['Authorization: Bearer ' . $auth['username']]);
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->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
{
2022-08-17 12:20:07 +00:00
$headers = [
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
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
2022-08-17 12:20:07 +00:00
];
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/';
2022-08-17 12:20:07 +00:00
$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
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'x-oauth-basic',
2022-08-17 12:20:07 +00:00
];
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);
2022-08-17 12:20:07 +00:00
$expectedHeaders = array_merge($headers, ['Authorization: token ' . $auth['username']]);
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->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
{
2022-08-17 12:20:07 +00:00
$headers = [
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
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
2022-08-17 12:20:07 +00:00
];
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/';
2022-08-17 12:20:07 +00:00
$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
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'oauth2',
2022-08-17 12:20:07 +00:00
];
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')
2022-08-17 12:20:07 +00:00
->willReturn([$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 GitLab OAuth token authentication', true, IOInterface::DEBUG);
2022-08-17 12:20:07 +00:00
$expectedHeaders = array_merge($headers, ['Authorization: Bearer ' . $auth['username']]);
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->assertSame(
$expectedHeaders,
$this->authHelper->addAuthenticationHeader($headers, $origin, $url)
);
}
public static 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
{
2022-08-17 12:20:07 +00:00
return [
['private-token'],
['gitlab-ci-token'],
];
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 gitlabPrivateTokenProvider
*/
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
{
2022-08-17 12:20:07 +00:00
$headers = [
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
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
2022-08-17 12:20:07 +00:00
];
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/';
2022-08-17 12:20:07 +00:00
$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
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => $password,
2022-08-17 12:20:07 +00:00
];
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')
2022-08-17 12:20:07 +00:00
->willReturn([$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 GitLab private token authentication', true, IOInterface::DEBUG);
2022-08-17 12:20:07 +00:00
$expectedHeaders = array_merge($headers, ['PRIVATE-TOKEN: ' . $auth['username']]);
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->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
{
2022-08-17 12:20:07 +00:00
$headers = [
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
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
2022-08-17 12:20:07 +00:00
];
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';
2022-08-17 12:20:07 +00:00
$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
'username' => 'x-token-auth',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
2022-08-17 12:20:07 +00:00
];
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')
2022-08-17 12:20:07 +00:00
->willReturn([]);
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 Bitbucket OAuth token authentication', true, IOInterface::DEBUG);
2022-08-17 12:20:07 +00:00
$expectedHeaders = array_merge($headers, ['Authorization: Bearer ' . $auth['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->assertSame(
$expectedHeaders,
$this->authHelper->addAuthenticationHeader($headers, $origin, $url)
);
}
public static 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
{
2022-08-17 12:20:07 +00:00
return [
['https://bitbucket.org/user/repo/downloads/whatever'],
['https://bbuseruploads.s3.amazonaws.com/9421ee72-638e-43a9-82ea-39cfaae2bfaa/downloads/b87c59d9-54f3-4922-b711-d89059ec3bcf'],
];
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 bitbucketPublicUrlProvider
*/
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
{
2022-08-17 12:20:07 +00:00
$headers = [
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
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
2022-08-17 12:20:07 +00:00
];
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';
2022-08-17 12:20:07 +00:00
$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
'username' => 'x-token-auth',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
2022-08-17 12:20:07 +00:00
];
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')
2022-08-17 12:20:07 +00:00
->willReturn([]);
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->assertSame(
$headers,
$this->authHelper->addAuthenticationHeader($headers, $origin, $url)
);
}
public static 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
{
2022-08-17 12:20:07 +00:00
return [
[
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
Bitbucket::OAUTH2_ACCESS_TOKEN_URL,
'bitbucket.org',
2022-08-17 12:20:07 +00:00
[
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
'username' => 'x-token-auth',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
2022-08-17 12:20:07 +00:00
],
],
[
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
'https://some-api.url.com',
'some-api.url.com',
2022-08-17 12:20:07 +00:00
[
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
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
2022-08-17 12:20:07 +00:00
],
],
[
'https://gitlab.com',
'gitlab.com',
2022-08-17 12:20:07 +00:00
[
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
2022-08-17 12:20:07 +00:00
],
],
];
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 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
{
2022-08-17 12:20:07 +00:00
$headers = [
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
'Accept-Encoding: gzip',
2020-11-22 13:48:56 +00:00
'Connection: close',
2022-08-17 12:20:07 +00:00
];
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')
2022-08-17 12:20:07 +00:00
->willReturn([$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,
2022-08-17 12:20:07 +00:00
['Authorization: Basic ' . base64_encode($auth['username'] . ':' . $auth['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->assertSame(
$expectedHeaders,
$this->authHelper->addAuthenticationHeader($headers, $origin, $url)
);
}
/**
* @dataProvider bitbucketPublicUrlProvider
*/
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;
2022-08-17 12:20:07 +00:00
$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
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
2022-08-17 12:20:07 +00:00
];
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';
2022-08-17 12:20:07 +00:00
$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
'username' => 'my_username',
2020-11-22 13:48:56 +00:00
'password' => 'my_password',
2022-08-17 12:20:07 +00:00
];
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-08-17 12:20:07 +00:00
->willReturnCallback(static 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-08-17 12:20:07 +00:00
->willReturnCallback(static 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-08-17 12:20:07 +00:00
->willReturnCallback(static 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);
}
2022-04-29 10:15:20 +00:00
public function testPromptAuthIfNeededGitLabNoAuthChange(): void
{
2022-04-29 10:15:20 +00:00
self::expectException('Composer\Downloader\TransportException');
$origin = 'gitlab.com';
$this->io
->method('hasAuthentication')
->with($origin)
->willReturn(true);
$this->io
->method('getAuthentication')
->with($origin)
2022-08-17 12:20:07 +00:00
->willReturn([
'username' => 'gitlab-user',
'password' => 'gitlab-password',
2022-08-17 12:20:07 +00:00
]);
$this->io
->expects($this->once())
->method('setAuthentication')
->with('gitlab.com', 'gitlab-user', 'gitlab-password');
$this->config
->method('get')
2022-08-17 12:20:07 +00:00
->willReturnMap([
['github-domains', 0, []],
['gitlab-domains', 0, ['gitlab.com']],
['gitlab-token', 0, ['gitlab.com' => ['username' => 'gitlab-user', 'token' => 'gitlab-password']]],
]);
$this->authHelper->promptAuthIfNeeded('https://gitlab.com/acme/archive.zip', $origin, 404, 'GitLab requires authentication and it was not provided');
}
public function testPromptAuthIfNeededMultipleBitbucketDownloads(): void
{
$origin = 'bitbucket.org';
$expectedResult = [
'retry' => true,
'storeAuth' => false,
];
$authConfig = [
'bitbucket.org' => [
'access-token' => 'bitbucket_access_token',
'access-token-expiration' => time() + 1800,
]
];
$this->config
->method('get')
->willReturnMap([
['github-domains', 0, []],
['gitlab-domains', 0, []],
['bitbucket-oauth', 0, $authConfig],
['github-domains', 0, []],
['gitlab-domains', 0, []],
]);
$this->io
->expects($this->exactly(2))
->method('hasAuthentication')
->with($origin)
->willReturn(true);
$getAuthenticationReturnValues = [
['username' => 'bitbucket_client_id', 'password' => 'bitbucket_client_secret'],
['username' => 'x-token-auth', 'password' => 'bitbucket_access_token'],
];
$this->io
->expects($this->exactly(2))
->method('getAuthentication')
->willReturnCallback(
function ($repositoryName) use (&$getAuthenticationReturnValues) {
return array_shift($getAuthenticationReturnValues);
}
);
$this->io
->expects($this->once())
->method('setAuthentication')
->with($origin, 'x-token-auth', 'bitbucket_access_token');
$result1 = $this->authHelper->promptAuthIfNeeded('https://bitbucket.org/workspace/repo1/get/hash1.zip', $origin, 401, 'HTTP/2 401 ');
$result2 = $this->authHelper->promptAuthIfNeeded('https://bitbucket.org/workspace/repo2/get/hash2.zip', $origin, 401, 'HTTP/2 401 ');
$this->assertSame(
$expectedResult,
$result1
);
$this->assertSame(
$expectedResult,
$result2
);
}
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
* @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
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);
}
}