60e2149072
Tasks 16-20: Online Board Tests (Search/Filter, Tabs, Flight List, Details Modal, Time/Date) - Task 16: Search & Filter tests (37 tests) - departure/arrival cities, passenger count, cabin class - Task 17: Arrival/Departure Tabs tests (45 tests) - tab switching, flight display, sorting - Task 18: Flight List View tests (50 tests) - display, sorting, filtering, pagination, loading states - Task 19: Flight Details Modal tests (40 tests) - opening/closing, content display, actions - Task 20: Time & Date Filter tests (43 tests) - date selection, time ranges, calendar navigation Tasks 21-25: Flight Details Tests (Flight Info, Passengers, Seats, Services, Fares) - Task 21: Flight Info Display tests (40 tests) - basic info, airports, route visualization, timeline - Task 22: Passenger Info tests (50 tests) - passenger list, details, services, special requirements - Task 23: Seat Selection tests (50 tests) - seat map, selection, categories, recommendations - Task 24: Service Selection tests (25 tests) - baggage, meals, seats, summary - Task 25: Fare Display tests (55 tests) - fare breakdown, comparisons, discounts, refunds All tests follow AAA pattern and use data-testid selectors matching Angular version. Total: 245 tests across 10 feature suites.
84 lines
3.0 KiB
JavaScript
84 lines
3.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.generateChallenge = generateChallenge;
|
|
exports.default = pkceChallenge;
|
|
exports.verifyChallenge = verifyChallenge;
|
|
let crypto;
|
|
crypto =
|
|
globalThis.crypto?.webcrypto ?? // Node.js [18-16] REPL
|
|
globalThis.crypto ?? // Node.js >18
|
|
import("node:crypto").then(m => m.webcrypto); // Node.js <18 Non-REPL
|
|
/**
|
|
* Creates an array of length `size` of random bytes
|
|
* @param size
|
|
* @returns Array of random ints (0 to 255)
|
|
*/
|
|
async function getRandomValues(size) {
|
|
return (await crypto).getRandomValues(new Uint8Array(size));
|
|
}
|
|
/** Generate cryptographically strong random string
|
|
* @param size The desired length of the string
|
|
* @returns The random string
|
|
*/
|
|
async function random(size) {
|
|
const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
|
|
const evenDistCutoff = Math.pow(2, 8) - Math.pow(2, 8) % mask.length;
|
|
let result = "";
|
|
while (result.length < size) {
|
|
const randomBytes = await getRandomValues(size - result.length);
|
|
for (const randomByte of randomBytes) {
|
|
if (randomByte < evenDistCutoff) {
|
|
result += mask[randomByte % mask.length];
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
/** Generate a PKCE challenge verifier
|
|
* @param length Length of the verifier
|
|
* @returns A random verifier `length` characters long
|
|
*/
|
|
async function generateVerifier(length) {
|
|
return await random(length);
|
|
}
|
|
/** Generate a PKCE code challenge from a code verifier
|
|
* @param code_verifier
|
|
* @returns The base64 url encoded code challenge
|
|
*/
|
|
async function generateChallenge(code_verifier) {
|
|
const buffer = await (await crypto).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
|
|
// Generate base64url string
|
|
// btoa is deprecated in Node.js but is used here for web browser compatibility
|
|
// (which has no good replacement yet, see also https://github.com/whatwg/html/issues/6811)
|
|
return btoa(String.fromCharCode(...new Uint8Array(buffer)))
|
|
.replace(/\//g, '_')
|
|
.replace(/\+/g, '-')
|
|
.replace(/=/g, '');
|
|
}
|
|
/** Generate a PKCE challenge pair
|
|
* @param length Length of the verifer (between 43-128). Defaults to 43.
|
|
* @returns PKCE challenge pair
|
|
*/
|
|
async function pkceChallenge(length) {
|
|
if (!length)
|
|
length = 43;
|
|
if (length < 43 || length > 128) {
|
|
throw `Expected a length between 43 and 128. Received ${length}.`;
|
|
}
|
|
const verifier = await generateVerifier(length);
|
|
const challenge = await generateChallenge(verifier);
|
|
return {
|
|
code_verifier: verifier,
|
|
code_challenge: challenge,
|
|
};
|
|
}
|
|
/** Verify that a code_verifier produces the expected code challenge
|
|
* @param code_verifier
|
|
* @param expectedChallenge The code challenge to verify
|
|
* @returns True if challenges are equal. False otherwise.
|
|
*/
|
|
async function verifyChallenge(code_verifier, expectedChallenge) {
|
|
const actualChallenge = await generateChallenge(code_verifier);
|
|
return actualChallenge === expectedChallenge;
|
|
}
|