Cleaned the comments and used test.describe to nest the tests

This commit is contained in:
David Rotermund 2025-05-26 12:07:06 +02:00
parent 795135e3c9
commit 77c248fa1e
2 changed files with 98 additions and 105 deletions

View file

@ -9,7 +9,6 @@ import (
"strings" "strings"
) )
// var fileNameComponentSanitizeRegexp = regexp.MustCompile(`(?i)\.\.|[<>:\"/\\|?*\x{0000}-\x{001F}]|^(con|prn|aux|nul|com\d|lpt\d)$`)
var fileNameComponentSanitizeRegexp = regexp.MustCompile(`(?i)[<>:\"/\\|?*\x{0000}-\x{001F}]|^(con|prn|aux|nul|com\d|lpt\d)$`) var fileNameComponentSanitizeRegexp = regexp.MustCompile(`(?i)[<>:\"/\\|?*\x{0000}-\x{001F}]|^(con|prn|aux|nul|com\d|lpt\d)$`)
// SanitizePath cleans and validates a file path // SanitizePath cleans and validates a file path

View file

@ -8,19 +8,12 @@
// services/repository/files/upload.go // services/repository/files/upload.go
// @watch end // @watch end
// https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md
// lies. Don't use
// make TAGS="sqlite sqlite_unlock_notify" backend
// use
// make TAGS="sqlite sqlite_unlock_notify" build
// otherwise the test fails.
import {expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {test, dynamic_id, save_visual} from './utils_e2e.ts'; import {test, dynamic_id, save_visual} from './utils_e2e.ts';
test.use({user: 'user2'}); test.use({user: 'user2'});
test.describe('Drag and Drop upload', () => {
test('drag and drop upload normal and special characters', async ({page}) => { test('normal and special characters', async ({page}) => {
const response = await page.goto(`/user2/file-uploads/_upload/main/`); const response = await page.goto(`/user2/file-uploads/_upload/main/`);
expect(response?.status()).toBe(200); // Status OK expect(response?.status()).toBe(200); // Status OK
@ -56,7 +49,7 @@ test('drag and drop upload normal and special characters', async ({page}) => {
await expect(page.locator('#diff-file-boxes').getByRole('link', {name: 'root_file.txt'})).toBeVisible(); await expect(page.locator('#diff-file-boxes').getByRole('link', {name: 'root_file.txt'})).toBeVisible();
}); });
test('drag and drop upload strange paths and spaces', async ({page}) => { test('strange paths and spaces', async ({page}) => {
const response = await page.goto(`/user2/file-uploads/_upload/main/`); const response = await page.goto(`/user2/file-uploads/_upload/main/`);
expect(response?.status()).toBe(200); // Status OK expect(response?.status()).toBe(200); // Status OK
@ -90,7 +83,7 @@ test('drag and drop upload strange paths and spaces', async ({page}) => {
await expect(page.locator('#diff-file-boxes').getByRole('link', {name: '..dots.txt'})).toBeVisible(); await expect(page.locator('#diff-file-boxes').getByRole('link', {name: '..dots.txt'})).toBeVisible();
}); });
test('drag and drop upload broken path slash in front', async ({page}) => { test('broken path slash in front', async ({page}) => {
const response = await page.goto(`/user2/file-uploads/_upload/main/`); const response = await page.goto(`/user2/file-uploads/_upload/main/`);
expect(response?.status()).toBe(200); // Status OK expect(response?.status()).toBe(200); // Status OK
@ -117,7 +110,7 @@ test('drag and drop upload broken path slash in front', async ({page}) => {
await save_visual(page); await save_visual(page);
}); });
test('drag and drop upload broken path with traversal', async ({page}) => { test('broken path with traversal', async ({page}) => {
const response = await page.goto(`/user2/file-uploads/_upload/main/`); const response = await page.goto(`/user2/file-uploads/_upload/main/`);
expect(response?.status()).toBe(200); // Status OK expect(response?.status()).toBe(200); // Status OK
@ -143,3 +136,4 @@ test('drag and drop upload broken path with traversal', async ({page}) => {
await save_visual(page); await save_visual(page);
}); });
});