summaryrefslogtreecommitdiff
path: root/packages/core/src/code_assist/oauth2.test.ts
diff options
context:
space:
mode:
authorSeth Troisi <[email protected]>2025-07-10 18:59:02 -0700
committerGitHub <[email protected]>2025-07-11 01:59:02 +0000
commit8a128d8dc6c1c5d7aea7004e0efa9fd175be36e5 (patch)
treecf9d6f3bb06586e6cefe3d72bdd015531f887494 /packages/core/src/code_assist/oauth2.test.ts
parentab66e3a24ebc3ec6c2e8f0c68065680066e265cf (diff)
Add NO_BROWSER environment variable to trigger offline oauth flow (#3713)
Diffstat (limited to 'packages/core/src/code_assist/oauth2.test.ts')
-rw-r--r--packages/core/src/code_assist/oauth2.test.ts22
1 files changed, 16 insertions, 6 deletions
diff --git a/packages/core/src/code_assist/oauth2.test.ts b/packages/core/src/code_assist/oauth2.test.ts
index 76d43726..d8cd525b 100644
--- a/packages/core/src/code_assist/oauth2.test.ts
+++ b/packages/core/src/code_assist/oauth2.test.ts
@@ -14,6 +14,7 @@ import open from 'open';
import crypto from 'crypto';
import * as os from 'os';
import { AuthType } from '../core/contentGenerator.js';
+import { Config } from '../config/config.js';
vi.mock('os', async (importOriginal) => {
const os = await importOriginal<typeof import('os')>();
@@ -28,6 +29,10 @@ vi.mock('http');
vi.mock('open');
vi.mock('crypto');
+const mockConfig = {
+ getNoBrowser: () => false,
+} as unknown as Config;
+
// Mock fetch globally
global.fetch = vi.fn();
@@ -136,7 +141,10 @@ describe('oauth2', () => {
return mockHttpServer as unknown as http.Server;
});
- const clientPromise = getOauthClient(AuthType.LOGIN_WITH_GOOGLE);
+ const clientPromise = getOauthClient(
+ AuthType.LOGIN_WITH_GOOGLE,
+ mockConfig,
+ );
// wait for server to start listening.
await serverListeningPromise;
@@ -214,7 +222,7 @@ describe('oauth2', () => {
() => mockClient as unknown as OAuth2Client,
);
- await getOauthClient(AuthType.LOGIN_WITH_GOOGLE);
+ await getOauthClient(AuthType.LOGIN_WITH_GOOGLE, mockConfig);
expect(fs.promises.readFile).toHaveBeenCalledWith(
'/user/home/.gemini/oauth_creds.json',
@@ -227,7 +235,7 @@ describe('oauth2', () => {
});
it('should use Compute to get a client if no cached credentials exist', async () => {
- await getOauthClient(AuthType.CLOUD_SHELL);
+ await getOauthClient(AuthType.CLOUD_SHELL, mockConfig);
expect(Compute).toHaveBeenCalledWith({});
expect(mockGetAccessToken).toHaveBeenCalled();
@@ -238,13 +246,13 @@ describe('oauth2', () => {
mockComputeClient.credentials = newCredentials;
mockGetAccessToken.mockResolvedValue({ token: 'new-adc-token' });
- await getOauthClient(AuthType.CLOUD_SHELL);
+ await getOauthClient(AuthType.CLOUD_SHELL, mockConfig);
expect(fs.promises.writeFile).not.toHaveBeenCalled();
});
it('should return the Compute client on successful ADC authentication', async () => {
- const client = await getOauthClient(AuthType.CLOUD_SHELL);
+ const client = await getOauthClient(AuthType.CLOUD_SHELL, mockConfig);
expect(client).toBe(mockComputeClient);
});
@@ -252,7 +260,9 @@ describe('oauth2', () => {
const testError = new Error('ADC Failed');
mockGetAccessToken.mockRejectedValue(testError);
- await expect(getOauthClient(AuthType.CLOUD_SHELL)).rejects.toThrow(
+ await expect(
+ getOauthClient(AuthType.CLOUD_SHELL, mockConfig),
+ ).rejects.toThrow(
'Could not authenticate using Cloud Shell credentials. Please select a different authentication method or ensure you are in a properly configured environment. Error: ADC Failed',
);
});