From db6df555355bc8e2ba4f7bdf450097fa340c2264 Mon Sep 17 00:00:00 2001 From: eggyhead <28715808+eggyhead@users.noreply.github.com> Date: Tue, 30 Jan 2024 21:55:50 +0000 Subject: [PATCH] updating alowed hosts in isGhes check updating alowed hosts in artifact ghes check using dot prepend ghe host --- __tests__/config.test.ts | 29 +++++++++++++++++++++++++++++ src/internal/shared/config.ts | 7 ++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 __tests__/config.test.ts diff --git a/__tests__/config.test.ts b/__tests__/config.test.ts new file mode 100644 index 0000000..d1d8604 --- /dev/null +++ b/__tests__/config.test.ts @@ -0,0 +1,29 @@ +import * as config from '../src/internal/shared/config' + + +beforeEach(() => { + jest.resetModules() + }); + + +describe('isGhes', () => { + it('should return false when the request domain is github.com', () => { + process.env.GITHUB_SERVER_URL = 'https://github.com' + expect(config.isGhes()).toBe(false) + }) + + it('should return false when the request domain ends with ghe.com', () => { + process.env.GITHUB_SERVER_URL = 'https://my.domain.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' + expect(config.isGhes()).toBe(false) + }) + + it('should return false when the request domain is specific to an enterprise', () => { + process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com' + expect(config.isGhes()).toBe(true) + }) +}) \ No newline at end of file diff --git a/src/internal/shared/config.ts b/src/internal/shared/config.ts index a5631bf..fc39a1c 100644 --- a/src/internal/shared/config.ts +++ b/src/internal/shared/config.ts @@ -27,7 +27,12 @@ export function isGhes(): boolean { const ghUrl = new URL( process.env['GITHUB_SERVER_URL'] || 'https://github.com' ) - return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM' + + const hostname = ghUrl.hostname.trimEnd().toUpperCase() + const isGitHubHost = (hostname == 'GITHUB.COM') + const isGheHost = (hostname.endsWith('.GHE.COM') || hostname.endsWith('.GHE.LOCALHOST')) + + return !isGitHubHost && !isGheHost } export function getGitHubWorkspaceDir(): string {