Skip to content

Commit b5cc002

Browse files
committed
Explain error causes and add tests
1 parent 29f3ff2 commit b5cc002

File tree

2 files changed

+136
-17
lines changed

2 files changed

+136
-17
lines changed

tests/integration/bash_tests/run_from_any/globus_auth.bash

Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ check_log_does_not_have()
2121
fi
2222
}
2323

24-
# Running #####################################################################
24+
# Helper functions ############################################################
2525
setup()
2626
{
2727
echo "##########################################################################################################"
@@ -75,7 +75,8 @@ get_endpoint()
7575
esac
7676
}
7777

78-
run_test_cases()
78+
# Tests #######################################################################
79+
test_single_auth_code()
7980
{
8081
local path_to_repo=$1
8182
local dst_endpoint=$2
@@ -95,7 +96,7 @@ run_test_cases()
9596
rm -rf ${INI_PATH}
9697
rm -rf ${TOKEN_FILE}
9798

98-
echo "Running globus_auth test"
99+
echo "Running test_single_auth_code"
99100
echo "Exit codes: 0 -- success, 1 -- zstash failed, 2 -- grep check failed"
100101

101102
case_name="run1"
@@ -155,12 +156,97 @@ run_test_cases()
155156
# Could also test -l and -v options, but the above code covers the important part.
156157
}
157158

159+
test_different_endpoint1()
160+
{
161+
local path_to_repo=$1
162+
local dst_endpoint=$2
163+
local dst_dir=$3
164+
165+
src_dir=${path_to_repo}/tests/utils/globus_auth
166+
mkdir -p ${src_dir}
167+
dst_endpoint_uuid=$(get_endpoint ${dst_endpoint})
168+
globus_path=globus://${dst_endpoint_uuid}/${dst_dir}
169+
170+
echo "Running test_different_endpoint1"
171+
echo "Exit codes: 0 -- success, 1 -- failure"
172+
173+
case_name="different_endpoint1"
174+
setup ${case_name} "${src_dir}"
175+
# Expecting to see exactly 1 authentication prompt
176+
zstash create --hpss=${globus_path}/${case_name} zstash_demo 2>&1 | tee ${case_name}.log
177+
check_log_has "INFO: Found stored refresh token - using it" ${case_name}.log
178+
check_log_has "ERROR: One possible cause" ${case_name}.log
179+
check_log_has "ERROR: Try deleting" ${case_name}.log
180+
check_log_has "ERROR: Another possible cause" ${case_name}.log
181+
check_log_has "ERROR: try revoking consents before re-running" ${case_name}.log
182+
check_log_has "ERROR: Exception: Insufficient Globus consents" ${case_name}.log
183+
}
184+
185+
test_different_endpoint2()
186+
{
187+
local path_to_repo=$1
188+
local dst_endpoint=$2
189+
local dst_dir=$3
190+
191+
src_dir=${path_to_repo}/tests/utils/globus_auth
192+
mkdir -p ${src_dir}
193+
dst_endpoint_uuid=$(get_endpoint ${dst_endpoint})
194+
globus_path=globus://${dst_endpoint_uuid}/${dst_dir}
195+
196+
echo "Running test_different_endpoint2"
197+
echo "Exit codes: 0 -- success, 1 -- failure"
198+
199+
case_name="different_endpoint2a"
200+
setup ${case_name} "${src_dir}"
201+
zstash create --hpss=${globus_path}/${case_name} zstash_demo 2>&1 | tee ${case_name}.log
202+
check_log_has ".zstash_globus_tokens.json exists. We can try to load tokens from it." ${case_name}.log
203+
check_log_has ".zstash_globus_tokens.json may be configured for a different Globus endpoint." ${case_name}.log
204+
check_log_has "Try deleting" ${case_name}.log
205+
check_log_has "globus_sdk.services.auth.errors.AuthAPIError: ('POST', 'https://auth.globus.org/v2/oauth2/token', None, 400, 'Error', 'Bad Request')" ${case_name}.log
206+
207+
rm -rf ~/.zstash_globus_tokens.json
208+
case_name="different_endpoint2b"
209+
setup ${case_name} "${src_dir}"
210+
# Expecting to see exactly 1 authentication prompt
211+
zstash create --hpss=${globus_path}/${case_name} zstash_demo 2>&1 | tee ${case_name}.log
212+
if [ $? != 0 ]; then
213+
echo "${case_name} failed. Check ${case_name}_create.log for details."
214+
exit 1
215+
fi
216+
}
217+
218+
test_different_endpoint3()
219+
{
220+
local path_to_repo=$1
221+
local dst_endpoint=$2
222+
local dst_dir=$3
223+
224+
src_dir=${path_to_repo}/tests/utils/globus_auth
225+
mkdir -p ${src_dir}
226+
dst_endpoint_uuid=$(get_endpoint ${dst_endpoint})
227+
globus_path=globus://${dst_endpoint_uuid}/${dst_dir}
228+
229+
echo "Running test_different_endpoint3"
230+
echo "Exit codes: 0 -- success, 1 -- failure"
231+
232+
rm -rf ~/.zstash_globus_tokens.json
233+
case_name="different_endpoint3"
234+
setup ${case_name} "${src_dir}"
235+
# Expecting to see exactly 1 authentication prompt
236+
zstash create --hpss=${globus_path}/${case_name} zstash_demo 2>&1 | tee ${case_name}.log
237+
if [ $? != 0 ]; then
238+
echo "${case_name} failed. Check ${case_name}_create.log for details."
239+
exit 1
240+
fi
241+
242+
}
243+
158244
# Follow these directions #####################################################
159245
# Modify these parameters as needed.
160246

