Skip to content

Commit

Permalink
incorporate test of pam irodsA write function with overwrite=False in…
Browse files Browse the repository at this point in the history
…to test003
  • Loading branch information
d-w-moore committed Dec 17, 2024
1 parent a3eab70 commit c5bf14e
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,26 @@ teardown()

@test create_secrets_file {
auth_file=~/.irods/.irodsA
# Old .irodsA is already created, so we delete it and alter the pam password.

CONTENTS1=$(cat $auth_file)

# Alter the pam password.
sudo chpasswd <<<"alice:$ALICES_NEW_PAM_PASSWD"
rm -f "$auth_file"
OUTPUT=$($PYTHON -c "import irods.client_init;
try:
irods.client_init.write_pam_credentials_to_secrets_file('$ALICES_NEW_PAM_PASSWD', overwrite = False)
except irods.client_init.irodsA_already_exists:
print ('CANNOT OVERWRITE')
")
[ "$OUTPUT" = "CANNOT OVERWRITE" ]
# Assert the previous contents of irodsA have not changed, and aren't zero length.
CONTENTS2=$(cat $auth_file)
[ -n "$CONTENTS1" -a "$CONTENTS1" = "$CONTENTS2" ]

# Now delete the already existing irodsA and repeat without negating overwrite.
$PYTHON -c "import irods.client_init; irods.client_init.write_pam_credentials_to_secrets_file('$ALICES_NEW_PAM_PASSWD')"
CONTENTS3=$(cat $auth_file)
[ "$CONTENTS2" != "$CONTENTS3" ]

# Define the core Python to be run, basically a minimal code block ensuring that we can authenticate to iRODS
# without an exception being raised.
Expand All @@ -44,15 +60,4 @@ print ('env_auth_scheme=%s' % ses.pool.account._original_authentication_scheme)
# Assert passing value
[[ $OUTPUT = "env_auth_scheme=pam"* ]]

# Test we are not overwriting the .irodsA file if overwrite parameter is set to False.
STAT1=$(stat -c%y "$auth_file")
CONTENTS1=$(cat "$auth_file")

$PYTHON -c "import irods.client_init; irods.client_init.write_pam_credentials_to_secrets_file('$ALICES_NEW_PAM_PASSWD', overwrite = False)"

STAT2=$(stat -c%y "$auth_file")
CONTENTS2=$(cat "$auth_file")

[ "$STAT1" = "$STAT2" ]
[ "$CONTENTS1" = "$CONTENTS2" ]
}

0 comments on commit c5bf14e

Please sign in to comment.