mirror of
https://github.com/Hopiu/llm.git
synced 2026-04-15 10:41:01 +00:00
Chmod 600 keys.json on creation, refs #351
This commit is contained in:
parent
1a4853d80e
commit
9119b03a07
2 changed files with 9 additions and 3 deletions
|
|
@ -517,6 +517,7 @@ def keys_set(name, value):
|
|||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not path.exists():
|
||||
path.write_text(json.dumps(default))
|
||||
path.chmod(0o600)
|
||||
try:
|
||||
current = json.loads(path.read_text())
|
||||
except json.decoder.JSONDecodeError:
|
||||
|
|
|
|||
|
|
@ -20,12 +20,17 @@ def test_keys_in_user_path(monkeypatch, env, user_path):
|
|||
|
||||
|
||||
def test_keys_set(monkeypatch, tmpdir):
|
||||
user_path = str(tmpdir / "user/keys")
|
||||
monkeypatch.setenv("LLM_USER_PATH", user_path)
|
||||
user_path = tmpdir / "user/keys"
|
||||
monkeypatch.setenv("LLM_USER_PATH", str(user_path))
|
||||
keys_path = user_path / "keys.json"
|
||||
assert not keys_path.exists()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["keys", "set", "openai"], input="foo")
|
||||
assert result.exit_code == 0
|
||||
content = open(user_path + "/keys.json").read()
|
||||
assert keys_path.exists()
|
||||
# Should be chmod 600
|
||||
assert oct(keys_path.stat().mode)[-3:] == "600"
|
||||
content = keys_path.read_text("utf-8")
|
||||
assert json.loads(content) == {
|
||||
"// Note": "This file stores secret API credentials. Do not share!",
|
||||
"openai": "foo",
|
||||
|
|
|
|||
Loading…
Reference in a new issue