Skip to content

Commit 2d51454

Browse files
committed
fix test
1 parent 9305058 commit 2d51454

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/VAPID.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,17 @@ public static function getVapidHeaders($audience, $subject, $publicKey, $private
8484
'alg' => 'ES256',
8585
);
8686

87-
$jwtPayload = array(
87+
$jwtPayload = json_encode(array(
8888
'aud' => $audience,
8989
'exp' => $expiration,
9090
'sub' => $subject,
91-
);
91+
), JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
9292

9393
$generator = EccFactory::getNistCurves()->generator256();
9494
$privateKeyObject = $generator->getPrivateKeyFrom(gmp_init(bin2hex($privateKey), 16));
9595
$pemSerialize = new PemPrivateKeySerializer(new DerPrivateKeySerializer());
9696
$pem = $pemSerialize->serialize($privateKeyObject);
97+
9798
$jwk = JWKFactory::createFromKey($pem, null);
9899
$jws = JWSFactory::createJWSToCompactJSON($jwtPayload, $jwk, $header);
99100

tests/VAPIDTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ public function testGetVapidHeaders($audience, $vapid, $expiration, $expectedAut
4545
$headers = VAPID::getVapidHeaders($audience, $vapid['subject'], $vapid['publicKey'], $vapid['privateKey'], $expiration);
4646

4747
$this->assertArrayHasKey('Authorization', $headers);
48-
$this->assertEquals($expectedAuthorization, $headers['Authorization']);
48+
$this->assertEquals($this->explodeAuthorization($expectedAuthorization), $this->explodeAuthorization($headers['Authorization']));
4949
$this->assertArrayHasKey('Crypto-Key', $headers);
5050
$this->assertEquals($expectedCryptoKey, $headers['Crypto-Key']);
5151
}
52+
53+
private function explodeAuthorization($auth)
54+
{
55+
$auth = explode('.', $auth);
56+
array_pop($auth); // delete the signature which changes each time
57+
return $auth;
58+
}
5259
}

0 commit comments

Comments
 (0)