From 79886daf632e6e853a0b53a86f8ea0a40cb33ef9 Mon Sep 17 00:00:00 2001 From: eggyhead <28715808+eggyhead@users.noreply.github.com> Date: Tue, 30 Jan 2024 22:22:49 +0000 Subject: [PATCH] updating allowed hosts to include ghe.com --- packages/artifact/__tests__/config.test.ts | 4 ++-- packages/artifact/src/internal/shared/config.ts | 12 ++++++++---- packages/cache/__tests__/cacheUtils.test.ts | 4 ++-- packages/cache/src/internal/cacheUtils.ts | 12 ++++++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/artifact/__tests__/config.test.ts b/packages/artifact/__tests__/config.test.ts index d1d86049..418d087c 100644 --- a/packages/artifact/__tests__/config.test.ts +++ b/packages/artifact/__tests__/config.test.ts @@ -13,12 +13,12 @@ describe('isGhes', () => { }) it('should return false when the request domain ends with ghe.com', () => { - process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.com' + process.env.GITHUB_SERVER_URL = 'https://github.ghe.com' expect(config.isGhes()).toBe(false) }) it('should return false when the request domain ends with ghe.localhost', () => { - process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost' + process.env.GITHUB_SERVER_URL = 'https://github.ghe.localhost' expect(config.isGhes()).toBe(false) }) diff --git a/packages/artifact/src/internal/shared/config.ts b/packages/artifact/src/internal/shared/config.ts index 5a9c0940..28aabf9d 100644 --- a/packages/artifact/src/internal/shared/config.ts +++ b/packages/artifact/src/internal/shared/config.ts @@ -28,11 +28,15 @@ export function isGhes(): boolean { process.env['GITHUB_SERVER_URL'] || 'https://github.com' ) - const hostname = ghUrl.hostname.trimEnd().toUpperCase() - const isGitHubHost = (hostname == 'GITHUB.COM') - const isProximaHost = (hostname.endsWith('GHE.COM') || hostname.endsWith('GHE.LOCALHOST')) + let githubHosts = [ + 'GITHUB.COM', + 'GITHUB.GHE.COM', + 'GITHUB.GHE.LOCALHOST' +]; - return !isGitHubHost && !isProximaHost + const hostname = ghUrl.hostname.trimEnd().toUpperCase() + + return !githubHosts.includes(hostname) } export function getGitHubWorkspaceDir(): string { diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index 9a4166cb..670a8ce5 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -49,7 +49,7 @@ test('isGhes returns false for github.com', async () => { }) test('isGhes returns false for ghe.com', async () => { - process.env.GITHUB_SERVER_URL = 'https://somedomain.ghe.com' + process.env.GITHUB_SERVER_URL = 'https://github.ghe.com' expect(cacheUtils.isGhes()).toBe(false) }) @@ -59,6 +59,6 @@ test('isGhes returns true for enterprise URL', async () => { }) test('isGhes returns false for ghe.localhost', () => { - process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost' + process.env.GITHUB_SERVER_URL = 'https://github.ghe.localhost' expect(cacheUtils.isGhes()).toBe(false) }) \ No newline at end of file diff --git a/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/cacheUtils.ts index aaa11190..c1f4564c 100644 --- a/packages/cache/src/internal/cacheUtils.ts +++ b/packages/cache/src/internal/cacheUtils.ts @@ -136,9 +136,13 @@ export function isGhes(): boolean { process.env['GITHUB_SERVER_URL'] || 'https://github.com' ) - const hostname = ghUrl.hostname.trimEnd().toUpperCase() - const isGitHubHost = (hostname == 'GITHUB.COM') - const isProximaHost = (hostname.endsWith('GHE.COM') || hostname.endsWith('GHE.LOCALHOST')) + let githubHosts = [ + 'GITHUB.COM', + 'GITHUB.GHE.COM', + 'GITHUB.GHE.LOCALHOST' +]; - return !isGitHubHost && !isProximaHost + const hostname = ghUrl.hostname.trimEnd().toUpperCase() + + return !githubHosts.includes(hostname) }