1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-04 11:36:46 +00:00

feat: add option to renew API key (#1214)

This commit is contained in:
Elias Schneider
2026-01-09 12:08:58 +01:00
committed by GitHub
parent 0a94f0fd64
commit 811e8772b6
16 changed files with 321 additions and 41 deletions

View File

@@ -96,7 +96,14 @@ export const apiKeys = [
{
id: '5f1fa856-c164-4295-961e-175a0d22d725',
key: '6c34966f57ef2bb7857649aff0e7ab3ad67af93c846342ced3f5a07be8706c20',
name: 'Test API Key'
name: 'Test API Key',
expired: false
},
{
id: '98900330-7a7b-48fe-881b-2cc6ad049976',
key: '141ff8ac9db640ba93630099de83d0ead8e7ac673e3a7d31b4fd7ff2252e6389',
name: 'Expired API Key',
expired: true
}
];

View File

@@ -1,9 +1,20 @@
{
"provider": "sqlite",
"version": 20251229173100,
"version": 20260106140900,
"tableOrder": ["users", "user_groups", "oidc_clients", "signup_tokens"],
"tables": {
"api_keys": [
{
"created_at": "2025-12-21T19:12:03Z",
"description": null,
"expiration_email_sent": false,
"expires_at": "2025-12-25T12:00:00Z",
"key": "141ff8ac9db640ba93630099de83d0ead8e7ac673e3a7d31b4fd7ff2252e6389",
"id": "98900330-7a7b-48fe-881b-2cc6ad049976",
"last_used_at": null,
"name": "Expired API Key",
"user_id": "f4b89dc2-62fb-46bf-9f5f-c34f4eafe93e"
},
{
"created_at": "2025-11-25T12:39:02Z",
"description": null,

View File

@@ -1,5 +1,5 @@
// frontend/tests/api-key.spec.ts
import { expect, test } from '@playwright/test';
import { expect, Page, test } from '@playwright/test';
import { apiKeys } from '../data';
import { cleanupBackend } from '../utils/cleanup.util';
@@ -19,15 +19,7 @@ test.describe('API Key Management', () => {
// Choose the date
const currentDate = new Date();
await page.getByRole('button', { name: 'Select a date' }).click();
await page.getByLabel('Select year').click();
// Select the next year
await page.getByRole('option', { name: (currentDate.getFullYear() + 1).toString() }).click();
// Select the first day of the month
await page
.getByRole('button', { name: /([A-Z][a-z]+), ([A-Z][a-z]+) 1, (\d{4})/ })
.first()
.click();
await selectDate(page, currentDate.getFullYear() + 1, currentDate.getMonth(), 1);
// Submit the form
await page.getByRole('button', { name: 'Save' }).click();
@@ -51,6 +43,30 @@ test.describe('API Key Management', () => {
await expect(page.getByRole('cell', { name }).first()).toContainText(name);
});
test('Renew API key', async ({ page }) => {
const apiKey = apiKeys[1];
await page
.getByRole('row', { name: apiKey.name })
.getByRole('button', { name: 'Toggle menu' })
.click();
await page.getByRole('menuitem', { name: 'Renew' }).click();
// Choose the date
const currentDate = new Date();
await selectDate(page, currentDate.getFullYear() + 1, currentDate.getMonth(), 1);
await page.getByRole('button', { name: 'Renew' }).click();
await expect(page.getByRole('heading', { name: 'API key renewed' })).toBeVisible();
// Verify the new expiration date is shown
const row = page.getByRole('row', { name: apiKey.name });
const expectedDate = new Date(currentDate.getFullYear() + 1, currentDate.getMonth(), 1);
await expect(row.getByRole('cell', { name: expectedDate.toLocaleString() })).toBeVisible();
});
test('Revoke API key', async ({ page }) => {
const apiKey = apiKeys[0];
@@ -70,3 +86,33 @@ test.describe('API Key Management', () => {
await expect(page.getByRole('cell', { name: apiKey.name })).not.toBeVisible();
});
});
async function selectDate(page: Page, year: number, month: number, day: number) {
// Open the date picker
await page.getByRole('button', { name: 'Select a date' }).click();
// Select the year
await page.getByLabel('Select year').click();
await page.getByRole('option', { name: year.toString() }).click();
// Select the month and day
const monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
const monthName = monthNames[month];
await page.getByRole('button', { name: 'Select month' }).click();
await page.getByRole('option', { name: monthName }).click();
await page
.getByRole('button', { name: new RegExp(`([A-Z][a-z]+), ([A-Z][a-z]+) ${day}, (\\d{4})`) }).first()
.click();
}