-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
persist core.sshCommand for submodules #184
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
persist core.sshCommand for submodules
- Loading branch information
commit 518a86712763e425471c9416e745630623e0c96d
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -437,15 +437,16 @@ describe('git-auth-helper tests', () => { | |
} | ||
) | ||
|
||
const configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeyNotSet = | ||
'configureSubmoduleAuth configures token when persist credentials true and SSH key not set' | ||
const configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeyNotSet = | ||
'configureSubmoduleAuth configures submodules when persist credentials false and SSH key not set' | ||
it( | ||
configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeyNotSet, | ||
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeyNotSet, | ||
async () => { | ||
// Arrange | ||
await setup( | ||
configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeyNotSet | ||
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeyNotSet | ||
) | ||
settings.persistCredentials = false | ||
settings.sshKey = '' | ||
const authHelper = gitAuthHelper.createAuthHelper(git, settings) | ||
await authHelper.configureAuth() | ||
|
@@ -456,31 +457,30 @@ describe('git-auth-helper tests', () => { | |
await authHelper.configureSubmoduleAuth() | ||
|
||
// Assert | ||
expect(mockSubmoduleForeach).toHaveBeenCalledTimes(3) | ||
expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch( | ||
expect(mockSubmoduleForeach).toBeCalledTimes(1) | ||
expect(mockSubmoduleForeach.mock.calls[0][0] as string).toMatch( | ||
/unset-all.*insteadOf/ | ||
) | ||
expect(mockSubmoduleForeach.mock.calls[1][0]).toMatch(/http.*extraheader/) | ||
expect(mockSubmoduleForeach.mock.calls[2][0]).toMatch(/url.*insteadOf/) | ||
} | ||
) | ||
|
||
const configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeySet = | ||
'configureSubmoduleAuth configures token when persist credentials true and SSH key set' | ||
const configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet = | ||
'configureSubmoduleAuth configures submodules when persist credentials false and SSH key set' | ||
it( | ||
configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeySet, | ||
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet, | ||
async () => { | ||
if (!sshPath) { | ||
process.stdout.write( | ||
`Skipped test "${configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeySet}". Executable 'ssh' not found in the PATH.\n` | ||
`Skipped test "${configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet}". Executable 'ssh' not found in the PATH.\n` | ||
) | ||
return | ||
} | ||
|
||
// Arrange | ||
await setup( | ||
configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeySet | ||
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet | ||
) | ||
settings.persistCredentials = false | ||
const authHelper = gitAuthHelper.createAuthHelper(git, settings) | ||
await authHelper.configureAuth() | ||
const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any> | ||
|
@@ -490,24 +490,23 @@ describe('git-auth-helper tests', () => { | |
await authHelper.configureSubmoduleAuth() | ||
|
||
// Assert | ||
expect(mockSubmoduleForeach).toHaveBeenCalledTimes(2) | ||
expect(mockSubmoduleForeach).toHaveBeenCalledTimes(1) | ||
expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch( | ||
/unset-all.*insteadOf/ | ||
) | ||
expect(mockSubmoduleForeach.mock.calls[1][0]).toMatch(/http.*extraheader/) | ||
} | ||
) | ||
|
||
const configureSubmoduleAuth_doesNotConfigureTokenWhenPersistCredentialsFalse = | ||
'configureSubmoduleAuth does not configure token when persist credentials false' | ||
const configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeyNotSet = | ||
'configureSubmoduleAuth configures submodules when persist credentials true and SSH key not set' | ||
it( | ||
configureSubmoduleAuth_doesNotConfigureTokenWhenPersistCredentialsFalse, | ||
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeyNotSet, | ||
async () => { | ||
// Arrange | ||
await setup( | ||
configureSubmoduleAuth_doesNotConfigureTokenWhenPersistCredentialsFalse | ||
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeyNotSet | ||
) | ||
settings.persistCredentials = false | ||
settings.sshKey = '' | ||
const authHelper = gitAuthHelper.createAuthHelper(git, settings) | ||
await authHelper.configureAuth() | ||
const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any> | ||
|
@@ -517,28 +516,30 @@ describe('git-auth-helper tests', () => { | |
await authHelper.configureSubmoduleAuth() | ||
|
||
// Assert | ||
expect(mockSubmoduleForeach).toBeCalledTimes(1) | ||
expect(mockSubmoduleForeach.mock.calls[0][0] as string).toMatch( | ||
expect(mockSubmoduleForeach).toHaveBeenCalledTimes(3) | ||
expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch( | ||
/unset-all.*insteadOf/ | ||
) | ||
expect(mockSubmoduleForeach.mock.calls[1][0]).toMatch(/http.*extraheader/) | ||
expect(mockSubmoduleForeach.mock.calls[2][0]).toMatch(/url.*insteadOf/) | ||
} | ||
) | ||
|
||
const configureSubmoduleAuth_doesNotConfigureUrlInsteadOfWhenPersistCredentialsTrueAndSshKeySet = | ||
'configureSubmoduleAuth does not configure URL insteadOf when persist credentials true and SSH key set' | ||
const configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet = | ||
'configureSubmoduleAuth configures submodules when persist credentials true and SSH key set' | ||
it( | ||
configureSubmoduleAuth_doesNotConfigureUrlInsteadOfWhenPersistCredentialsTrueAndSshKeySet, | ||
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet, | ||
async () => { | ||
if (!sshPath) { | ||
process.stdout.write( | ||
`Skipped test "${configureSubmoduleAuth_doesNotConfigureUrlInsteadOfWhenPersistCredentialsTrueAndSshKeySet}". Executable 'ssh' not found in the PATH.\n` | ||
`Skipped test "${configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet}". Executable 'ssh' not found in the PATH.\n` | ||
) | ||
return | ||
} | ||
|
||
// Arrange | ||
await setup( | ||
configureSubmoduleAuth_doesNotConfigureUrlInsteadOfWhenPersistCredentialsTrueAndSshKeySet | ||
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet | ||
) | ||
const authHelper = gitAuthHelper.createAuthHelper(git, settings) | ||
await authHelper.configureAuth() | ||
|
@@ -549,37 +550,12 @@ describe('git-auth-helper tests', () => { | |
await authHelper.configureSubmoduleAuth() | ||
|
||
// Assert | ||
expect(mockSubmoduleForeach).toHaveBeenCalledTimes(2) | ||
expect(mockSubmoduleForeach).toHaveBeenCalledTimes(3) | ||
expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch( | ||
/unset-all.*insteadOf/ | ||
) | ||
expect(mockSubmoduleForeach.mock.calls[1][0]).toMatch(/http.*extraheader/) | ||
} | ||
) | ||
|
||
const configureSubmoduleAuth_removesUrlInsteadOfWhenPersistCredentialsFalse = | ||
'configureSubmoduleAuth removes URL insteadOf when persist credentials false' | ||
it( | ||
configureSubmoduleAuth_removesUrlInsteadOfWhenPersistCredentialsFalse, | ||
async () => { | ||
// Arrange | ||
await setup( | ||
configureSubmoduleAuth_removesUrlInsteadOfWhenPersistCredentialsFalse | ||
) | ||
settings.persistCredentials = false | ||
const authHelper = gitAuthHelper.createAuthHelper(git, settings) | ||
await authHelper.configureAuth() | ||
const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any> | ||
mockSubmoduleForeach.mockClear() // reset calls | ||
|
||
// Act | ||
await authHelper.configureSubmoduleAuth() | ||
|
||
// Assert | ||
expect(mockSubmoduleForeach).toBeCalledTimes(1) | ||
expect(mockSubmoduleForeach.mock.calls[0][0] as string).toMatch( | ||
/unset-all.*insteadOf/ | ||
) | ||
expect(mockSubmoduleForeach.mock.calls[2][0]).toMatch(/core\.sshCommand/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert core.sshCommand was added |
||
} | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5122,6 +5122,7 @@ class GitAuthHelper { | |
this.tokenConfigKey = `http.https://${HOSTNAME}/.extraheader`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont review index.js (generated) |
||
this.insteadOfKey = `url.https://${HOSTNAME}/.insteadOf`; | ||
this.insteadOfValue = `git@${HOSTNAME}:`; | ||
this.sshCommand = ''; | ||
this.sshKeyPath = ''; | ||
this.sshKnownHostsPath = ''; | ||
this.temporaryHomePath = ''; | ||
|
@@ -5205,8 +5206,12 @@ class GitAuthHelper { | |
core.debug(`Replacing token placeholder in '${configPath}'`); | ||
this.replaceTokenPlaceholder(configPath); | ||
} | ||
// Configure HTTPS instead of SSH | ||
if (!this.settings.sshKey) { | ||
if (this.settings.sshKey) { | ||
// Configure core.sshCommand | ||
yield this.git.submoduleForeach(`git config --local '${SSH_COMMAND_KEY}' '${this.sshCommand}'`, this.settings.nestedSubmodules); | ||
} | ||
else { | ||
// Configure HTTPS instead of SSH | ||
yield this.git.submoduleForeach(`git config --local '${this.insteadOfKey}' '${this.insteadOfValue}'`, this.settings.nestedSubmodules); | ||
} | ||
} | ||
|
@@ -5268,16 +5273,16 @@ class GitAuthHelper { | |
yield fs.promises.writeFile(this.sshKnownHostsPath, knownHosts); | ||
// Configure GIT_SSH_COMMAND | ||
const sshPath = yield io.which('ssh', true); | ||
let sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename(this.sshKeyPath)}"`; | ||
this.sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename(this.sshKeyPath)}"`; | ||
if (this.settings.sshStrict) { | ||
sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no'; | ||
this.sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no'; | ||
} | ||
sshCommand += ` -o "UserKnownHostsFile=$RUNNER_TEMP/${path.basename(this.sshKnownHostsPath)}"`; | ||
core.info(`Temporarily overriding GIT_SSH_COMMAND=${sshCommand}`); | ||
this.git.setEnvironmentVariable('GIT_SSH_COMMAND', sshCommand); | ||
this.sshCommand += ` -o "UserKnownHostsFile=$RUNNER_TEMP/${path.basename(this.sshKnownHostsPath)}"`; | ||
core.info(`Temporarily overriding GIT_SSH_COMMAND=${this.sshCommand}`); | ||
this.git.setEnvironmentVariable('GIT_SSH_COMMAND', this.sshCommand); | ||
// Configure core.sshCommand | ||
if (this.settings.persistCredentials) { | ||
yield this.git.config(SSH_COMMAND_KEY, sshCommand); | ||
yield this.git.config(SSH_COMMAND_KEY, this.sshCommand); | ||
} | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some of the tests for configureSubmoduleAuth were redundant so i collapsed based on input combinations:
persist-credentials: false
,ssh-key: ''
persist-credentials: false
,ssh-key: 'set'
persist-credentials: true
,ssh-key: ''
persist-credentials: true
,ssh-key: 'set'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each test just tests the submoduleForeach calls so it made sense to collapse.