Skip to content

Commit

Permalink
fix(sshd_config): Use normalized option keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Oct 16, 2024
1 parent b9b932d commit c3d1ec3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion server/handlers/sshd_config/analyzer/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
protocol "github.com/tliron/glsp/protocol_3_16"
)

var matchOption = fields.CreateNormalizedName("Match")

func analyzeMatchBlocks(
ctx *analyzerContext,
) {
for matchBlock, options := range ctx.document.Indexes.AllOptionsPerName["Match"] {
for matchBlock, options := range ctx.document.Indexes.AllOptionsPerName[matchOption] {
option := options[0]
// Check if the match block has filled out all fields
if matchBlock == nil || matchBlock.MatchValue == nil || len(matchBlock.MatchValue.Entries) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion server/handlers/sshd_config/ast/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Match Address 192.168.0.2
}

firstOption, firstMatchBlock := p.FindOption(uint32(3))
if !(firstOption.Key.Key == "PasswordAuthentication" && firstOption.OptionValue.Value.Value == "yes") {
if !(firstOption.Key.Key == "passwordauthentication" && firstOption.OptionValue.Value.Value == "yes") {
t.Errorf("Expected first option to be 'PasswordAuthentication yes' and first match block to be 'Match Address 192.168.0.1', but got: %v, %v", firstOption, firstMatchBlock)
}

Expand Down
4 changes: 3 additions & 1 deletion server/handlers/sshd_config/indexes/indexes_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

var whitespacePattern = regexp.MustCompile(`\S+`)

var includeOption = fields.CreateNormalizedName("Include")

func CreateIndexes(config ast.SSHDConfig) (*SSHDIndexes, []common.LSPError) {
errs := make([]common.LSPError, 0)
indexes := &SSHDIndexes{
Expand Down Expand Up @@ -42,7 +44,7 @@ func CreateIndexes(config ast.SSHDConfig) (*SSHDIndexes, []common.LSPError) {
}

// Add Includes
for matchBlock, options := range indexes.AllOptionsPerName["Include"] {
for matchBlock, options := range indexes.AllOptionsPerName[includeOption] {
includeOption := options[0]
rawValue := includeOption.OptionValue.Value.Value
pathIndexes := whitespacePattern.FindAllStringIndex(rawValue, -1)
Expand Down
4 changes: 2 additions & 2 deletions server/handlers/sshd_config/indexes/indexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ Match Address 192.168.0.1/24
}

firstMatchBlock := config.FindMatchBlock(uint32(6))
opts := indexes.AllOptionsPerName["PermitRootLogin"]
opts := indexes.AllOptionsPerName["permitrootlogin"]
if !(len(opts) == 2 &&
len(opts[nil]) == 1 &&
opts[nil][0].Value.Value == "PermitRootLogin yes" &&
opts[nil][0].Start.Line == 0 &&
len(opts[firstMatchBlock]) == 1 &&
opts[firstMatchBlock][0].Value.Value == "\tPermitRootLogin no" &&
opts[firstMatchBlock][0].Start.Line == 6 &&
opts[firstMatchBlock][0].Key.Key == "PermitRootLogin") {
opts[firstMatchBlock][0].Key.Key == "permitrootlogin") {
t.Errorf("Expected 3 PermitRootLogin options, but got %v", opts)
}
}
Expand Down

0 comments on commit c3d1ec3

Please sign in to comment.