Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/__test__/git-auth-helper.test.ts
diff options
context:
space:
mode:
authorPeter Murray <681306+peter-murray@users.noreply.github.com>2022-09-26 17:34:52 +0100
committerGitHub <noreply@github.com>2022-09-26 12:34:52 -0400
commite33cfa574212e8722034156757f8383979e76cb9 (patch)
tree0c9284b63ea98535c6a10b080a477136102a6856 /__test__/git-auth-helper.test.ts
parentfa9591092fd91f59e3dbebbb92da3e2787a0bc03 (diff)
Inject GitHub host to be able to clone from another GitHub instance (#922)
* Adding the ability to specify the GitHub Server URL and allowing for it to differ from the Actions workflow host * Adding tests for injecting the GitHub URL * Addressing code review comments for PR #922
Diffstat (limited to '__test__/git-auth-helper.test.ts')
-rw-r--r--__test__/git-auth-helper.test.ts45
1 files changed, 39 insertions, 6 deletions
diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts
index a6731c2..2acec38 100644
--- a/__test__/git-auth-helper.test.ts
+++ b/__test__/git-auth-helper.test.ts
@@ -20,6 +20,7 @@ let tempHomedir: string
let git: IGitCommandManager & {env: {[key: string]: string}}
let settings: IGitSourceSettings
let sshPath: string
+let githubServerUrl: string
describe('git-auth-helper tests', () => {
beforeAll(async () => {
@@ -67,11 +68,18 @@ describe('git-auth-helper tests', () => {
}
})
- const configureAuth_configuresAuthHeader =
- 'configureAuth configures auth header'
- it(configureAuth_configuresAuthHeader, async () => {
+ async function testAuthHeader(
+ testName: string,
+ serverUrl: string | undefined = undefined
+ ) {
// Arrange
- await setup(configureAuth_configuresAuthHeader)
+ let expectedServerUrl = 'https://github.com'
+ if (serverUrl) {
+ githubServerUrl = serverUrl
+ expectedServerUrl = githubServerUrl
+ }
+
+ await setup(testName)
expect(settings.authToken).toBeTruthy() // sanity check
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
@@ -88,9 +96,33 @@ describe('git-auth-helper tests', () => {
).toString('base64')
expect(
configContent.indexOf(
- `http.https://github.com/.extraheader AUTHORIZATION: basic ${basicCredential}`
+ `http.${expectedServerUrl}/.extraheader AUTHORIZATION: basic ${basicCredential}`
)
).toBeGreaterThanOrEqual(0)
+ }
+
+ const configureAuth_configuresAuthHeader =
+ 'configureAuth configures auth header'
+ it(configureAuth_configuresAuthHeader, async () => {
+ await testAuthHeader(configureAuth_configuresAuthHeader)
+ })
+
+ const configureAuth_AcceptsGitHubServerUrl =
+ 'inject https://my-ghes-server.com as github server url'
+ it(configureAuth_AcceptsGitHubServerUrl, async () => {
+ await testAuthHeader(
+ configureAuth_AcceptsGitHubServerUrl,
+ 'https://my-ghes-server.com'
+ )
+ })
+
+ const configureAuth_AcceptsGitHubServerUrlSetToGHEC =
+ 'inject https://github.com as github server url'
+ it(configureAuth_AcceptsGitHubServerUrlSetToGHEC, async () => {
+ await testAuthHeader(
+ configureAuth_AcceptsGitHubServerUrl,
+ 'https://github.com'
+ )
})
const configureAuth_configuresAuthHeaderEvenWhenPersistCredentialsFalse =
@@ -778,7 +810,8 @@ async function setup(testName: string): Promise<void> {
sshKnownHosts: '',
sshStrict: true,
workflowOrganizationId: 123456,
- setSafeDirectory: true
+ setSafeDirectory: true,
+ githubServerUrl: githubServerUrl
}
}