Skip to content

Commit e8adca0

Browse files
committed
fix(AuthHelper): check the authorization type first and do other checks later
1 parent 282bba0 commit e8adca0

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

src/Composer/Util/AuthHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ public function addAuthenticationHeader(array $headers, string $origin, string $
257257
$authenticationDisplayMessage = 'Using GitHub token authentication';
258258
}
259259
} elseif (
260-
in_array($origin, $this->config->get('gitlab-domains'), true)
261-
&& in_array($auth['password'], ['oauth2', 'private-token', 'gitlab-ci-token'], true)
260+
in_array($auth['password'], ['oauth2', 'private-token', 'gitlab-ci-token'], true)
261+
&& in_array($origin, $this->config->get('gitlab-domains'), true)
262262
) {
263263
if ($auth['password'] === 'oauth2') {
264264
$headers[] = 'Authorization: Bearer '.$auth['username'];

tests/Composer/Test/Util/AuthHelperTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,6 @@ public function testAddAuthenticationHeaderWithBitbucketOathToken(): void
203203

204204
$this->expectsAuthentication($origin, $auth);
205205

206-
$this->config->expects($this->once())
207-
->method('get')
208-
->with('gitlab-domains')
209-
->willReturn([]);
210-
211206
$this->io->expects($this->once())
212207
->method('writeError')
213208
->with('Using Bitbucket OAuth token authentication', true, IOInterface::DEBUG);
@@ -245,11 +240,6 @@ public function testAddAuthenticationHeaderWithBitbucketPublicUrl(string $url):
245240

246241
$this->expectsAuthentication($origin, $auth);
247242

248-
$this->config->expects($this->once())
249-
->method('get')
250-
->with('gitlab-domains')
251-
->willReturn([]);
252-
253243
self::assertSame(
254244
$headers,
255245
$this->authHelper->addAuthenticationHeader($headers, $origin, $url)
@@ -302,11 +292,6 @@ public function testAddAuthenticationHeaderWithBasicHttpAuthentication(string $u
302292

303293
$this->expectsAuthentication($origin, $auth);
304294

305-
$this->config->expects($this->once())
306-
->method('get')
307-
->with('gitlab-domains')
308-
->willReturn([$origin]);
309-
310295
$this->io->expects($this->once())
311296
->method('writeError')
312297
->with(

0 commit comments

Comments
 (0)