forked from dedis/d-voting
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from c4dt/block_admin_changes
Don't let non-form-owner add voters
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
formid.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# This script tests that an admin who is not the owner of a form | ||
# cannot add voters to the form. | ||
# It also tests that the admin who created the form can actually add | ||
# voters to the form. | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
"$SCRIPT_DIR/run_local.sh" | ||
|
||
. "$SCRIPT_DIR/local_vars.sh" | ||
SECOND_ADMIN=123321 | ||
echo "Adding $SECOND_ADMIN to admin" | ||
(cd web/backend && npx ts-node src/cli.ts addAdmin --sciper $SECOND_ADMIN | grep -v Executing) | ||
|
||
"$SCRIPT_DIR/local_proxies.sh" | ||
"$SCRIPT_DIR/local_forms.sh" | ||
|
||
. "$SCRIPT_DIR/formid.env" | ||
|
||
tmp_dir=$(mktemp -d) | ||
trap 'rm -rf -- "tmpdir"' EXIT | ||
|
||
tmp_cookie_owner="$tmp_dir/cookie_owner" | ||
curl -k "$FRONTEND_URL/api/get_dev_login/$REACT_APP_SCIPER_ADMIN" -X GET -c "$tmp_cookie_owner" -o /dev/null -s | ||
tmp_cookie_nonowner="$tmp_dir/cookie_nonowner" | ||
curl -k "$FRONTEND_URL/api/get_dev_login/$SECOND_ADMIN" -X GET -c "$tmp_cookie_nonowner" -o /dev/null -s | ||
|
||
echo "This should fail with an error that we're not allowed" | ||
tmp_output="$tmp_dir/output" | ||
curl -s 'http://localhost:3000/api/add_role' \ | ||
-H 'Content-Type: application/json' \ | ||
--data-raw "{\"userId\":444555,\"subject\":\"$FORMID\",\"permission\":\"vote\"}" \ | ||
-b "$tmp_cookie_nonowner" 2>&1 | tee "$tmp_output" | ||
echo | ||
|
||
if ! grep -q "not owner of form" "$tmp_output"; then | ||
echo | ||
echo "ERROR: Reply should be 'not owner of form'" | ||
exit 1 | ||
fi | ||
|
||
echo "This should pass for the owner of the form" | ||
curl 'http://localhost:3000/api/add_role' \ | ||
-H 'Content-Type: application/json' \ | ||
--data-raw "{\"userId\":444555,\"subject\":\"$FORMID\",\"permission\":\"vote\"}" \ | ||
-b "$tmp_cookie_owner" | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters