Add tests for the individual login_shell detection functions
This commit is contained in:
parent
3fb7ce7100
commit
c00e8b1709
@ -8,8 +8,9 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from kittens.ssh.main import bootstrap_script, get_connection_data
|
from kittens.ssh.main import bootstrap_script, get_connection_data
|
||||||
from kitty.utils import SSHConnectionData
|
from kitty.constants import is_macos
|
||||||
from kitty.fast_data_types import CURSOR_BEAM
|
from kitty.fast_data_types import CURSOR_BEAM
|
||||||
|
from kitty.utils import SSHConnectionData
|
||||||
|
|
||||||
from . import BaseTest
|
from . import BaseTest
|
||||||
from .shell_integration import bash_ok, basic_shell_env
|
from .shell_integration import bash_ok, basic_shell_env
|
||||||
@ -45,6 +46,24 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
|||||||
# test simple untar with only sh
|
# test simple untar with only sh
|
||||||
with tempfile.TemporaryDirectory() as tdir:
|
with tempfile.TemporaryDirectory() as tdir:
|
||||||
self.check_bootstrap('sh', tdir, 'sh', SHELL_INTEGRATION_VALUE='')
|
self.check_bootstrap('sh', tdir, 'sh', SHELL_INTEGRATION_VALUE='')
|
||||||
|
# test various detection methods for login_shell
|
||||||
|
methods = []
|
||||||
|
if shutil.which('python') or shutil.which('python3') or shutil.which('python2'):
|
||||||
|
methods.append('using_python')
|
||||||
|
if is_macos:
|
||||||
|
methods += ['using_id']
|
||||||
|
else:
|
||||||
|
if shutil.which('getent'):
|
||||||
|
methods.append('using_getent')
|
||||||
|
if os.access('/etc/passwd', os.R_OK):
|
||||||
|
methods.append('using_passwd')
|
||||||
|
self.assertTrue(methods)
|
||||||
|
import pwd
|
||||||
|
expected_login_shell = pwd.getpwuid(os.geteuid()).pw_shell
|
||||||
|
for m in methods:
|
||||||
|
with self.subTest(method=m):
|
||||||
|
pty = self.check_bootstrap('sh', tdir, extra_exec=f'{m}; echo "$login_shell"; exit 0', SHELL_INTEGRATION_VALUE='')
|
||||||
|
self.assertIn(expected_login_shell, pty.screen_contents())
|
||||||
|
|
||||||
ok_login_shell = ''
|
ok_login_shell = ''
|
||||||
for sh in ('dash', 'zsh', 'bash', 'posh', 'sh'):
|
for sh in ('dash', 'zsh', 'bash', 'posh', 'sh'):
|
||||||
@ -64,9 +83,9 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
|||||||
with tempfile.TemporaryDirectory() as tdir:
|
with tempfile.TemporaryDirectory() as tdir:
|
||||||
self.check_bootstrap('sh', tdir, ok_login_shell, val)
|
self.check_bootstrap('sh', tdir, ok_login_shell, val)
|
||||||
|
|
||||||
def check_bootstrap(self, sh, home_dir, login_shell, SHELL_INTEGRATION_VALUE='enabled'):
|
def check_bootstrap(self, sh, home_dir, login_shell='', SHELL_INTEGRATION_VALUE='enabled', extra_exec=''):
|
||||||
script = bootstrap_script(
|
script = bootstrap_script(
|
||||||
EXEC_CMD='echo "UNTAR_DONE"',
|
EXEC_CMD=f'echo "UNTAR_DONE"; {extra_exec}',
|
||||||
OVERRIDE_LOGIN_SHELL=login_shell,
|
OVERRIDE_LOGIN_SHELL=login_shell,
|
||||||
SHELL_INTEGRATION_VALUE=SHELL_INTEGRATION_VALUE,
|
SHELL_INTEGRATION_VALUE=SHELL_INTEGRATION_VALUE,
|
||||||
)
|
)
|
||||||
@ -75,7 +94,6 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
|||||||
os.makedirs(os.path.join(home_dir, '.local', 'share', 'fish', 'generated_completions'), exist_ok=True)
|
os.makedirs(os.path.join(home_dir, '.local', 'share', 'fish', 'generated_completions'), exist_ok=True)
|
||||||
# prevent newuser-install from running
|
# prevent newuser-install from running
|
||||||
open(os.path.join(home_dir, '.zshrc'), 'w').close()
|
open(os.path.join(home_dir, '.zshrc'), 'w').close()
|
||||||
self.assertFalse(os.path.exists(os.path.join(home_dir, '.terminfo/kitty.terminfo')))
|
|
||||||
pty = self.create_pty(f'{sh} -c {shlex.quote(script)}', cwd=home_dir, env=env)
|
pty = self.create_pty(f'{sh} -c {shlex.quote(script)}', cwd=home_dir, env=env)
|
||||||
del script
|
del script
|
||||||
|
|
||||||
@ -91,3 +109,4 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
|||||||
self.assertEqual(pty.screen.cursor.shape, 0)
|
self.assertEqual(pty.screen.cursor.shape, 0)
|
||||||
else:
|
else:
|
||||||
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM)
|
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM)
|
||||||
|
return pty
|
||||||
|
|||||||
@ -87,9 +87,6 @@ if [ -x "$(command -v tic)" ]; then
|
|||||||
if [ "$rc" != "0" ]; then die "$tic_out"; fi
|
if [ "$rc" != "0" ]; then die "$tic_out"; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If a command was passed to SSH execute it here
|
|
||||||
EXEC_CMD
|
|
||||||
|
|
||||||
shell_integration_dir="$HOME/SHELL_INTEGRATION_DIR"
|
shell_integration_dir="$HOME/SHELL_INTEGRATION_DIR"
|
||||||
|
|
||||||
login_shell_is_ok() {
|
login_shell_is_ok() {
|
||||||
@ -113,7 +110,7 @@ using_getent() {
|
|||||||
if [ -n "$cmd" ]; then
|
if [ -n "$cmd" ]; then
|
||||||
output=$($cmd passwd $USER 2>/dev/null)
|
output=$($cmd passwd $USER 2>/dev/null)
|
||||||
if [ $? = 0 ]; then
|
if [ $? = 0 ]; then
|
||||||
login_shell=$(echo $output | cut -d: -f7);
|
login_shell=$(echo $output | grep -o '[^:]*$');
|
||||||
if login_shell_is_ok; then return 0; fi
|
if login_shell_is_ok; then return 0; fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -162,6 +159,9 @@ execute_with_python() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If a command was passed to SSH execute it here
|
||||||
|
EXEC_CMD
|
||||||
|
|
||||||
LOGIN_SHELL="OVERRIDE_LOGIN_SHELL"
|
LOGIN_SHELL="OVERRIDE_LOGIN_SHELL"
|
||||||
if [ -n "$LOGIN_SHELL" ]; then
|
if [ -n "$LOGIN_SHELL" ]; then
|
||||||
login_shell="$LOGIN_SHELL"
|
login_shell="$LOGIN_SHELL"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user