| 1 | export class StubAuth |
| 2 | { |
| 3 | constructor () |
| 4 | { |
| 5 | this.sessions = new Set(); |
| 6 | } |
| 7 | |
| 8 | claimIdentity () |
| 9 | { |
| 10 | const taken = new Set(); |
| 11 | for (const session of this.sessions) |
| 12 | { |
| 13 | const match = /^admin-(\d+)$/.exec(session.authSubject); |
| 14 | if (match) |
| 15 | { taken.add(Number(match[1])); } |
| 16 | } |
| 17 | |
| 18 | let n = this.sessions.size + 1; |
| 19 | while (taken.has(n)) |
| 20 | { n += 1; } |
| 21 | |
| 22 | return { |
| 23 | authSubject: `admin-${n}`, |
| 24 | isAdmin: true, |
| 25 | email: null, |
| 26 | username: `admin-${n}`, |
| 27 | accessToken: null, |
| 28 | stub: true |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | async authenticateRequest (_req) |
| 33 | { |
| 34 | return this.claimIdentity(); |
| 35 | } |
| 36 | |
| 37 | async statusFromRequest (_req) |
| 38 | { |
| 39 | const identity = this.claimIdentity(); |
| 40 | return { |
| 41 | authenticated: true, |
| 42 | authSubject: identity.authSubject, |
| 43 | username: identity.username, |
| 44 | email: identity.email, |
| 45 | stub: true |
| 46 | }; |
| 47 | } |
| 48 | |
| 49 | register (session) |
| 50 | { |
| 51 | this.sessions.add(session); |
| 52 | } |
| 53 | |
| 54 | release (session) |
| 55 | { |
| 56 | this.sessions.delete(session); |
| 57 | } |
| 58 | |
| 59 | startSessionMaintenance (_session) |
| 60 | { |
| 61 | // no-op |
| 62 | } |
| 63 | } |