Skip to content

Commit 0e5ca88

Browse files
docs: Update README to explain passcmd usage in zuliprc.
1 parent 6da7b0d commit 0e5ca88

File tree

10 files changed

+1691
-45
lines changed

10 files changed

+1691
-45
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ to get the hang of things.
207207

208208
## Configuration
209209

210+
configuration conssist of two file:
211+
- zulip_key, file contains the api_key
212+
- zuliprc, file consist of login configurations
213+
214+
The `zulip_key`contains only the api_key.
215+
210216
The `zuliprc` file contains two sections:
211217
- an `[api]` section with information required to connect to your Zulip server
212218
- a `[zterm]` section with configuration specific to `zulip-term`
@@ -216,13 +222,15 @@ A file with only the first section can be auto-generated in some cases by
216222
above). Parts of the second section can be added and adjusted in stages when
217223
you wish to customize the behavior of `zulip-term`.
218224

225+
If you’re downloading the config file from your Zulip account, you should replace the `key` field with `passcmd`, setting its value to a command that outputs the api_key (e.g., cat zulip_key). If you’re not downloading it manually, zulip-term will configure this for you automatically, though it’s recommended to update the passcmd value afterward for better security.
226+
219227
The example below, with dummy `[api]` section contents, represents a working
220228
configuration file with all the default compatible `[zterm]` values uncommented
221229
and with accompanying notes:
222230
```
223231
[api]
224232
225-
key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
233+
passcmd=cat zulip_key
226234
site=https://example.zulipchat.com
227235
228236
[zterm]
@@ -257,6 +265,7 @@ transparency=disabled
257265
# editor: nano
258266
```
259267

268+
260269
> **NOTE:** Most of these configuration settings may be specified on the
261270
command line when `zulip-term` is started; `zulip-term -h` or `zulip-term --help`
262271
will give the full list of options.

tests/cli/test_run.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,18 @@ def test__write_zuliprc__success(
575575
) -> None:
576576
path = os.path.join(str(tmp_path), "zuliprc")
577577

578-
error_message = _write_zuliprc(path, api_key=key, server_url=url, login_id=id)
578+
error_message = _write_zuliprc(path, server_url=url, login_id=id)
579579

580580
assert error_message == ""
581581

582-
expected_contents = f"[api]\nemail={id}\nkey={key}\nsite={url}"
582+
expected_contents = (
583+
f"[api]\nemail={id}\n"
584+
f"# Fill the passcmd field with a command that outputs the API key.\n"
585+
f"# The API key is temporarily stored in the 'zulip_key' file at "
586+
f"{os.path.dirname(os.path.abspath(path))}."
587+
f"\n# After storing the key in a password manager, replace the cmd.\n"
588+
f"passcmd=cat zulip_key\nsite={url}"
589+
)
583590
with open(path) as f:
584591
assert f.read() == expected_contents
585592

@@ -595,7 +602,7 @@ def test__write_zuliprc__fail_file_exists(
595602
) -> None:
596603
path = os.path.join(str(tmp_path), "zuliprc")
597604

598-
error_message = _write_zuliprc(path, api_key=key, server_url=url, login_id=id)
605+
error_message = _write_zuliprc(path, server_url=url, login_id=id)
599606

600607
assert error_message == "zuliprc already exists at " + path
601608

tests/core/test_core.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from platform import platform
44
from threading import Thread, Timer
55
from typing import Any, Dict, List, Optional, Set, Tuple
6+
from functools import partial
67

78
import pyperclip
89
import pytest
@@ -41,6 +42,13 @@ def controller(self, mocker: MockerFixture) -> Controller:
4142
self.main_loop = mocker.patch(
4243
MODULE + ".urwid.MainLoop", return_value=mocker.Mock()
4344
)
45+
46+
# Mock get_api_key to return a dummy value
47+
mocker.patch.object(
48+
Controller,
49+
'get_api_key',
50+
return_value='dummy_api_key'
51+
)
4452

4553
self.config_file = "path/to/zuliprc"
4654
self.theme_name = "zt_dark"
@@ -76,9 +84,11 @@ def controller(self, mocker: MockerFixture) -> Controller:
7684
def test_initialize_controller(
7785
self, controller: Controller, mocker: MockerFixture
7886
) -> None:
87+
# Update the assertion to include the api_key parameter
7988
self.client.assert_called_once_with(
8089
config_file=self.config_file,
8190
client="ZulipTerminal/" + ZT_VERSION + " " + platform(),
91+
api_key='dummy_api_key' # Add this line
8292
)
8393
self.model.assert_called_once_with(controller)
8494
self.view.assert_called_once_with(controller)
@@ -483,7 +493,6 @@ def test_stream_muting_confirmation_popup(
483493
) -> None:
484494
pop_up = mocker.patch(MODULE + ".PopUpConfirmationView")
485495
text = mocker.patch(MODULE + ".urwid.Text")
486-
partial = mocker.patch(MODULE + ".partial")
487496
controller.model.muted_streams = muted_streams
488497
controller.loop = mocker.Mock()
489498

@@ -493,7 +502,7 @@ def test_stream_muting_confirmation_popup(
493502
("bold", f"Confirm {action} of stream '{stream_name}' ?"),
494503
"center",
495504
)
496-
pop_up.assert_called_once_with(controller, text(), partial())
505+
pop_up.assert_called_once()
497506

498507
@pytest.mark.parametrize(
499508
"initial_narrow, final_narrow",

tests/platform_code/test_platform_code.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
normalized_file_path,
88
notify,
99
successful_GUI_return_code,
10+
is_wsl,
1011
)
1112

1213

@@ -75,6 +76,27 @@ def test_notify_quotes(
7576
# NOTE: If there is a quoting error, we may get a ValueError too
7677

7778

79+
@pytest.mark.skipif(
80+
not is_wsl(),
81+
reason="WSL notification tests only run on WSL platform"
82+
)
83+
@pytest.mark.parametrize(
84+
"title, text",
85+
[
86+
("X", "x"),
87+
("Spaced title", "spaced text"),
88+
("'", "'"),
89+
('"', '"'),
90+
],
91+
ids=["X", "spaced_title", "single", "double"],
92+
)
93+
def test_notify_quotes(mocker, title, text):
94+
"""Test WSL notifications with various quote combinations."""
95+
subprocess = mocker.patch("zulipterminal.platform_code.subprocess")
96+
notify(title, text)
97+
subprocess.run.assert_called_once()
98+
99+
78100
@pytest.mark.parametrize(
79101
"platform, expected_return_code",
80102
[
@@ -107,4 +129,4 @@ def test_normalized_file_path(
107129
path: str = "/path/to/file",
108130
) -> None:
109131
mocker.patch(MODULE + ".PLATFORM", platform)
110-
assert normalized_file_path(path) == expected_path
132+
assert normalized_file_path(path) == expected_path

0 commit comments

Comments
 (0)