Skip to content

Commit f9d7321

Browse files
committed
fix test compilation issues
1 parent 6bf9f78 commit f9d7321

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

test/unit/middleware/withAuthorizedSpace.spec.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ const createLocator = (expectedDigest, locateResponse) => ({
7878
}
7979
})
8080

81-
const gatewayIdentity = (await ed25519.Signer.generate()).withDID(
81+
const gatewaySigner = (await ed25519.Signer.generate()).signer
82+
const gatewayIdentity = gatewaySigner.withDID(
8283
'did:web:test.w3s.link'
8384
)
8485

@@ -134,7 +135,9 @@ describe('withAuthorizedSpace', async () => {
134135
nb: { token: 'a1b2c3' }
135136
})
136137
]),
137-
gatewayIdentity
138+
delegationProofs: [],
139+
gatewaySigner,
140+
gatewayIdentity,
138141
}
139142
)
140143

@@ -178,6 +181,8 @@ describe('withAuthorizedSpace', async () => {
178181
nb: { token: null }
179182
})
180183
]),
184+
delegationProofs: [],
185+
gatewaySigner,
181186
gatewayIdentity
182187
}
183188
)
@@ -224,6 +229,8 @@ describe('withAuthorizedSpace', async () => {
224229
nb: { token: 'a1b2c3' }
225230
})
226231
]),
232+
delegationProofs: [],
233+
gatewaySigner,
227234
gatewayIdentity
228235
}
229236
)
@@ -288,7 +295,7 @@ describe('withAuthorizedSpace', async () => {
288295
const response1 = await withAuthorizedSpace(innerHandler)(
289296
request,
290297
{},
291-
{ ...ctx, authToken: 'space1-token' }
298+
{ ...ctx, authToken: 'space1-token', delegationProofs: [], gatewaySigner }
292299
)
293300

294301
expect(await response1.json()).to.deep.equal({
@@ -302,7 +309,7 @@ describe('withAuthorizedSpace', async () => {
302309
withAuthorizedSpace(sinon.fake(innerHandler))(
303310
request,
304311
{},
305-
{ ...ctx, authToken: 'space2-token' }
312+
{ ...ctx, authToken: 'space2-token', delegationProofs: [], gatewaySigner }
306313
)
307314
)
308315

@@ -314,7 +321,7 @@ describe('withAuthorizedSpace', async () => {
314321
const response3 = await withAuthorizedSpace(innerHandler)(
315322
request,
316323
{},
317-
{ ...ctx, authToken: 'space3-token' }
324+
{ ...ctx, authToken: 'space3-token', delegationProofs: [], gatewaySigner }
318325
)
319326

320327
expect(await response3.json()).to.deep.equal({
@@ -351,7 +358,7 @@ describe('withAuthorizedSpace', async () => {
351358
const responseWithoutToken = await withAuthorizedSpace(innerHandler)(
352359
request,
353360
{},
354-
{ ...ctx, authToken: null }
361+
{ ...ctx, authToken: null, delegationProofs: [], gatewaySigner }
355362
)
356363

357364
expect(await responseWithoutToken.json()).to.deep.equal({
@@ -363,7 +370,7 @@ describe('withAuthorizedSpace', async () => {
363370

364371
const ih = sinon.fake(innerHandler)
365372
const errorWithToken = await rejection(
366-
withAuthorizedSpace(ih)(request, {}, { ...ctx, authToken: 'a1b2c3' })
373+
withAuthorizedSpace(ih)(request, {}, { ...ctx, authToken: 'a1b2c3', delegationProofs: [], gatewaySigner })
367374
)
368375

369376
expect(ih.notCalled).to.be.true
@@ -400,6 +407,8 @@ describe('withAuthorizedSpace', async () => {
400407
nb: { token: 'a1b2c3' }
401408
})
402409
]),
410+
delegationProofs: [],
411+
gatewaySigner,
403412
gatewayIdentity
404413
}
405414
)
@@ -444,6 +453,8 @@ describe('withAuthorizedSpace', async () => {
444453
nb: { token: 'a1b2c3' }
445454
})
446455
]),
456+
delegationProofs: [],
457+
gatewaySigner,
447458
gatewayIdentity
448459
}
449460
)
@@ -487,6 +498,8 @@ describe('withAuthorizedSpace', async () => {
487498
nb: { token: 'a1b2c3' }
488499
})
489500
]),
501+
delegationProofs: [],
502+
gatewaySigner,
490503
gatewayIdentity
491504
}
492505
)
@@ -532,7 +545,7 @@ describe('withAuthorizedSpace', async () => {
532545

533546
const ih = sinon.fake(innerHandler)
534547
const error = await rejection(
535-
withAuthorizedSpace(ih)(request, {}, { ...ctx, authToken: 'a1b2c3' })
548+
withAuthorizedSpace(ih)(request, {}, { ...ctx, authToken: 'a1b2c3', delegationProofs: [], gatewaySigner })
536549
)
537550

538551
expect(ih.notCalled).to.be.true

test/unit/middleware/withEgressTracker.spec.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { CID } from 'multiformats'
1111
import { withEgressTracker } from '../../../src/middleware/withEgressTracker.js'
1212
import { Builder, toBlobKey } from '../../helpers/builder.js'
1313
import { CARReaderStream } from 'carstream'
14+
import { SpaceDID } from '@web3-storage/capabilities/utils'
15+
import { ed25519 } from '@ucanto/principal'
1416

1517
/**
1618
* @typedef {import('../../../src/middleware/withEgressTracker.types.js').Environment} EgressTrackerEnvironment
@@ -21,7 +23,7 @@ const env =
2123
/** @satisfies {EgressTrackerEnvironment} */
2224
({
2325
DEBUG: 'true',
24-
FF_EGRESS_TRACKER_ENABLED: 'true'
26+
FF_EGRESS_TRACKER_ENABLED: 'true',
2527
})
2628

2729
const recordEgressMock = sinon.fake()
@@ -31,26 +33,33 @@ const recordEgressMock = sinon.fake()
3133
*
3234
* @returns {import('../../../src/middleware/withEgressClient.types.js').EgressClient}
3335
*/
34-
const UCantoClient = () => {
35-
if (process.env.DEBUG) {
36-
console.log('[mock] UCantoClient created')
36+
const EgressClient = () => {
37+
if (process.env.DEBUG === 'true') {
38+
console.log('[mock] EgressClient created')
3739
}
3840

3941
return {
4042
record: recordEgressMock,
41-
getTokenMetadata: sinon.fake()
4243
}
4344
}
45+
const gatewaySigner = (await ed25519.Signer.generate()).signer
46+
const gatewayIdentity = gatewaySigner.withDID('did:web:test.w3s.link')
47+
/** @type {import('@ucanto/interface').Delegation<import('@ucanto/interface').Capabilities>[]} */
48+
const stubDelegations = []
4449

4550
const ctx =
4651
/** @satisfies {EgressTrackerContext} */
4752
({
48-
space: 'did:key:z6MkknBAHEGCWvBzAi4amdH5FXEXrdKoWF1UJuvc8Psm2Mda',
53+
space: SpaceDID.from('did:key:z6MkknBAHEGCWvBzAi4amdH5FXEXrdKoWF1UJuvc8Psm2Mda'),
4954
dataCid: CID.parse('bafybeibv7vzycdcnydl5n5lbws6lul2omkm6a6b5wmqt77sicrwnhesy7y'),
55+
gatewaySigner,
56+
gatewayIdentity,
57+
delegationsStorage: { find: async () => ({ ok: stubDelegations }) },
58+
delegationProofs: [],
5059
waitUntil: sinon.stub().returns(undefined),
5160
path: '',
5261
searchParams: new URLSearchParams(),
53-
egressClient: UCantoClient()
62+
egressClient: EgressClient()
5463
})
5564

5665
describe('withEgressTracker', async () => {

test/unit/middleware/withRateLimit.spec.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ const createContext = async ({ authToken } = {}) => ({
6666
waitUntil: strictStub(sandbox, 'waitUntil').returns(undefined),
6767
path: '',
6868
searchParams: new URLSearchParams(),
69-
authToken: authToken ?? null,
70-
ucantoClient: {
71-
record: strictStub(sandbox, 'record'),
72-
getTokenMetadata: strictStub(sandbox, 'getTokenMetadata').returns(null)
73-
}
69+
authToken: authToken ?? null
7470
})
7571

7672
describe('withRateLimits', async () => {

0 commit comments

Comments
 (0)