2020-07-17 13:54:39 +02:00
|
|
|
import {GitCommandManager} from '../lib/git-command-manager'
|
2024-01-31 12:05:33 +01:00
|
|
|
import {GitConfigHelper} from '../lib/git-config-helper'
|
2020-07-17 13:54:39 +02:00
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
const REPO_PATH = '/git/local/repos/test-base'
|
2020-07-17 13:54:39 +02:00
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
const extraheaderConfigKey = 'http.https://127.0.0.1/.extraheader'
|
2020-07-17 13:54:39 +02:00
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
describe('git-config-helper integration tests', () => {
|
2020-07-17 13:54:39 +02:00
|
|
|
let git: GitCommandManager
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
git = await GitCommandManager.create(REPO_PATH)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('tests save and restore with no persisted auth', async () => {
|
2024-01-31 12:05:33 +01:00
|
|
|
const gitConfigHelper = await GitConfigHelper.create(git)
|
|
|
|
await gitConfigHelper.close()
|
2020-07-17 13:54:39 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('tests configure and removal of auth', async () => {
|
2024-01-31 12:05:33 +01:00
|
|
|
const gitConfigHelper = await GitConfigHelper.create(git)
|
|
|
|
await gitConfigHelper.configureToken('github-token')
|
2020-07-17 13:54:39 +02:00
|
|
|
expect(await git.configExists(extraheaderConfigKey)).toBeTruthy()
|
|
|
|
expect(await git.getConfigValue(extraheaderConfigKey)).toEqual(
|
|
|
|
'AUTHORIZATION: basic eC1hY2Nlc3MtdG9rZW46Z2l0aHViLXRva2Vu'
|
|
|
|
)
|
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
await gitConfigHelper.close()
|
2020-07-17 13:54:39 +02:00
|
|
|
expect(await git.configExists(extraheaderConfigKey)).toBeFalsy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('tests save and restore of persisted auth', async () => {
|
|
|
|
const extraheaderConfigValue = 'AUTHORIZATION: basic ***persisted-auth***'
|
|
|
|
await git.config(extraheaderConfigKey, extraheaderConfigValue)
|
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
const gitConfigHelper = await GitConfigHelper.create(git)
|
2020-07-17 13:54:39 +02:00
|
|
|
|
|
|
|
const exists = await git.configExists(extraheaderConfigKey)
|
|
|
|
expect(exists).toBeFalsy()
|
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
await gitConfigHelper.close()
|
2020-07-17 13:54:39 +02:00
|
|
|
|
|
|
|
const configValue = await git.getConfigValue(extraheaderConfigKey)
|
|
|
|
expect(configValue).toEqual(extraheaderConfigValue)
|
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
const unset = await git.tryConfigUnset(
|
|
|
|
extraheaderConfigKey,
|
|
|
|
'^AUTHORIZATION:'
|
|
|
|
)
|
|
|
|
expect(unset).toBeTruthy()
|
2020-07-17 13:54:39 +02:00
|
|
|
})
|
2023-04-05 01:41:18 +02:00
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
it('tests not adding/removing the safe.directory config when it already exists', async () => {
|
2023-04-05 01:41:18 +02:00
|
|
|
await git.config('safe.directory', '/another-value', true, true)
|
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
const gitConfigHelper = await GitConfigHelper.create(git)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await git.configExists('safe.directory', '/another-value', true)
|
|
|
|
).toBeTruthy()
|
|
|
|
|
|
|
|
await gitConfigHelper.close()
|
|
|
|
|
|
|
|
const unset = await git.tryConfigUnset(
|
|
|
|
'safe.directory',
|
|
|
|
'/another-value',
|
|
|
|
true
|
|
|
|
)
|
|
|
|
expect(unset).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('tests adding and removing the safe.directory config', async () => {
|
|
|
|
const gitConfigHelper = await GitConfigHelper.create(git)
|
2023-04-05 01:41:18 +02:00
|
|
|
|
|
|
|
expect(
|
|
|
|
await git.configExists('safe.directory', REPO_PATH, true)
|
|
|
|
).toBeTruthy()
|
|
|
|
|
2024-01-31 12:05:33 +01:00
|
|
|
await gitConfigHelper.close()
|
2023-04-05 01:41:18 +02:00
|
|
|
|
|
|
|
expect(
|
|
|
|
await git.configExists('safe.directory', REPO_PATH, true)
|
|
|
|
).toBeFalsy()
|
|
|
|
})
|
2020-07-17 13:54:39 +02:00
|
|
|
})
|