chore: add private static variable to skip GCE residency checks - #682
Conversation
There was a problem hiding this comment.
My understanding is this issue was introduced with the Linux Residency check. So it would be much more prudent to have the ability to skip there, rather than skip the entire GCE check. Additionally rather than make it a public constant and a public env var, it would be even MORE prudent to make it a private static variable that we can manipulate with Reflection in the tests.
|
Sounds good! I like the way you mention it. Just for some context I checked that it seems to be a common pattern to have a And in Python: So i thought might as well follow this pattern. But I like your suggestion, updating it! |
bshaffer
left a comment
There was a problem hiding this comment.
Thank you for fixing this!!
Problem
When running unit tests on Google-managed machines (such as Cloudtop or GCP VMs), tests in
GCECredentialsTestandApplicationDefaultCredentialsTestthat simulate non-GCE environments fail.Although tests mock HTTP failure responses from the metadata server,
GCECredentials::onGce()falls back to checking the host's SMBIOS product name (/sys/class/dmi/id/product_name). Because Cloudtop instances run on Google infrastructure, this file containsGoogle Compute Engine, causingonGce()to evaluate totrueand breaking assertions that expect non-GCE behavior.Solution
NO_GCE_CHECKenvironment variable inGCECredentials::onGce()(matching parity with Pythongoogle-authand Javagoogle-auth-library-java). When set,onGce()immediately returnsfalsewithout pinging or checking SMBIOS.skipGceCheck()helper intests/bootstrap.php(similar tosetHomeEnv()) and updated tests that verify non-GCE behavior.NO_GCE_CHECKbehavior.The tests are now working on my cloudtop.
BEGIN_COMMIT_OVERRIDE
chore(tests): add private static variable to skip GCE residency checks (#682)
END_COMMIT_OVERRIDE