Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sas token from recently queried v2 checkpoint incase the one we currently have is expired #7579

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading