-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): add support for multiple auth tokens via env vars (#339)
* test(fixtures): add the ability to set env variables in the scope of a single fixture Define the custom_env function in your fixture to set environment variables. * feat(server): add reading of tokens from file (#338) Add support for reading a list of newline separated tokens from a file which path is being supplied through the following environment variables: - AUTH_FILE - DELETE_FILE * docs(authentication): add new file option to readme (#338) * test(fixtures): add auth and delete file tests and fix expiring file error - add fixture for auth file testing - add fixture for delete file texting - expiring-file-upload would sometimes fail, so I increased the sleep duration
- Loading branch information
Showing
12 changed files
with
149 additions
and
8 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
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
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,4 @@ | ||
bread | ||
brioche | ||
baguette | ||
naan |
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,8 @@ | ||
[server] | ||
address = "127.0.0.1:8000" | ||
max_content_length = "10MB" | ||
upload_path = "./upload" | ||
|
||
[paste] | ||
default_extension = "txt" | ||
duplicate_files = false |
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,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
content1="test data" | ||
content2="other test" | ||
|
||
custom_env() { | ||
export AUTH_TOKENS_FILE=./auth_file | ||
} | ||
|
||
setup() { | ||
echo "$content1" >file1 | ||
echo "$content2" >file2 | ||
} | ||
|
||
run_test() { | ||
file_url=$(curl -s -F "file=@file1" -H "Authorization: bread" localhost:8000) | ||
test "$content1" = "$(cat upload/file1.txt)" | ||
sleep 2 | ||
|
||
result="$(curl -s $file_url)" | ||
test "$content1" = "$result" | ||
|
||
file_url=$(curl -s -F "file=@file2" -H "Authorization: naan" localhost:8000) | ||
test "$content2" = "$(cat upload/file2.txt)" | ||
sleep 2 | ||
|
||
result="$(curl -s $file_url)" | ||
test "$content2" = "$result" | ||
|
||
result=$(curl -s -F "file=@file2" -H "Authorization: tomato" localhost:8000) | ||
test "$result" = "unauthorized" | ||
} | ||
|
||
teardown() { | ||
rm file1 | ||
rm file2 | ||
rm -r upload | ||
} |
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,8 @@ | ||
[server] | ||
address = "127.0.0.1:8000" | ||
max_content_length = "10MB" | ||
upload_path = "./upload" | ||
|
||
[paste] | ||
default_extension = "txt" | ||
duplicate_files = false |
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,4 @@ | ||
bread | ||
brioche | ||
baguette | ||
naan |
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,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
content1="test data" | ||
del_resp="file deleted" | ||
|
||
custom_env() { | ||
export DELETE_TOKENS_FILE=./delete_file | ||
} | ||
|
||
setup() { | ||
echo "$content" >file | ||
} | ||
|
||
run_test() { | ||
file_url=$(curl -s -F "file=@file" localhost:8000) | ||
test "$del_rep"="$(curl -s -H "Authorization: naan" -X DELETE $file_url)" | ||
|
||
sleep 2 | ||
file_url=$(curl -s -F "file=@file" localhost:8000) | ||
test "$del_re"="$(curl -s -H "Authorization: bread" -X DELETE $file_url)" | ||
|
||
file_url=$(curl -s -F "file=@file" localhost:8000) | ||
test "unauthorized"=$(curl -s -H "Authorization: tomato" -X DELETE $file_url) | ||
} | ||
|
||
teardown() { | ||
rm file | ||
rm -r upload | ||
} |
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