Skip to content

Commit b57d879

Browse files
committed
pam/integration-tests/exec: Add tests checking child behavior on signals
When the child receives signals should ignore them and just return a generic PAM system error, but still we need to check that they're properly handled
1 parent 6c328c1 commit b57d879

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pam/integration-tests/cmd/exec-client/modulewrapper.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ package main
55
import (
66
"context"
77
"errors"
8+
"os"
9+
"syscall"
10+
"time"
811

912
"github.com/msteinert/pam/v2"
13+
"github.com/ubuntu/authd/log"
1014
"github.com/ubuntu/authd/pam/internal/dbusmodule"
1115
)
1216

@@ -28,3 +32,20 @@ func (m *moduleWrapper) SimulateClientPanic(text string) {
2832
func (m *moduleWrapper) SimulateClientError(errorMsg string) error {
2933
return errors.New(errorMsg)
3034
}
35+
36+
// SimulateClientSignal sends a signal to the child process.
37+
func (m *moduleWrapper) SimulateClientSignal(sig syscall.Signal, shouldExit bool) {
38+
pid := os.Getpid()
39+
log.Debugf(context.Background(), "Sending signal %v to self pid (%v)",
40+
sig, pid)
41+
42+
if err := syscall.Kill(pid, sig); err != nil {
43+
log.Errorf(context.Background(), "Sending signal %v failed: %v", sig, err)
44+
return
45+
}
46+
47+
if shouldExit {
48+
// The program is expected to exit once the signal is sent, so let's wait
49+
<-time.After(24 * time.Hour)
50+
}
51+
}

pam/integration-tests/exec_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path/filepath"
99
"reflect"
1010
"strings"
11+
"syscall"
1112
"testing"
1213

1314
"github.com/godbus/dbus/v5"
@@ -231,6 +232,14 @@ func TestExecModule(t *testing.T) {
231232
methodCalls: []cliMethodCall{{m: "SimulateClientError", args: []any{"Client error!"}}},
232233
wantError: pam.ErrSystem,
233234
},
235+
"Error_when_client_fails_because_a_client_SIGTERM_signal": {
236+
methodCalls: []cliMethodCall{{m: "SimulateClientSignal", args: []any{syscall.SIGTERM, true}}},
237+
wantError: pam.ErrSystem,
238+
},
239+
"Error_when_client_fails_because_a_client_SIGKILL_signal": {
240+
methodCalls: []cliMethodCall{{m: "SimulateClientSignal", args: []any{syscall.SIGKILL, true}}},
241+
wantError: pam.ErrSystem,
242+
},
234243
}
235244
for name, tc := range cliTests {
236245
t.Run("Client "+name, func(t *testing.T) {
@@ -1006,6 +1015,8 @@ func getVariant(value any) dbus.Variant {
10061015
switch v := value.(type) {
10071016
case pam.Error:
10081017
return getVariant(int(v))
1018+
case syscall.Signal:
1019+
return getVariant(int(v))
10091020
case nil:
10101021
return getVariant("<@mv nothing>")
10111022
default:

0 commit comments

Comments
 (0)