You've already forked coredns-powerdns-api-wrapper
first commit
This commit is contained in:
30
privdrop_test.go
Normal file
30
privdrop_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestDropPrivilegesNonRootSkipsDrop covers the non-root half (Phase 6): when
|
||||
// the test binary is not running as root (the normal CI/dev case), dropPrivileges
|
||||
// must take the skip path — log a warning and return — without calling exit
|
||||
// or erroring. The root half (actual setuid/setgid) requires a root-owned
|
||||
// process and is exercised at the container level (Phase 6), not here.
|
||||
func TestDropPrivilegesNonRootSkipsDrop(t *testing.T) {
|
||||
if os.Getuid() == 0 {
|
||||
t.Skip("this test asserts the non-root skip path; running as root here")
|
||||
}
|
||||
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
|
||||
// If dropPrivileges took the root path here, it would call
|
||||
// syscall.Setgid/Setuid as non-root, fail, and os.Exit(1) — which would
|
||||
// kill the test binary. Reaching this point at all proves the skip path
|
||||
// was taken, without erroring or exiting.
|
||||
dropPrivileges(logger, 1000, 1000)
|
||||
}
|
||||
Reference in New Issue
Block a user