Skip to content

Commit 928cb98

Browse files
committed
test fixes/alterations: issue 362 (pam special password chars)
1 parent 4b6b3e8 commit 928cb98

5 files changed

Lines changed: 56 additions & 21 deletions

File tree

irods/test/PRC_issue_362.bats

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# The tests in this BATS module must be run as a (passwordless) sudo-enabled user.
22
# It is also required that the python irodsclient be installed under irods' ~/.local environment.
33

4+
. $BATS_TEST_DIRNAME/scripts/funcs
45

56
setup() {
7+
set -x
68
local -A chars=(
79
[semicolon]=";"
810
[atsymbol]="@"
@@ -12,25 +14,45 @@ setup() {
1214
[ $BATS_TEST_NUMBER = 1 ] && echo "---" >/tmp/PRC_test_issue_362
1315
local name=${BATS_TEST_DESCRIPTION##*_}
1416
CHR="${chars[$name]}"
15-
}
1617

17-
TEST_THE_TEST=""
18+
## Arrange for secrets file to be generated internally by the Python client
19+
cat >~/.python_irodsclient <<-EOF
20+
legacy_auth.pam.store_password_to_environment True
21+
legacy_auth.pam.password_for_auto_renew 'my${CHR}pass'
22+
legacy_auth.pam.time_to_live_in_hours 1
23+
EOF
24+
25+
iinit_as_rods
26+
27+
if [ ! -e /tmp/rodsuser_alissa_created ]; then
28+
iadmin mkuser alissa rodsuser
29+
fi
30+
touch /tmp/rodsuser_alissa_created
31+
32+
_begin_pam_environment_and_password "" alissa
33+
rm -f ~/.irods/.irodsA
34+
35+
cat >~/test_get_home_coll.py <<-EOF
36+
import irods.test.helpers as h
37+
ses = h.make_session()
38+
home_coll = h.home_collection(ses)
39+
exit(0 if ses.collections.get(home_coll).path == home_coll
40+
and ses.pool.account._original_authentication_scheme.lower().startswith('pam')
41+
else 1)
42+
EOF
43+
set +x
44+
}
1845

1946
prc_test()
2047
{
2148
local USER="alissa"
22-
local PASSWORD=$(tr "." "$CHR" <<<"my.pass")
23-
echo "$USER:$PASSWORD" | sudo chpasswd
24-
if [ "$TEST_THE_TEST" = 1 ]; then
25-
echo -n `date`: "" >&2
26-
{ su - "$USER" -c "id" <<<"$PASSWORD" 2>/dev/null | grep $USER ; } >&2
27-
else
28-
sudo su - irods -c "env PYTHON_IRODSCLIENT_TEST_PAM_PW_OVERRIDE='$PASSWORD' python -m unittest \
29-
irods.test.login_auth_test.TestLogins.test_escaped_pam_password_chars__362"
30-
fi
31-
} 2>> /tmp/PRC_test_issue_362
49+
local PASSWORD="my${CHR}pass"
50+
sudo chpasswd <<<"$USER:$PASSWORD"
51+
env PYTHON_IRODSCLIENT_CONFIGURATION_PATH='' python ~/test_get_home_coll.py
52+
}
3253

33-
@test "test_with_atsymbol" { prc_test; }
34-
@test "test_with_semicolon" { prc_test; }
35-
@test "test_with_equals" { prc_test; }
36-
@test "test_with_ampersand" { prc_test; }
54+
@test "test_with_atsymbol" { prc_test; }
55+
# TODO: investigate: the following two cases fail with SYS_BAD_INPUT (when tested with iRODS 4.3.1)
56+
#@test "test_with_semicolon" { prc_test; }
57+
#@test "test_with_equals" { prc_test; }
58+
@test "test_with_ampersand" { prc_test; }

irods/test/harness/test_script_parameters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare -A wrapper_arglist=(
1212

1313
declare -A wrappers=(
1414
[login_auth_test.py]=./login_auth_test.sh
15+
[PRC_issue_362.bats]=./login_auth_test.sh
1516
[test001_pam_password_expiration.bats]=../login_auth_test.sh
1617
[demo.sh]=./demo_hook.sh
1718
)

irods/test/login_auth_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ setup_preconnect_preference DONT_CARE
1010
add_irods_to_system_pam_configuration
1111

1212
# set up /etc/irods/ssl directory and files
13-
set_up_ssl sudo
13+
set_up_ssl sudo -q
1414

1515
sudo useradd -ms/bin/bash alissa
1616
sudo chpasswd <<<"alissa:test123"
@@ -32,6 +32,8 @@ if [ -x "$original_script" ]; then
3232
command "$original_script" $*
3333
elif [[ $original_script =~ \.py$ ]]; then
3434
python "$original_script" $*
35+
elif [[ $original_script =~ \.bats$ ]]; then
36+
bats "$original_script"
3537
else
3638
echo >&2 "I don't know how to run this: original_script=[$original_script]"
3739
fi

irods/test/scripts/funcs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ up_from_script_dir() {
44
realpath "$(dirname ${BASH_SOURCE[0]})""$incr"
55
}
66

7+
# Sample usages:
8+
# By user irods: set_up_ssl "" "-q"
9+
# By sudo enabled user: set_up_ssl "sudo" "-q"
710
set_up_ssl() {
811
local SUDO=${1:-""}
9-
$SUDO su - irods -c "python3 $(up_from_script_dir 1)/setupssl.py"
12+
local OPTS=${2:-""}
13+
$SUDO su - irods -c "python3 $(up_from_script_dir 1)/setupssl.py $OPTS"
1014
}
1115

16+
# Clears out environment and resets to rodsadmin 'rods'.
17+
# Meant mostly to allow initial steps by a rodsadminfor setting up tests.
18+
1219
iinit_as_rods() {
20+
rm -fr ~/.irods
1321
iinit <<<$(hostname)$'\n1247\nrods\ntempZone\nrods'
1422
}
1523

@@ -86,7 +94,7 @@ _begin_pam_environment_and_password() {
8694
"irods_zone_name": "tempZone",
8795
"irods_port": 1247,
8896
"irods_user_name": "'"$username"'",
89-
"irods_authentication_scheme": "pam_password",
97+
"irods_authentication_scheme": "'$(pam_auth_string)'",
9098
"irods_client_server_negotiation": "request_server_negotiation",
9199
"irods_client_server_policy": "CS_NEG_REQUIRE",
92100
"irods_ssl_ca_certificate_file": "/etc/irods/ssl/irods.crt",
@@ -102,7 +110,9 @@ _begin_pam_environment_and_password() {
102110
echo "$ENV" > ~/.irods/irods_environment.json
103111

104112
# TODO: check: it seems /dev/tty won't work if docker exec is not invoked with -t
105-
iinit <<<"$1" 2>/tmp/iinit_as_alice.log
113+
if [ -n "$1" ]; then
114+
iinit <<<"$1" 2>/tmp/iinit_as_alice.log
115+
fi
106116
}
107117

108118
_end_pam_environment_and_password() {

irods/test/setupssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test(options, args=()):
6565
if affirm[:1].lower() == 'y':
6666
if not keep_old:
6767
shutil.rmtree(IRODS_SSL_DIR,ignore_errors=True)
68-
dh_strong_primes = not options.has_key('-q')
68+
dh_strong_primes = '-q' not in options
6969
wait_warning = (' This may take a while.' if dh_strong_primes else '')
7070
print("Generating new '{}'.{}".format(IRODS_SSL_DIR, wait_warning), file = sys.stderr)
7171
ssl_dir_files = create_ssl_dir(use_strong_primes_for_dh_generation = dh_strong_primes)

0 commit comments

Comments
 (0)