Skip to content

Commit

Permalink
updating alowed hosts in isGhes check
Browse files Browse the repository at this point in the history
updating alowed hosts in artifact ghes check

using dot prepend ghe host
  • Loading branch information
eggyhead committed Jan 31, 2024
1 parent 1fe633e commit 3b02a6f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
29 changes: 29 additions & 0 deletions packages/artifact/__tests__/config.test.ts
@@ -0,0 +1,29 @@
import * as config from '../src/internal/shared/config'


Check failure on line 3 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Delete `⏎`

Check failure on line 3 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Delete `⏎`

Check failure on line 3 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Delete `␍⏎`
beforeEach(() => {
jest.resetModules()

Check failure on line 5 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Replace `····jest.resetModules()·` with `··jest.resetModules()`

Check failure on line 5 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Replace `····jest.resetModules()·` with `··jest.resetModules()`

Check failure on line 5 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Replace `····jest.resetModules()·` with `··jest.resetModules()`
});

Check failure on line 6 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Replace `··});⏎··` with `})`

Check failure on line 6 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Extra semicolon

Check failure on line 6 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Replace `··});⏎··` with `})`

Check failure on line 6 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Extra semicolon

Check failure on line 6 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Replace `··});␍⏎··` with `})`

Check failure on line 6 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Extra semicolon


describe('isGhes', () => {
it('should return false when the request domain is github.com', () => {

Check failure on line 10 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Delete `··`

Check failure on line 10 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Delete `··`

Check failure on line 10 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Delete `··`
process.env.GITHUB_SERVER_URL = 'https://github.com'

Check failure on line 11 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Replace `········` with `····`

Check failure on line 11 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Replace `········` with `····`

Check failure on line 11 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Replace `········` with `····`
expect(config.isGhes()).toBe(false)

Check failure on line 12 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Delete `····`

Check failure on line 12 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Delete `····`

Check failure on line 12 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Delete `····`
})

Check failure on line 13 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Delete `··`

Check failure on line 13 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Delete `··`

Check failure on line 13 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Delete `··`

it('should return false when the request domain ends with ghe.com', () => {

Check failure on line 15 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Replace `····` with `··`

Check failure on line 15 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Replace `····` with `··`

Check failure on line 15 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Delete `··`
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.com'

Check failure on line 16 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Delete `····`

Check failure on line 16 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Delete `····`

Check failure on line 16 in packages/artifact/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Delete `····`
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)
})
})
7 changes: 6 additions & 1 deletion packages/artifact/src/internal/shared/config.ts
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions packages/cache/__tests__/cacheUtils.test.ts
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
})
7 changes: 6 additions & 1 deletion packages/cache/src/internal/cacheUtils.ts
Expand Up @@ -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
}

0 comments on commit 3b02a6f

Please sign in to comment.