Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Commit 1a489c1

Browse files
committed
Fix tests
1 parent 9f49142 commit 1a489c1

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/Plugin/rest/resource/AuthCodeResource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function post(Request $request) {
135135
'error' => [
136136
'code' => 'simple_oauth_auth_code_invalid_payload',
137137
'message' => 'Invalid payload: Missing field "email".',
138-
]
138+
],
139139
], Response::HTTP_BAD_REQUEST);
140140
}
141141

@@ -144,7 +144,7 @@ public function post(Request $request) {
144144
'error' => [
145145
'code' => 'simple_oauth_auth_code_invalid_payload',
146146
'message' => 'Invalid payload: Missing field "operation".',
147-
]
147+
],
148148
], Response::HTTP_BAD_REQUEST);
149149
}
150150

@@ -158,7 +158,7 @@ public function post(Request $request) {
158158
'error' => [
159159
'code' => 'simple_oauth_auth_code_invalid_payload',
160160
'message' => 'Invalid payload',
161-
]
161+
],
162162
], Response::HTTP_BAD_REQUEST);
163163
}
164164

tests/src/Kernel/AuthCodeGeneratorTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ protected function setUp(): void {
6060
* Test auth code generation.
6161
*/
6262
public function testGenerateAuthCode() {
63+
$now = new \DateTimeImmutable();
6364
$authCode = $this->authCodeGenerator->generateAuthCode(self::CLIENT_ID, $this->user);
6465

6566
$this->assertNotNull($authCode);
6667
$payload = $this->decryptAuthCode($authCode);
67-
$now = time();
68-
6968
// Get auth code expiration time from client.
7069
$expirationTime = (int) $this->client->get('one_time_login_auth_code_expiration')->value;
7170

7271
// Create a timestamp that is $expirationTime seconds into the future.
73-
$timestamp = $expirationTime + $now;
72+
$timestamp = $expirationTime + $now->getTimestamp();
7473

7574
$this->assertEquals(self::CLIENT_ID, $payload['client_id']);
7675
$this->assertEquals($this->user->id(), $payload['user_id']);

tests/src/Kernel/AuthCodeResourceTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Drupal\user\Entity\User;
1414
use Stack\StackedHttpKernel;
1515
use Symfony\Component\HttpFoundation\Request;
16-
use Symfony\Component\HttpKernel\Kernel;
1716

1817
/**
1918
* Test the auth code rest resource.
@@ -148,7 +147,7 @@ public function testResource() {
148147
$request = $this->createJsonRequest('POST', $this->url->toString(), $payload);
149148
$response = $this->httpKernel->handle($request);
150149

151-
$this->assertEquals(401, $response->getStatusCode());
150+
$this->assertEquals(403, $response->getStatusCode());
152151
}
153152

154153
/**

0 commit comments

Comments
 (0)