/** * @test * * @uses Lcobucci\JWT\Signer\Ecdsa::__construct * @uses Lcobucci\JWT\Signer\Key * * @covers Lcobucci\JWT\Signer\Ecdsa::createHash * @covers Lcobucci\JWT\Signer\Ecdsa::createSigningHash * @covers Lcobucci\JWT\Signer\Ecdsa::createSignatureHash */ public function createHashShouldReturnAHashUsingPrivateKey() { $signer = $this->getSigner(); $key = new Key('testing'); $privateKey = $this->getMock(PrivateKeyInterface::class); $point = $this->getMock(PointInterface::class); $privateKey->method('getPoint')->willReturn($point); $point->method('getOrder')->willReturn('1'); $this->parser->expects($this->once())->method('getPrivateKey')->with($key)->willReturn($privateKey); $this->randomGenerator->expects($this->once())->method('generate')->with('1')->willReturn('123'); $this->adapter->expects($this->once())->method('hexDec')->willReturn('123'); $this->adapter->expects($this->exactly(2))->method('decHex')->willReturn('123'); $this->signer->expects($this->once())->method('sign')->with($privateKey, $this->isType('string'), $this->isType('string'))->willReturn(new Signature('1234', '456')); $this->assertInternalType('string', $signer->createHash('testing', $key, $this->randomGenerator)); }
/** * @test * * @covers \Lcobucci\JWT\Signer\Ecdsa\EccAdapter::createHash * * @uses \Lcobucci\JWT\Signer\Ecdsa\EccAdapter::__construct */ public function createHashShouldReturnASerializedSignature() { $key = $this->createMock(PrivateKeyInterface::class); $point = $this->createMock(GeneratorPoint::class); $signature = $this->createMock(SignatureInterface::class); $order = gmp_init(1, 10); $randomK = gmp_init(2, 10); $signingHash = gmp_init(3, 10); $key->method('getPoint')->willReturn($point); $point->method('getOrder')->willReturn($order); $this->numberGenerator->expects($this->once())->method('generate')->with($order)->willReturn($randomK); $this->signer->expects($this->once())->method('sign')->with($key, $signingHash, $randomK)->willReturn($signature); $this->serializer->expects($this->once())->method('serialize')->with($signature, 'sha256')->willReturn('serialized_signature'); $adapter = $this->createAdapter(); self::assertEquals('serialized_signature', $adapter->createHash($key, $signingHash, 'sha256')); }