Skip to content

Commit c7a01c0

Browse files
committed
FIXUP: review, Mar 4
1 parent 758ee79 commit c7a01c0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

internal/postgres/hba.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package postgres
66

77
import (
88
"fmt"
9+
"maps"
910
"regexp"
1011
"slices"
1112
"strings"
@@ -155,8 +156,8 @@ func (hba *HostBasedAuthentication) NoSSL() *HostBasedAuthentication {
155156
// Options specifies any options for the authentication method.
156157
func (hba *HostBasedAuthentication) Options(opts map[string]string) *HostBasedAuthentication {
157158
hba.options = ""
158-
for k, v := range opts {
159-
hba.options = fmt.Sprintf("%s %s=%s", hba.options, hba.quote(k), hba.quote(v))
159+
for _, k := range slices.Sorted(maps.Keys(opts)) {
160+
hba.options = fmt.Sprintf("%s %s=%s", hba.options, hba.quote(k), hba.quote(opts[k]))
160161
}
161162
return hba
162163
}

internal/postgres/hba_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ func TestHostBasedAuthentication(t *testing.T) {
6060
assert.Equal(t, `hostnossl all all all "reject"`,
6161
NewHBA().NoSSL().Method("reject").String())
6262

63+
t.Run("OptionsSorted", func(t *testing.T) {
64+
assert.Equal(t, `hostssl all all all "ldap" "ldapbasedn"="dc=example,dc=org" "ldapserver"="example.org"`,
65+
NewHBA().TLS().Method("ldap").Options(map[string]string{
66+
"ldapserver": "example.org",
67+
"ldapbasedn": "dc=example,dc=org",
68+
}).String())
69+
})
70+
6371
t.Run("SpecialCharactersEscaped", func(t *testing.T) {
6472
// Databases; slash U+002F triggers regex escaping; regex characters themselves do not
6573
assert.Equal(t, `local "/^[/]asdf_[+][?]1234$","/^[/][*][$]$","+*$" all`,

0 commit comments

Comments
 (0)