mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Merge pull request #20009 from strapi/fix/creating-api-tokens
fix: making api tokens creation work
This commit is contained in:
commit
6fe2e78edf
@ -190,7 +190,8 @@ export const EditView = () => {
|
||||
const res = await createToken({
|
||||
...body,
|
||||
// lifespan must be "null" for unlimited (0 would mean instantly expired and isn't accepted)
|
||||
lifespan: body?.lifespan || null,
|
||||
lifespan:
|
||||
body?.lifespan && body.lifespan !== '0' ? parseInt(body.lifespan.toString(), 10) : null,
|
||||
permissions: body.type === 'custom' ? state.selectedActions : null,
|
||||
});
|
||||
|
||||
@ -220,7 +221,7 @@ export const EditView = () => {
|
||||
tokenType: API_TOKEN_TYPE,
|
||||
});
|
||||
|
||||
navigate(res.data.id.toString(), {
|
||||
navigate(`../api-tokens/${res.data.id.toString()}`, {
|
||||
state: { apiToken: res.data },
|
||||
replace: true,
|
||||
});
|
||||
|
||||
52
tests/e2e/tests/admin/api-tokens.spec.ts
Normal file
52
tests/e2e/tests/admin/api-tokens.spec.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { login } from '../../utils/login';
|
||||
import { resetDatabaseAndImportDataFromPath } from '../../scripts/dts-import';
|
||||
import { navToHeader } from '../../utils/shared';
|
||||
|
||||
const createAPIToken = async (page, tokenName, duration, type) => {
|
||||
await navToHeader(page, ['Settings', 'API Tokens', 'Create new API Token'], 'Create API Token');
|
||||
|
||||
await page.getByLabel('Name*').click();
|
||||
await page.getByLabel('Name*').fill(tokenName);
|
||||
|
||||
await page.getByLabel('Token duration').click();
|
||||
await page.getByRole('option', { name: duration }).click();
|
||||
|
||||
await page.getByLabel('Token type').click();
|
||||
await page.getByRole('option', { name: type }).click();
|
||||
|
||||
await page.getByRole('button', { name: 'Save' }).click();
|
||||
|
||||
await expect(page.getByText('Make sure to copy this token')).toBeVisible();
|
||||
await expect(page.getByText('Expiration date:')).toBeVisible();
|
||||
};
|
||||
|
||||
test.describe('API Tokens', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await resetDatabaseAndImportDataFromPath('with-admin.tar');
|
||||
await page.goto('/admin');
|
||||
await login({ page });
|
||||
});
|
||||
|
||||
// Test token creation
|
||||
const testCases = [
|
||||
['30-day Read-only token', '30 days', 'Read-only'],
|
||||
['30-day full-access token', '30 days', 'Full access'],
|
||||
['7-day token', '7 days', 'Full access'],
|
||||
['90-day token', '90 days', 'Full access'],
|
||||
['unlimited token', 'Unlimited', 'Full access'],
|
||||
];
|
||||
for (const [name, duration, type] of testCases) {
|
||||
test(`A user should be able to create a ${name}`, async ({ page }) => {
|
||||
await createAPIToken(page, name, duration, type);
|
||||
});
|
||||
}
|
||||
|
||||
test('Created tokens list page should be correct', async ({ page }) => {
|
||||
await createAPIToken(page, 'my test token', 'unlimited', 'Full access');
|
||||
await navToHeader(page, ['Settings', 'API Tokens'], 'API Tokens');
|
||||
|
||||
const row = page.getByRole('gridcell', { name: 'my test token', exact: true });
|
||||
await expect(row).toBeVisible();
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user