Skip to content

Commit f52db30

Browse files
d-w-moorealanking
authored andcommitted
[#583] add test for SSL connection timeout functionality
1 parent 6be959e commit f52db30

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
ALICES_PAM_PASSWORD=test123
14+
15+
setup()
16+
{
17+
setup_pam_login_for_alice "$ALICES_PAM_PASSWORD"
18+
}
19+
20+
teardown()
21+
{
22+
23+
finalize_pam_login_for_alice
24+
test_specific_cleanup
25+
}
26+
27+
@test f001 {
28+
29+
# Create and put into iRODS a large file which will take a significant fraction of a
30+
# second (>1e-5 on any CPU + Network combination) to checksum.
31+
32+
export LARGE_FILE=/tmp/largefile
33+
export LARGE_FILE_BASENAME=$(basename "$LARGE_FILE")
34+
dd if=/dev/zero count=150k bs=1k of=$LARGE_FILE
35+
cat >/tmp/test_script <<-EOF
36+
import ssl
37+
from irods.helpers import make_session, home_collection
38+
39+
def check_all_sockets_are_ssl():
40+
if {type(conn.socket) for conn in ses.pool.idle | ses.pool.active} != {ssl.SSLSocket}:
41+
print('not all sockets are SSL')
42+
exit(1)
43+
ses = make_session()
44+
45+
coll = home_collection(ses)
46+
ses.data_objects.put('$LARGE_FILE', coll)
47+
48+
check_all_sockets_are_ssl()
49+
50+
# Set timeout too low for chksum reaction time.
51+
ses.connection_timeout = 1e-5
52+
53+
path1 = coll+'/$LARGE_FILE_BASENAME'
54+
path2 = coll+'/$LARGE_FILE_BASENAME'+'2'
55+
try:
56+
ses.data_objects.chksum(path1)
57+
except Exception as e:
58+
print(type(e), 'thrown')
59+
60+
# Set timeout high enough for any reaction time.
61+
ses.connection_timeout = None
62+
63+
ses.data_objects.copy(path1, path2)
64+
with ses.data_objects.open(path2,'a') as object:
65+
object.write(b'\0')
66+
x = ses.data_objects.chksum(path2)
67+
check_all_sockets_are_ssl()
68+
EOF
69+
70+
OUTPUT=$(python /tmp/test_script 2>/tmp/test_stderr | tee /tmp/test_stdout)
71+
72+
[[ $OUTPUT =~ NetworkException.*thrown$ ]]
73+
}

0 commit comments

Comments
 (0)