This CL refactors _test_gerrit_ensure_authenticated_common by splitting
it into:
- The actual mock and common code path
- Test case specific setup (e.g. scm.GIT.SetConfig)
In addition, fixes a few issues with the existing code:
- _Authenticator.get() is now mocked correctly, so a CookiesAuthenticator
is returned in relevant tests. Previously it returned the "production"
ChainedAuthenticator, which could call other authenticators (such as
GitCredsAuthenticator based on the runtime environment)
- Adds mock patch cleanup functions. Previously, cleanup functions
aren't registered, so the mock leaks and got overwritten by other test
cases.
- Rewrite 'Bearer' in Authorization header check to be more robust.
Previously, the test case raise a KeyError exception when the
Authorization header isn't set at all in request headers.
This is a preparation CL for implementing ensure_authenticated() method
in ChainedAuthenticator and GitCredsAuthenticator in future CLs.
Bug: 348024314
Change-Id: I28a7fabbc6cf2dc33dccc1339b89d20a22dc12ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7082265
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>