From 754e1129529d20e31cde692469b3475bce1c1f9c Mon Sep 17 00:00:00 2001 From: "nick.tessier" <22119573+nick4598@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:24:29 -0500 Subject: [PATCH 1/2] use token from recentyl queried v2 checkpoint --- core/backend/src/CheckpointManager.ts | 2 ++ .../src/integration/Checkpoints.test.ts | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/core/backend/src/CheckpointManager.ts b/core/backend/src/CheckpointManager.ts index a58c7ad2ddbf..1a96a94f5e27 100644 --- a/core/backend/src/CheckpointManager.ts +++ b/core/backend/src/CheckpointManager.ts @@ -199,6 +199,8 @@ export class V2CheckpointManager { try { const container = this.getContainer(v2props, checkpoint); const dbName = v2props.dbName; + // Use the new token from the recently queried v2 checkpoint just incase the one we currently have is expired. + container.accessToken = v2props.sasToken; if (!container.isConnected) container.connect(this.cloudCache); container.checkForChanges(); diff --git a/full-stack-tests/backend/src/integration/Checkpoints.test.ts b/full-stack-tests/backend/src/integration/Checkpoints.test.ts index 6fefa91082e8..ec0580da80da 100644 --- a/full-stack-tests/backend/src/integration/Checkpoints.test.ts +++ b/full-stack-tests/backend/src/integration/Checkpoints.test.ts @@ -335,6 +335,41 @@ describe("Checkpoints", () => { expect(stats.totalClients).to.equal(0); }); + it("should be able to open multiple checkpoints in same container when sas expires", async () => { + const iModel = await SnapshotDb.openCheckpointFromRpc({ + accessToken, + iTwinId: testITwinId, + iModelId: testIModelId, + changeset: testChangeSet, + }); + + await iModel.refreshContainerForRpc(accessToken); + + const checkpointContainer = iModel[_nativeDb].cloudContainer; + iModel.close(); + + // simulate sas token expiration / bad token + expect(checkpointContainer).to.not.be.undefined; + checkpointContainer!.accessToken = ""; + + // Open iModel from same container, expect it to refresh the token + const iModel2 = await SnapshotDb.openCheckpointFromRpc({ + accessToken, + iTwinId: testITwinId, + iModelId: testIModelId, + changeset: testChangeSetFirstVersion, + }); + expect(checkpointContainer?.accessToken).to.not.be.empty; + assert.equal(iModel2.iModelId, testIModelId); + assert.equal(iModel2.changeset.id, testChangeSetFirstVersion.id); + assert.equal(iModel2.iTwinId, testITwinId); + assert.equal(iModel2.rootSubject.name, "Stadium Dataset 1"); + const numModels = await queryBisModelCount(iModel2); + assert.equal(numModels, 3); + iModel2.close(); + + }); + it("should be able to open and read checkpoint for Rpc with daemon running", async () => { let iModel = await SnapshotDb.openCheckpointFromRpc({ accessToken, From 1d00eaf1341a1ac7d285b57698d98fd8a11aebee Mon Sep 17 00:00:00 2001 From: "nick.tessier" <22119573+nick4598@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:24:51 -0500 Subject: [PATCH 2/2] rush change --- .../nick-tokencloudsqlitebug_2025-01-21-19-24.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@itwin/core-backend/nick-tokencloudsqlitebug_2025-01-21-19-24.json diff --git a/common/changes/@itwin/core-backend/nick-tokencloudsqlitebug_2025-01-21-19-24.json b/common/changes/@itwin/core-backend/nick-tokencloudsqlitebug_2025-01-21-19-24.json new file mode 100644 index 000000000000..99b35bb89b62 --- /dev/null +++ b/common/changes/@itwin/core-backend/nick-tokencloudsqlitebug_2025-01-21-19-24.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@itwin/core-backend", + "comment": "", + "type": "none" + } + ], + "packageName": "@itwin/core-backend" +} \ No newline at end of file