mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
Refactor extraheader auth handling
This commit is contained in:
parent
a6a1a418bf
commit
24012f5c84
9 changed files with 460 additions and 419 deletions
|
@ -82,10 +82,6 @@ describe('create-or-update-branch tests', () => {
|
|||
|
||||
beforeAll(async () => {
|
||||
git = await GitCommandManager.create(REPO_PATH)
|
||||
git.setAuthGitOptions([
|
||||
'-c',
|
||||
'http.https://github.com/.extraheader=AUTHORIZATION: basic xxx'
|
||||
])
|
||||
git.setIdentityGitOptions([
|
||||
'-c',
|
||||
'author.name=Author Name',
|
||||
|
|
49
__test__/git-auth-helper.int.test.ts
Normal file
49
__test__/git-auth-helper.int.test.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import {GitCommandManager} from '../lib/git-command-manager'
|
||||
import {GitAuthHelper} from '../lib/git-auth-helper'
|
||||
|
||||
const REPO_PATH = '/git/test-repo'
|
||||
|
||||
const extraheaderConfigKey = 'http.https://github.com/.extraheader'
|
||||
|
||||
describe('git-auth-helper tests', () => {
|
||||
let git: GitCommandManager
|
||||
let gitAuthHelper: GitAuthHelper
|
||||
|
||||
beforeAll(async () => {
|
||||
git = await GitCommandManager.create(REPO_PATH)
|
||||
gitAuthHelper = new GitAuthHelper(git)
|
||||
})
|
||||
|
||||
it('tests save and restore with no persisted auth', async () => {
|
||||
await gitAuthHelper.savePersistedAuth()
|
||||
await gitAuthHelper.restorePersistedAuth()
|
||||
})
|
||||
|
||||
it('tests configure and removal of auth', async () => {
|
||||
await gitAuthHelper.configureToken('github-token')
|
||||
expect(await git.configExists(extraheaderConfigKey)).toBeTruthy()
|
||||
expect(await git.getConfigValue(extraheaderConfigKey)).toEqual(
|
||||
'AUTHORIZATION: basic eC1hY2Nlc3MtdG9rZW46Z2l0aHViLXRva2Vu'
|
||||
)
|
||||
|
||||
await gitAuthHelper.removeAuth()
|
||||
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)
|
||||
|
||||
await gitAuthHelper.savePersistedAuth()
|
||||
|
||||
const exists = await git.configExists(extraheaderConfigKey)
|
||||
expect(exists).toBeFalsy()
|
||||
|
||||
await gitAuthHelper.restorePersistedAuth()
|
||||
|
||||
const configValue = await git.getConfigValue(extraheaderConfigKey)
|
||||
expect(configValue).toEqual(extraheaderConfigValue)
|
||||
|
||||
await gitAuthHelper.removeAuth()
|
||||
})
|
||||
})
|
|
@ -1,117 +0,0 @@
|
|||
import {GitCommandManager} from '../lib/git-command-manager'
|
||||
import {GitConfigHelper} from '../lib/git-config-helper'
|
||||
|
||||
const REPO_PATH = '/git/test-repo'
|
||||
|
||||
describe('git-config-helper tests', () => {
|
||||
let gitConfigHelper: GitConfigHelper
|
||||
|
||||
beforeAll(async () => {
|
||||
const git = await GitCommandManager.create(REPO_PATH)
|
||||
gitConfigHelper = new GitConfigHelper(git)
|
||||
})
|
||||
|
||||
it('adds and unsets a config option', async () => {
|
||||
const add = await gitConfigHelper.addConfigOption(
|
||||
'test.add.and.unset.config.option',
|
||||
'foo'
|
||||
)
|
||||
expect(add).toBeTruthy()
|
||||
const unset = await gitConfigHelper.unsetConfigOption(
|
||||
'test.add.and.unset.config.option'
|
||||
)
|
||||
expect(unset).toBeTruthy()
|
||||
})
|
||||
|
||||
it('adds and unsets a config option with value regex', async () => {
|
||||
const add = await gitConfigHelper.addConfigOption(
|
||||
'test.add.and.unset.config.option',
|
||||
'foo bar'
|
||||
)
|
||||
expect(add).toBeTruthy()
|
||||
const unset = await gitConfigHelper.unsetConfigOption(
|
||||
'test.add.and.unset.config.option',
|
||||
'^foo'
|
||||
)
|
||||
expect(unset).toBeTruthy()
|
||||
})
|
||||
|
||||
it('determines that a config option exists', async () => {
|
||||
const result = await gitConfigHelper.configOptionExists('remote.origin.url')
|
||||
expect(result).toBeTruthy()
|
||||
})
|
||||
|
||||
it('determines that a config option does not exist', async () => {
|
||||
const result = await gitConfigHelper.configOptionExists(
|
||||
'this.key.does.not.exist'
|
||||
)
|
||||
expect(result).toBeFalsy()
|
||||
})
|
||||
|
||||
it('successfully retrieves a config option', async () => {
|
||||
const add = await gitConfigHelper.addConfigOption(
|
||||
'test.get.config.option',
|
||||
'foo'
|
||||
)
|
||||
expect(add).toBeTruthy()
|
||||
const option = await gitConfigHelper.getConfigOption(
|
||||
'test.get.config.option'
|
||||
)
|
||||
expect(option.value).toEqual('foo')
|
||||
const unset = await gitConfigHelper.unsetConfigOption(
|
||||
'test.get.config.option'
|
||||
)
|
||||
expect(unset).toBeTruthy()
|
||||
})
|
||||
|
||||
it('gets a config option with value regex', async () => {
|
||||
const add = await gitConfigHelper.addConfigOption(
|
||||
'test.get.config.option',
|
||||
'foo bar'
|
||||
)
|
||||
expect(add).toBeTruthy()
|
||||
const option = await gitConfigHelper.getConfigOption(
|
||||
'test.get.config.option',
|
||||
'^foo'
|
||||
)
|
||||
expect(option.value).toEqual('foo bar')
|
||||
const unset = await gitConfigHelper.unsetConfigOption(
|
||||
'test.get.config.option',
|
||||
'^foo'
|
||||
)
|
||||
expect(unset).toBeTruthy()
|
||||
})
|
||||
|
||||
it('gets and unsets a config option', async () => {
|
||||
const add = await gitConfigHelper.addConfigOption(
|
||||
'test.get.and.unset.config.option',
|
||||
'foo'
|
||||
)
|
||||
expect(add).toBeTruthy()
|
||||
const getAndUnset = await gitConfigHelper.getAndUnsetConfigOption(
|
||||
'test.get.and.unset.config.option'
|
||||
)
|
||||
expect(getAndUnset.value).toEqual('foo')
|
||||
})
|
||||
|
||||
it('gets and unsets a config option with value regex', async () => {
|
||||
const add = await gitConfigHelper.addConfigOption(
|
||||
'test.get.and.unset.config.option',
|
||||
'foo bar'
|
||||
)
|
||||
expect(add).toBeTruthy()
|
||||
const getAndUnset = await gitConfigHelper.getAndUnsetConfigOption(
|
||||
'test.get.and.unset.config.option',
|
||||
'^foo'
|
||||
)
|
||||
expect(getAndUnset.value).toEqual('foo bar')
|
||||
})
|
||||
|
||||
it('fails to get and unset a config option', async () => {
|
||||
const getAndUnset = await gitConfigHelper.getAndUnsetConfigOption(
|
||||
'this.key.does.not.exist'
|
||||
)
|
||||
expect(getAndUnset.name).toEqual('')
|
||||
expect(getAndUnset.value).toEqual('')
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue