Fix Kiro password field detection

This commit is contained in:
QLHazyCoder
2026-05-20 00:28:06 +08:00
parent 4687d07e2d
commit f165b80597
2 changed files with 311 additions and 26 deletions
+142 -2
View File
@@ -5,7 +5,86 @@ const vm = require('node:vm');
const source = fs.readFileSync('content/kiro/register-page.js', 'utf8');
function createTextNode(textContent = '') {
return { textContent };
}
function createInputElement({
id = '',
type = 'text',
placeholder = '',
label = '',
value = '',
} = {}) {
const attributes = {
id,
type,
placeholder,
autocomplete: 'off',
};
return {
tagName: 'INPUT',
id,
type,
value,
labels: label ? [createTextNode(label)] : [],
disabled: false,
readOnly: false,
form: null,
getAttribute(name) {
return attributes[name] || '';
},
getBoundingClientRect() {
return { width: 455, height: 32 };
},
closest(selector) {
if (selector === 'label') {
return null;
}
return null;
},
};
}
function createButtonElement({ text = 'Continue', testId = 'test-primary-button' } = {}) {
return {
tagName: 'BUTTON',
textContent: text,
value: '',
disabled: false,
form: null,
getAttribute(name) {
if (name === 'data-testid') return testId;
if (name === 'type') return 'submit';
return '';
},
getBoundingClientRect() {
return { width: 455, height: 32 };
},
closest() {
return null;
},
};
}
function createHarness({ href, hostname, title = '', bodyText = '' }) {
return createDomHarness({ href, hostname, title, bodyText });
}
function createDomHarness({
href,
hostname,
title = '',
bodyText = '',
inputs = [],
buttons = [],
} = {}) {
const elementsById = new Map();
for (const element of [...inputs, ...buttons]) {
if (element.id) {
elementsById.set(element.id, element);
}
}
const context = {
console: { log() {}, warn() {}, error() {}, info() {} },
location: { href, hostname },
@@ -20,10 +99,22 @@ function createHarness({ href, hostname, title = '', bodyText = '' }) {
},
setAttribute() {},
},
getElementById(id) {
return elementsById.get(id) || null;
},
querySelector() {
return null;
},
querySelectorAll() {
querySelectorAll(selector) {
if (String(selector).startsWith('label[for=')) {
return [];
}
if (String(selector).trim().startsWith('input')) {
return inputs;
}
if (String(selector).includes('button') || String(selector).includes('[role="button"]')) {
return buttons;
}
return [];
},
},
@@ -37,14 +128,18 @@ function createHarness({ href, hostname, title = '', bodyText = '' }) {
sleep() {
return Promise.resolve();
},
fillInput() {},
fillInput(element, value) {
element.value = value;
},
MouseEvent: class {},
PointerEvent: class {},
KeyboardEvent: class {},
Event: class {},
};
context.window = context;
context.globalThis = context;
context.window.getComputedStyle = () => ({ display: 'block', visibility: 'visible' });
context.CSS = { escape: (value) => String(value) };
vm.createContext(context);
vm.runInContext(source, context);
@@ -105,3 +200,48 @@ test('kiro register content extracts signed-in account email from Kiro account p
assert.equal(detected.accountEmail, 'scrap-aged-quirk@duck.com');
assert.equal(detected.email, 'scrap-aged-quirk@duck.com');
});
test('kiro register content fills primary and confirm password fields separately', async () => {
const passwordInput = createInputElement({
id: 'formField15-1779204320095-7559',
type: 'text',
placeholder: 'Enter password',
label: '\u5bc6\u7801',
});
const confirmPasswordInput = createInputElement({
id: 'formField16-1779204320096-1309',
type: 'text',
placeholder: 'Re-enter password',
label: '\u786e\u8ba4\u5bc6\u7801',
});
const checkboxInput = createInputElement({
id: '17-1779204320097-4334',
type: 'checkbox',
label: '\u663e\u793a\u5bc6\u7801',
value: 'on',
});
const continueButton = createButtonElement();
const clicks = [];
const harness = createDomHarness({
href: 'https://us-east-1.signin.aws/platform/d-9067642ac7/signup',
hostname: 'us-east-1.signin.aws',
title: 'Amazon Web Services',
bodyText: 'Create your password',
inputs: [passwordInput, confirmPasswordInput, checkboxInput],
buttons: [continueButton],
});
harness.simulateClick = (element) => clicks.push(element);
const detected = harness.detectKiroRegisterPageState();
assert.equal(detected.state, 'password_page');
assert.equal(detected.passwordInput, passwordInput);
assert.equal(detected.confirmPasswordInput, confirmPasswordInput);
const result = await harness.submitKiroPassword({ password: 'mdy8U9_rzqhw6D' });
assert.equal(result.state, 'password_submitted');
assert.equal(passwordInput.value, 'mdy8U9_rzqhw6D');
assert.equal(confirmPasswordInput.value, 'mdy8U9_rzqhw6D');
assert.deepEqual(clicks, [continueButton]);
});