Skip to content

Commit

Permalink
fix test compilation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Nov 12, 2024
1 parent ab9bf91 commit 010162b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
29 changes: 21 additions & 8 deletions test/unit/middleware/withAuthorizedSpace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const createLocator = (expectedDigest, locateResponse) => ({
}
})

const gatewayIdentity = (await ed25519.Signer.generate()).withDID(
const gatewaySigner = (await ed25519.Signer.generate()).signer
const gatewayIdentity = gatewaySigner.withDID(
'did:web:test.w3s.link'
)

Expand Down Expand Up @@ -134,7 +135,9 @@ describe('withAuthorizedSpace', async () => {
nb: { token: 'a1b2c3' }
})
]),
gatewayIdentity
delegationProofs: [],
gatewaySigner,
gatewayIdentity,
}
)

Expand Down Expand Up @@ -178,6 +181,8 @@ describe('withAuthorizedSpace', async () => {
nb: { token: null }
})
]),
delegationProofs: [],
gatewaySigner,
gatewayIdentity
}
)
Expand Down Expand Up @@ -224,6 +229,8 @@ describe('withAuthorizedSpace', async () => {
nb: { token: 'a1b2c3' }
})
]),
delegationProofs: [],
gatewaySigner,
gatewayIdentity
}
)
Expand Down Expand Up @@ -288,7 +295,7 @@ describe('withAuthorizedSpace', async () => {
const response1 = await withAuthorizedSpace(innerHandler)(
request,
{},
{ ...ctx, authToken: 'space1-token' }
{ ...ctx, authToken: 'space1-token', delegationProofs: [], gatewaySigner }
)

expect(await response1.json()).to.deep.equal({
Expand All @@ -302,7 +309,7 @@ describe('withAuthorizedSpace', async () => {
withAuthorizedSpace(sinon.fake(innerHandler))(
request,
{},
{ ...ctx, authToken: 'space2-token' }
{ ...ctx, authToken: 'space2-token', delegationProofs: [], gatewaySigner }
)
)

Expand All @@ -314,7 +321,7 @@ describe('withAuthorizedSpace', async () => {
const response3 = await withAuthorizedSpace(innerHandler)(
request,
{},
{ ...ctx, authToken: 'space3-token' }
{ ...ctx, authToken: 'space3-token', delegationProofs: [], gatewaySigner }
)

expect(await response3.json()).to.deep.equal({
Expand Down Expand Up @@ -351,7 +358,7 @@ describe('withAuthorizedSpace', async () => {
const responseWithoutToken = await withAuthorizedSpace(innerHandler)(
request,
{},
{ ...ctx, authToken: null }
{ ...ctx, authToken: null, delegationProofs: [], gatewaySigner }
)

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

const ih = sinon.fake(innerHandler)
const errorWithToken = await rejection(
withAuthorizedSpace(ih)(request, {}, { ...ctx, authToken: 'a1b2c3' })
withAuthorizedSpace(ih)(request, {}, { ...ctx, authToken: 'a1b2c3', delegationProofs: [], gatewaySigner })
)

expect(ih.notCalled).to.be.true
Expand Down Expand Up @@ -400,6 +407,8 @@ describe('withAuthorizedSpace', async () => {
nb: { token: 'a1b2c3' }
})
]),
delegationProofs: [],
gatewaySigner,
gatewayIdentity
}
)
Expand Down Expand Up @@ -444,6 +453,8 @@ describe('withAuthorizedSpace', async () => {
nb: { token: 'a1b2c3' }
})
]),
delegationProofs: [],
gatewaySigner,
gatewayIdentity
}
)
Expand Down Expand Up @@ -487,6 +498,8 @@ describe('withAuthorizedSpace', async () => {
nb: { token: 'a1b2c3' }
})
]),
delegationProofs: [],
gatewaySigner,
gatewayIdentity
}
)
Expand Down Expand Up @@ -532,7 +545,7 @@ describe('withAuthorizedSpace', async () => {

const ih = sinon.fake(innerHandler)
const error = await rejection(
withAuthorizedSpace(ih)(request, {}, { ...ctx, authToken: 'a1b2c3' })
withAuthorizedSpace(ih)(request, {}, { ...ctx, authToken: 'a1b2c3', delegationProofs: [], gatewaySigner })
)

expect(ih.notCalled).to.be.true
Expand Down
23 changes: 16 additions & 7 deletions test/unit/middleware/withEgressTracker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { CID } from 'multiformats'
import { withEgressTracker } from '../../../src/middleware/withEgressTracker.js'
import { Builder, toBlobKey } from '../../helpers/builder.js'
import { CARReaderStream } from 'carstream'
import { SpaceDID } from '@web3-storage/capabilities/utils'
import { ed25519 } from '@ucanto/principal'

/**
* @typedef {import('../../../src/middleware/withEgressTracker.types.js').Environment} EgressTrackerEnvironment
Expand All @@ -21,7 +23,7 @@ const env =
/** @satisfies {EgressTrackerEnvironment} */
({
DEBUG: 'true',
FF_EGRESS_TRACKER_ENABLED: 'true'
FF_EGRESS_TRACKER_ENABLED: 'true',
})

const recordEgressMock = sinon.fake()
Expand All @@ -31,26 +33,33 @@ const recordEgressMock = sinon.fake()
*
* @returns {import('../../../src/middleware/withEgressClient.types.js').EgressClient}
*/
const UCantoClient = () => {
if (process.env.DEBUG) {
console.log('[mock] UCantoClient created')
const EgressClient = () => {
if (process.env.DEBUG === 'true') {
console.log('[mock] EgressClient created')
}

return {
record: recordEgressMock,
getTokenMetadata: sinon.fake()
}
}
const gatewaySigner = (await ed25519.Signer.generate()).signer
const gatewayIdentity = gatewaySigner.withDID('did:web:test.w3s.link')
/** @type {import('@ucanto/interface').Delegation<import('@ucanto/interface').Capabilities>[]} */
const stubDelegations = []

const ctx =
/** @satisfies {EgressTrackerContext} */
({
space: 'did:key:z6MkknBAHEGCWvBzAi4amdH5FXEXrdKoWF1UJuvc8Psm2Mda',
space: SpaceDID.from('did:key:z6MkknBAHEGCWvBzAi4amdH5FXEXrdKoWF1UJuvc8Psm2Mda'),
dataCid: CID.parse('bafybeibv7vzycdcnydl5n5lbws6lul2omkm6a6b5wmqt77sicrwnhesy7y'),
gatewaySigner,
gatewayIdentity,
delegationsStorage: { find: async () => ({ ok: stubDelegations }) },
delegationProofs: [],
waitUntil: sinon.stub().returns(undefined),
path: '',
searchParams: new URLSearchParams(),
egressClient: UCantoClient()
egressClient: EgressClient()
})

describe('withEgressTracker', async () => {
Expand Down
6 changes: 1 addition & 5 deletions test/unit/middleware/withRateLimit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ const createContext = async ({ authToken } = {}) => ({
waitUntil: strictStub(sandbox, 'waitUntil').returns(undefined),
path: '',
searchParams: new URLSearchParams(),
authToken: authToken ?? null,
ucantoClient: {
record: strictStub(sandbox, 'record'),
getTokenMetadata: strictStub(sandbox, 'getTokenMetadata').returns(null)
}
authToken: authToken ?? null
})

describe('withRateLimits', async () => {
Expand Down

0 comments on commit 010162b

Please sign in to comment.