Skip to content

Commit

Permalink
Use sas token from recently queried v2 checkpoint incase the one we c…
Browse files Browse the repository at this point in the history
…urrently have is expired (#7579)

(cherry picked from commit ba25688)
  • Loading branch information
nick4598 authored and mergify[bot] committed Jan 21, 2025
1 parent 157d897 commit d89aecc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-backend",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/core-backend"
}
2 changes: 2 additions & 0 deletions core/backend/src/CheckpointManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
35 changes: 35 additions & 0 deletions full-stack-tests/backend/src/integration/Checkpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d89aecc

Please sign in to comment.