Skip to content

Commit fcfac53

Browse files
committed
[_517] tests
1 parent 543fa6b commit fcfac53

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed

irods/test/scripts/test002.bats

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Test creation of .irodsA for iRODS native authentication using the free function,
4+
# irods.client_init.write_pam_credentials_to_secrets_file
5+
6+
. "$BATS_TEST_DIRNAME"/test_support_functions
7+
PYTHON=python3
8+
9+
# Setup/prerequisites are same as for login_auth_test.
10+
# Run as ubuntu user with sudo; python_irodsclient must be installed (in either ~/.local or a virtualenv)
11+
#
12+
13+
OLD_PAM_PASSWD="test123"
14+
NEW_PAM_PASSWD="new_pass"
15+
16+
setup()
17+
{
18+
setup_pam_login_for_alice "$OLD_PAM_PASSWD"
19+
}
20+
21+
teardown()
22+
{
23+
finalize_pam_login_for_alice
24+
test_specific_cleanup
25+
}
26+
27+
@test create_secrets_file {
28+
29+
# Old .irodsA is already created, so we delete it and alter the pam password.
30+
sudo chpasswd <<<"alice:$NEW_PAM_PASSWD"
31+
rm -f ~/.irods/.irodsA
32+
$PYTHON -c "import irods.client_init; irods.client_init.write_pam_credentials_to_secrets_file('$NEW_PAM_PASSWD')"
33+
34+
# Define the core Python to be run, basically a minimal code block ensuring that we can authenticate to iRODS
35+
# without an exception being raised.
36+
37+
local SCRIPT="
38+
import irods.test.helpers as h
39+
ses = h.make_session()
40+
ses.collections.get(h.home_collection(ses))
41+
print ('env_auth_scheme=%s' % ses.pool.account._original_authentication_scheme)
42+
"
43+
OUTPUT=$($PYTHON -c "$SCRIPT")
44+
# Assert passing value
45+
[ $OUTPUT = "env_auth_scheme=pam_password" ]
46+
47+
}

irods/test/scripts/test003.bats

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Test creation of .irodsA for iRODS pam_password authentication using the free function,
4+
# irods.client_init.write_native_credentials_to_secrets_file
5+
6+
. "$BATS_TEST_DIRNAME"/test_support_functions
7+
PYTHON=python3
8+
9+
# Setup/prerequisites are same as for login_auth_test.
10+
# Run as ubuntu user with sudo; python_irodsclient must be installed (in either ~/.local or a virtualenv)
11+
#
12+
13+
@test create_irods_secrets_file {
14+
15+
rm -fr ~/.irods
16+
mkdir ~/.irods
17+
cat > ~/.irods/irods_environment.json <<-EOF
18+
{ "irods_host":"$(hostname)",
19+
"irods_port":1247,
20+
"irods_user_name":"rods",
21+
"irods_zone_name":"tempZone"
22+
}
23+
EOF
24+
$PYTHON -c "import irods.client_init; irods.client_init.write_native_credentials_to_secrets_file('rods')"
25+
26+
# Define the core Python to be run, basically a minimal code block ensuring that we can authenticate to iRODS
27+
# without an exception being raised.
28+
29+
local SCRIPT="
30+
import irods.test.helpers as h
31+
ses = h.make_session()
32+
ses.collections.get(h.home_collection(ses))
33+
print ('env_auth_scheme=%s' % ses.pool.account._original_authentication_scheme)
34+
"
35+
OUTPUT=$($PYTHON -c "$SCRIPT")
36+
# Assert passing value
37+
[ $OUTPUT = "env_auth_scheme=native" ]
38+
}

irods/test/scripts/test012.bats

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Test creation of .irodsA for iRODS pam_password authentication, this time purely internal to the PRC
4+
# library code.
5+
6+
. "$BATS_TEST_DIRNAME"/test_support_functions
7+
PYTHON=python3
8+
9+
# Setup/prerequisites are same as for login_auth_test.
10+
# Run as ubuntu user with sudo; python_irodsclient must be installed (in either ~/.local or a virtualenv)
11+
#
12+
13+
PASSWD=test123
14+
15+
setup()
16+
{
17+
export SKIP_IINIT_FOR_PASSWORD=1
18+
setup_pam_login_for_alice $PASSWD
19+
SKIP_IINIT_FOR_PASSWORD=""
20+
}
21+
22+
teardown()
23+
{
24+
:
25+
# finalize_pam_login_for_alice
26+
# test_specific_cleanup
27+
}
28+
29+
@test f001 {
30+
31+
AUTH_FILE=~/.irods/.irodsA
32+
33+
# Test assertion: No pre-existing authentication file.
34+
! [ -e $AUTH_FILE ]
35+
36+
local SCRIPT="
37+
import irods.test.helpers as h
38+
ses = h.make_session()
39+
ses.collections.get(h.home_collection(ses))
40+
print ('env_auth_scheme=%s' % ses.pool.account._original_authentication_scheme)
41+
"
42+
43+
# First invocation. PRC will both authenticate with pam_password, and write the generated secrets to the auth file,
44+
OUTPUT=$($PYTHON -c "import irods.client_configuration as cfg
45+
cfg.legacy_auth.pam.password_for_auto_renew = '$PASSWD'
46+
cfg.legacy_auth.pam.time_to_live_in_hours = 1
47+
cfg.legacy_auth.pam.store_password_to_environment = True
48+
$SCRIPT")
49+
50+
SECRETS_0=$(cat $AUTH_FILE)
51+
STAT_0=$(stat -c%y $AUTH_FILE)
52+
53+
sleep 1.1
54+
55+
# Second invocation. PRC will use previously generated secrets from the auth file generated in the first invocation.
56+
OUTPUT=$($PYTHON -c "import irods.client_configuration as cfg
57+
#cfg.legacy_auth.pam.password_for_auto_renew = '$PASSWD'
58+
cfg.legacy_auth.pam.time_to_live_in_hours = 1
59+
cfg.legacy_auth.pam.store_password_to_environment = True
60+
$SCRIPT")
61+
62+
SECRETS_1=$(cat $AUTH_FILE)
63+
STAT_1=$(stat -c%y $AUTH_FILE)
64+
65+
# Test assertion: authentication file is the same, before and after, with identical modification date and contents.
66+
[ "$STAT_1" = "$STAT_0" ]
67+
[ "$SECRETS_0" = "$SECRETS_1" ]
68+
69+
# Test assertion: authentication method is pam_password
70+
[ $OUTPUT = "env_auth_scheme=pam_password" ]
71+
}

0 commit comments

Comments
 (0)