diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..6d32adf --- /dev/null +++ b/.env.test @@ -0,0 +1,24 @@ +BASE_URL=http://localhost:8080 +NAME=OsecCTF +HOME_CONTENT=This is +LOGIN_TOKEN=test_team_token +DIVISIONS={"hs":"High School","college":"College", "other":"Other"} + +TEST_CHAL=High school/1. Can you find root user? +TEST_CHAL_ANSWER=flag(1m_r0Ot_us3r) + +TEST_REG_EMAIL=test_user@gmail.com +TEST_REG_NAME=test_user@gmail.com + + +TEST_UPDATE_EMAIL=test_user@gmail.com +TEST_UPDATE_NAME=test_user@gmail.com + +TEST_NEW_MEMBER=test_user@gmail.com + +TEST_NEW_CHAL_NAME=Challenge-test +TEST_NEW_CHAL_AUTHOR=luffy +TEST_NEW_CHAL_DES=This is one piece challenge +TEST_NEW_CHAL_FLAG=flag(on3_p1e5c3_f0und) + +REGULAR_USER_TOKEN=admin_team_token \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index 68e54bf..9c4642b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -34,6 +34,7 @@ module.exports = { overrides: [ { files: ['*.ts', '*.tsx'], + excludedFiles: ['**/playwright.config.ts'], extends: [ 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking', diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 0060c12..d8e5aaa 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -75,3 +75,28 @@ fix/bug-description refactor/some-component docs/some-component ``` + +## E2E Tests + +rCTF uses [Playwright](https://playwright.dev/) for end-to-end testing. The `.env.test` file in the repository root contains the test configuration variables. See `packages/client/testConfig.ts` for the complete list. + +### Running E2E Tests + +1. **Install Playwright browsers** (first time only): + +```bash +cd packages/client +npx playwright install +``` + +2. **Run all E2E tests**: + +```bash +npx playwright test +``` + +3. **Run a specific test file**: + +```bash +npx playwright test tests/auth.spec.ts +``` diff --git a/.gitignore b/.gitignore index 0a84956..16ea16d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ $RECYCLE.BIN # coverage coverage + +test-results \ No newline at end of file diff --git a/packages/client/.eslintrc.js b/packages/client/.eslintrc.js index b7285a4..7b6a516 100644 --- a/packages/client/.eslintrc.js +++ b/packages/client/.eslintrc.js @@ -17,7 +17,7 @@ module.exports = { }, parserOptions: { tsconfigRootDir: __dirname, - project: ['./tsconfig.json'], + project: ['./tsconfig.json', './tsconfig.playwright.json'], }, overrides: [ { diff --git a/packages/client/.gitignore b/packages/client/.gitignore new file mode 100644 index 0000000..21328f5 --- /dev/null +++ b/packages/client/.gitignore @@ -0,0 +1,8 @@ + +# Playwright +node_modules/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ +*.env \ No newline at end of file diff --git a/packages/client/package.json b/packages/client/package.json index 765a6e6..3789a52 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -24,6 +24,7 @@ "@babel/preset-react": "7.16.0", "@babel/preset-typescript": "7.16.0", "@emotion/jest": "11.5.0", + "@playwright/test": "1.50.1", "@prefresh/babel-plugin": "0.4.1", "@prefresh/webpack": "3.3.2", "@reach/auto-id": "0.16.0", @@ -39,6 +40,7 @@ "@testing-library/preact": "2.0.1", "@testing-library/user-event": "13.5.0", "@theme-ui/preset-base": "0.9.1", + "@types/node": "16.11.6", "@types/react": "17.0.33", "@types/webpack-env": "1.16.3", "babel-loader": "8.2.3", diff --git a/packages/client/playwright.config.ts b/packages/client/playwright.config.ts new file mode 100644 index 0000000..ab9614e --- /dev/null +++ b/packages/client/playwright.config.ts @@ -0,0 +1,35 @@ +import { defineConfig, devices } from '@playwright/test' +export default defineConfig({ + testDir: './tests', + fullyParallel: true, + forbidOnly: !!process.env.CI, + retries: 0, + workers: process.env.CI ? 1 : undefined, + reporter: 'html', + use: { + trace: 'on-first-retry', + + baseURL: 'http://localhost:8080', + headless: true, + viewport: { width: 1280, height: 720 }, + ignoreHTTPSErrors: true, + }, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + + { + name: 'webkit', + use: { ...devices['Desktop Safari'] }, + }, + + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, + ], + + timeout: 30000, +}) diff --git a/packages/client/src/components/admin/problem.js b/packages/client/src/components/admin/problem.js index 0e480bb..b04f78b 100644 --- a/packages/client/src/components/admin/problem.js +++ b/packages/client/src/components/admin/problem.js @@ -236,13 +236,15 @@ const Problem = ({ classes, problem, update: updateClient }) => { const ProblemActions = hasChallsWritePermission() ? ( - + ) : null @@ -251,129 +253,145 @@ const Problem = ({ classes, problem, update: updateClient }) => {
-
-
-
- - -
- +
+
+ {/* Section: Basic Info */} +
+
+ + + + + + +
+ +
+ + + + +
+ + +
+
+
+ + {/* Section: Description */} +
+ +