Skip to content

Commit 36144c5

Browse files
committed
Code cleanup
- Change mixed tabs/spaces to spaces - Add trailing commas to arrays - Make method opening bracket consistent across methods - Remove trailing whitespaces - Add trailing newline to file
1 parent 4a9adb0 commit 36144c5

1 file changed

Lines changed: 43 additions & 43 deletions

File tree

tests/unit/Utils/DPOPTest.php

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,56 @@
1313
class DPOPTest extends TestCase
1414
{
1515

16-
private $dpop;
17-
private $url;
18-
private $serverRequest;
19-
20-
protected function sign($dpop, $privateKey=null)
21-
{
22-
$keyPath = __DIR__ . '/../../fixtures/keys';
23-
if (!$privateKey) {
24-
$privateKey = file_get_contents($keyPath . '/private.key');
25-
}
26-
27-
$signature = '';
16+
private $dpop;
17+
private $url;
18+
private $serverRequest;
19+
20+
protected function sign($dpop, $privateKey = null)
21+
{
22+
$keyPath = __DIR__ . '/../../fixtures/keys';
23+
if (!$privateKey) {
24+
$privateKey = file_get_contents($keyPath . '/private.key');
25+
}
26+
27+
$signature = '';
2828
$success = \openssl_sign(
2929
Base64Url::encode(json_encode($dpop['header'])).'.'.
30-
Base64Url::encode(json_encode($dpop['payload'])),
31-
$signature,
32-
$privateKey,
30+
Base64Url::encode(json_encode($dpop['payload'])),
31+
$signature,
32+
$privateKey,
3333
OPENSSL_ALGO_SHA256
3434
);
3535

3636
if (!$success) {
37-
throw new \Exception('unable to sign dpop');
37+
throw new \Exception('unable to sign dpop');
3838
}
3939
$token = Base64Url::encode(json_encode($dpop['header'])).'.'.
40-
Base64Url::encode(json_encode($dpop['payload'])).'.'.
41-
Base64Url::encode($signature);
40+
Base64Url::encode(json_encode($dpop['payload'])).'.'.
41+
Base64Url::encode($signature);
4242

4343
return array_merge($dpop, [
44-
'signature' => $signature,
45-
'token' => $token
44+
'signature' => $signature,
45+
'token' => $token,
4646
]);
47-
}
47+
}
4848

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

5555
$keyInfo = \openssl_pkey_get_details(\openssl_pkey_get_public($publicKey));
5656
$jwk = [
5757
'kty' => 'RSA',
5858
'n' => Base64Url::encode($keyInfo['rsa']['n']),
59-
'e' => Base64Url::encode($keyInfo['rsa']['e'])
59+
'e' => Base64Url::encode($keyInfo['rsa']['e']),
6060
];
6161

6262
$header = [
6363
'typ' => 'dpop+jwt',
6464
'alg' => 'RS256',
65-
'jwk' => $jwk
65+
'jwk' => $jwk,
6666
];
6767

6868
$payload = [
@@ -72,22 +72,22 @@ protected function setUp(): void
7272
'htu' => 'https://www.example.com',
7373
'iat' => time(),
7474
'nbf' => time(),
75-
'exp' => time()+3600
75+
'exp' => time()+3600,
7676
];
7777

7878
$this->dpop = $this->sign([
79-
'header' => $header,
80-
'payload' => $payload
79+
'header' => $header,
80+
'payload' => $payload,
8181
]);
8282

83-
$this->url = 'https://www.example.com';
83+
$this->url = 'https://www.example.com';
8484
$this->serverRequest = new \Laminas\Diactoros\ServerRequest(array(),array(), $this->url);
85+
}
8586

86-
}
87-
88-
private function getWrongKey() {
89-
$keyPath = __DIR__ . '/../../fixtures/keys';
90-
$wrongKey = file_get_contents($keyPath . '/wrong.key');
87+
private function getWrongKey()
88+
{
89+
$keyPath = __DIR__ . '/../../fixtures/keys';
90+
$wrongKey = file_get_contents($keyPath . '/wrong.key');
9191

9292
$keyInfo = \openssl_pkey_get_details(\openssl_pkey_get_public($wrongKey));
9393
return $keyInfo;
@@ -96,7 +96,7 @@ private function getWrongKey() {
9696
/**
9797
* @covers ::validateDpop
9898
*/
99-
public function testWrongTyp(): void
99+
public function testWrongTyp(): void
100100
{
101101
$this->dpop['header']['typ'] = 'jwt';
102102
$token = $this->sign($this->dpop);
@@ -111,7 +111,7 @@ public function testWrongTyp(): void
111111
/**
112112
* @covers ::validateDpop
113113
*/
114-
public function testAlgNone(): void
114+
public function testAlgNone(): void
115115
{
116116
$this->dpop['header']['alg'] = 'none';
117117
$token = $this->sign($this->dpop);
@@ -132,17 +132,17 @@ public function testWrongKey(): void
132132
$this->dpop['header']['jwk'] = [
133133
'kty' => 'RSA',
134134
'n' => Base64Url::encode($theWrongKey['rsa']['n']),
135-
'e' => Base64Url::encode($theWrongKey['rsa']['e'])
135+
'e' => Base64Url::encode($theWrongKey['rsa']['e']),
136136
];
137137
$token = $this->sign($this->dpop);
138138

139139
$dpop = new DPop();
140140
try {
141-
$dpop->validateDpop($token['token'], $this->serverRequest);
142-
} catch(RequiredConstraintsViolated $e) {
141+
$dpop->validateDpop($token['token'], $this->serverRequest);
142+
} catch(RequiredConstraintsViolated $e) {
143143
// need to check the actual violation in the exception, so expectExceptionMessage is not sufficient
144-
$this->assertSame($e->violations()[0]->getMessage(),'Token signature mismatch');
145-
}
144+
$this->assertSame($e->violations()[0]->getMessage(),'Token signature mismatch');
145+
}
146146
}
147147

148148
/**
@@ -157,4 +157,4 @@ public function testCorrectToken(): void
157157
$this->assertTrue($result);
158158
}
159159

160-
}
160+
}

0 commit comments

Comments
 (0)