161247
# Step 1. Update try_num for each new test run to avoid conflicts with previous runs.
162248
# Alternative: Remove previous test directories manually.
163-
try_num=17
249+
try_num=18
164250

165251
# Step 2. Set paths for your environment by uncommenting the appropriate lines.
166252
# Ordered by: Chrysalis, Perlmutter, Compy
@@ -191,7 +277,21 @@ compy_dst_dir=/compyfs/fors729/zstash_tests/test_globus_auth_try${try_num} # Usi
191277
# E. Cleanup
192278
# - Re-comment the line
193279
# - `rm -rf ../../../utils/globus_auth` to remove test directories
194-
run_test_cases ${path_to_repo} LCRC_IMPROV_DTN_ENDPOINT ${chrysalis_dst_dir}
195-
# run_test_cases ${path_to_repo} NERSC_PERLMUTTER_ENDPOINT ${perlmutter_dst_dir}
196-
# run_test_cases ${path_to_repo} NERSC_HPSS_ENDPOINT ${hpss_dst_dir}
197-
# run_test_cases ${path_to_repo} PIC_COMPY_DTN_ENDPOINT ${compy_dst_dir}
280+
# test_single_auth_code ${path_to_repo} LCRC_IMPROV_DTN_ENDPOINT ${chrysalis_dst_dir}
281+
# test_single_auth_code ${path_to_repo} NERSC_PERLMUTTER_ENDPOINT ${perlmutter_dst_dir}
282+
# test_single_auth_code ${path_to_repo} NERSC_HPSS_ENDPOINT ${hpss_dst_dir}
283+
# test_single_auth_code ${path_to_repo} PIC_COMPY_DTN_ENDPOINT ${compy_dst_dir}
284+
285+
# Step 4. Now, some follow-up tests
286+
287+
# Make sure you use a different endpoint than the last one tested above.
288+
# Uncomment, run (expecting no auth codes to paste), re-comment:
289+
# test_different_endpoint1 ${path_to_repo} NERSC_PERLMUTTER_ENDPOINT ${perlmutter_dst_dir}
290+
291+
# Reset consents again: https://auth.globus.org/v2/web/consents > Manage Your Consents > Globus Endpoint Performance Monitoring > rescind all"
292+
# Uncomment, run (expecting 1 auth code to paste), re-comment:
293+
# test_different_endpoint2 ${path_to_repo} NERSC_PERLMUTTER_ENDPOINT ${perlmutter_dst_dir}
294+
295+
# Uncomment, run (expecting 1 auth code to paste), re-comment:
296+
test_different_endpoint3 ${path_to_repo} NERSC_HPSS_ENDPOINT ${hpss_dst_dir}
297+
# Check https://auth.globus.org/v2/web/consents: you should have *two* consents there now.

zstash/globus_utils.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
TransferData,
1818
)
1919
from globus_sdk.response import GlobusHTTPResponse
20+
from globus_sdk.services.auth.errors import AuthAPIError
2021

2122
from .settings import logger
2223

@@ -134,11 +135,19 @@ def get_transfer_client_with_auth(
134135
logger.info("Found stored refresh token - using it")
135136
# Create a simple auth client for the RefreshTokenAuthorizer
136137
auth_client = NativeAppAuthClient(ZSTASH_CLIENT_ID)
137-
transfer_authorizer = RefreshTokenAuthorizer(
138-
refresh_token=token_data["refresh_token"], auth_client=auth_client
139-
)
140-
transfer_client = TransferClient(authorizer=transfer_authorizer)
141-
return transfer_client
138+
try:
139+
transfer_authorizer = RefreshTokenAuthorizer(
140+
refresh_token=token_data["refresh_token"], auth_client=auth_client
141+
)
142+
transfer_client = TransferClient(authorizer=transfer_authorizer)
143+
return transfer_client
144+
except AuthAPIError as e:
145+
logger.error("Stored refresh token is invalid.")
146+
logger.error(
147+
f"One possible cause: {TOKEN_FILE} may be configured for a different Globus endpoint. For example, you may have previously set a different destination endpoint for `--hpss=globus://`."
148+
)
149+
logger.error("Try deleting {TOKEN_FILE} and re-running.")
150+
raise e
142151

143152
# No stored tokens, need to authenticate
144153
logger.info("No stored tokens found - starting authentication")
@@ -262,12 +271,22 @@ def submit_transfer_with_checks(transfer_client, transfer_data) -> GlobusHTTPRes
262271
logger.error(
263272
"With proper scope handling, this block should not be reached."
264273
)
274+
275+
logger.error(
276+
f"One possible cause: {TOKEN_FILE} may be configured for a different Globus endpoint. For example, you may have previously set a different destination endpoint for `--hpss=globus://`."
277+
)
278+
logger.error("Try deleting {TOKEN_FILE} and re-running.")
279+
280+
logger.error(
281+
"Another possible cause: insufficient Globus consents. It's possible the consent on https://auth.globus.org/v2/web/consents is for a different destination endpoint."
282+
)
283+
logger.error(
284+
"If you don't need any other Globus consents at the moment, try revoking consents before re-running: https://auth.globus.org/v2/web/consents > Manage Your Consents > Globus Endpoint Performance Monitoring > rescind all"
285+
)
265286
logger.error(
266-
"Please report this bug at https://github.com/E3SM-Project/zstash/issues, with details of what you were trying to do."
287+
"If neither of those work, please report this bug at https://github.com/E3SM-Project/zstash/issues, with details of what you were trying to do."
267288
)
268-
raise RuntimeError(
269-
"Insufficient Globus consents - please report this bug"
270-
) from err
289+
raise RuntimeError("Insufficient Globus consents") from err
271290
else:
272291
raise err
273292
return task

0 commit comments

Comments
 (0)