brain-memory 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,14 +11,19 @@ const crypto = require('crypto');
11
11
 
12
12
  const { createVerifier, looksLikeJwt, OidcError } = require('../lib/oidc');
13
13
  const { startMockIssuer, makeKey, sign } = require('./mock-issuer');
14
- const { client, startReferenceStore, sampleArchive } = require('../conformance/helpers');
14
+ const { client, plainFetch, startReferenceStore, sampleArchive } = require('../conformance/helpers');
15
+
16
+ // Every verifier here talks to the mock issuer through plainFetch rather than the
17
+ // global fetch, so no pooled connection outlives the test process (see
18
+ // conformance/helpers.js). The default-fetch path is covered by the connector's
19
+ // OIDC test, which runs on a newer Node.
15
20
 
16
21
  describe('ID-token verification', () => {
17
22
  let idp;
18
23
  let verifier;
19
24
  before(async () => {
20
25
  idp = await startMockIssuer();
21
- verifier = createVerifier({ issuer: idp.issuer, audience: idp.clientId });
26
+ verifier = createVerifier({ issuer: idp.issuer, audience: idp.clientId, fetch: plainFetch });
22
27
  });
23
28
  after(() => idp.close());
24
29
 
@@ -113,7 +118,7 @@ describe('issuer safeguards', () => {
113
118
  const idp = await startMockIssuer();
114
119
  try {
115
120
  const fetchLying = async (url) => {
116
- const res = await fetch(url);
121
+ const res = await plainFetch(url);
117
122
  const body = await res.json();
118
123
  if (body.issuer) body.issuer = 'https://somewhere-else.example';
119
124
  return { ok: true, status: 200, json: async () => body };
@@ -132,22 +137,22 @@ describe('allow-lists', () => {
132
137
  after(() => idp.close());
133
138
 
134
139
  it('admits a verified address in an allowed domain, and nobody else', async () => {
135
- const v = createVerifier({ issuer: idp.issuer, audience: idp.clientId, allowedDomains: 'example.org, other.test' });
140
+ const v = createVerifier({ issuer: idp.issuer, audience: idp.clientId, allowedDomains: 'example.org, other.test', fetch: plainFetch });
136
141
  await v.verify(idp.idToken());
137
142
  await assert.rejects(v.verify(idp.idToken({ email: 'mallory@evil.test' })), /allow-list/);
138
143
  await assert.rejects(v.verify(idp.idToken({ email: 'x@notexample.org' })), /allow-list/);
139
144
  });
140
145
 
141
146
  it('ignores an address the issuer has not verified', async () => {
142
- const v = createVerifier({ issuer: idp.issuer, audience: idp.clientId, allowedDomains: 'example.org' });
147
+ const v = createVerifier({ issuer: idp.issuer, audience: idp.clientId, allowedDomains: 'example.org', fetch: plainFetch });
143
148
  await assert.rejects(v.verify(idp.idToken({ email_verified: false })), /allow-list/);
144
149
  await assert.rejects(v.verify(idp.idToken({ email_verified: undefined })), /allow-list/);
145
150
  });
146
151
 
147
152
  it('admits by Google hosted-domain claim and by exact address', async () => {
148
- const byHd = createVerifier({ issuer: idp.issuer, audience: idp.clientId, allowedDomains: 'corp.test' });
153
+ const byHd = createVerifier({ issuer: idp.issuer, audience: idp.clientId, allowedDomains: 'corp.test', fetch: plainFetch });
149
154
  await byHd.verify(idp.idToken({ hd: 'corp.test', email: 'someone@gmail.test' }));
150
- const byEmail = createVerifier({ issuer: idp.issuer, audience: idp.clientId, allowedEmails: ['Alice@Example.org'] });
155
+ const byEmail = createVerifier({ issuer: idp.issuer, audience: idp.clientId, allowedEmails: ['Alice@Example.org'], fetch: plainFetch });
151
156
  await byEmail.verify(idp.idToken());
152
157
  await assert.rejects(byEmail.verify(idp.idToken({ email: 'bob@example.org' })), /allow-list/);
153
158
  });
@@ -158,7 +163,7 @@ describe('the store accepts ID tokens', () => {
158
163
  let ref;
159
164
  before(async () => {
160
165
  idp = await startMockIssuer();
161
- ref = await startReferenceStore({ oidc: { issuer: idp.issuer, audience: idp.clientId } });
166
+ ref = await startReferenceStore({ oidc: { issuer: idp.issuer, audience: idp.clientId, fetch: plainFetch } });
162
167
  });
163
168
  after(async () => { await ref.close(); await idp.close(); });
164
169