Skip to content

Commit 8bee68a

Browse files
committed
Fix registry auth to send base64url-encoded X-Registry-Auth header
1 parent 19d23b4 commit 8bee68a

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎src/Client.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ private function json($data)
16141614
*
16151615
* Description from Docker's docs (see links):
16161616
*
1617-
* AuthConfig, set as the X-Registry-Auth header, is currently a Base64
1617+
* AuthConfig, set as the X-Registry-Auth header, is currently a base64url
16181618
* encoded (JSON) string with the following structure:
16191619
* ```
16201620
* {"username": "string", "password": "string", "email": "string", "serveraddress" : "string", "auth": ""}
@@ -1632,7 +1632,7 @@ private function authHeaders($registryAuth)
16321632
{
16331633
$headers = array();
16341634
if ($registryAuth !== null) {
1635-
$headers['X-Registry-Auth'] = base64_encode($this->json($registryAuth));
1635+
$headers['X-Registry-Auth'] = strtr(base64_encode($this->json($registryAuth)), '+/', '-_');
16361636
}
16371637

16381638
return $headers;

‎tests/ClientTest.php‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ public function testImagePushStream()
573573

574574
public function testImagePushCustomRegistry()
575575
{
576-
// TODO: verify headers
577576
$auth = array();
578577
$json = array();
579578
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
@@ -585,6 +584,19 @@ public function testImagePushCustomRegistry()
585584
$this->expectPromiseResolveWith($json, $this->client->imagePush('123', 'test', 'demo.acme.com:5000', $auth));
586585
}
587586

587+
public function testImagePushWithRegistryAuth()
588+
{
589+
$auth = array('username' => 'user', 'password' => 'p>ss?word!');
590+
$json = array();
591+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
592+
593+
$this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'images/123/push', array('X-Registry-Auth' => 'eyJ1c2VybmFtZSI6InVzZXIiLCJwYXNzd29yZCI6InA-c3M_d29yZCEifQ=='))->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json)));
594+
$this->streamingParser->expects($this->once())->method('parseJsonStream')->willReturn($stream);
595+
$this->streamingParser->expects($this->once())->method('deferredStream')->with($stream)->willReturn(\React\Promise\resolve($json));
596+
597+
$this->expectPromiseResolveWith($json, $this->client->imagePush('123', null, null, $auth));
598+
}
599+
588600
public function testImageTag()
589601
{
590602
$this->expectRequestFlow('post', 'images/123/tag?repo=test', $this->createResponse(), 'expectEmpty');

0 commit comments

Comments
 (0)