Skip to content

Commit 01f7596

Browse files
committed
test: updated tests to reflect new behaviour
fix: tests
1 parent 4be96ba commit 01f7596

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

tests/client/handlers/auth.test.ts

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import type {
2-
IdentityRequestData,
3-
IdentityResponseData,
4-
} from '#src/client/types.js';
1+
import type { IdentityResponseData } from '#src/client/types.js';
52
import type { TLSConfig } from '#network/types.js';
63
import fs from 'node:fs';
74
import path from 'node:path';
@@ -17,7 +14,7 @@ import Token from '#tokens/Token.js';
1714
import ClientService from '#client/ClientService.js';
1815
import * as keysUtils from '#keys/utils/index.js';
1916
import * as networkUtils from '#network/utils.js';
20-
import * as clientErrors from '#client/errors.js';
17+
import * as nodesUtils from '#nodes/utils.js';
2118

2219
describe('authSignToken', () => {
2320
const logger = new Logger('authSignToken test', LogLevel.WARN, [
@@ -91,44 +88,12 @@ describe('authSignToken', () => {
9188
});
9289
});
9390

94-
test('should sign a valid token', async () => {
95-
// Create token with separate key pair
96-
const keyPair = keysUtils.generateKeyPair();
97-
const token = Token.fromPayload<IdentityRequestData>({
98-
publicKey: keyPair.publicKey.toString('base64url'),
99-
returnURL: 'test',
100-
});
101-
token.signWithPrivateKey(keyPair);
102-
103-
// Get the node to sign the token as well
104-
const encodedToken = token.toEncoded();
105-
const identityToken = await rpcClient.methods.authSignToken(encodedToken);
106-
107-
// Check the signature of both the incoming token and the original sent token
91+
test('should return a signed token', async () => {
92+
const identityToken = await rpcClient.methods.authSignToken({});
10893
const decodedToken = Token.fromEncoded<IdentityResponseData>(identityToken);
10994
const decodedPublicKey = keysUtils.publicKeyFromNodeId(keyRing.getNodeId());
11095
expect(decodedToken.verifyWithPublicKey(decodedPublicKey)).toBeTrue();
111-
const requestToken = Token.fromEncoded<IdentityRequestData>(
112-
decodedToken.payload.requestToken,
113-
);
114-
expect(requestToken.verifyWithPublicKey(keyPair.publicKey)).toBeTrue();
115-
});
116-
117-
test('should fail if public key does not match signature', async () => {
118-
// Create token with a key pair and sign it with another
119-
const keyPair1 = keysUtils.generateKeyPair();
120-
const keyPair2 = keysUtils.generateKeyPair();
121-
const token = Token.fromPayload<IdentityRequestData>({
122-
publicKey: keyPair1.publicKey.toString('base64url'),
123-
returnURL: 'test',
124-
});
125-
token.signWithPrivateKey(keyPair2);
126-
127-
// The token should fail validation
128-
const encodedToken = token.toEncoded();
129-
await testsUtils.expectRemoteError(
130-
rpcClient.methods.authSignToken(encodedToken),
131-
clientErrors.ErrorClientAuthenticationInvalidToken,
132-
);
96+
const encodedNodeId = nodesUtils.encodeNodeId(keyRing.getNodeId());
97+
expect(decodedToken.payload.nodeId).toBe(encodedNodeId);
13398
});
13499
});

0 commit comments

Comments
 (0)