fix(clients): express endpoints are key-only; has_oauth covers service accounts; make google-live
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -887,7 +887,7 @@ TEST(google_live_armor, oauth_token_reads_templates_and_findings) {
|
||||
|
||||
TEST(google_live_armor, express_key_is_refused) {
|
||||
std::string key = Credentials::env("GOOGLE_API_KEY");
|
||||
if (!std::getenv("MOLO_LIVE_NET") || key.empty() || !Credentials::env("GOOGLE_ACCESS_TOKEN").empty() ||
|
||||
if (!std::getenv("MOLO_LIVE_NET") || key.empty() || Credentials::has_oauth() ||
|
||||
Credentials::env("GOOGLE_CLOUD_PROJECT").empty()) {
|
||||
std::cout << "SKIP google_live_armor.express_key_is_refused (needs MOLO_LIVE_NET=1, "
|
||||
"GOOGLE_API_KEY, GOOGLE_CLOUD_PROJECT and no GOOGLE_ACCESS_TOKEN)\n";
|
||||
|
||||
@@ -75,7 +75,9 @@ bool invalid_without_traffic(Rig& rig, const std::function<void()>& fn) {
|
||||
class EnvGuard {
|
||||
public:
|
||||
EnvGuard() {
|
||||
for (const char* k : {"GOOGLE_ACCESS_TOKEN", "GOOGLE_CLOUD_PROJECT"}) {
|
||||
for (const char* k : {"GOOGLE_ACCESS_TOKEN", "GOOGLE_ACCESS_TOKEN_FILE",
|
||||
"GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_CLOUD_PROJECT",
|
||||
"MOLO_ENV_FILES", "MOLO_LIVE_NET"}) {
|
||||
const char* v = std::getenv(k);
|
||||
saved_.push_back({k, v != nullptr, v ? v : ""});
|
||||
}
|
||||
@@ -126,6 +128,10 @@ TEST(optimize_model, oauth_with_a_project_uses_the_global_project_path) {
|
||||
TEST(optimize_model, without_a_token_it_is_vertex_express) {
|
||||
EnvGuard guard;
|
||||
unsetenv("GOOGLE_ACCESS_TOKEN");
|
||||
unsetenv("GOOGLE_ACCESS_TOKEN_FILE");
|
||||
unsetenv("GOOGLE_APPLICATION_CREDENTIALS");
|
||||
unsetenv("MOLO_LIVE_NET");
|
||||
setenv("MOLO_ENV_FILES", "off", 1); // no .env.json.local service account
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "p1", 1);
|
||||
Rig rig;
|
||||
auto model = make_gemini_model(rig.client, "m1");
|
||||
|
||||
@@ -46,7 +46,7 @@ TEST(optimize_live, evaluate_instances_computation_metrics) {
|
||||
TEST(optimize_live, resource_lists_need_oauth) {
|
||||
if (!live("optimize_live.resource_lists_need_oauth", true)) return;
|
||||
EvaluationResources res(GoogleClient::from_env(), CloudContext::from_env());
|
||||
if (Credentials::env("GOOGLE_ACCESS_TOKEN").empty()) {
|
||||
if (!Credentials::has_oauth()) {
|
||||
// Verified 2026-10-24: API keys are refused with 401 UNAUTHENTICATED.
|
||||
try {
|
||||
res.list(Collection::kEvaluationRuns, ListOptions{1, "", "", 1});
|
||||
@@ -68,7 +68,7 @@ TEST(optimize_live, resource_lists_need_oauth) {
|
||||
|
||||
TEST(optimize_live, observability_reads_with_oauth) {
|
||||
if (!live("optimize_live.observability_reads_with_oauth", true)) return;
|
||||
if (Credentials::env("GOOGLE_ACCESS_TOKEN").empty()) {
|
||||
if (!Credentials::has_oauth()) {
|
||||
std::cout << "SKIP optimize_live.observability_reads_with_oauth (needs GOOGLE_ACCESS_TOKEN)\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ bool live_ready(const char* test) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool have_oauth() { return !Credentials::env("GOOGLE_ACCESS_TOKEN").empty(); }
|
||||
bool have_oauth() { return Credentials::has_oauth(); }
|
||||
|
||||
// With OAuth the call must work, or answer 403 SERVICE_DISABLED (the API is
|
||||
// not enabled on the project: the path and auth were accepted, enabling an
|
||||
|
||||
Reference in New Issue
Block a user