Skip to content

Commit a8a8f8d

Browse files
committed
Use auth keys for test uploads
1 parent 2aff4d5 commit a8a8f8d

File tree

4 files changed

+73
-28
lines changed

4 files changed

+73
-28
lines changed

README-testing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ python/cpython-x.y.z`) or something similar, such as loading a conda or
3636
virtual environment, please run the relevant commands before invoking
3737
`psij-ci-setup`.
3838

39+
Note: To upload data to the test server, you will need an authentication
40+
key. You can obtain such a key from https://testing.psij.io/auth.html.
41+
Obtaining a key requires a valid email.
42+
3943

4044
Testing with the CI Runner
4145
==========================

psij-ci-setup

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,60 @@ check_email() {
206206
fi
207207
}
208208

209+
check_key() {
210+
if ! -f ~/.psij/key ; then
211+
BASE_URL=`egrep '^[^#]*server_url.*' ./testing.conf |awk '{split($0, a, "="); print a[2]}'|xargs`
212+
AUTH_URL="${BASE_URL}/auth.html"
213+
214+
echo
215+
echo "================================================================"
216+
echo "There is no upload key (~/.psij/key). An upload key is needed "
217+
echo "to upload results to the results site. To obtain a key, please "
218+
echo "go to ${AUTH_URL}/auth.html in a browser and follow "
219+
echo "the instructions on that page. "
220+
echo "================================================================"
221+
echo
222+
223+
RESPONSE=""
224+
DONE="0"
225+
226+
while [ "$DONE" == "0" ]; do
227+
echo "1. (C)ontinue without a key "
228+
echo "2. E(x)it? "
229+
echo "3. (E)nter a key here to be placed in ~/.psij/key "
230+
if [ "$XDG_CURRENT_DESKTOP" != "" ]; then
231+
echo "4. (O)pen $AUTH_URL in a browser "
232+
fi
233+
read -n1 RESPONSE
234+
echo
235+
RESPONSE=${RESPONSE^}
236+
237+
if [ "$RESPONSE" == "C" ] || [ "$RESPONSE" == "1" ]; then
238+
DONE=1
239+
elif [ "$RESPONSE" == "X" ] || [ "$RESPONSE" == "2" ]; then
240+
echo "Operation canceled"
241+
exit 1
242+
elif [ "$RESPONSE" == "E" ] || [ "$RESPONSE" == "3" ]; then
243+
RESPONSE=""
244+
while [ "$RESPONSE" != "Y" ]; do
245+
echo -n "Enter key: "
246+
read KEY
247+
echo "You entered '$KEY'."
248+
echo "Is this correct (Y/N)?"
249+
read -n1 RESPONSE
250+
RESPONSE=${RESPONSE^}
251+
done
252+
echo "$KEY" > ~/.psij/key
253+
chmod 600 ~/.psij/key
254+
DONE=1
255+
elif [ "$RESPONSE" == "O" ] || [ "$RESPONSE" == "4" ]; then
256+
xdg-open "$AUTH_URL"
257+
fi
258+
done
259+
260+
fi
261+
}
262+
209263
FORCE=0
210264

211265
if [ "$1" == "-f" ]; then
@@ -230,6 +284,8 @@ continue_or_exit
230284

231285
check_email
232286

287+
check_key
288+
233289
cd "$MYPATH"
234290

235291
echo -n "Installing dependencies..."

testing.conf

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,28 +133,6 @@ custom_attributes =
133133
server_url = https://testing.psij.io
134134

135135

136-
#
137-
# A key authenticates a test ID such that it reduces the odds that two machines
138-
# compete to overwrite each other's results. The machines are identified by their
139-
# IDs. However, without additional steps, any other test deployment can set its
140-
# ID to an existing one. The "key" setting allows a secret to be used to
141-
# authenticate requests. There are two valid values:
142-
#
143-
# random:
144-
# Generates a random key on the first upload attempt. The server will then
145-
# only accept subsequent requests from the same ID if the key matches. There
146-
# is a 7 day expiration of a pairing which allows for a new key to be used
147-
# if an old key has not been used for 7 or more days. Random keys are
148-
# persisted locally in ~/.psij
149-
#
150-
# "<string>":
151-
# A custom string to be used as a key.
152-
#
153-
# key = random | "<string>"
154-
155-
key = random
156-
157-
158136
#
159137
# The maximum age, in hours, for saved test results to be kept on disk. When
160138
# tests are run with the "--save-results", test results are saved on disk.

tests/conftest.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,20 @@ def _cache(file_path, fn):
249249

250250

251251
def _get_key(config):
252-
key = config.getoption('key')
253-
if key == 'random':
254-
return _cache(KEY_FILE, secrets.token_hex)
255-
elif key[0] == '"' and key[-1] == '"':
256-
return key[1:-1]
252+
if Path('~/.psij/key').exists():
253+
with open('~/.psij/key') as f:
254+
return f.read().strip()
257255
else:
258-
raise ValueError('Invalid value for --key argument: "%s"' % key)
256+
# use legacy if needed
257+
key = config.getoption('key')
258+
logger.warning('Legacy keys are deprecated. Please go to https://testing.psij.io/auth.html '
259+
'to obtain an authentication key.')
260+
if key == 'random':
261+
return _cache(KEY_FILE, secrets.token_hex)
262+
elif key[0] == '"' and key[-1] == '"':
263+
return key[1:-1]
264+
else:
265+
raise ValueError('Invalid value for --key argument: "%s"' % key)
259266

260267

261268
def _get_id(config):

0 commit comments

Comments
 (0)