Skip to content

Commit 6cbd9f7

Browse files
committed
added the wrong key as a fixture
added check on result fixed reading fixture files added comment for unusual exception test
1 parent ee3015b commit 6cbd9f7

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

tests/fixtures/keys/wrong.key

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiGzr51tpH6F2HwMUSKCX
3+
zxyYfZyNJpKZWzNb3AMrNZTGlKDHHuVCkxNmHV0yFIxr3flRNmvxebLxsuYPAmCF
4+
ccV1r+1Pry244MHOIq3aq5mIRq+smVSPk350WpyO4jn8mOLOiH+CYe9LXmJSPBvO
5+
zZHwjEp+VmIGp5oDUZc5nnrf/UkQcj6jvKj0TanD8vGpDg9w3WbkQHWbFAMGPQdc
6+
YF5CZ68QPKPS86/aOdcnyoliSyIMn9BhrSXS8+Q3fCZHsYgejUjD7e0sx/+gBCrW
7+
MOuzbyD29mgbqETiSCZS1YLxgPnA34NRRKY06G0fMusXSGsXC+y7EU8JjTvTs4/L
8+
PwIDAQAB
9+
-----END PUBLIC KEY-----

tests/unit/Utils/DPOPTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function sign($dpop, $privateKey=null)
4848

4949
protected function setUp(): void
5050
{
51-
$keyPath = dirname(__DIR__) . '/../fixtures/keys';
51+
$keyPath = __DIR__ . '/../../fixtures/keys';
5252
$privateKey = file_get_contents($keyPath . '/private.key');
5353
$publicKey = file_get_contents($keyPath . '/public.key');
5454

@@ -86,20 +86,11 @@ protected function setUp(): void
8686
}
8787

8888
private function getWrongKey() {
89-
$key = <<<EOF
90-
-----BEGIN PUBLIC KEY-----
91-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiGzr51tpH6F2HwMUSKCX
92-
zxyYfZyNJpKZWzNb3AMrNZTGlKDHHuVCkxNmHV0yFIxr3flRNmvxebLxsuYPAmCF
93-
ccV1r+1Pry244MHOIq3aq5mIRq+smVSPk350WpyO4jn8mOLOiH+CYe9LXmJSPBvO
94-
zZHwjEp+VmIGp5oDUZc5nnrf/UkQcj6jvKj0TanD8vGpDg9w3WbkQHWbFAMGPQdc
95-
YF5CZ68QPKPS86/aOdcnyoliSyIMn9BhrSXS8+Q3fCZHsYgejUjD7e0sx/+gBCrW
96-
MOuzbyD29mgbqETiSCZS1YLxgPnA34NRRKY06G0fMusXSGsXC+y7EU8JjTvTs4/L
97-
PwIDAQAB
98-
-----END PUBLIC KEY-----
99-
EOF;
100-
// Get public key
101-
$pubkey=\openssl_pkey_get_details(\openssl_pkey_get_public($key));
102-
return $pubkey;
89+
$keyPath = __DIR__ . '/../../fixtures/keys';
90+
$wrongKey = file_get_contents($keyPath . '/wrong.key');
91+
92+
$keyInfo = \openssl_pkey_get_details(\openssl_pkey_get_public($wrongKey));
93+
return $keyInfo;
10394
}
10495

10596
/**
@@ -129,6 +120,7 @@ public function testAlgNone(): void
129120
$this->expectException(\Exception::class);
130121
$this->expectExceptionMessage('alg is none');
131122
$result = $dpop->validateDpop($token['token'], $this->serverRequest);
123+
$this->assertTrue($result);
132124
}
133125

134126
/**
@@ -146,12 +138,11 @@ public function testWrongKey(): void
146138

147139
$dpop = new DPop();
148140
try {
149-
$result = $dpop->validateDpop($token['token'], $this->serverRequest);
141+
$dpop->validateDpop($token['token'], $this->serverRequest);
150142
} catch(RequiredConstraintsViolated $e) {
151-
$result = false;
143+
// need to check the actual violation in the exception, so expectExceptionMessage is not sufficient
152144
$this->assertSame($e->violations()[0]->getMessage(),'Token signature mismatch');
153145
}
154-
$this->assertFalse($result);
155146
}
156147

157148
/**

0 commit comments

Comments
 (0)