pythongoogle-app-engineprotorpc

AppEngine testing User Service from the command-line


How can I test the user service from the command-line using curl?

Let's say I have a protoRPC service running and I issue something like:

curl -H 'content-type:application/json' -d '{"name":"test1"}' http://localhost:8080/api.context_create

but this service requires a logged-in user. How can I simulate one?


Solution

  • It looks like you need to do it in two steps (see this link for the details). The first is submitting a request to:

    $ curl http://localhost:8000/_ah/login -d "email=youremail@here.com&action=Log+In" -c -
    

    The response will look something like this:

    localhost FALSE / FALSE 0 dev_appserver_login "youremail@here.com:False:0123456789101112"
    

    You can then submit a request to your target page, using the cookie provided. In your case (assuming the above cookie) you could try:

    curl -H 'content-type:application/json' \
        -d '{"name":"test1"}' \
        -b "dev_appserver_login="youremail@here.com:False:0123456789101112"" \
        http://localhost:8080/api.context_create