-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50d37dd
commit 0b3bf96
Showing
13 changed files
with
365 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/oidf-resolution-tests/__tests__/localAgent.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { IdentifierResolution, IIdentifierResolution } from '../../identifier-resolution/src' // FIXME fix when new types have been absorbed throughout ssi-sdk | ||
import { SphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager' | ||
import { SphereonKeyManagementSystem } from '@sphereon/ssi-sdk-ext.kms-local' | ||
import { createAgent, IKeyManager, TAgent } from '@veramo/core' | ||
import { Entities, KeyStore, migrations, PrivateKeyStore } from '@veramo/data-store' | ||
import { SecretBox } from '@veramo/kms-local' | ||
import { OrPromise } from '@veramo/utils' | ||
import { DataSource } from 'typeorm' | ||
import { IJwtService, JwtService } from '@sphereon/ssi-sdk-ext.jwt-service' | ||
import oidfResolutionTests from './shared/oidfResolutionTest' | ||
import { OIDFClient } from '@sphereon/ssi-sdk.oidf-client' | ||
import { ResourceResolver } from '@sphereon/ssi-sdk.resource-resolver' | ||
|
||
jest.setTimeout(30000) | ||
|
||
const KMS_SECRET_KEY = 'd17c8674f5db9396f8eecccde25e882bb0336316bc411ae38dc1f3dcd7ed100f' | ||
let databaseFile = ':memory:' | ||
let dbConnection: OrPromise<DataSource> | ||
let agent: TAgent<IKeyManager & IIdentifierResolution & IJwtService> | ||
|
||
|
||
const setup = async (): Promise<boolean> => { | ||
const db: OrPromise<DataSource> = new DataSource({ | ||
type: 'sqlite', | ||
database: databaseFile, | ||
synchronize: false, | ||
logging: ['info', 'warn'], | ||
entities: [...Entities], | ||
migrations: [...migrations], | ||
migrationsRun: true, | ||
}).initialize() | ||
const secretBox = new SecretBox(KMS_SECRET_KEY) | ||
|
||
const localAgent = createAgent<IKeyManager & IIdentifierResolution & IJwtService>({ | ||
plugins: [ | ||
new SphereonKeyManager({ | ||
store: new KeyStore(db), | ||
kms: { | ||
local: new SphereonKeyManagementSystem(new PrivateKeyStore(db, secretBox)), | ||
}, | ||
}), | ||
new IdentifierResolution(), | ||
new JwtService(), | ||
new ResourceResolver(), | ||
new OIDFClient(), | ||
], | ||
}) | ||
agent = localAgent | ||
dbConnection = db | ||
return true | ||
} | ||
|
||
const tearDown = async (): Promise<boolean> => { | ||
await (await dbConnection).destroy() | ||
return true | ||
} | ||
|
||
const getAgent = () => agent | ||
|
||
const testContext = { getAgent, setup, tearDown } | ||
|
||
describe('Local integration tests', () => { | ||
oidfResolutionTests(testContext) | ||
}) |
118 changes: 118 additions & 0 deletions
118
packages/oidf-resolution-tests/__tests__/restAgent.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { IdentifierResolution, IIdentifierResolution } from '../../identifier-resolution/src' // FIXME fix when new types have been absorbed throughout ssi-sdk | ||
import { SphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager' | ||
import { SphereonKeyManagementSystem } from '@sphereon/ssi-sdk-ext.kms-local' | ||
|
||
import { createAgent, IAgent, IAgentOptions, IKeyManager, TAgent } from '@veramo/core' | ||
import { Entities, KeyStore, migrations, PrivateKeyStore } from '@veramo/data-store' | ||
import { SecretBox } from '@veramo/kms-local' | ||
import { AgentRestClient } from '@veramo/remote-client' | ||
import { AgentRouter, RequestWithAgentRouter } from '@veramo/remote-server' | ||
import { OrPromise } from '@veramo/utils' | ||
|
||
// @ts-ignore | ||
import express from 'express' | ||
import { Server } from 'http' | ||
import { DataSource } from 'typeorm' | ||
|
||
import oidfResolutionTests from './shared/oidfResolutionTest' | ||
import { ResourceResolver } from '@sphereon/ssi-sdk.resource-resolver' | ||
import { OIDFClient } from '@sphereon/ssi-sdk.oidf-client' | ||
import { IJwtService, JwtService } from '@sphereon/ssi-sdk-ext.jwt-service' | ||
|
||
jest.setTimeout(30000) | ||
|
||
const databaseFile = ':memory:' | ||
const port = 13213 | ||
const basePath = '/agent' | ||
|
||
// const PRIVATE_KEY_HEX = '7dd923e40f4615ac496119f7e793cc2899e99b64b88ca8603db986700089532b' | ||
|
||
let serverAgent: IAgent | ||
let clientAgent: TAgent<IKeyManager & IIdentifierResolution & IJwtService> | ||
let restServer: Server | ||
let dbConnection: OrPromise<DataSource> | ||
|
||
const KMS_SECRET_KEY = 'd17c8674f5db9396f8eecccde25e882bb0336316bc411ae38dc1f3dcd7ed100f' | ||
|
||
const getAgent = (options?: IAgentOptions) => { | ||
if (!serverAgent) { | ||
throw Error('Server agent not available yet (missed await?)') | ||
} | ||
if (!clientAgent) { | ||
clientAgent = createAgent<IIdentifierResolution & IKeyManager & IJwtService>({ | ||
...options, | ||
plugins: [ | ||
new AgentRestClient({ | ||
url: 'http://localhost:' + port + basePath, | ||
enabledMethods: serverAgent.availableMethods(), | ||
schema: serverAgent.getSchema(), | ||
}), | ||
], | ||
}) | ||
} | ||
|
||
return clientAgent | ||
} | ||
|
||
const setup = async (): Promise<boolean> => { | ||
if (serverAgent) { | ||
return true | ||
} | ||
const db: OrPromise<DataSource> = new DataSource({ | ||
type: 'sqlite', | ||
database: databaseFile, | ||
synchronize: false, | ||
logging: ['info', 'warn'], | ||
entities: [...Entities], | ||
migrations: [...migrations], | ||
migrationsRun: true, | ||
}).initialize() | ||
|
||
const secretBox = new SecretBox(KMS_SECRET_KEY) | ||
|
||
const agent = createAgent<IKeyManager & IIdentifierResolution & IJwtService>({ | ||
plugins: [ | ||
new SphereonKeyManager({ | ||
store: new KeyStore(db), | ||
kms: { | ||
local: new SphereonKeyManagementSystem(new PrivateKeyStore(db, secretBox)), | ||
}, | ||
}), | ||
new IdentifierResolution(), | ||
new JwtService(), | ||
new ResourceResolver(), | ||
new OIDFClient(), | ||
], | ||
}) | ||
|
||
serverAgent = agent | ||
dbConnection = db | ||
|
||
const agentRouter = AgentRouter({ | ||
exposedMethods: serverAgent.availableMethods(), | ||
}) | ||
|
||
const requestWithAgent = RequestWithAgentRouter({ | ||
agent: serverAgent, | ||
}) | ||
|
||
return new Promise((resolve) => { | ||
const app = express() | ||
app.use(basePath, requestWithAgent, agentRouter) | ||
restServer = app.listen(port, () => { | ||
resolve(true) | ||
}) | ||
}) | ||
} | ||
|
||
const tearDown = async (): Promise<boolean> => { | ||
restServer.close() | ||
await (await dbConnection).dropDatabase() | ||
return true | ||
} | ||
|
||
const testContext = { getAgent, setup, tearDown } | ||
|
||
describe('REST integration tests', () => { | ||
oidfResolutionTests(testContext) | ||
}) |
65 changes: 65 additions & 0 deletions
65
packages/oidf-resolution-tests/__tests__/shared/oidfResolutionTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
ExternalIdentifierOIDFEntityIdResult, | ||
ExternalIdentifierResult, | ||
IIdentifierResolution, | ||
} from '../../../identifier-resolution/src/types' // FIXME fix when new types have been absorbed throughout ssi-sdk | ||
import { IKeyManager, TAgent } from '@veramo/core' | ||
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service' | ||
import { describe } from 'node:test' | ||
|
||
type ConfiguredAgent = TAgent<IKeyManager & IIdentifierResolution & IJwtService> | ||
|
||
export default (testContext: { | ||
getAgent: () => ConfiguredAgent; | ||
setup: () => Promise<boolean>; | ||
tearDown: () => Promise<boolean> | ||
}) => { | ||
let agent: ConfiguredAgent | ||
// let key: IKey | ||
|
||
// tbe above key as hex | ||
const privateKeyHex = '8E9B109E719098BF980487DF1F5D77E9CB29606EBED2263B5F57C213DF84F4B2'.toLowerCase() | ||
|
||
beforeAll(async () => { | ||
await testContext.setup().then(() => (agent = testContext.getAgent())) | ||
await agent.keyManagerImport({kid: 'test', type: 'Secp256r1', kms: 'local', privateKeyHex}) | ||
}) | ||
afterAll(testContext.tearDown) | ||
|
||
|
||
|
||
describe('oidf-identifier-resolution', () => { | ||
it('should resolve OIDF entity ID against multiple trust anchors', async () => { | ||
const EXAMPLE_ENTITY_ID = 'https://agent.findynet.demo.sphereon.com/oid4vci' | ||
const result: ExternalIdentifierResult = await agent.identifierExternalResolve({ | ||
identifier: EXAMPLE_ENTITY_ID, | ||
trustAnchors: ['https://federation.demo.sphereon.com', 'https://federation.dev.findy.fi'] | ||
}) | ||
|
||
expect(result).toBeDefined() | ||
expect(result.method).toEqual('entity_id') | ||
|
||
if (result.method === 'entity_id') { | ||
const entityResult = result as ExternalIdentifierOIDFEntityIdResult | ||
expect(entityResult.trustedAnchors).toBeDefined() | ||
|
||
expect(entityResult.trustedAnchors['https://federation.demo.sphereon.com']) | ||
.toEqual('036f147e164a6b2ae860330b75bb54243b028086b4297a8d663bb4afe4080afec7') | ||
|
||
expect(entityResult.errorList).toBeDefined() | ||
if(entityResult.errorList) { | ||
expect(entityResult.errorList['https://federation.dev.findy.fi']) | ||
.toEqual('A Trust chain could not be established') | ||
} | ||
|
||
expect(Array.isArray(entityResult.jwks)).toBe(true) | ||
expect(entityResult.jwks).toHaveLength(1) | ||
|
||
const jwk = entityResult.jwks[0] | ||
expect(jwk.jwkThumbprint).toEqual('PjWRF5oJSGKQQaf_NPMndBA528S_Ulqcu6E_ZWZkkWY') | ||
|
||
expect(entityResult.trustEstablished).toBeTruthy() | ||
} | ||
}) | ||
}) | ||
} |
Oops, something went wrong.