Ask Your Question
0

testing horizon with curl

asked 2016-07-25 15:10:34 -0500

Is there any way to test horizon using curl?

The tests from horizon use selenium, but I would need a minimal command with minimal dependencies, just to check the login.

I have tried with curl by using this script:

curl -L -v -c cookies.txt -b cookies.txt -o output.1.html http://10.0.0.11/horizon/

CRS_TOKEN=$(grep csrftoken cookies.txt | awk '{print $NF}')

curl -L -v -c cookies.txt -b cookies.txt \
-d "csrfmiddlewaretoken=$CRS_TOKEN&\
fake_email=admin&\
fake_password=$PASSWORD&\
region=http%3A%2F%2Fcontroller%3A5000%2Fv3&\
domain=default&\
username=$USERNAME&\
password=$PASSWORD" \
-o output.2.html \
http://10.0.0.11/horizon/

The output.2.html just shows the login screen again.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-07-26 07:30:44 -0500

for example the logical of my script, who download under the admin tab the csv usage reports, are:

#first curl to get the token on cookie file
$CURL -c $COOKIE_FILE -b $COOKIE_FILE --output /dev/null -s "$HORIZON_HOST/dashboard/auth/login/"

TOKEN=`cat $COOKIE_FILE | grep csrftoken | sed 's/^.*csrftoken\s*//'`

DATA="username=$HORIZON_USER&password=$HORIZON_PASSWORD&region=$HORIZON_REGION&csrfmiddlewaretoken=$TOKEN"

#now we can authenticate
$CURL -c $COOKIE_FILE -b $COOKIE_FILE --output /dev/null -s -d "$DATA" --referer "$HORIZON_HOST/dashboard/" "$HORIZON_HOST/dashboard/auth/login/"

#verify the presence of sessionid
SESSIONID=`cat $COOKIE_FILE | grep sessionid | sed 's/^.*sessionid\s*//'`
if [ "$SESSIONID" == "" ]; then
    log_debug "Error: sessionid not present on file $COOKIE_FILE ...Exit"
    exit 1
fi

#ADAPT TO YOUR ENVIRONMENT!!!!
TENANT_URL="https://your_fqdn/dashboard/auth/switch/xPUT_HERE_YOUR_TENANTIDx/?next=/dashboard/project/"
$CURL -c $COOKIE_FILE -b $COOKIE_FILE --output /dev/null -s "$TENANT_URL"

#finally you can get your csv :)
URL="$HORIZON_HOST/dashboard/admin/?start=$DATE_START&end=$DATE_END&format=csv"
$CURL -c $COOKIE_FILE -b $COOKIE_FILE --output $CSV_FILE -s "$URL"

HTH Amedeo

edit flag offensive delete link more

Comments

Thank you! that did work. For Ubuntu/Mitaka, I used "horizon" instead of "dashboard" on the URL, and the curl command must include the option "-L" to follow redirects.

Julen Larrucea gravatar imageJulen Larrucea ( 2016-07-26 14:50:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2016-07-25 15:10:34 -0500

Seen: 546 times

Last updated: Jul 26 '16