|
1 | 1 | import { TORUS_LEGACY_NETWORK, TORUS_SAPPHIRE_NETWORK } from "@toruslabs/constants";
|
2 | 2 | import { generatePrivate } from "@toruslabs/eccrypto";
|
3 | 3 | import NodeManager from "@toruslabs/fetch-node-details";
|
| 4 | +import { fail } from "assert"; |
4 | 5 | import BN from "bn.js";
|
5 | 6 | import { expect } from "chai";
|
6 | 7 | import faker from "faker";
|
@@ -374,6 +375,55 @@ describe("torus utils sapphire devnet", function () {
|
374 | 375 | });
|
375 | 376 | });
|
376 | 377 |
|
| 378 | + it("should fail at get or set nonce when server time offset is expired", async function () { |
| 379 | + const email = "[email protected]"; |
| 380 | + const verifier = "google-lrc"; |
| 381 | + const token = generateIdToken(email, "ES256"); |
| 382 | + |
| 383 | + const LEGACY_TORUS_NODE_MANAGER = new NodeManager({ |
| 384 | + network: TORUS_LEGACY_NETWORK.TESTNET, |
| 385 | + }); |
| 386 | + |
| 387 | + const verifierDetails = { verifier, verifierId: email }; |
| 388 | + const legacyTorus = new TorusUtils({ |
| 389 | + network: TORUS_LEGACY_NETWORK.TESTNET, |
| 390 | + clientId: "YOUR_CLIENT_ID", |
| 391 | + enableOneKey: true, |
| 392 | + serverTimeOffset: -100, |
| 393 | + }); |
| 394 | + const { torusNodeSSSEndpoints: torusNodeEndpoints, torusIndexes } = await LEGACY_TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); |
| 395 | + try { |
| 396 | + await legacyTorus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: email }, token); |
| 397 | + fail("should not reach here"); |
| 398 | + } catch (err) { |
| 399 | + expect(err.status).to.equal(403); |
| 400 | + } |
| 401 | + }); |
| 402 | + |
| 403 | + it("should pass at get or set nonce when server time offset is not passed with default time offset", async function () { |
| 404 | + const email = "[email protected]"; |
| 405 | + const verifier = "google-lrc"; |
| 406 | + const token = generateIdToken(email, "ES256"); |
| 407 | + |
| 408 | + const LEGACY_TORUS_NODE_MANAGER = new NodeManager({ |
| 409 | + network: TORUS_LEGACY_NETWORK.TESTNET, |
| 410 | + }); |
| 411 | + |
| 412 | + const verifierDetails = { verifier, verifierId: email }; |
| 413 | + const legacyTorus = new TorusUtils({ |
| 414 | + network: TORUS_LEGACY_NETWORK.TESTNET, |
| 415 | + clientId: "YOUR_CLIENT_ID", |
| 416 | + enableOneKey: true, |
| 417 | + }); |
| 418 | + const { torusNodeSSSEndpoints: torusNodeEndpoints, torusIndexes } = await LEGACY_TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); |
| 419 | + try { |
| 420 | + const response = await legacyTorus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: email }, token); |
| 421 | + expect(response.metadata.typeOfUser).to.equal("v2"); |
| 422 | + } catch (err) { |
| 423 | + fail("should not reach here"); |
| 424 | + } |
| 425 | + }); |
| 426 | + |
377 | 427 | it("should be able to update the `sessionTime` of the token signature data", async function () {
|
378 | 428 | const token = generateIdToken(TORUS_TEST_EMAIL, "ES256");
|
379 | 429 |
|
|
0 commit comments