mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-09-25 01:53:03 +02:00
migrate file-access tokens onto shared OneTimeToken model (hash-at-rest)
This commit is contained in:
@@ -55,12 +55,16 @@ class FileAccessTokenTest extends TestCase
|
||||
|
||||
$token = $this->db->generateAccessToken($requestId, 24);
|
||||
|
||||
$stmt = $this->pdo->prepare('SELECT * FROM file_access_tokens WHERE request_id = ?');
|
||||
$stmt->execute([$requestId]);
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT * FROM one_time_tokens WHERE purpose = 'file_access' ORDER BY id DESC LIMIT 1"
|
||||
);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
|
||||
$this->assertNotFalse($row);
|
||||
$this->assertSame($token, $row['token'], 'Current impl stores the plaintext token');
|
||||
$this->assertSame(hash('sha256', $token), $row['token_hash'], 'Only the hash is stored, never the plaintext');
|
||||
$this->assertNotSame($token, $row['token_hash']);
|
||||
$this->assertSame(['request_id' => $requestId], json_decode($row['context'], true));
|
||||
$this->assertSame(1, (int) $row['is_valid']);
|
||||
$this->assertNull($row['used_at']);
|
||||
$this->assertNotNull($row['expires_at']);
|
||||
@@ -87,8 +91,10 @@ class FileAccessTokenTest extends TestCase
|
||||
|
||||
$this->db->redeemAccessToken($token, '1.2.3.4', 'ua');
|
||||
|
||||
$stmt = $this->pdo->prepare('SELECT used_at, is_valid FROM file_access_tokens WHERE request_id = ?');
|
||||
$stmt->execute([$requestId]);
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT used_at, is_valid FROM one_time_tokens WHERE purpose = 'file_access'"
|
||||
);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
|
||||
$this->assertNotNull($row['used_at']);
|
||||
|
||||
Reference in New Issue
Block a user