Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cookie Login #259

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions agent/createtest/createtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions agent/createtest/shorter/createtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions agent/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ config:
headers:
TestTime: '\${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions common/test/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions common/test/basicheadersall.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions common/test/basicnopeakload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions common/test/basicwithenv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
test: ${test}
general:
bucket_size: 1m
Expand Down
3 changes: 1 addition & 2 deletions common/test/basicwithfiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions common/test/basicwithvars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
6 changes: 2 additions & 4 deletions controller/components/YamlViewer/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ client:
headers:
TestTime: '\${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down Expand Up @@ -54,8 +53,7 @@ client:
headers:
TestTime: '\${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
2 changes: 1 addition & 1 deletion controller/components/YamlWriterForm/writeyaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const createYamlJson = ({ urls, patterns, vars, providers, loggers }: Omi
// Default config
myYaml.config = {};
myYaml.config.client = {};
myYaml.config.client.headers = {"User-Agent": "FS-QA-SystemTest"};
myYaml.config.client.headers = {"User-Agent": "PewPew Performance Load Test"};
// eslint-disable-next-line camelcase
myYaml.config.general = {bucket_size: "1m", log_provider_stats: "1m"};

Expand Down
27 changes: 16 additions & 11 deletions controller/pages/api/util/authserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import {
} from "openid-client";
import { GetServerSidePropsContext, NextApiRequest, NextApiResponse } from "next";
import { LogLevel, log, logger } from "@fs/ppaas-common";
import { parse as cookieParse, serialize as cookieSerialize } from "cookie";
import { formatPageHref, getHostUrl } from "./clientutil";
import { IncomingMessage } from "http";
import cookie from "cookie";
import { createErrorResponse } from "./util";
import { getClientSecretOpenId } from "./secrets";
import nextCookie from "next-cookies";
Expand Down Expand Up @@ -265,7 +265,7 @@ function getTokenFromQueryOrHeader (req: NextApiRequest, headerName: string = AU
log("header token: " + JSON.stringify(token), LogLevel.DEBUG);
}
if (!token && req.headers.cookie && !Array.isArray(req.headers.cookie)) {
const cookies = cookie.parse(req.headers.cookie);
const cookies = cookieParse(req.headers.cookie);
token = cookies[headerName];
log("cookie token: " + JSON.stringify(token), LogLevel.DEBUG);
}
Expand Down Expand Up @@ -374,7 +374,7 @@ export async function authApi (req: NextApiRequest, res: NextApiResponse, requir
// If we don't have permissions or the permissions are not greater than requiredPermissions
if (authPermissions.authPermission < requiredPermissions) {
log("User was not authorized for api", LogLevel.WARN, { token, method: req.method, url: req.url });
res.status(403).json({ message: "User is not authorized for this api. If you think this is an error, please contact the PerformanceQA team." });
res.status(403).json({ message: "User is not authorized for this api. If you think this is an error, please contact the Performance team." });
return undefined;
}

Expand Down Expand Up @@ -428,15 +428,20 @@ export function setCookies (
log(`Set cookie to ${token} on ${domain}`, LogLevel.DEBUG);
// server side
const oneDay: number = 60 * 60 * 24;
const cookies: string[] = [cookie.serialize(AUTH_COOKIE_NAME, token, { domain, path, maxAge: oneDay * COOKIE_DURATION_DAYS })];
if (refreshToken) {
cookies.push(cookie.serialize(REFRESH_COOKIE_NAME, refreshToken, { domain, path, maxAge: oneDay * REFRESH_COOKIE_DURATION_DAYS }));
}
if (hintToken) {
cookies.push(cookie.serialize(HINT_COOKIE_NAME, hintToken, { domain, path, maxAge: oneDay * COOKIE_DURATION_DAYS }));
try {
const cookies: string[] = [cookieSerialize(AUTH_COOKIE_NAME, token, { domain, path, maxAge: oneDay * COOKIE_DURATION_DAYS })];
if (refreshToken) {
cookies.push(cookieSerialize(REFRESH_COOKIE_NAME, refreshToken, { domain, path, maxAge: oneDay * REFRESH_COOKIE_DURATION_DAYS }));
}
if (hintToken) {
cookies.push(cookieSerialize(HINT_COOKIE_NAME, hintToken, { domain, path, maxAge: oneDay * COOKIE_DURATION_DAYS }));
}
// Set the cookie and then redirect
ctx.res.setHeader("Set-Cookie", cookies);
} catch (error: unknown) {
log("Error setting cookies in header", LogLevel.WARN, error, { token: token !== undefined, refreshToken: refreshToken !== undefined, hintToken: hintToken !== undefined });
throw error;
}
// Set the cookie and then redirect
ctx.res.setHeader("Set-Cookie", cookies);
}

function getTokenFromCookieOrHeader (ctx: GetServerSidePropsContext, cookieName: string = AUTH_COOKIE_NAME, headerName?: string): string | undefined {
Expand Down
2 changes: 1 addition & 1 deletion controller/pages/api/util/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function createSecret (secretKeyName: string, value: string | Buffe
try {
const input: CreateSecretCommandInput = {
Name: secretKeyName,
Description: "Testing Secrets Manager for PerformanceQA/Pewpew",
Description: "Testing Secrets Manager for Performance/Pewpew",
SecretString: typeof value === "string" ? value : undefined,
SecretBinary: typeof value !== "string" ? new Uint8Array(value.buffer) : undefined
};
Expand Down
6 changes: 3 additions & 3 deletions controller/pages/api/util/testmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export async function validateYamlfile (
if (bypassParser) {
if (authPermissions.authPermission < AuthPermission.Admin) {
log("Unauthorized User attempted to bypass the config parser.", LogLevel.WARN, { yamlFile, userId: authPermissions.userId });
return { json: { message: "User is not authorized to bypass the config parser. If you think this is an error, please contact the PerformanceQA team." }, status: 403 };
return { json: { message: "User is not authorized to bypass the config parser. If you think this is an error, please contact the Performance team." }, status: 403 };
}
} else {
// bypassPaser is false or undefined, run the parser
Expand Down Expand Up @@ -1167,7 +1167,7 @@ export abstract class TestManager {
} else if (PEWPEW_BINARY_EXECUTABLE_NAMES.includes(file.originalFilename)) {
if (authPermission < AuthPermission.Admin) {
log("Unauthorized User attempted to use custom pewpew binary.", LogLevel.WARN, { yamlFile });
return { json: { message: "User is not authorized to use custom pewpew binaries. If you think this is an error, please contact the PerformanceQA team." }, status: 403 };
return { json: { message: "User is not authorized to use custom pewpew binaries. If you think this is an error, please contact the Performance team." }, status: 403 };
}
log("Authorized user uploaded custom binary.", LogLevel.INFO, { yamlFile });
additionalFileNames.push(file.originalFilename);
Expand Down Expand Up @@ -1511,7 +1511,7 @@ export abstract class TestManager {
if (bypassParser) {
if (authPermission < AuthPermission.Admin) {
log("Unauthorized User attempted to bypass the config parser.", LogLevel.WARN, { yamlFile });
return { json: { message: "User is not authorized to bypass the config parser. If you think this is an error, please contact the PerformanceQA team." }, status: 403 };
return { json: { message: "User is not authorized to bypass the config parser. If you think this is an error, please contact the Performance team." }, status: 403 };
}
} else {
// Read in the actual variables so we can inject them and make sure it's valid.
Expand Down
3 changes: 1 addition & 2 deletions controller/test/basicheadersall.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions controller/test/basicnopeakload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions controller/test/basicwithfiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down
3 changes: 1 addition & 2 deletions controller/test/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ config:
headers:
TestTime: '${epoch("ms")}'
Accept: application/json
FS-User-Agent-Chain: PPAAS-Agent-Performance Test
User-Agent: FS-QA-SystemTest PPAAS Agent Performance Test
User-Agent: PPAAS Agent Performance Test
general:
bucket_size: 1m
log_provider_stats: 1m
Expand Down