auth

Main authentication module for my projects
git clone git://git.finwo.net/app/auth
Log | Files | Refs

http-app-hosts.test.js (3587B)


      1 import test from 'node:test';
      2 import assert from 'node:assert/strict';
      3 
      4 import {
      5   createHttpHarness,
      6 } from './helpers/http-harness.js';
      7 
      8 test('HTTP system app hosting', async (t) => {
      9   const harness = await createHttpHarness();
     10   const {
     11     identity,
     12     acme,
     13     app,
     14     origin,
     15     publicUrl,
     16     port,
     17     accessToken,
     18   } = harness;
     19 
     20   try {
     21     await t.test('configured static app callbacks are accepted', async () => {
     22       const admin = await accessToken(identity, {
     23         clientId: 'admin',
     24         identifier: 'admin@system.test',
     25         redirectUri: `http://admin.test:${port}/callback`,
     26       });
     27       assert.ok(admin.access_token);
     28 
     29       const account = await accessToken(identity, {
     30         clientId: 'account',
     31         identifier: 'guest@personal.test',
     32         redirectUri: `http://account.test:${port}/callback`,
     33       });
     34       assert.ok(account.access_token);
     35     });
     36 
     37     await t.test('split apps are served on their allowed hosts', async (t) => {
     38       const admin = await identity({ path: '/app/admin' });
     39       if (admin.status === 503) {
     40         t.skip('app builds are not available');
     41         return;
     42       }
     43       assert.equal(admin.status, 200);
     44       assert.match(admin.headers['content-type'], /text\/html/);
     45       assert.match(admin.text, /app-shell/);
     46 
     47       const adminRealm = await acme({ path: '/app/admin' });
     48       assert.equal(adminRealm.status, 404);
     49 
     50       const accountCanonical = await identity({ path: '/app/account' });
     51       assert.equal(accountCanonical.status, 200);
     52       assert.match(accountCanonical.text, /app-shell/);
     53 
     54       const accountRealm = await acme({ path: '/app/account' });
     55       assert.equal(accountRealm.status, 200);
     56 
     57       const accountClient = await app({ path: '/app/account' });
     58       assert.equal(accountClient.status, 200);
     59 
     60       const login = await identity({ path: '/oidc/admin/login' });
     61       assert.equal(login.status, 200);
     62       assert.match(login.text, /auth-page/);
     63 
     64       const loginRealm = await acme({ path: '/oidc/admin/login' });
     65       assert.equal(loginRealm.status, 404);
     66     });
     67 
     68     await t.test('account clients work for guests on canonical and realm hosts', async (t) => {
     69       const canonical = await identity({ path: '/oidc/account/openid-configuration' });
     70       assert.equal(canonical.status, 200);
     71       assert.equal(canonical.json.issuer, publicUrl);
     72 
     73       const realmHost = await acme({ path: '/oidc/account/openid-configuration' });
     74       assert.equal(realmHost.status, 200);
     75       assert.equal(realmHost.json.issuer, publicUrl);
     76 
     77       const clientHost = await app({ path: '/oidc/account/openid-configuration' });
     78       assert.equal(clientHost.status, 404);
     79 
     80       const account = await accessToken(acme, {
     81         clientId: 'account',
     82         identifier: 'guest@personal.test',
     83         redirectUri: `${origin('acme.localhost')}/app/account/callback`,
     84       });
     85       assert.ok(account.access_token);
     86       assert.ok(account.refresh_token);
     87 
     88       const userinfo = await acme({
     89         path: '/oidc/account/userinfo',
     90         bearer: account.access_token,
     91       });
     92       assert.equal(userinfo.status, 200);
     93       assert.equal(userinfo.json.preferred_username, 'guest');
     94 
     95       const refreshed = await acme({
     96         method: 'POST',
     97         path: '/oidc/account/token',
     98         form: {
     99           grant_type: 'refresh_token',
    100           client_id: 'account',
    101           refresh_token: account.refresh_token,
    102         },
    103       });
    104       assert.equal(refreshed.status, 200);
    105       assert.ok(refreshed.json.refresh_token);
    106     });
    107 
    108   } finally {
    109     await harness.close();
    110   }
    111 });