cojson 0.20.2 → 0.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +10 -7
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +14 -5
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +5 -0
- package/dist/permissions.js.map +1 -1
- package/dist/tests/group.parentGroupCache.test.js +2 -2
- package/dist/tests/group.parentGroupCache.test.js.map +1 -1
- package/dist/tests/permissions.test.js +83 -2
- package/dist/tests/permissions.test.js.map +1 -1
- package/package.json +4 -4
- package/src/coValueCore/coValueCore.ts +15 -5
- package/src/permissions.ts +6 -0
- package/src/tests/group.parentGroupCache.test.ts +2 -2
- package/src/tests/permissions.test.ts +118 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
1
|
+
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { expectMap } from "../coValue.js";
|
|
3
3
|
import { ControlledAgent } from "../coValues/account.js";
|
|
4
4
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
loadCoValueOrFail,
|
|
14
14
|
newGroup,
|
|
15
15
|
newGroupHighLevel,
|
|
16
|
+
setupTestAccount,
|
|
17
|
+
setupTestNode,
|
|
16
18
|
waitFor,
|
|
17
19
|
} from "./testUtils.js";
|
|
18
20
|
import { Role } from "../permissions.js";
|
|
@@ -2727,3 +2729,118 @@ test("Can revoke read permission from 'everyone'", async () => {
|
|
|
2727
2729
|
// Verify the new account cannot read after revocation
|
|
2728
2730
|
expect(childContent2.get("foo")).toEqual("bar");
|
|
2729
2731
|
});
|
|
2732
|
+
|
|
2733
|
+
describe("Private transactions in groups", () => {
|
|
2734
|
+
beforeEach(async () => {
|
|
2735
|
+
setupTestNode({ isSyncServer: true });
|
|
2736
|
+
});
|
|
2737
|
+
|
|
2738
|
+
test("Admins can make private transactions directly in accounts", async () => {
|
|
2739
|
+
const alice = await setupTestAccount();
|
|
2740
|
+
|
|
2741
|
+
const group = alice.node.createGroup();
|
|
2742
|
+
const map = group.createMap();
|
|
2743
|
+
|
|
2744
|
+
// Count valid transactions before attempting private transaction
|
|
2745
|
+
const validTransactionsBefore = alice.account.core.getValidTransactions();
|
|
2746
|
+
const countBefore = validTransactionsBefore.length;
|
|
2747
|
+
|
|
2748
|
+
alice.account.set("root", map.id, "private");
|
|
2749
|
+
|
|
2750
|
+
const validTransactions = alice.account.core.getValidTransactions();
|
|
2751
|
+
expect(validTransactions).toHaveLength(countBefore + 1);
|
|
2752
|
+
|
|
2753
|
+
expect(alice.account.get("root")).toEqual(map.id);
|
|
2754
|
+
expect(alice.account.core.getCurrentReadKey()).not.toBeUndefined();
|
|
2755
|
+
});
|
|
2756
|
+
|
|
2757
|
+
test("Admins cannot make private transactions directly in groups", async () => {
|
|
2758
|
+
const alice = await setupTestAccount();
|
|
2759
|
+
|
|
2760
|
+
const group = alice.node.createGroup();
|
|
2761
|
+
const map = group.createMap();
|
|
2762
|
+
|
|
2763
|
+
// Count valid transactions before attempting private transaction
|
|
2764
|
+
const validTransactionsBefore = group.core.getValidTransactions();
|
|
2765
|
+
const countBefore = validTransactionsBefore.length;
|
|
2766
|
+
|
|
2767
|
+
// Attempt to make a private transaction directly on the group
|
|
2768
|
+
group.set("root", map.id, "private");
|
|
2769
|
+
|
|
2770
|
+
// Verify the transaction is marked invalid (count should not increase)
|
|
2771
|
+
const validTransactions = group.core.getValidTransactions();
|
|
2772
|
+
expect(validTransactions).toHaveLength(countBefore);
|
|
2773
|
+
|
|
2774
|
+
// Verify the change didn't take effect
|
|
2775
|
+
expect(group.get("root")).toBeUndefined();
|
|
2776
|
+
});
|
|
2777
|
+
|
|
2778
|
+
test("Writers cannot make private transactions directly in groups", async () => {
|
|
2779
|
+
const alice = await setupTestAccount({ connected: true });
|
|
2780
|
+
const bob = await setupTestAccount({ connected: true });
|
|
2781
|
+
|
|
2782
|
+
const group = alice.node.createGroup();
|
|
2783
|
+
const map = group.createMap();
|
|
2784
|
+
|
|
2785
|
+
group.addMember(bob.account, "writer");
|
|
2786
|
+
|
|
2787
|
+
// Count valid transactions before attempting private transaction
|
|
2788
|
+
const validTransactionsBefore = group.core.getValidTransactions();
|
|
2789
|
+
const countBefore = validTransactionsBefore.length;
|
|
2790
|
+
|
|
2791
|
+
const groupAsBob = await loadCoValueOrFail(bob.node, group.id);
|
|
2792
|
+
|
|
2793
|
+
// Attempt to make a private transaction directly on the group
|
|
2794
|
+
groupAsBob.set("root", map.id, "private");
|
|
2795
|
+
|
|
2796
|
+
// Verify the transaction is marked invalid (count should not increase)
|
|
2797
|
+
const validTransactions = groupAsBob.core.getValidTransactions();
|
|
2798
|
+
expect(validTransactions).toHaveLength(countBefore);
|
|
2799
|
+
|
|
2800
|
+
// Verify the change didn't take effect
|
|
2801
|
+
expect(groupAsBob.get("root")).toBeUndefined();
|
|
2802
|
+
});
|
|
2803
|
+
|
|
2804
|
+
test("Managers cannot make private transactions directly in groups", async () => {
|
|
2805
|
+
const alice = await setupTestAccount({ connected: true });
|
|
2806
|
+
const bob = await setupTestAccount({ connected: true });
|
|
2807
|
+
|
|
2808
|
+
const group = alice.node.createGroup();
|
|
2809
|
+
const map = group.createMap();
|
|
2810
|
+
|
|
2811
|
+
group.addMember(bob.account, "manager");
|
|
2812
|
+
|
|
2813
|
+
// Count valid transactions before attempting private transaction
|
|
2814
|
+
const validTransactionsBefore = group.core.getValidTransactions();
|
|
2815
|
+
const countBefore = validTransactionsBefore.length;
|
|
2816
|
+
|
|
2817
|
+
const groupAsBob = await loadCoValueOrFail(bob.node, group.id);
|
|
2818
|
+
|
|
2819
|
+
// Attempt to make a private transaction directly on the group
|
|
2820
|
+
groupAsBob.set("root", map.id, "private");
|
|
2821
|
+
|
|
2822
|
+
// Verify the transaction is marked invalid (count should not increase)
|
|
2823
|
+
const validTransactions = groupAsBob.core.getValidTransactions();
|
|
2824
|
+
expect(validTransactions).toHaveLength(countBefore);
|
|
2825
|
+
|
|
2826
|
+
// Verify the change didn't take effect
|
|
2827
|
+
expect(groupAsBob.get("root")).toBeUndefined();
|
|
2828
|
+
});
|
|
2829
|
+
|
|
2830
|
+
test("A Group with a private transaction can be loaded without issues", async () => {
|
|
2831
|
+
const alice = await setupTestAccount({ connected: true });
|
|
2832
|
+
const bob = await setupTestAccount({ connected: true });
|
|
2833
|
+
|
|
2834
|
+
const group = alice.node.createGroup();
|
|
2835
|
+
const map = group.createMap();
|
|
2836
|
+
|
|
2837
|
+
// Attempt to make a private transaction directly on the group
|
|
2838
|
+
group.set("root", map.id, "private");
|
|
2839
|
+
group.addMember(bob.account, "reader");
|
|
2840
|
+
|
|
2841
|
+
const groupAsBob = await loadCoValueOrFail(bob.node, group.id);
|
|
2842
|
+
|
|
2843
|
+
expect(groupAsBob.myRole()).toBe("reader");
|
|
2844
|
+
expect(groupAsBob.core.getCurrentReadKey()).not.toBeUndefined();
|
|
2845
|
+
});
|
|
2846
|
+
});
|