如何在用Go语言编写的本地Google App Engine测试中使用身份验证?

I'm building a webapp in Go that requires authentication. I'd like to run local tests using appengine/aetest that validate the authentication behavior. However, I do not see any way to create an aetest.Context with a dummy user. Am I missing something?

I had a similar issue with Python sdk. The gist of the solution is to bypass authentication when tests run locally.

You should have access to the [web] app object at the the test setup time - create a user object and save it into the app (or wherever your get_current_user() method will check).

This will let you unit test all application functions except authentication itself. For the later part you can deploy your latest changes as unpublished google app version, then test authentication and if all works - publish the version.

I've discovered some header values that seem to do the trick. appengine/user/user_dev.go has the following:

    X-AppEngine-Internal-User-Email
    X-AppEngine-Internal-User-Federated-Identity
    X-AppEngine-Internal-User-Federated-Provider
    X-AppEngine-Internal-User-Id
    X-AppEngine-Internal-User-Is-Admin

If I set those headers on the Context's Request when doing in-process tests, things seem to work as expected. If I set the headers on a request that I create separately, things are less successful, since the 'user.Current()' call consults the Context's Request.

These headers might work in a Python environment as well.