Enable optionally using a stored session file in integration test, bypassing login
This commit is contained in:
parent
ee2b287fd9
commit
f8988abef1
@ -18,7 +18,10 @@ pipeline:
|
||||
integration_test:
|
||||
image: offline-twitter/go
|
||||
secrets:
|
||||
- offline_twatter_passwd
|
||||
# - offline_twatter_passwd
|
||||
- offline_twatter_session_file
|
||||
environment:
|
||||
- SESSION_FILE_PATH="/tmp/Offline_Twatter.session" # Temp location, to be imported by the integration test
|
||||
when: # At least one
|
||||
- path:
|
||||
- pkg/scraper/**
|
||||
@ -26,6 +29,7 @@ pipeline:
|
||||
- branch: v*.*.*
|
||||
commands:
|
||||
- cd cmd
|
||||
- echo "$OFFLINE_TWATTER_SESSION_FILE" > $SESSION_FILE_PATH # Write the session file to temp location
|
||||
- ./tests.sh
|
||||
|
||||
webserver_test:
|
||||
@ -40,10 +44,11 @@ pipeline:
|
||||
|
||||
version_bump_test:
|
||||
image: offline-twitter/go
|
||||
when:
|
||||
branch: v*.*.*
|
||||
# when:
|
||||
# branch: v*.*.*
|
||||
secrets:
|
||||
- offline_twatter_passwd
|
||||
# - offline_twatter_passwd
|
||||
- offline_twatter_session_file
|
||||
commands:
|
||||
- export version=$(echo $CI_COMMIT_BRANCH | grep -Poh "(?<=^v)\d+\.\d+\.\d+")
|
||||
- curl https://apt.playfulpachyderm.com/KEY.gpg | sudo apt-key add -
|
||||
@ -53,7 +58,9 @@ pipeline:
|
||||
- which twitter
|
||||
- twitter create_profile outdated_profile
|
||||
- cd outdated_profile
|
||||
- twitter login offline_twatter "$OFFLINE_TWATTER_PASSWD"
|
||||
# TODO: The CI server appears to have been IP-banned. Replacing login with session-file secret for now
|
||||
# - twitter login offline_twatter "$OFFLINE_TWATTER_PASSWD"
|
||||
- echo "$OFFLINE_TWATTER_SESSION_FILE" > Offline_Twatter.session # Write the session file
|
||||
- twitter fetch_user pcmonk
|
||||
- twitter --session Offline_Twatter get_user_tweets pcmonk
|
||||
- (cd ../cmd && ./compile.sh $version)
|
||||
|
23
cmd/tests.sh
23
cmd/tests.sh
@ -5,10 +5,11 @@ set -x
|
||||
|
||||
PS4='+(${BASH_SOURCE}:${LINENO}): '
|
||||
|
||||
if [[ -z "$OFFLINE_TWATTER_PASSWD" ]]; then
|
||||
echo "OFFLINE_TWATTER_PASSWD not set! Exiting."
|
||||
if [[ -z "$OFFLINE_TWATTER_PASSWD" && -z "$SESSION_FILE_PATH" ]]; then
|
||||
echo "Neither SESSION_FILE_PATH nor OFFLINE_TWATTER_PASSWD is set! Please provide one or the other. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FAKE_VERSION="1.100.3489"
|
||||
./compile.sh $FAKE_VERSION
|
||||
|
||||
@ -28,21 +29,29 @@ cd data
|
||||
test $(find profile_images | wc -l) = "2"
|
||||
test -f profile_images/default_profile.png
|
||||
|
||||
|
||||
|
||||
# Print an error message in red before exiting if a test fails
|
||||
trap 'echo -e "\033[31mTEST FAILURE. Aborting\033[0m"' ERR
|
||||
|
||||
# Testing login
|
||||
tw login offline_twatter "$OFFLINE_TWATTER_PASSWD"
|
||||
test -f Offline_Twatter.session
|
||||
# If a SESSION_FILE_PATH is provided, then use it instead of logging in
|
||||
if [[ -n "$SESSION_FILE_PATH" ]]; then
|
||||
echo "Using provided session file: $SESSION_FILE_PATH"
|
||||
cp $SESSION_FILE_PATH Offline_Twatter.session
|
||||
else
|
||||
# Testing login
|
||||
test ! -e Offline_Twatter.session
|
||||
tw login offline_twatter "$OFFLINE_TWATTER_PASSWD"
|
||||
test -f Offline_Twatter.session
|
||||
fi
|
||||
# Ensure session file is valid
|
||||
test "$(jq .UserHandle Offline_Twatter.session)" = "\"Offline_Twatter\""
|
||||
test "$(jq .IsAuthenticated Offline_Twatter.session)" = "true"
|
||||
jq .CSRFToken Offline_Twatter.session | grep -P '"\w+"'
|
||||
|
||||
|
||||
shopt -s expand_aliases
|
||||
alias tw="tw --session Offline_Twatter"
|
||||
|
||||
|
||||
# Fetch a user
|
||||
initial_profile_images_count=$(find profile_images | wc -l)
|
||||
tw fetch_user wrathofgnon
|
||||
|
Loading…
x
Reference in New Issue
Block a user