Merge branch 'dev' of https://github.com/QLHazyCoder/codex-oauth-automation-extension into dev
This commit is contained in:
@@ -2099,6 +2099,98 @@ test('phone verification helper completes add-phone flow, clears current activat
|
||||
assert.deepStrictEqual(actions, ['getPrices', 'getNumber', 'getStatus', 'setStatus']);
|
||||
});
|
||||
|
||||
test('phone verification helper forwards signup profile payload when submitting the phone verification code', async () => {
|
||||
let currentState = {
|
||||
heroSmsApiKey: 'demo-key',
|
||||
verificationResendCount: 0,
|
||||
currentPhoneActivation: null,
|
||||
reusablePhoneActivation: null,
|
||||
};
|
||||
const submittedPayloads = [];
|
||||
|
||||
const helpers = api.createPhoneVerificationHelpers({
|
||||
addLog: async () => {},
|
||||
ensureStep8SignupPageReady: async () => {},
|
||||
fetchImpl: async (url) => {
|
||||
const parsedUrl = new URL(url);
|
||||
const action = parsedUrl.searchParams.get('action');
|
||||
if (action === 'getPrices') {
|
||||
return {
|
||||
ok: true,
|
||||
text: async () => buildHeroSmsPricesPayload(),
|
||||
};
|
||||
}
|
||||
if (action === 'getNumber') {
|
||||
return {
|
||||
ok: true,
|
||||
text: async () => 'ACCESS_NUMBER:123456:66959916439',
|
||||
};
|
||||
}
|
||||
if (action === 'getStatus') {
|
||||
return {
|
||||
ok: true,
|
||||
text: async () => 'STATUS_OK:654321',
|
||||
};
|
||||
}
|
||||
if (action === 'setStatus') {
|
||||
return {
|
||||
ok: true,
|
||||
text: async () => 'ACCESS_ACTIVATION',
|
||||
};
|
||||
}
|
||||
throw new Error(`Unexpected HeroSMS action: ${action}`);
|
||||
},
|
||||
generateRandomBirthday: () => ({ year: 2003, month: 6, day: 19 }),
|
||||
generateRandomName: () => ({ firstName: 'Ada', lastName: 'Lovelace' }),
|
||||
getOAuthFlowStepTimeoutMs: async (defaultTimeoutMs) => defaultTimeoutMs,
|
||||
getState: async () => ({ ...currentState }),
|
||||
sendToContentScriptResilient: async (_source, message) => {
|
||||
if (message.type === 'SUBMIT_PHONE_NUMBER') {
|
||||
return {
|
||||
phoneVerificationPage: true,
|
||||
url: 'https://auth.openai.com/phone-verification',
|
||||
};
|
||||
}
|
||||
if (message.type === 'SUBMIT_PHONE_VERIFICATION_CODE') {
|
||||
submittedPayloads.push(message.payload);
|
||||
return {
|
||||
success: true,
|
||||
consentReady: true,
|
||||
url: 'https://auth.openai.com/authorize',
|
||||
};
|
||||
}
|
||||
throw new Error(`Unexpected content-script message: ${message.type}`);
|
||||
},
|
||||
setState: async (updates) => {
|
||||
currentState = { ...currentState, ...updates };
|
||||
},
|
||||
sleepWithStop: async () => {},
|
||||
throwIfStopped: () => {},
|
||||
});
|
||||
|
||||
const result = await helpers.completePhoneVerificationFlow(1, {
|
||||
addPhonePage: true,
|
||||
phoneVerificationPage: false,
|
||||
url: 'https://auth.openai.com/add-phone',
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(result, {
|
||||
success: true,
|
||||
consentReady: true,
|
||||
url: 'https://auth.openai.com/authorize',
|
||||
});
|
||||
assert.deepStrictEqual(submittedPayloads, [{
|
||||
code: '654321',
|
||||
signupProfile: {
|
||||
firstName: 'Ada',
|
||||
lastName: 'Lovelace',
|
||||
year: 2003,
|
||||
month: 6,
|
||||
day: 19,
|
||||
},
|
||||
}]);
|
||||
});
|
||||
|
||||
test('phone verification helper uses the configured HeroSMS country for both number acquisition and add-phone submission', async () => {
|
||||
const requests = [];
|
||||
const submittedPayloads = [];
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const source = fs.readFileSync('content/signup-page.js', 'utf8');
|
||||
|
||||
function extractFunction(name) {
|
||||
const markers = [`async function ${name}(`, `function ${name}(`];
|
||||
const start = markers
|
||||
.map((marker) => source.indexOf(marker))
|
||||
.find((index) => index >= 0);
|
||||
if (start < 0) {
|
||||
throw new Error(`missing function ${name}`);
|
||||
}
|
||||
|
||||
let parenDepth = 0;
|
||||
let signatureEnded = false;
|
||||
let braceStart = -1;
|
||||
for (let i = start; i < source.length; i += 1) {
|
||||
const ch = source[i];
|
||||
if (ch === '(') {
|
||||
parenDepth += 1;
|
||||
} else if (ch === ')') {
|
||||
parenDepth -= 1;
|
||||
if (parenDepth === 0) {
|
||||
signatureEnded = true;
|
||||
}
|
||||
} else if (ch === '{' && signatureEnded) {
|
||||
braceStart = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (braceStart < 0) {
|
||||
throw new Error(`missing body for function ${name}`);
|
||||
}
|
||||
|
||||
let depth = 0;
|
||||
let end = braceStart;
|
||||
for (; end < source.length; end += 1) {
|
||||
const ch = source[end];
|
||||
if (ch === '{') depth += 1;
|
||||
if (ch === '}') {
|
||||
depth -= 1;
|
||||
if (depth === 0) {
|
||||
end += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return source.slice(start, end);
|
||||
}
|
||||
|
||||
test('step 9 auto-fills profile when phone verification lands on signup profile page', async () => {
|
||||
const api = new Function(`
|
||||
const profilePayloads = [];
|
||||
const logs = [];
|
||||
let consentReady = false;
|
||||
|
||||
const location = {
|
||||
href: 'https://auth.openai.com/create-account/profile',
|
||||
};
|
||||
|
||||
function log(message, level = 'info') {
|
||||
logs.push({ message, level });
|
||||
}
|
||||
|
||||
function isStep5Ready() {
|
||||
return !consentReady;
|
||||
}
|
||||
|
||||
function isSignupProfilePageUrl(url = location.href) {
|
||||
return /\\/create-account\\/profile(?:[/?#]|$)/i.test(String(url || ''));
|
||||
}
|
||||
|
||||
function isStep8Ready() {
|
||||
return consentReady;
|
||||
}
|
||||
|
||||
function isAddPhonePageReady() {
|
||||
return false;
|
||||
}
|
||||
|
||||
async function sleep() {}
|
||||
function throwIfStopped() {}
|
||||
|
||||
const phoneAuthHelpers = {
|
||||
async submitPhoneVerificationCode() {
|
||||
return {
|
||||
success: true,
|
||||
assumed: true,
|
||||
url: location.href,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
async function step5_fillNameBirthday(payload) {
|
||||
profilePayloads.push(payload);
|
||||
consentReady = true;
|
||||
location.href = 'https://auth.openai.com/authorize';
|
||||
return {
|
||||
skippedPostSubmitCheck: true,
|
||||
directProceedToStep6: true,
|
||||
};
|
||||
}
|
||||
|
||||
${extractFunction('waitForPhoneVerificationProfileCompletion')}
|
||||
${extractFunction('submitPhoneVerificationCodeWithProfileFallback')}
|
||||
|
||||
return {
|
||||
run(payload) {
|
||||
return submitPhoneVerificationCodeWithProfileFallback(payload);
|
||||
},
|
||||
snapshot() {
|
||||
return {
|
||||
profilePayloads,
|
||||
logs,
|
||||
};
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
const result = await api.run({
|
||||
code: '123456',
|
||||
signupProfile: {
|
||||
firstName: 'Ada',
|
||||
lastName: 'Lovelace',
|
||||
year: 2003,
|
||||
month: 6,
|
||||
day: 19,
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(result, {
|
||||
success: true,
|
||||
consentReady: true,
|
||||
profileCompleted: true,
|
||||
url: 'https://auth.openai.com/authorize',
|
||||
});
|
||||
assert.deepStrictEqual(api.snapshot().profilePayloads, [{
|
||||
firstName: 'Ada',
|
||||
lastName: 'Lovelace',
|
||||
year: 2003,
|
||||
month: 6,
|
||||
day: 19,
|
||||
}]);
|
||||
});
|
||||
|
||||
test('step 9 leaves the existing consent flow untouched when no profile page appears', async () => {
|
||||
const api = new Function(`
|
||||
const profilePayloads = [];
|
||||
const location = {
|
||||
href: 'https://auth.openai.com/authorize',
|
||||
};
|
||||
|
||||
function isStep5Ready() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isSignupProfilePageUrl(url = location.href) {
|
||||
return /\\/create-account\\/profile(?:[/?#]|$)/i.test(String(url || ''));
|
||||
}
|
||||
|
||||
function isStep8Ready() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function isAddPhonePageReady() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function throwIfStopped() {}
|
||||
async function sleep() {}
|
||||
|
||||
const phoneAuthHelpers = {
|
||||
async submitPhoneVerificationCode() {
|
||||
return {
|
||||
success: true,
|
||||
consentReady: true,
|
||||
url: location.href,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
async function step5_fillNameBirthday(payload) {
|
||||
profilePayloads.push(payload);
|
||||
}
|
||||
|
||||
${extractFunction('waitForPhoneVerificationProfileCompletion')}
|
||||
${extractFunction('submitPhoneVerificationCodeWithProfileFallback')}
|
||||
|
||||
return {
|
||||
run(payload) {
|
||||
return submitPhoneVerificationCodeWithProfileFallback(payload);
|
||||
},
|
||||
snapshot() {
|
||||
return {
|
||||
profilePayloads,
|
||||
};
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
const result = await api.run({
|
||||
code: '123456',
|
||||
signupProfile: {
|
||||
firstName: 'Ada',
|
||||
lastName: 'Lovelace',
|
||||
year: 2003,
|
||||
month: 6,
|
||||
day: 19,
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(result, {
|
||||
success: true,
|
||||
consentReady: true,
|
||||
url: 'https://auth.openai.com/authorize',
|
||||
});
|
||||
assert.deepStrictEqual(api.snapshot().profilePayloads, []);
|
||||
});
|
||||
Reference in New Issue
Block a user