diff --git a/pages/api/control/error/client-fail.js b/pages/api/control/error/client-fail.js index 615ae57..28537a5 100644 --- a/pages/api/control/error/client-fail.js +++ b/pages/api/control/error/client-fail.js @@ -1,5 +1,3 @@ -import { checkSutAuth } from '../../../../src/services/sut-utils'; - /** * @swagger * /api/control/error/client-fail: @@ -10,9 +8,6 @@ import { checkSutAuth } from '../../../../src/services/sut-utils'; * description: Unauthorized error */ export default function handler(req, res) { - if (!checkSutAuth(req)) { - return res.status(401).json({ error: 'Authentication required' }); - } res.status(401).json({ error: 'Unauthorized (401)' }); } diff --git a/pages/api/control/error/redirect-temp.js b/pages/api/control/error/redirect-temp.js index 97688e7..868eb44 100644 --- a/pages/api/control/error/redirect-temp.js +++ b/pages/api/control/error/redirect-temp.js @@ -1,5 +1,3 @@ -import { checkSutAuth } from '../../../../src/services/sut-utils'; - /** * @swagger * /api/control/error/redirect-temp: @@ -12,9 +10,6 @@ import { checkSutAuth } from '../../../../src/services/sut-utils'; * description: Unauthorized */ export default function handler(req, res) { - if (!checkSutAuth(req)) { - return res.status(401).json({ error: 'Authentication required' }); - } res.redirect(307, '/api/control/error/success'); } diff --git a/pages/api/control/error/server-fail.js b/pages/api/control/error/server-fail.js index ab2f5de..55c0b8e 100644 --- a/pages/api/control/error/server-fail.js +++ b/pages/api/control/error/server-fail.js @@ -1,5 +1,3 @@ -import { checkSutAuth } from '../../../../src/services/sut-utils'; - /** * @swagger * /api/control/error/server-fail: @@ -12,9 +10,6 @@ import { checkSutAuth } from '../../../../src/services/sut-utils'; * description: Unauthorized */ export default function handler(req, res) { - if (!checkSutAuth(req)) { - return res.status(401).json({ error: 'Authentication required' }); - } res.status(503).json({ error: 'Service Unavailable (503)' }); } diff --git a/pages/api/control/error/success.js b/pages/api/control/error/success.js index f88fe56..b5c6ec6 100644 --- a/pages/api/control/error/success.js +++ b/pages/api/control/error/success.js @@ -1,5 +1,3 @@ -import { checkSutAuth } from '../../../../src/services/sut-utils'; - /** * @swagger * /api/control/error/success: @@ -12,9 +10,6 @@ import { checkSutAuth } from '../../../../src/services/sut-utils'; * description: Unauthorized */ export default function handler(req, res) { - if (!checkSutAuth(req)) { - return res.status(401).json({ error: 'Authentication required' }); - } res.status(200).json({ message: 'Success (200 OK)' }); } diff --git a/pages/api/control/latency/avg.js b/pages/api/control/latency/avg.js index f5ea608..dc40804 100644 --- a/pages/api/control/latency/avg.js +++ b/pages/api/control/latency/avg.js @@ -1,4 +1,4 @@ -import { delay, checkSutAuth } from '../../../../src/services/sut-utils'; +import { delay } from '../../../../src/services/sut-utils'; /** * @swagger @@ -12,10 +12,6 @@ import { delay, checkSutAuth } from '../../../../src/services/sut-utils'; * description: Unauthorized */ export default async function handler(req, res) { - // Check authentication - if (!checkSutAuth(req)) { - return res.status(401).json({ error: 'Authentication required' }); - } await delay(500); res.status(200).json({ status: 'OK', latency: '500ms' }); diff --git a/pages/api/control/latency/p99-outlier.js b/pages/api/control/latency/p99-outlier.js index ef9f1a5..8862c2a 100644 --- a/pages/api/control/latency/p99-outlier.js +++ b/pages/api/control/latency/p99-outlier.js @@ -1,4 +1,4 @@ -import { delay, checkSutAuth } from '../../../../src/services/sut-utils'; +import { delay } from '../../../../src/services/sut-utils'; /** * @swagger @@ -12,9 +12,6 @@ import { delay, checkSutAuth } from '../../../../src/services/sut-utils'; * description: Unauthorized */ export default async function handler(req, res) { - if (!checkSutAuth(req)) { - return res.status(401).json({ error: 'Authentication required' }); - } const randomValue = Math.random(); const delayTime = randomValue < 0.01 ? 5000 : 200; // 1% slow, 99% fast diff --git a/pages/api/control/latency/threshold.js b/pages/api/control/latency/threshold.js index b2f0a39..53eb0dd 100644 --- a/pages/api/control/latency/threshold.js +++ b/pages/api/control/latency/threshold.js @@ -1,4 +1,4 @@ -import { delay, checkSutAuth } from '../../../../src/services/sut-utils'; +import { delay } from '../../../../src/services/sut-utils'; /** * @swagger @@ -12,9 +12,6 @@ import { delay, checkSutAuth } from '../../../../src/services/sut-utils'; * description: Unauthorized */ export default async function handler(req, res) { - if (!checkSutAuth(req)) { - return res.status(401).json({ error: 'Authentication required' }); - } await delay(3500); res.status(200).json({ status: 'OK', flag: 'slow' }); diff --git a/pages/api/zero/errors.js b/pages/api/zero/errors.js index 8d1b162..6592ad3 100644 --- a/pages/api/zero/errors.js +++ b/pages/api/zero/errors.js @@ -1,5 +1,3 @@ -import { checkSutAuth } from '../../../src/services/sut-utils'; - /** * @swagger * /api/zero/errors: @@ -12,9 +10,6 @@ import { checkSutAuth } from '../../../src/services/sut-utils'; * description: Unauthorized */ export default function handler(req, res) { - if (!checkSutAuth(req)) { - return res.status(401).json({ error: 'Authentication required' }); - } res.status(200).json({ message: 'Perfect run, zero errors targeted.' }); } diff --git a/pages/sut/dashboard.jsx b/pages/sut/dashboard.jsx index 96def63..eafc40c 100644 --- a/pages/sut/dashboard.jsx +++ b/pages/sut/dashboard.jsx @@ -2,7 +2,6 @@ import Head from 'next/head'; import { useEffect, useState } from 'react'; import { useRouter } from 'next/router'; import Link from 'next/link'; -import { checkSutAuth } from '../../src/services/sut-utils'; export default function SutDashboard() { const router = useRouter(); diff --git a/pages/sut/index.jsx b/pages/sut/index.jsx index 57b0062..a603b9a 100644 --- a/pages/sut/index.jsx +++ b/pages/sut/index.jsx @@ -5,7 +5,7 @@ export default function SutIndex() { const router = useRouter(); useEffect(() => { - router.replace('/sut/login'); + router.replace('/sut/dashboard'); }, [router]); return
Redirecting to SUT Login...
; diff --git a/pages/sut/login.jsx b/pages/sut/login.jsx deleted file mode 100644 index b90e356..0000000 --- a/pages/sut/login.jsx +++ /dev/null @@ -1,137 +0,0 @@ -import Head from 'next/head'; -import { useEffect, useState } from 'react'; -import { useRouter } from 'next/router'; -import { DUMMY_USERNAME, DUMMY_PASSWORD, sessions, generateSessionId } from '../../src/services/sut-utils'; - -export default function SutLogin() { - const router = useRouter(); - const [username, setUsername] = useState(DUMMY_USERNAME); - const [password, setPassword] = useState(DUMMY_PASSWORD); - const [error, setError] = useState(''); - - const handleSubmit = async (e) => { - e.preventDefault(); - setError(''); - - if (username === DUMMY_USERNAME && password === DUMMY_PASSWORD) { - const sessionId = generateSessionId(); - sessions[sessionId] = { userId: DUMMY_USERNAME, timestamp: Date.now() }; - - // Set cookie on client side - document.cookie = `sutSessionId=${sessionId}; path=/; max-age=3600`; - - router.push('/sut/dashboard'); - } else { - setError('Login failed. Please check credentials.'); - } - }; - - return ( - <> - - SUT Login - Load Testing - - -
-
-

SDET Login

-
-
- - setUsername(e.target.value)} - required - style={styles.input} - /> -
-
- - setPassword(e.target.value)} - required - style={styles.input} - /> -
- - {error &&
{error}
} -
-

- Use dummy credentials for load testing. -

-
-
- - ); -} - -const styles = { - container: { - maxWidth: '400px', - margin: '40px auto', - padding: '20px', - fontFamily: 'Inter, sans-serif', - }, - card: { - backgroundColor: 'white', - borderRadius: '12px', - boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)', - padding: '24px', - textAlign: 'center', - }, - heading: { - color: '#1e3a8a', - marginBottom: '20px', - }, - formGroup: { - marginBottom: '15px', - textAlign: 'left', - }, - label: { - display: 'block', - marginBottom: '5px', - fontWeight: '500', - }, - input: { - width: '100%', - padding: '10px', - border: '1px solid #ccc', - borderRadius: '6px', - boxSizing: 'border-box', - }, - button: { - backgroundColor: '#1e3a8a', - color: 'white', - padding: '10px 20px', - border: 'none', - borderRadius: '6px', - cursor: 'pointer', - width: '100%', - marginTop: '10px', - fontWeight: '600', - }, - error: { - marginTop: '15px', - padding: '10px', - backgroundColor: '#fee2e2', - color: '#991b1b', - borderRadius: '6px', - }, - hint: { - marginTop: '15px', - color: '#6b7280', - }, -}; diff --git a/src/services/sut-utils.js b/src/services/sut-utils.js index e1d36f4..8ecdb56 100644 --- a/src/services/sut-utils.js +++ b/src/services/sut-utils.js @@ -51,33 +51,11 @@ const getBaseHtml = (title, bodyContent) => ` `; -const generateSessionId = () => Math.random().toString(36).substring(2, 15); - -// Simple auth check - returns session info or null -const checkSutAuth = (req) => { - const cookieHeader = req.headers.cookie; - let sessionId = null; - - if (cookieHeader) { - const sessionCookie = cookieHeader.split('; ').find(row => row.startsWith('sutSessionId=')); - if (sessionCookie) { - sessionId = sessionCookie.split('=')[1]; - } - } - - if (sessionId && sessions[sessionId]) { - return { sessionId, session: sessions[sessionId] }; - } - - return null; -}; - module.exports = { DUMMY_USERNAME, DUMMY_PASSWORD, sessions, delay, getBaseHtml, - generateSessionId, - checkSutAuth + generateSessionId };