Skip to content

Commit e3b26eb

Browse files
authored
Update tests, fix issues (#228)
1 parent ea0b47a commit e3b26eb

20 files changed

Lines changed: 963 additions & 156 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/go.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ permissions:
1717

1818
jobs:
1919
build:
20-
name: Build Go ${{ matrix.go-version }}
21-
runs-on: ubuntu-latest
20+
name: Build Go ${{ matrix.go-version }} ${{ matrix.os }}
21+
runs-on: ${{ matrix.os }}
2222
strategy:
2323
matrix:
24-
go-version: [1.25.x]
24+
os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm]
25+
go-version: [1.25.x, 1.26.x]
2526
steps:
2627
- name: Set up Go ${{ matrix.go-version }}
2728
uses: actions/setup-go@v5

.github/workflows/ldap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
LDAP_ADMIN_PASSWORD: "admin"
3232
strategy:
3333
matrix:
34-
go-version: [1.25.x]
34+
go-version: [1.26.x]
3535
steps:
3636
- uses: actions/checkout@v4
3737
- uses: actions/setup-go@v5

.github/workflows/vulncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
go-version: [ 1.25.x ]
17+
go-version: [ 1.26.x ]
1818
steps:
1919
- name: Check out code into the Go module directory
2020
uses: actions/checkout@v4

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ linters:
3434
- examples$
3535
formatters:
3636
enable:
37-
- gofmt
37+
- gofumpt
3838
- goimports
3939
exclusions:
4040
generated: lax

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ all: test
66

77
getdeps:
88
@mkdir -p ${GOPATH}/bin
9-
@echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin
9+
@echo "Installing golangci-lint" && go install tool
1010

1111
lint: getdeps
1212
@echo "Running $@ check"
13-
@${GOPATH}/bin/golangci-lint cache clean
1413
@${GOPATH}/bin/golangci-lint run --build-tags kqueue --timeout=10m --config ./.golangci.yml
1514

1615
lint-fix: getdeps
1716
@echo "Running $@ check"
18-
@${GOPATH}/bin/golangci-lint cache clean
1917
@${GOPATH}/bin/golangci-lint run --build-tags kqueue --timeout=10m --config ./.golangci.yml --fix
2018

2119
test: lint

certs/cert_pool_windows.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import (
2828
func loadSystemRoots() (*x509.CertPool, error) {
2929
const CRYPTENOTFOUND = 0x80092004
3030

31-
store, err := syscall.CertOpenSystemStore(0, syscall.StringToUTF16Ptr("ROOT"))
31+
rootPtr, err := syscall.UTF16PtrFromString("ROOT")
32+
if err != nil {
33+
return nil, err
34+
}
35+
store, err := syscall.CertOpenSystemStore(0, rootPtr)
3236
if err != nil {
3337
return nil, err
3438
}

certs/certificate2.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,17 @@ func watchFile(ctx context.Context, path string, ch chan notify.EventInfo, wg *s
203203
}
204204
symLink := st.Mode()&os.ModeSymlink == os.ModeSymlink
205205
if !symLink {
206-
// Windows doesn't allow for watching file changes but instead allows
207-
// for directory changes only, while we can still watch for changes
208-
// on files on other platforms. For other platforms it's also better
209-
// to watch the directory to catch all changes. Some updates are written
210-
// to a new file and then renamed to the destination file. This method
211-
// ensures we catch all such changes.
212-
//
213-
// Note: Certificate reloading relies on atomic file updates (write new
214-
// file, then rename). If certificate files are updated in-place without
215-
// atomicity, there is a window where partial/corrupted data may be read.
216-
// The hash comparison will skip reloads when content hasn't changed, but
217-
// does not protect against temporary inconsistency during partial writes.
218-
return notify.Watch(filepath.Dir(path), ch, eventWrite...)
206+
stop, err := watchDirSafe(filepath.Dir(path), path, ch, ctx.Done())
207+
if err != nil {
208+
return err
209+
}
210+
wg.Add(1)
211+
go func() {
212+
defer wg.Done()
213+
<-ctx.Done()
214+
stop()
215+
}()
216+
return nil
219217
}
220218

221219
wg.Add(1)

certs/certificate2_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"path/filepath"
2525
"reflect"
26+
"runtime"
2627
"testing"
2728
"time"
2829
)
@@ -89,6 +90,9 @@ func TestCertificate2_AutoReload(t *testing.T) {
8990
}
9091

9192
func TestCertificate2_AutoReloadSymlink(t *testing.T) {
93+
if runtime.GOOS == "windows" {
94+
t.Skip("symlinks require admin on Windows")
95+
}
9296
testCertificate2AutoReload(t, true)
9397
}
9498

@@ -177,6 +181,9 @@ func TestCertificate2_AutoReloadCertFileOnly(t *testing.T) {
177181
}
178182

179183
func TestCertificate2_AutoReloadCertFileOnlySymlink(t *testing.T) {
184+
if runtime.GOOS == "windows" {
185+
t.Skip("symlinks require admin on Windows")
186+
}
180187
testCertificate2AutoReloadCertFileOnly(t, true)
181188
}
182189

@@ -216,6 +223,9 @@ func TestCertificate2_InvalidReloadIgnored(t *testing.T) {
216223
}
217224

218225
func TestCertificate2_InvalidReloadIgnoredSymlink(t *testing.T) {
226+
if runtime.GOOS == "windows" {
227+
t.Skip("symlinks require admin on Windows")
228+
}
219229
testCertificate2InvalidReloadIgnored(t, true)
220230
}
221231

@@ -286,8 +296,8 @@ func overwriteFile(t *testing.T, src, dst string, symlink bool) {
286296
func updateCertWithWait(t *testing.T, cert *Certificate2, symlink bool, update func()) {
287297
done := make(chan struct{})
288298
wait := time.Second
289-
if symlink {
290-
wait = wait + symlinkReloadInterval // can take up to symlinkReloadInterval to detect changes
299+
if symlink || runtime.GOOS == "windows" {
300+
wait = wait + symlinkReloadInterval
291301
}
292302
ctx, cancel := context.WithTimeout(context.Background(), wait)
293303
defer cancel()

certs/certs.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,17 @@ func (c *Certificate) Watch(ctx context.Context, interval time.Duration, signals
149149
if !certFileSymLink && !keyFileSymLink && !isk8s {
150150
go func() {
151151
events := make(chan notify.EventInfo, 1)
152-
if err := notify.Watch(filepath.Dir(c.certFile), events, eventWrite...); err != nil {
152+
stop1, err := watchDirSafe(filepath.Dir(c.certFile), c.certFile, events, ctx.Done())
153+
if err != nil {
153154
return
154155
}
155-
if err := notify.Watch(filepath.Dir(c.keyFile), events, eventWrite...); err != nil {
156-
notify.Stop(events)
156+
stop2, err := watchDirSafe(filepath.Dir(c.keyFile), c.keyFile, events, ctx.Done())
157+
if err != nil {
158+
stop1()
157159
return
158160
}
159-
defer notify.Stop(events)
161+
defer stop1()
162+
defer stop2()
160163
for {
161164
select {
162165
case <-events:

0 commit comments

Comments
 (0)