summaryrefslogtreecommitdiff
path: root/packages/cli/src/validateNonInterActiveAuth.test.ts
diff options
context:
space:
mode:
authorGal Zahavi <[email protected]>2025-07-25 10:19:38 -0700
committerGitHub <[email protected]>2025-07-25 17:19:38 +0000
commit63214428658da3608180fc07b811e7fd2d143e63 (patch)
tree50563bbe21bc32dd3c97b642188faab8f8d00983 /packages/cli/src/validateNonInterActiveAuth.test.ts
parentfb0db2dfd6ff4150150c2a7b88442da5625cd609 (diff)
feat(auth): Enhance non-interactive gcp auth (#4811)
Diffstat (limited to 'packages/cli/src/validateNonInterActiveAuth.test.ts')
-rw-r--r--packages/cli/src/validateNonInterActiveAuth.test.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/cli/src/validateNonInterActiveAuth.test.ts b/packages/cli/src/validateNonInterActiveAuth.test.ts
index 9238bbe4..184a70e0 100644
--- a/packages/cli/src/validateNonInterActiveAuth.test.ts
+++ b/packages/cli/src/validateNonInterActiveAuth.test.ts
@@ -14,6 +14,7 @@ import { AuthType } from '@google/gemini-cli-core';
describe('validateNonInterActiveAuth', () => {
let originalEnvGeminiApiKey: string | undefined;
let originalEnvVertexAi: string | undefined;
+ let originalEnvGcp: string | undefined;
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
let processExitSpy: ReturnType<typeof vi.spyOn>;
let refreshAuthMock: jest.MockedFunction<
@@ -23,8 +24,10 @@ describe('validateNonInterActiveAuth', () => {
beforeEach(() => {
originalEnvGeminiApiKey = process.env.GEMINI_API_KEY;
originalEnvVertexAi = process.env.GOOGLE_GENAI_USE_VERTEXAI;
+ originalEnvGcp = process.env.GOOGLE_GENAI_USE_GCA;
delete process.env.GEMINI_API_KEY;
delete process.env.GOOGLE_GENAI_USE_VERTEXAI;
+ delete process.env.GOOGLE_GENAI_USE_GCA;
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
processExitSpy = vi.spyOn(process, 'exit').mockImplementation((code) => {
throw new Error(`process.exit(${code}) called`);
@@ -43,6 +46,11 @@ describe('validateNonInterActiveAuth', () => {
} else {
delete process.env.GOOGLE_GENAI_USE_VERTEXAI;
}
+ if (originalEnvGcp !== undefined) {
+ process.env.GOOGLE_GENAI_USE_GCA = originalEnvGcp;
+ } else {
+ delete process.env.GOOGLE_GENAI_USE_GCA;
+ }
vi.restoreAllMocks();
});
@@ -62,6 +70,15 @@ describe('validateNonInterActiveAuth', () => {
expect(processExitSpy).toHaveBeenCalledWith(1);
});
+ it('uses LOGIN_WITH_GOOGLE if GOOGLE_GENAI_USE_GCA is set', async () => {
+ process.env.GOOGLE_GENAI_USE_GCA = 'true';
+ const nonInteractiveConfig: NonInteractiveConfig = {
+ refreshAuth: refreshAuthMock,
+ };
+ await validateNonInteractiveAuth(undefined, nonInteractiveConfig);
+ expect(refreshAuthMock).toHaveBeenCalledWith(AuthType.LOGIN_WITH_GOOGLE);
+ });
+
it('uses USE_GEMINI if GEMINI_API_KEY is set', async () => {
process.env.GEMINI_API_KEY = 'fake-key';
const nonInteractiveConfig: NonInteractiveConfig = {
@@ -92,6 +109,19 @@ describe('validateNonInterActiveAuth', () => {
expect(refreshAuthMock).toHaveBeenCalledWith(AuthType.USE_VERTEX_AI);
});
+ it('uses LOGIN_WITH_GOOGLE if GOOGLE_GENAI_USE_GCA is set, even with other env vars', async () => {
+ process.env.GOOGLE_GENAI_USE_GCA = 'true';
+ process.env.GEMINI_API_KEY = 'fake-key';
+ process.env.GOOGLE_GENAI_USE_VERTEXAI = 'true';
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ process.env.GOOGLE_CLOUD_LOCATION = 'us-central1';
+ const nonInteractiveConfig: NonInteractiveConfig = {
+ refreshAuth: refreshAuthMock,
+ };
+ await validateNonInteractiveAuth(undefined, nonInteractiveConfig);
+ expect(refreshAuthMock).toHaveBeenCalledWith(AuthType.LOGIN_WITH_GOOGLE);
+ });
+
it('uses USE_VERTEX_AI if both GEMINI_API_KEY and GOOGLE_GENAI_USE_VERTEXAI are set', async () => {
process.env.GEMINI_API_KEY = 'fake-key';
process.env.GOOGLE_GENAI_USE_VERTEXAI = 'true';