Enable optionally using a stored session file in integration test, bypassing login

This commit is contained in:
Alessio 2024-08-19 14:15:57 -07:00
parent ee2b287fd9
commit f8988abef1
2 changed files with 28 additions and 12 deletions

View File

@ -18,7 +18,10 @@ pipeline:
integration_test: integration_test:
image: offline-twitter/go image: offline-twitter/go
secrets: 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 when: # At least one
- path: - path:
- pkg/scraper/** - pkg/scraper/**
@ -26,6 +29,7 @@ pipeline:
- branch: v*.*.* - branch: v*.*.*
commands: commands:
- cd cmd - cd cmd
- echo "$OFFLINE_TWATTER_SESSION_FILE" > $SESSION_FILE_PATH # Write the session file to temp location
- ./tests.sh - ./tests.sh
webserver_test: webserver_test:
@ -40,10 +44,11 @@ pipeline:
version_bump_test: version_bump_test:
image: offline-twitter/go image: offline-twitter/go
when: # when:
branch: v*.*.* # branch: v*.*.*
secrets: secrets:
- offline_twatter_passwd # - offline_twatter_passwd
- offline_twatter_session_file
commands: commands:
- export version=$(echo $CI_COMMIT_BRANCH | grep -Poh "(?<=^v)\d+\.\d+\.\d+") - export version=$(echo $CI_COMMIT_BRANCH | grep -Poh "(?<=^v)\d+\.\d+\.\d+")
- curl https://apt.playfulpachyderm.com/KEY.gpg | sudo apt-key add - - curl https://apt.playfulpachyderm.com/KEY.gpg | sudo apt-key add -
@ -53,7 +58,9 @@ pipeline:
- which twitter - which twitter
- twitter create_profile outdated_profile - twitter create_profile outdated_profile
- cd 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 fetch_user pcmonk
- twitter --session Offline_Twatter get_user_tweets pcmonk - twitter --session Offline_Twatter get_user_tweets pcmonk
- (cd ../cmd && ./compile.sh $version) - (cd ../cmd && ./compile.sh $version)

View File

@ -5,10 +5,11 @@ set -x
PS4='+(${BASH_SOURCE}:${LINENO}): ' PS4='+(${BASH_SOURCE}:${LINENO}): '
if [[ -z "$OFFLINE_TWATTER_PASSWD" ]]; then if [[ -z "$OFFLINE_TWATTER_PASSWD" && -z "$SESSION_FILE_PATH" ]]; then
echo "OFFLINE_TWATTER_PASSWD not set! Exiting." echo "Neither SESSION_FILE_PATH nor OFFLINE_TWATTER_PASSWD is set! Please provide one or the other. Exiting."
exit 1 exit 1
fi fi
FAKE_VERSION="1.100.3489" FAKE_VERSION="1.100.3489"
./compile.sh $FAKE_VERSION ./compile.sh $FAKE_VERSION
@ -28,21 +29,29 @@ cd data
test $(find profile_images | wc -l) = "2" test $(find profile_images | wc -l) = "2"
test -f profile_images/default_profile.png test -f profile_images/default_profile.png
# Print an error message in red before exiting if a test fails # Print an error message in red before exiting if a test fails
trap 'echo -e "\033[31mTEST FAILURE. Aborting\033[0m"' ERR trap 'echo -e "\033[31mTEST FAILURE. Aborting\033[0m"' ERR
# 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 # Testing login
test ! -e Offline_Twatter.session
tw login offline_twatter "$OFFLINE_TWATTER_PASSWD" tw login offline_twatter "$OFFLINE_TWATTER_PASSWD"
test -f Offline_Twatter.session test -f Offline_Twatter.session
fi
# Ensure session file is valid
test "$(jq .UserHandle Offline_Twatter.session)" = "\"Offline_Twatter\"" test "$(jq .UserHandle Offline_Twatter.session)" = "\"Offline_Twatter\""
test "$(jq .IsAuthenticated Offline_Twatter.session)" = "true" test "$(jq .IsAuthenticated Offline_Twatter.session)" = "true"
jq .CSRFToken Offline_Twatter.session | grep -P '"\w+"' jq .CSRFToken Offline_Twatter.session | grep -P '"\w+"'
shopt -s expand_aliases shopt -s expand_aliases
alias tw="tw --session Offline_Twatter" alias tw="tw --session Offline_Twatter"
# Fetch a user # Fetch a user
initial_profile_images_count=$(find profile_images | wc -l) initial_profile_images_count=$(find profile_images | wc -l)
tw fetch_user wrathofgnon tw fetch_user wrathofgnon