Skip to content

Commit 7372143

Browse files
sambacc: fix join interactive test
Fix how the Joiner and the test for interactive login was using stdin. When the test was run without pytest capturing the stdio, the test would hang waiting on input. This behavior was incorrect. Add a hook to the Joiner for the unit tests to use so that the stdin of the interactive join command can be manipulated. Signed-off-by: John Mulligan <[email protected]>
1 parent eca9d79 commit 7372143

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

sambacc/join.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def _read_from(self, path: str) -> UserPass:
169169
raise JoinError("invalid file content: invalid password")
170170
return upass
171171

172+
def _interactive_input(self) -> typing.Optional[typing.IO]:
173+
return None
174+
172175
def _join(self, upass: UserPass, dns_updates: bool = False) -> None:
173176
args = []
174177
if not dns_updates:
@@ -177,7 +180,7 @@ def _join(self, upass: UserPass, dns_updates: bool = False) -> None:
177180

178181
if upass.password is _PROMPT:
179182
cmd = list(self._net_ads_join[args])
180-
proc = subprocess.Popen(cmd)
183+
proc = subprocess.Popen(cmd, stdin=self._interactive_input())
181184
else:
182185
cmd = list(self._net_ads_join[args])
183186
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE)

tests/test_join.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ class TestJoiner(sambacc.join.Joiner):
4545
_net_ads_join = samba_cmds.SambaCommand(fake_net_script)["ads", "join"]
4646
path = tmp_path
4747
logpath = data_path / "log"
48+
_nullfh = None
4849

49-
return TestJoiner()
50+
def _interactive_input(self):
51+
return self._nullfh
52+
53+
with open(os.devnull, "rb") as dnull:
54+
TestJoiner._null = dnull
55+
yield TestJoiner()
5056

5157

5258
def test_no_sources(testjoiner):

0 commit comments

Comments
 (0)