Skip to content

Commit 78d3890

Browse files
authored
core: fix isolation tests (#429)
1 parent d85ca6f commit 78d3890

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

infrastructure/evault-core/src/core/protocol/vault-access-guard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ export class VaultAccessGuard {
176176
// Check if envelope exists and user has access
177177
const { hasAccess, exists } = await this.checkAccess(metaEnvelopeId, context);
178178

179-
// For update operations, if envelope doesn't exist, allow the resolver to create it
179+
// For update operations with input, allow in-place creation if envelope doesn't exist
180180
if (!exists && args.input) {
181-
// This is an update/create operation - let the resolver handle it
181+
// Envelope doesn't exist for this eName - allow in-place creation
182182
const result = await resolver(parent, args, context);
183183
return this.filterACL(result);
184184
}

infrastructure/evault-core/src/e2e/evault-core.e2e.spec.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -346,19 +346,22 @@ describe("web3-adapter + evault-core Integration", () => {
346346
data: { original: "data" },
347347
});
348348

349-
// Try to update evault1's data using evault2's w3id - should fail
350-
await expect(
351-
client.updateMetaEnvelopeById(id1, {
352-
w3id: evault2.w3id,
353-
schemaId: "CrossTenantUpdate",
354-
data: { hacked: "data" },
355-
})
356-
).rejects.toThrow();
349+
// Update with evault2's w3id creates a separate envelope for evault2 (in-place creation)
350+
await client.updateMetaEnvelopeById(id1, {
351+
w3id: evault2.w3id,
352+
schemaId: "CrossTenantUpdate",
353+
data: { hacked: "data" },
354+
});
357355

358-
// Verify original data is still intact
356+
// Verify original data in evault1 is still intact (isolation maintained)
359357
const fetched = await client.fetchMetaEnvelope(id1, evault1.w3id);
360358
expect(fetched.data.original).toBe("data");
361359
expect(fetched.data.hacked).toBeUndefined();
360+
361+
// Verify evault2 has its own separate envelope
362+
const fetchedEvault2 = await client.fetchMetaEnvelope(id1, evault2.w3id);
363+
expect(fetchedEvault2.data.hacked).toBe("data");
364+
expect(fetchedEvault2.data.original).toBeUndefined();
362365
});
363366

364367
it("should handle multiple operations across tenants", async () => {
@@ -547,39 +550,50 @@ describe("web3-adapter + evault-core Integration", () => {
547550
).rejects.toThrow();
548551
});
549552

550-
it("should fail when updating non-existent envelope", async () => {
553+
it("should create envelope in-place when updating non-existent envelope", async () => {
551554
const nonExistentId = "non-existent-envelope-id";
552555

553-
await expect(
554-
client.updateMetaEnvelopeById(nonExistentId, {
555-
w3id: evault1.w3id,
556-
schemaId: "UpdateTest",
557-
data: { test: "data" },
558-
})
559-
).rejects.toThrow();
556+
// updateMetaEnvelopeById on non-existent envelope creates it in-place
557+
await client.updateMetaEnvelopeById(nonExistentId, {
558+
w3id: evault1.w3id,
559+
schemaId: "UpdateTest",
560+
data: { test: "data" },
561+
});
562+
563+
// Verify it was created
564+
const fetched = await client.fetchMetaEnvelope(nonExistentId, evault1.w3id);
565+
expect(fetched.data.test).toBe("data");
560566
});
561567

562-
it("should fail when using wrong eName for existing envelope", async () => {
568+
it("should maintain isolation when using different eName", async () => {
563569
// Store with evault1
564570
const id = await client.storeMetaEnvelope({
565571
w3id: evault1.w3id,
566572
schemaId: "WrongTenant",
567573
data: { original: "data" },
568574
});
569575

570-
// Try to fetch with evault2's w3id
576+
// Try to fetch with evault2's w3id - should fail (doesn't exist for evault2)
571577
await expect(
572578
client.fetchMetaEnvelope(id, evault2.w3id)
573579
).rejects.toThrow();
574580

575-
// Try to update with evault2's w3id
576-
await expect(
577-
client.updateMetaEnvelopeById(id, {
578-
w3id: evault2.w3id,
579-
schemaId: "WrongTenant",
580-
data: { hacked: "data" },
581-
})
582-
).rejects.toThrow();
581+
// Update with evault2's w3id creates separate envelope for evault2
582+
await client.updateMetaEnvelopeById(id, {
583+
w3id: evault2.w3id,
584+
schemaId: "WrongTenant",
585+
data: { hacked: "data" },
586+
});
587+
588+
// Now fetch works for evault2 and shows its own data
589+
const fetchedEvault2 = await client.fetchMetaEnvelope(id, evault2.w3id);
590+
expect(fetchedEvault2.data.hacked).toBe("data");
591+
expect(fetchedEvault2.data.original).toBeUndefined();
592+
593+
// Verify evault1's data is still intact
594+
const fetchedEvault1 = await client.fetchMetaEnvelope(id, evault1.w3id);
595+
expect(fetchedEvault1.data.original).toBe("data");
596+
expect(fetchedEvault1.data.hacked).toBeUndefined();
583597
});
584598
});
585599
});

0 commit comments

Comments
 (0)