Files
Gitea/tests/e2e/admin.test.ts
T
Joe (Agent) Stump 3bec08f998 feat: manage bot accounts from the admin UI, API and CLI (#38966)
Adds first-class bot accounts (`UserTypeBot`): local, password-less
users for automation that authenticate only with access tokens.

1. Admin UI: create bots, filter users by type, manage a bot's access
tokens, convert between user and bot
2. API: `POST /admin/users/{username}/convert-type`, and user objects
gain a GitHub-compatible `type` (`User`, `Organization`, `Bot`)
3. CLI: `gitea admin user change-type`, `--user-type` accepts `User` or
`Bot` case-insensitively
4. Converting keeps the password, 2FA, OAuth2 grants and access tokens,
and since sign-in rejects bots, converting back restores the account.
Only local, non-admin accounts can be converted, and conversions are
audited
5. Session, reverse proxy, SSPI, external source and password reset
sign-in reject non-individual users, so a bot never gets an interactive
session
6. Bots receive no notifications or emails

Co-authored-by: Nicolas <bircni@icloud.com>
Co-authored-by: joestump <joe@joestump.net>
Co-authored-by: Joe Stump <joe@stu.mp>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2026-09-18 12:43:36 +00:00

27 lines
1.3 KiB
TypeScript

import {env} from 'node:process';
import {test, expect} from '@playwright/test';
import {login, randomString} from './utils.ts';
test('create a bot and manage its access token', async ({page, request}) => {
const botName = `e2e-bot-${randomString(8)}`;
await login(page);
await page.goto('/-/admin/users/new');
await page.getByLabel('Username').fill(botName);
await page.getByLabel('Username').press('Tab');
await page.getByRole('option', {name: 'Bot'}).click();
await page.getByLabel('Email Address').fill(`${botName}@${env.GITEA_TEST_E2E_DOMAIN}`);
await page.getByRole('button', {name: 'Create User Account'}).click();
await page.waitForURL(/\/-\/admin\/users\/\d+$/);
await page.getByLabel('Token Name').fill('e2e-token');
await page.getByRole('row', {name: /^user /}).getByRole('radio', {name: 'Read', exact: true}).check();
await page.getByRole('button', {name: 'Generate Token'}).click();
const token = await page.getByRole('code').textContent();
const response = await request.get('/api/v1/user', {headers: {Authorization: `token ${token}`}});
expect(await response.json()).toMatchObject({login: botName, type: 'Bot'});
await page.getByRole('button', {name: 'Delete'}).click();
await page.getByRole('button', {name: 'Yes'}).click();
await expect(page.getByText('The token has been deleted.')).toBeVisible();
});