Skip to content

Commit 0f1b2dc

Browse files
authored
Add test for macaroon with root caveat (#117)
* Added intergration test for staging directory and option to create macaroon with root: caveat * Recreate macaroon if root: caveat is not set correctly
1 parent e6f7ad6 commit 0f1b2dc

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

tests/integration_test.sh

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ test_ada_delete_channels() {
340340
done
341341
}
342342

343-
344343
# Stage a file
345344
test_ada_stage_file() {
346345
command="ada/ada --tokenfile ${token_file} --stage /${tape_path}/${dirname}/${testfile} --api ${api}"
@@ -371,6 +370,23 @@ test_ada_unstage_file() {
371370
assertEquals "State of target:" "COMPLETED" $state
372371
}
373372

373+
# Stage a directory
374+
test_ada_stage_dir() {
375+
command="ada/ada --tokenfile ${token_file} --stage /${tape_path}/${dirname} --api ${api}"
376+
echo "Running command:"
377+
echo $command
378+
eval $command >${stdoutF} 2>${stderrF}
379+
result=$?
380+
assertEquals "ada returned error code ${result}" 0 ${result} || return
381+
request_url=`grep "request-url" "${stdoutF}" | awk '{print $2}' | tr -d '\r'`
382+
assertNotNull "No request-url found" $request_url || return
383+
sleep 2 # needed if request is still RUNNING
384+
state=`curl -X GET "${request_url}" -H "accept: application/json" -H "Authorization: Bearer $token" | jq -r '.targets[0].state'`
385+
assertEquals "State of target:" "SKIPPED" $state
386+
state=`curl -X GET "${request_url}" -H "accept: application/json" -H "Authorization: Bearer $token" | jq -r '.targets[1].state'`
387+
assertEquals "State of target:" "COMPLETED" $state
388+
}
389+
374390
# Stages files in file_list
375391
test_ada_stage_filelist() {
376392
command="ada/ada --tokenfile ${token_file} --stage --from-file ${outputDir}/file_list --api ${api}"
@@ -435,15 +451,28 @@ oneTimeSetUp() {
435451
token=$(sed -n 's/^bearer_token *= *//p' "$token_file")
436452
check_token "$token"
437453
error=$?
454+
# Check if root: caveat is set correctly.
455+
ada/ada --viewtoken --tokenfile "$token_file" | grep "cid root" >/dev/null
456+
result=$?
457+
if [ $chroot = true ] && [ $result -eq 1 ] ; then # expecting macaroon with root: caveat
458+
error=1
459+
elif [ $chroot = false ] && [ $result -eq 0 ] ; then # expecting macaroon without root: caveat
460+
error=1
461+
fi
438462
if [ $error -eq 1 ]; then
439463
echo "The tests expect a valid macaroon. Please enter your CUA credentials to create one."
440-
get-macaroon --url "${webdav_url}"/"${user_path}" --duration P1D --user $user --permissions DOWNLOAD,UPLOAD,DELETE,MANAGE,LIST,READ_METADATA,UPDATE_METADATA,STAGE --output rclone $(basename "${token_file%.*}")
464+
if [ $chroot = true ] ; then
465+
get-macaroon --chroot --url "${webdav_url}"/"${user_path}" --duration P1D --user $user --permissions DOWNLOAD,UPLOAD,DELETE,MANAGE,LIST,READ_METADATA,UPDATE_METADATA,STAGE --output rclone $(basename "${token_file%.*}")
466+
else
467+
get-macaroon --url "${webdav_url}"/"${user_path}" --duration P1D --user $user --permissions DOWNLOAD,UPLOAD,DELETE,MANAGE,LIST,READ_METADATA,UPDATE_METADATA,STAGE --output rclone $(basename "${token_file%.*}")
468+
fi
441469
if [ $? -eq 1 ]; then
442470
echo "Failed to create a macaroon. Aborting."
443471
exit
444472
fi
445473
token=$(sed -n 's/^bearer_token *= *//p' "$token_file")
446474
fi
475+
447476
# curl options for various activities;
448477
curl_options_common=(
449478
-H "accept: application/json"
@@ -459,7 +488,6 @@ oneTimeSetUp() {
459488
# Refer to the file with the header
460489
curl_authorization=( "--config" "$curl_authorization_header_file" )
461490

462-
463491
# Define test files and directories
464492
dirname="integration_test"
465493
testfile="1GBfile"

tests/test_example.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ webdav_url=""
33
user_path=""
44
disk_path=""
55
tape_path=""
6-
token_file=""
6+
token_file=""
7+
8+
# to test macaroon with root: caveat, set chroot=true
9+
# in this case, leave $user_path from $disk_path and $tape_path
10+
chroot=false

0 commit comments

Comments
 (0)