aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/test_password_options.mjs (4095B)


      1 import assert from 'node:assert/strict';
      2 import fs from 'node:fs/promises';
      3 import {createRequire} from 'node:module';
      4 import {GameTest} from './game_test.mjs';
      5 
      6 const {chromium} = createRequire(import.meta.url)('playwright');
      7 const [url, output] = process.argv.slice(2);
      8 await fs.mkdir(output, {recursive: true});
      9 const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
     10   args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage']});
     11 try {
     12   const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     13   const page = await context.newPage();
     14   const game = await GameTest.attach(page);
     15   await page.goto(url);
     16   await game.ready();
     17   await page.keyboard.press('Control+Alt+M');
     18   await page.waitForFunction(() => !document.querySelector('#account-choices').disabled);
     19   assert.equal(await page.locator('#password-button').isVisible(), false);
     20 
     21   // Save the current visitor through Options and open its password form with real input.
     22   await page.locator('#claim-button').click();
     23   await page.locator('#account-name').fill('Passwordtest');
     24   for (const password of ['', 'abcd']) {
     25     await page.locator('#account-password').fill(password);
     26     await page.locator('#account-submit').click();
     27     assert.equal(await page.locator('#account-password').evaluate(input => input.checkValidity()), false);
     28     assert.equal((await (await context.request.get(url + 'browser-account')).json()).adopted, false);
     29   }
     30   await page.locator('#account-password').fill('original password');
     31   await Promise.all([page.waitForEvent('load'), page.locator('#account-submit').click()]);
     32   await game.ready();
     33   const stream = game.worldStream;
     34   const navigation = game.navigation;
     35   const actor = game.local().id;
     36   const cookie = (await context.cookies()).find(value => value.name === 'ao_client').value;
     37   await page.keyboard.press('Control+Alt+M');
     38   await page.locator('#password-button').click();
     39   assert.equal(await page.locator('#account-name').isVisible(), false);
     40   assert.equal(await page.locator('#account-name').isDisabled(), true);
     41   assert.equal(await page.locator('#account-description').isVisible(), false);
     42   assert.equal(await page.getByLabel('New password', {exact: true}).getAttribute('autocomplete'), 'new-password');
     43   for (const password of ['', 'abcd']) {
     44     await page.locator('#account-password').fill(password);
     45     await page.locator('#account-submit').click();
     46     assert.equal(await page.locator('#account-password').evaluate(input => input.checkValidity()), false);
     47     assert.equal(await page.locator('#account-form').isVisible(), true);
     48   }
     49   await page.locator('#account-back').click();
     50 
     51   for (const password of ['updated password', 'valid']) {
     52     await page.locator('#password-button').click();
     53     await page.getByLabel('New password', {exact: true}).fill(password);
     54     const saved = page.waitForResponse(response => response.url().endsWith('/browser-account/password'));
     55     await page.locator('#account-submit').click();
     56     assert.equal((await saved).status(), 204);
     57     await page.getByRole('status').filter({hasText: 'Password changed.'}).waitFor();
     58     assert.equal(await page.locator('#account-form').isVisible(), false);
     59     assert.equal(await page.locator('#account-password').inputValue(), '');
     60     assert.equal((await context.cookies()).find(value => value.name === 'ao_client').value, cookie);
     61     assert.equal(game.worldStream, stream);
     62     assert.equal(game.navigation, navigation);
     63   }
     64   await page.screenshot({path: output + '/password-saved.png'});
     65   await page.locator('#player-menu').getByRole('button', {name: 'Close', exact: true}).click();
     66   await game.ready();
     67   assert.equal(game.local().id, actor);
     68   assert.equal(game.worldStream, stream);
     69   assert.equal(game.navigation, navigation);
     70   assert.deepEqual(game.errors, []);
     71   await game.save(output + '/game');
     72   console.log('PASS: visitor eligibility, saved player password form, Back, long and minimum-length passwords, unchanged browser credential and live game stream');
     73 } finally {
     74   await browser.close();
     75 }