@xiaolikt/ai-vault 0.9.1 → 0.11.0
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/Cargo.lock +1 -1
- package/README.md +395 -243
- package/README.zh.md +417 -0
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/src/cli.rs +300 -88
- package/crates/ai-vault/src/dialog.rs +14 -7
- package/crates/ai-vault/src/i18n.rs +56 -0
- package/crates/ai-vault/src/import.rs +85 -48
- package/crates/ai-vault/src/main.rs +1 -0
- package/crates/ai-vault/src/store.rs +237 -5
- package/package.json +5 -5
- package/packages/pi-ai-vault/README.md +40 -45
- package/packages/pi-ai-vault/README.zh.md +84 -0
- package/packages/pi-ai-vault/package.json +5 -4
- package/packages/pi-ai-vault/src/bitwarden.ts +41 -25
- package/packages/pi-ai-vault/src/cli.ts +11 -4
- package/packages/pi-ai-vault/src/ente.ts +4 -3
- package/packages/pi-ai-vault/src/i18n.ts +31 -0
- package/packages/pi-ai-vault/src/import-map.ts +166 -58
- package/packages/pi-ai-vault/src/index.ts +194 -114
- package/packages/pi-ai-vault/src/prompt.ts +3 -2
- package/packages/pi-ai-vault/src/types.ts +52 -0
- package/test/cli.sh +44 -0
- package/tests/bitwarden-tools.test.mjs +2 -2
- package/tests/import-map.test.mjs +75 -38
- package/tests/mocks/bin/bw +5 -1
- package/tests/mocks/bin/zenity +7 -2
- package/tests/vault-cli.test.mjs +56 -0
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* instead. Upstream pi shows typed text in the clear; OMP masks it.
|
|
9
9
|
*/
|
|
10
10
|
import { spawn, spawnSync } from "node:child_process";
|
|
11
|
+
import { tr } from "./i18n.js";
|
|
11
12
|
import { existsSync } from "node:fs";
|
|
12
13
|
import { join } from "node:path";
|
|
13
14
|
|
|
@@ -190,8 +191,8 @@ export async function confirmWindow(
|
|
|
190
191
|
"--no-markup",
|
|
191
192
|
"--width=520",
|
|
192
193
|
"--default-cancel",
|
|
193
|
-
|
|
194
|
-
|
|
194
|
+
`--ok-label=${tr("Allow", "允许")}`,
|
|
195
|
+
`--cancel-label=${tr("Deny", "拒绝")}`,
|
|
195
196
|
`--timeout=${DIALOG_MS / 1000}`,
|
|
196
197
|
],
|
|
197
198
|
signal,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape of a vault entry, shared by the extension's import mapping and
|
|
3
|
+
* its tools. Mirrors the CLI's `store.rs` and Bitwarden's own item envelope:
|
|
4
|
+
* a type, the type's own fields under `data`, plus `notes` and custom
|
|
5
|
+
* `fields` that every type carries.
|
|
6
|
+
*/
|
|
7
|
+
export type ItemType =
|
|
8
|
+
| "login"
|
|
9
|
+
| "secureNote"
|
|
10
|
+
| "card"
|
|
11
|
+
| "identity"
|
|
12
|
+
| "sshKey"
|
|
13
|
+
| "bankAccount"
|
|
14
|
+
| "driversLicense"
|
|
15
|
+
| "passport";
|
|
16
|
+
|
|
17
|
+
/** A custom field, as Bitwarden stores it: 0 text · 1 hidden · 2 boolean · 3 linked. */
|
|
18
|
+
export interface Field {
|
|
19
|
+
name: string;
|
|
20
|
+
value: string;
|
|
21
|
+
type: number;
|
|
22
|
+
linkedId?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Source {
|
|
26
|
+
kind: string;
|
|
27
|
+
id: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What a tool hands to `ai-vault save` / `add`: the same envelope, sparse. */
|
|
31
|
+
export interface Draft {
|
|
32
|
+
name: string;
|
|
33
|
+
type: ItemType;
|
|
34
|
+
username?: string;
|
|
35
|
+
password?: string;
|
|
36
|
+
uris?: string[];
|
|
37
|
+
data?: Record<string, string>;
|
|
38
|
+
notes?: string;
|
|
39
|
+
fields?: Field[];
|
|
40
|
+
source?: Source;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** What `list` returns: metadata only, every secret masked. */
|
|
44
|
+
export interface ItemSummary {
|
|
45
|
+
name: string;
|
|
46
|
+
type: ItemType;
|
|
47
|
+
username?: string | null;
|
|
48
|
+
uris: string[];
|
|
49
|
+
fields: Record<string, string>;
|
|
50
|
+
hasNotes?: boolean;
|
|
51
|
+
updatedAt: string;
|
|
52
|
+
}
|
package/test/cli.sh
CHANGED
|
@@ -168,6 +168,50 @@ grep -q 'ENTE_KEY_PLAINTEXT' "$AI_VAULT_DIR/ente.session.json" && bad "the ente
|
|
|
168
168
|
"$BIN" settings ente.unlock session --json >/dev/null
|
|
169
169
|
check "switching back to session clears the ente key" 5 "$BIN" ente-session get
|
|
170
170
|
|
|
171
|
+
echo "== item types =="
|
|
172
|
+
# The tamper block consumed the earlier host token; open a fresh host session.
|
|
173
|
+
HOST_JSON=$(printf 'correct horse' | "$BIN" unlock --password-stdin --json)
|
|
174
|
+
TOKEN=$(printf '%s' "$HOST_JSON" | json token)
|
|
175
|
+
cat >"$TMP/all-types.json" <<'JSON'
|
|
176
|
+
{"items":[
|
|
177
|
+
{"id":"t1","type":1,"name":"Login","login":{"username":"u","password":"gh-pw","totp":"JBSWY3DP"},"fields":[{"name":"API_KEY","value":"hf_sk_abc987xyz456","type":1},{"name":"Plan","value":"Team","type":0}]},
|
|
178
|
+
{"id":"t2","type":2,"name":"Note","secureNote":{},"notes":"body: hunter2"},
|
|
179
|
+
{"id":"t3","type":3,"name":"Card","card":{"cardholderName":"Li","brand":"Visa","number":"4111111111111111","expMonth":"12","expYear":"2029","code":"123"}},
|
|
180
|
+
{"id":"t4","type":4,"name":"Identity","identity":{"firstName":"Jun","ssn":"123-45-6789","licenseNumber":"DL-99"}},
|
|
181
|
+
{"id":"t5","type":5,"name":"Key","sshKey":{"privateKey":"PEM-PRIVATE","publicKey":"ssh-ed25519 PUB"}},
|
|
182
|
+
{"id":"t6","type":6,"name":"Bank","bankAccount":{"bankName":"ICBC","accountNumber":"6222000011112222","pin":"9080"}},
|
|
183
|
+
{"id":"t7","type":7,"name":"Licence","driversLicense":{"licenseNumber":"110101"}},
|
|
184
|
+
{"id":"t8","type":8,"name":"Passport","passport":{"passportNumber":"E1234567","nationality":"CN"}}
|
|
185
|
+
]}
|
|
186
|
+
JSON
|
|
187
|
+
check "import every item type" 0 "$BIN" import "$TMP/all-types.json" --yes --token "$TOKEN" --json
|
|
188
|
+
"$BIN" list --token "$TOKEN" --json >"$TMP/typed-list"
|
|
189
|
+
python3 - "$TMP/typed-list" <<'PY' && ok "list carries the type of each entry" || bad "list does not carry types"
|
|
190
|
+
import json,sys
|
|
191
|
+
items = json.load(open(sys.argv[1]))["items"]
|
|
192
|
+
types = {i["name"]: i["type"] for i in items}
|
|
193
|
+
for name, kind in {"Login":"login","Note":"secureNote","Card":"card","Identity":"identity","Key":"sshKey","Bank":"bankAccount","Licence":"driversLicense","Passport":"passport"}.items():
|
|
194
|
+
assert types.get(name) == kind, (name, types.get(name))
|
|
195
|
+
PY
|
|
196
|
+
for secret in gh-pw hunter2 4111111111111111 123-45-6789 DL-99 hf_sk_abc987xyz456 PEM-PRIVATE 6222000011112222 110101 E1234567 JBSWY3DP; do
|
|
197
|
+
grep -q "$secret" "$TMP/typed-list" && bad "list leaked $secret"
|
|
198
|
+
done
|
|
199
|
+
ok "list masks passwords, card number and code, keys, PIN, account and document numbers, hidden fields, TOTP seeds"
|
|
200
|
+
grep -q '"hasNotes":true' "$TMP/typed-list" && ok "list flags which entries carry notes" || bad "hasNotes missing"
|
|
201
|
+
# a manual entry of a non-login type, secret typed (stdin here for the primary field)
|
|
202
|
+
check "add a card by hand with --type and --field" 0 bash -c "printf '999\n' | '$BIN' add --name HandCard --type card --field brand=Amex --field cardholderName='Li Jun' --field expYear=2031 --field number=378282246310005 --password-stdin --yes --token '$TOKEN' --json"
|
|
203
|
+
check "a wrong field name is refused" 2 "$BIN" add --name X --type card --field cvv=1 --yes --token "$TOKEN"
|
|
204
|
+
check "a wrong type name is refused" 2 "$BIN" add --name X --type wifi --yes --token "$TOKEN"
|
|
205
|
+
check "--secret rejects a non-secret field" 2 bash -c "'$BIN' add --name X --type card --field brand=Visa --secret brand=Visa --secret code=1 --yes --token '$TOKEN'"
|
|
206
|
+
relay Card y >"$TMP/card" 2>&1; [[ $? -eq 0 ]] && ok "get returns a card with its data block" || bad "get of a card failed"
|
|
207
|
+
python3 - "$TMP/card" <<'PY' && ok "get shows the type's fields by Bitwarden's names" || bad "get output is wrong"
|
|
208
|
+
import json,sys
|
|
209
|
+
d = json.load(open(sys.argv[1]))
|
|
210
|
+
assert d["type"] == "card" and d["data"]["code"] == "123" and d["data"]["number"] == "4111111111111111", d
|
|
211
|
+
PY
|
|
212
|
+
relay Note y >"$TMP/note" 2>&1; [[ $? -eq 0 ]] && ok "get returns a secure note's body" || bad "get of a note failed"
|
|
213
|
+
grep -q 'body: hunter2' "$TMP/note" && ok "the note body is in notes" || bad "note body missing"
|
|
214
|
+
|
|
171
215
|
echo "== rekey (L2) =="
|
|
172
216
|
OLD_N=$(python3 -c "import json;print(json.load(open('$AI_VAULT_DIR/store.json'))['kdf']['N'])")
|
|
173
217
|
check "rekey with the password" 0 bash -c "printf 'correct horse' | '$BIN' rekey --password-stdin --json"
|
|
@@ -175,8 +175,8 @@ test("a denied confirmation never fetches the entry; an approved one fetches it
|
|
|
175
175
|
|
|
176
176
|
// An id is looked up in the listing, so a wrong one fails before any window.
|
|
177
177
|
await assert.rejects(
|
|
178
|
-
b.tool("bw_run", { item: "
|
|
179
|
-
/No Bitwarden item with id
|
|
178
|
+
b.tool("bw_run", { item: "ffff9999-9999-4999-8999-999999999999", command: "true" }),
|
|
179
|
+
/No Bitwarden item with id ffff9999/,
|
|
180
180
|
);
|
|
181
181
|
});
|
|
182
182
|
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { test } from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
-
import {
|
|
3
|
+
import { bitwardenItems, filterItems, isSecretField, parseItemType } from "../packages/pi-ai-vault/src/import-map.ts";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const login = (name, extra = {}) => ({
|
|
6
6
|
id: extra.id,
|
|
7
|
+
type: 1,
|
|
7
8
|
name,
|
|
8
9
|
login: { username: extra.username, password: extra.password ?? "pw-value-1", uris: extra.uri ? [{ uri: extra.uri }] : [] },
|
|
9
10
|
notes: extra.notes,
|
|
11
|
+
fields: extra.fields,
|
|
10
12
|
});
|
|
11
13
|
|
|
12
14
|
test("reads a Bitwarden export object and a raw array", () => {
|
|
13
|
-
const fromExport =
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
const fromArray = bitwardenLogins([item("GitHub", { username: "me", uri: "https://github.com", notes: "n" })]);
|
|
15
|
+
const fromExport = bitwardenItems({ items: [login("GitHub", { username: "me", uri: "https://github.com", notes: "n" })] });
|
|
16
|
+
const fromArray = bitwardenItems([login("GitHub", { username: "me", uri: "https://github.com", notes: "n" })]);
|
|
17
17
|
assert.equal(fromExport.length, 1);
|
|
18
18
|
assert.deepEqual(fromExport[0], {
|
|
19
19
|
name: "GitHub",
|
|
20
|
+
type: "login",
|
|
20
21
|
username: "me",
|
|
21
22
|
password: "pw-value-1",
|
|
22
23
|
uris: ["https://github.com"],
|
|
@@ -25,50 +26,86 @@ test("reads a Bitwarden export object and a raw array", () => {
|
|
|
25
26
|
assert.deepEqual(fromArray, fromExport);
|
|
26
27
|
});
|
|
27
28
|
|
|
29
|
+
test("every item type maps field for field, by Bitwarden's names", () => {
|
|
30
|
+
const drafts = bitwardenItems({
|
|
31
|
+
items: [
|
|
32
|
+
{ id: "n", type: 2, name: "Wifi", secureNote: {}, notes: "guest: hunter2" },
|
|
33
|
+
{ id: "c", type: 3, name: "Visa", card: { cardholderName: "Li", brand: "Visa", number: "4111", expMonth: "12", expYear: "2029", code: "123" } },
|
|
34
|
+
{ id: "i", type: 4, name: "Me", identity: { title: "Mr", firstName: "Jun", lastName: "Li", ssn: "123-45-6789" } },
|
|
35
|
+
{ id: "k", type: 5, name: "key", sshKey: { privateKey: "PEM", publicKey: "ssh-ed25519 AAA", keyFingerprint: "SHA256:x" } },
|
|
36
|
+
{ id: "b", type: 6, name: "Bank", bankAccount: { bankName: "ICBC", accountNumber: "6222", pin: "9080", iban: null } },
|
|
37
|
+
{ id: "d", type: 7, name: "Licence", driversLicense: { licenseNumber: "110101", expirationDate: "2030-01-01" } },
|
|
38
|
+
{ id: "p", type: 8, name: "Passport", passport: { passportNumber: "E123", nationality: "CN" } },
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
const byName = Object.fromEntries(drafts.map((d) => [d.name, d]));
|
|
42
|
+
assert.equal(byName.Wifi.type, "secureNote");
|
|
43
|
+
assert.equal(byName.Wifi.notes, "guest: hunter2");
|
|
44
|
+
assert.equal(byName.Wifi.data, undefined, "a secure note has no fields of its own");
|
|
45
|
+
assert.deepEqual(byName.Visa.data, { cardholderName: "Li", brand: "Visa", number: "4111", expMonth: "12", expYear: "2029", code: "123" });
|
|
46
|
+
assert.equal(byName.Me.data.ssn, "123-45-6789");
|
|
47
|
+
assert.equal(byName["key"].data.privateKey, "PEM");
|
|
48
|
+
assert.deepEqual(byName.Bank.data, { bankName: "ICBC", accountNumber: "6222", pin: "9080" }, "a null field is dropped");
|
|
49
|
+
assert.equal(byName.Licence.data.licenseNumber, "110101");
|
|
50
|
+
assert.equal(byName.Passport.data.passportNumber, "E123");
|
|
51
|
+
assert.equal(byName.Me.password, undefined, "only a login carries the flat password mirror");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("custom fields keep their Bitwarden type, so a hidden one stays hidden", () => {
|
|
55
|
+
const [draft] = bitwardenItems([login("GH", { fields: [{ name: "API_KEY", value: "hf_abc", type: 1 }, { name: "Plan", value: "Team", type: 0 }] })]);
|
|
56
|
+
assert.deepEqual(draft.fields, [
|
|
57
|
+
{ name: "API_KEY", value: "hf_abc", type: 1 },
|
|
58
|
+
{ name: "Plan", value: "Team", type: 0 },
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
28
62
|
test("each entry keeps the id of the Bitwarden item it came from", () => {
|
|
29
|
-
const [draft] =
|
|
63
|
+
const [draft] = bitwardenItems({ items: [login("Cloud", { id: "bw-1", username: "root" })] });
|
|
30
64
|
assert.deepEqual(draft.source, { kind: "bitwarden", id: "bw-1" });
|
|
31
65
|
});
|
|
32
66
|
|
|
33
67
|
test("an encrypted export is refused instead of importing nothing", () => {
|
|
34
|
-
assert.throws(
|
|
35
|
-
() => bitwardenLogins({ encrypted: true, encKeyValidation: "…", data: "2.0|…" }),
|
|
36
|
-
/encrypted Bitwarden export/,
|
|
37
|
-
);
|
|
68
|
+
assert.throws(() => bitwardenItems({ encrypted: true, encKeyValidation: "…", data: "2.0|…" }), /encrypted Bitwarden export/);
|
|
38
69
|
});
|
|
39
70
|
|
|
40
71
|
test("a payload that is neither an export nor an item array is refused", () => {
|
|
41
|
-
assert.throws(() =>
|
|
42
|
-
assert.throws(() =>
|
|
72
|
+
assert.throws(() => bitwardenItems({ hello: "world" }), /Not a Bitwarden export/);
|
|
73
|
+
assert.throws(() => bitwardenItems(null), /Not a Bitwarden export/);
|
|
43
74
|
});
|
|
44
75
|
|
|
45
|
-
test("
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
{ name: "empty-login", login: { username: "a", password: "" } },
|
|
50
|
-
{ name: " \n", login: { password: "pw-value-1" } },
|
|
51
|
-
],
|
|
52
|
-
});
|
|
53
|
-
assert.equal(drafts.length, 1);
|
|
54
|
-
assert.equal(drafts[0].name, "unnamed");
|
|
76
|
+
test("an unknown type number is an error, a blank name becomes 'unnamed'", () => {
|
|
77
|
+
assert.throws(() => bitwardenItems([{ type: 99, name: "x" }]), /unsupported Bitwarden item type 99/);
|
|
78
|
+
const [draft] = bitwardenItems([{ type: 1, name: " \n", login: { password: "p" } }]);
|
|
79
|
+
assert.equal(draft.name, "unnamed");
|
|
55
80
|
});
|
|
56
81
|
|
|
57
|
-
test("disambiguates duplicate names
|
|
58
|
-
const drafts =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
["GitHub|a", "GitHub (2)|b", "Other|z"],
|
|
62
|
-
);
|
|
82
|
+
test("disambiguates duplicate names within a type, not across types", () => {
|
|
83
|
+
const drafts = bitwardenItems([login("GitHub", { username: "b" }), login("GitHub", { username: "a" }), { type: 2, name: "GitHub", secureNote: {} }]);
|
|
84
|
+
const names = drafts.map((d) => `${d.type}:${d.name}|${d.username ?? ""}`);
|
|
85
|
+
assert.deepEqual(names, ["login:GitHub|a", "login:GitHub (2)|b", "secureNote:GitHub|"]);
|
|
63
86
|
});
|
|
64
87
|
|
|
65
|
-
test("
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
assert.equal(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
test("type names parse the way a human writes them", () => {
|
|
89
|
+
assert.equal(parseItemType(undefined), "login");
|
|
90
|
+
assert.equal(parseItemType("SSH key"), "sshKey");
|
|
91
|
+
assert.equal(parseItemType("secure-note"), "secureNote");
|
|
92
|
+
assert.equal(parseItemType("driver's licence"), "driversLicense");
|
|
93
|
+
assert.equal(parseItemType("wifi"), undefined);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("secret fields are known per type", () => {
|
|
97
|
+
assert.equal(isSecretField("login", "password"), true);
|
|
98
|
+
assert.equal(isSecretField("card", "number"), true);
|
|
99
|
+
assert.equal(isSecretField("card", "brand"), false);
|
|
100
|
+
assert.equal(isSecretField("bankAccount", "pin"), true);
|
|
101
|
+
assert.equal(isSecretField("identity", "ssn"), true);
|
|
102
|
+
assert.equal(isSecretField("passport", "passportNumber"), true);
|
|
103
|
+
assert.equal(isSecretField("passport", "nationality"), false);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("filterItems matches name, username, and URIs across every type", () => {
|
|
107
|
+
const items = bitwardenItems([login("GitHub", { username: "me", uri: "https://github.com" }), { type: 3, name: "Visa", card: { brand: "Visa" } }]);
|
|
108
|
+
assert.equal(filterItems(items, "visa")[0]?.name, "Visa");
|
|
109
|
+
assert.equal(filterItems(items, "github.com")[0]?.name, "GitHub");
|
|
110
|
+
assert.equal(filterItems(items).length, 2);
|
|
74
111
|
});
|
package/tests/mocks/bin/bw
CHANGED
|
@@ -30,11 +30,15 @@ case "$args" in
|
|
|
30
30
|
fi ;;
|
|
31
31
|
"sync --nointeraction") exit 0 ;;
|
|
32
32
|
"list items --nointeraction")
|
|
33
|
-
echo '[{"id":"aaaa1111-1111-4111-8111-111111111111","name":"TestService","login":{"username":"alice","password":"supersecret-value-123","totp":null,"uris":[{"uri":"https://test.example.com"}]},"notes":"note-secret-abc","fields":[{"name":"API_KEY","value":"hf_sk-abc987xyz456","type":1}]},{"id":"bbbb2222-2222-4222-8222-222222222222","name":"OtherService","login":{"username":"bob","password":"other-pw-999","uris":[]},"fields":[]}]' ;;
|
|
33
|
+
echo '[{"id":"aaaa1111-1111-4111-8111-111111111111","name":"TestService","login":{"username":"alice","password":"supersecret-value-123","totp":null,"uris":[{"uri":"https://test.example.com"}]},"notes":"note-secret-abc","fields":[{"name":"API_KEY","value":"hf_sk-abc987xyz456","type":1}]},{"id":"bbbb2222-2222-4222-8222-222222222222","name":"OtherService","login":{"username":"bob","password":"other-pw-999","uris":[]},"fields":[]},{"id":"cccc3333-3333-4333-8333-333333333333","type":3,"name":"CorpCard","card":{"cardholderName":"Li Jun","brand":"Visa","number":"4111111111111111","expMonth":"12","expYear":"2029","code":"123"}},{"id":"dddd4444-4444-4444-8444-444444444444","type":2,"name":"WifiNote","secureNote":{},"notes":"guest network: hunter2"}]' ;;
|
|
34
34
|
"get item aaaa1111-1111-4111-8111-111111111111 --nointeraction")
|
|
35
35
|
echo '{"id":"aaaa1111-1111-4111-8111-111111111111","name":"TestService","login":{"username":"alice","password":"supersecret-value-123","uris":[]},"fields":[{"name":"API_KEY","value":"hf_sk-abc987xyz456","type":1}]}' ;;
|
|
36
36
|
"get item bbbb2222-2222-4222-8222-222222222222 --nointeraction")
|
|
37
37
|
echo '{"id":"bbbb2222-2222-4222-8222-222222222222","name":"OtherService","login":{"username":"bob","password":"other-pw-999","uris":[]},"fields":[]}' ;;
|
|
38
|
+
"get item cccc3333-3333-4333-8333-333333333333 --nointeraction")
|
|
39
|
+
echo '{"id":"cccc3333-3333-4333-8333-333333333333","type":3,"name":"CorpCard","card":{"cardholderName":"Li Jun","brand":"Visa","number":"4111111111111111","expMonth":"12","expYear":"2029","code":"123"}}' ;;
|
|
40
|
+
"get item dddd4444-4444-4444-8444-444444444444 --nointeraction")
|
|
41
|
+
echo '{"id":"dddd4444-4444-4444-8444-444444444444","type":2,"name":"WifiNote","secureNote":{},"notes":"guest network: hunter2"}' ;;
|
|
38
42
|
"lock --nointeraction") touch "$MOCK_DIR/locked"; exit 0 ;;
|
|
39
43
|
"get item "*" --nointeraction") echo "Not found." >&2; exit 1 ;;
|
|
40
44
|
*) echo "mock bw: unhandled: $args" >&2; exit 1 ;;
|
package/tests/mocks/bin/zenity
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
# Mock zenity for the ai-vault tests. Every call is one line in
|
|
3
3
|
# $OMP_VAULT_MOCK/zenity.log (newlines inside an argument show as ⏎).
|
|
4
|
-
# --password a master-password dialog (its title says 主密码
|
|
4
|
+
# --password a master-password dialog (its title says 主密码 or "master
|
|
5
|
+
# password"/"unlock"/"set master password") answers with
|
|
5
6
|
# the first line of $OMP_VAULT_MOCK/passwords, or "testmaster"
|
|
6
7
|
# when that file is missing or empty; any other password dialog
|
|
7
8
|
# answers with the first line of $OMP_VAULT_MOCK/entry-passwords
|
|
@@ -24,7 +25,11 @@ for arg in "$@"; do
|
|
|
24
25
|
case "$arg" in
|
|
25
26
|
--password)
|
|
26
27
|
kind="entry"
|
|
27
|
-
for a in "$@"; do
|
|
28
|
+
for a in "$@"; do
|
|
29
|
+
case "$a" in
|
|
30
|
+
--title=*主密码*|--title=*解锁*|--title=*创建*|--title=*master\ password*|--title=*unlock*) kind="master" ;;
|
|
31
|
+
esac
|
|
32
|
+
done
|
|
28
33
|
if [[ "$kind" == "master" ]]; then
|
|
29
34
|
if [[ -s "$DIR/passwords" ]]; then take_first "$DIR/passwords"; else echo "testmaster"; fi
|
|
30
35
|
elif [[ -f "$DIR/entry-passwords" ]]; then
|
package/tests/vault-cli.test.mjs
CHANGED
|
@@ -313,3 +313,59 @@ test("a relayed read approval is signed by the host: the raw CLI refuses a bare
|
|
|
313
313
|
assert.match(tampered.stderr, /modified outside ai-vault/);
|
|
314
314
|
assert.equal(readdirSync(dir).includes(`${token}.json`), false, "the tampered file is deleted");
|
|
315
315
|
});
|
|
316
|
+
|
|
317
|
+
test("vault_add stores a card: non-secret fields from the model, the CVV typed in a dialog", async () => {
|
|
318
|
+
const b = bind(aiVault, true);
|
|
319
|
+
const ctx = makeCtx().ctx;
|
|
320
|
+
answers.master(dir, PW);
|
|
321
|
+
answers.questions(dir, "y");
|
|
322
|
+
answers.entryPassword(dir, "000");
|
|
323
|
+
const result = await b.tool(
|
|
324
|
+
"vault_add",
|
|
325
|
+
{
|
|
326
|
+
name: "MyCard",
|
|
327
|
+
type: "card",
|
|
328
|
+
fields: { brand: "Mastercard", cardholderName: "Li Jun", expMonth: "01", expYear: "2030", code: undefined },
|
|
329
|
+
},
|
|
330
|
+
ctx,
|
|
331
|
+
);
|
|
332
|
+
assert.equal(result.isError, undefined, textOf(result));
|
|
333
|
+
assert.match(textOf(result), /as a card/);
|
|
334
|
+
// The list shows the type and the non-secret fields, never the code.
|
|
335
|
+
answers.master(dir, PW);
|
|
336
|
+
const listed = JSON.parse(textOf(await b.tool("vault_list", {}, ctx)));
|
|
337
|
+
const card = listed.find((i) => i.name === "MyCard");
|
|
338
|
+
assert.equal(card.type, "card");
|
|
339
|
+
assert.equal(card.fields.brand, "Mastercard");
|
|
340
|
+
assert.equal(JSON.stringify(listed).includes("000"), false);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("vault_add refuses a secret the model tried to supply itself", async () => {
|
|
344
|
+
const b = bind(aiVault, true);
|
|
345
|
+
const ctx = makeCtx().ctx;
|
|
346
|
+
answers.master(dir, PW);
|
|
347
|
+
const result = await b.tool("vault_add", { name: "Leaky", type: "card", fields: { code: "123" } }, ctx);
|
|
348
|
+
assert.equal(result.isError, true);
|
|
349
|
+
assert.match(textOf(result), /secret field/);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test("vault_get falls back to Bitwarden for a non-login hit and imports it with its fields", async () => {
|
|
353
|
+
const b = bind(aiVault, true);
|
|
354
|
+
const ctx = makeCtx().ctx;
|
|
355
|
+
answers.master(dir, PW);
|
|
356
|
+
await b.cmd("unlock", ctx);
|
|
357
|
+
answers.master(dir, "testmaster");
|
|
358
|
+
answers.questions(dir, "y", "y");
|
|
359
|
+
const result = await b.tool("vault_get", { name: "CorpCard" }, ctx);
|
|
360
|
+
assert.equal(result.details.via, "imported-from-bitwarden");
|
|
361
|
+
const body = JSON.parse(textOf(result));
|
|
362
|
+
assert.equal(body.type, "card");
|
|
363
|
+
assert.equal(body.data.number, "4111111111111111");
|
|
364
|
+
assert.equal(body.data.code, "123");
|
|
365
|
+
answers.master(dir, PW);
|
|
366
|
+
const listed = JSON.parse(textOf(await b.tool("vault_list", {}, ctx)));
|
|
367
|
+
const card = listed.find((i) => i.name === "CorpCard");
|
|
368
|
+
assert.equal(card.type, "card");
|
|
369
|
+
assert.equal(card.fields.cardholderName, "Li Jun");
|
|
370
|
+
assert.equal(JSON.stringify(listed).includes("4111111111111111"), false, "list must mask the card number");
|
|
371
|
+
});
|