From 3d34748d8eb848f4c5e601af1bd0fc1711eb5d77 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__/cacheUtils.test.ts | 24 ++++++++++++++++++++++++ src/internal/cacheUtils.ts | 7 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/__tests__/cacheUtils.test.ts b/__tests__/cacheUtils.test.ts index 25124b4..9a4166c 100644 --- a/__tests__/cacheUtils.test.ts +++ b/__tests__/cacheUtils.test.ts @@ -2,6 +2,10 @@ import {promises as fs} from 'fs' import * as path from 'path' import * as cacheUtils from '../src/internal/cacheUtils' +beforeEach(() => { + jest.resetModules() +}); + test('getArchiveFileSizeInBytes returns file size', () => { const filePath = path.join(__dirname, '__fixtures__', 'helloWorld.txt') @@ -38,3 +42,23 @@ test('resolvePaths works on github workspace directory', async () => { const paths = await cacheUtils.resolvePaths([workspace]) expect(paths.length).toBeGreaterThan(0) }) + +test('isGhes returns false for github.com', async () => { + process.env.GITHUB_SERVER_URL = 'https://github.com' + expect(cacheUtils.isGhes()).toBe(false) +}) + +test('isGhes returns false for ghe.com', async () => { + process.env.GITHUB_SERVER_URL = 'https://somedomain.ghe.com' + expect(cacheUtils.isGhes()).toBe(false) +}) + +test('isGhes returns true for enterprise URL', async () => { + process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com' + expect(cacheUtils.isGhes()).toBe(true) +}) + +test('isGhes returns false for ghe.localhost', () => { + process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost' + expect(cacheUtils.isGhes()).toBe(false) +}) \ No newline at end of file diff --git a/src/internal/cacheUtils.ts b/src/internal/cacheUtils.ts index 650653a..8bc3ce2 100644 --- a/src/internal/cacheUtils.ts +++ b/src/internal/cacheUtils.ts @@ -135,5 +135,10 @@ 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 }