Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Option to view an individual file's history in the source control menu (#960)
- Change context menu now lists IPM packages from all Git-enabled namespaces, prefixed with the namespace name (#952)
- Pull event handler option in settings page now displays user-friendly names for options (#908)
- Validation that SSH key file path is not a directory when configuring Embedded Git (#943)

### Fixed
- Changes to % routines mapped to the current namespace may now be added to source control and committed (#944)
Expand Down
13 changes: 13 additions & 0 deletions cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ ClassMethod HasNamespaceWebApp(Output webAppDirectory) As %Boolean [ Internal ]
Method OnAfterConfigure() As %Boolean [ Internal ]
{
set defaultPromptFlag = $$$DisableBackupCharMask + $$$TrapCtrlCMask + $$$EnableQuitCharMask + $$$DisableHelpCharMask + $$$DisableHelpContextCharMask + $$$TrapErrorMask
set sc = ..ValidatePrivateKeyFilePath(..privateKeyFile)
if $$$ISERR(sc) {
write !, $System.Status.GetErrorText(sc), !
quit
}
if (..privateKeyFile '= "") && '##class(%File).Exists(..privateKeyFile) {
set value = 1
set response = ##class(%Library.Prompt).GetYesNo("Do you wish to create a new SSH key pair?",.value,,defaultPromptFlag)
Expand Down Expand Up @@ -508,6 +513,14 @@ Method OnAfterConfigure() As %Boolean [ Internal ]
}
}

ClassMethod ValidatePrivateKeyFilePath(path As %String) As %Status
{
if (path '= "") && ##class(%File).DirectoryExists(path) {
quit $$$ERROR($$$GeneralError, "SSH key file path is a directory. Please specify the full path to the key file.")
}
quit $$$OK
}

Method ConfigureBinPath(ByRef path As %String) As %Boolean [ Internal ]
{
if (path = "") { return 1 }
Expand Down
9 changes: 7 additions & 2 deletions csp/gitprojectsettings.csp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,12 @@ body {
<div class="col-sm-7">
<server>
Set fileExists = ##class(%File).Exists(settings.privateKeyFile)
if (settings.privateKeyFile = "") {
set validateSC = ##class(SourceControl.Git.Settings).ValidatePrivateKeyFilePath(settings.privateKeyFile)
if $$$ISERR(validateSC) {
set class = "form-control is-invalid"
set divClass = "invalid-feedback"
set feedbackText = $System.Status.GetErrorText(validateSC)
} elseif (settings.privateKeyFile = "") {
set class = "form-control"
set divClass = "neutral-feedback"
set feedbackText = "You must configure an SSH private key to be able to work with remotes. This should be set up as a deploy key / equivalent, authenticating the server, not a specific user."
Expand All @@ -379,7 +384,7 @@ body {
</div>

<server>
if (settings.privateKeyFile '= "") && fileExists {
if (settings.privateKeyFile '= "") && fileExists && $$$ISOK(validateSC) {
set pubKeyName = settings.privateKeyFile_".pub"
if ##class(%File).Exists(pubKeyName) {
set pubStream = ##class(%Stream.FileCharacter).%OpenId(pubKeyName)
Expand Down
15 changes: 15 additions & 0 deletions test/UnitTest/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,19 @@ Method %OnClose() As %Status
quit $$$OK
}

Method TestValidatePrivateKeyFilePath()
{
// empty path is OK
do $$$AssertStatusOK(##class(SourceControl.Git.Settings).ValidatePrivateKeyFilePath(""))

// nonexistent file path is OK (will trigger key-generation prompt separately)
do $$$AssertStatusOK(##class(SourceControl.Git.Settings).ValidatePrivateKeyFilePath("/nonexistent/path/id_rsa"))

// a directory path is an error
set mgrDir = ##class(%File).NormalizeDirectory($System.Util.ManagerDirectory())
set sc = ##class(SourceControl.Git.Settings).ValidatePrivateKeyFilePath(mgrDir)
do $$$AssertStatusNotOK(sc)
do $$$AssertTrue($System.Status.GetErrorText(sc) [ "SSH key file path is a directory")
}

}
Loading