-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: added tests that use node:crypto
Signed-off-by: Berend Sliedrecht <[email protected]>
- Loading branch information
1 parent
7438a1d
commit b7733e2
Showing
27 changed files
with
514 additions
and
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import assert from 'node:assert/strict' | ||
import { subtle } from 'node:crypto' | ||
import { describe, it } from 'node:test' | ||
|
||
import nock from 'nock' | ||
|
||
import { createEntityConfiguration, fetchEntityConfiguration } from '../src/entityConfiguration' | ||
import { createEntityStatement, fetchEntityStatement } from '../src/entityStatement' | ||
import type { SignCallback, VerifyCallback } from '../src/utils' | ||
|
||
describe('End To End', async () => { | ||
const key = await subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']) | ||
const exportedKey = await subtle.exportKey('jwk', key.publicKey) | ||
const publicKeyJwk = { | ||
kid: 'some-id', | ||
kty: 'EC', | ||
key_ops: exportedKey.key_ops, | ||
x: exportedKey.x, | ||
y: exportedKey.y, | ||
} | ||
|
||
const signJwtCallback: SignCallback = async ({ toBeSigned }) => | ||
new Uint8Array(await subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, key.privateKey, toBeSigned)) | ||
|
||
const verifyJwtCallback: VerifyCallback = async ({ signature, data }) => | ||
subtle.verify({ name: 'ECDSA', hash: 'SHA-256' }, key.publicKey, signature, data) | ||
|
||
it('should fetch an entity configuration', async () => { | ||
const iss = 'https://example.org' | ||
|
||
const claims = { | ||
iss, | ||
sub: iss, | ||
exp: new Date(), | ||
iat: new Date(), | ||
jwks: { | ||
keys: [publicKeyJwk], | ||
}, | ||
} | ||
|
||
const entityConfigurationJwt = await createEntityConfiguration({ | ||
signJwtCallback, | ||
claims, | ||
header: { | ||
kid: 'some-id', | ||
typ: 'entity-statement+jwt', | ||
}, | ||
}) | ||
|
||
const scope = nock(iss).get('/.well-known/openid-federation').reply(200, entityConfigurationJwt, { | ||
'content-type': 'application/entity-statement+jwt', | ||
}) | ||
|
||
const fetchedEntityConfigurationClaims = await fetchEntityConfiguration({ | ||
entityId: iss, | ||
verifyJwtCallback, | ||
}) | ||
|
||
assert.deepStrictEqual(fetchedEntityConfigurationClaims, claims) | ||
|
||
scope.done() | ||
}) | ||
|
||
it('should fetch an entity statement', async () => { | ||
const iss = 'https://example.org' | ||
const sub = 'https://sub.example.org' | ||
|
||
const entityConfigurationJwt = await createEntityConfiguration({ | ||
signJwtCallback, | ||
claims: { | ||
iss, | ||
sub: iss, | ||
exp: new Date(), | ||
iat: new Date(), | ||
jwks: { | ||
keys: [publicKeyJwk], | ||
}, | ||
source_endpoint: `${iss}/fetch`, | ||
}, | ||
header: { | ||
kid: 'some-id', | ||
typ: 'entity-statement+jwt', | ||
}, | ||
}) | ||
|
||
const entityStamentClaims = { | ||
iss, | ||
sub: iss, | ||
exp: new Date(), | ||
iat: new Date(), | ||
jwks: { | ||
keys: [], | ||
}, | ||
authority_hints: [iss], | ||
metadata: { | ||
federation_entity: { | ||
organization_name: 'my org!', | ||
}, | ||
}, | ||
} | ||
|
||
const entityStatementJwt = await createEntityStatement({ | ||
signJwtCallback, | ||
claims: entityStamentClaims, | ||
header: { | ||
kid: 'some-id', | ||
typ: 'entity-statement+jwt', | ||
}, | ||
jwk: publicKeyJwk, | ||
}) | ||
|
||
const scope = nock(iss) | ||
.get('/.well-known/openid-federation') | ||
.reply(200, entityConfigurationJwt, { | ||
'content-type': 'application/entity-statement+jwt', | ||
}) | ||
.get('/fetch') | ||
.query({ iss, sub }) | ||
.reply(200, entityStatementJwt, { | ||
'content-type': 'application/entity-statement+jwt', | ||
}) | ||
|
||
const fetchedEntityConfigurationClaims = await fetchEntityConfiguration({ | ||
entityId: iss, | ||
verifyJwtCallback, | ||
}) | ||
|
||
const fetchedEntityStatementClaims = await fetchEntityStatement({ | ||
iss, | ||
sub, | ||
issEntityConfiguration: fetchedEntityConfigurationClaims, | ||
verifyJwtCallback, | ||
}) | ||
|
||
assert.deepStrictEqual(fetchedEntityStatementClaims, entityStamentClaims) | ||
|
||
scope.done() | ||
}) | ||
}) |
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
Oops, something went wrong.