Skip to content

Commit 0cdc941

Browse files
committed
test: Make sure closing stdin gets propagated to host apps
This only works when we don't accidentally keep any fd open in the proxy.
1 parent f5f35ec commit 0cdc941

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "org.example.writeonclose",
3+
"description": "Writes a file to $TMPDIR/xnmp-write-on-close when stdin gets closed",
4+
"path": "write-on-close.py",
5+
"type": "stdio",
6+
"allowed_extensions": [
7+
8+
]
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import os
4+
from pathlib import Path
5+
6+
while True:
7+
r = sys.stdin.buffer.read(1)
8+
if len(r) == 0:
9+
break
10+
11+
(Path(os.environ["TMPDIR"]) / "xnmp-write-on-close").touch()

tests/test_xnmp.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import xnmp
44
import errno
5+
from pathlib import Path
56

67

78
class TestXnmp:
@@ -117,3 +118,21 @@ def fd_closed():
117118
xnmp.wait_for(fd_closed)
118119
finally:
119120
os.close(stdin_fd)
121+
122+
def test_close_stdin(self, xdg_native_messaging_proxy, manifests, dbus_con):
123+
iface = xnmp.get_iface(dbus_con)
124+
manifest_name = "org.example.writeonclose"
125+
extension = "[email protected]"
126+
mode = "firefox"
127+
128+
(stdin, stdout, stderr, handle) = iface.Start(
129+
manifest_name, extension, mode, {}
130+
)
131+
132+
fpath = Path(os.environ["TMPDIR"]) / "xnmp-write-on-close"
133+
assert not fpath.exists()
134+
135+
stdin_fd = stdin.take()
136+
137+
os.close(stdin_fd)
138+
xnmp.wait_for(lambda: fpath.exists())

0 commit comments

Comments
 (0)