Skip to content

Commit

Permalink
pam/integration-tests/exec: Add test case for calling invalid method
Browse files Browse the repository at this point in the history
It's nice to increase coverage... :)
  • Loading branch information
3v1n0 committed Mar 3, 2025
1 parent caaf5e3 commit 5dacb53
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pam/go-exec/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ const char *UBUNTU_AUTHD_PAM_OBJECT_NODE =
" <arg type='i' name='status' direction='out'/>"
" <arg type='s' name='response' direction='out'/>"
" </method>"
#ifdef AUTHD_TEST_EXEC_MODULE
" <method name='InvalidMethod' />"
#endif
" </interface>"
"</node>";

Expand Down
10 changes: 9 additions & 1 deletion pam/integration-tests/cmd/exec-client/modulewrapper.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build pam_tests_exec_client
//-go:build pam_tests_exec_client

package main

Check failure on line 3 in pam/integration-tests/cmd/exec-client/modulewrapper.go

View workflow job for this annotation

GitHub Actions / Go: Code sanity

package-comments: should have a package comment (revive)

Expand All @@ -9,6 +9,7 @@ import (
"syscall"
"time"

"github.com/godbus/dbus/v5"
"github.com/msteinert/pam/v2"
"github.com/ubuntu/authd/log"
"github.com/ubuntu/authd/pam/internal/dbusmodule"
Expand All @@ -23,6 +24,13 @@ func newModuleWrapper(serverAddress string) (pam.ModuleTransaction, func(), erro
return &moduleWrapper{mTx}, closeFunc, err
}

// SimulateClientPanic forces the client to panic with the provided text.
func (m *moduleWrapper) CallInvalidMethod() error {

Check failure on line 28 in pam/integration-tests/cmd/exec-client/modulewrapper.go

View workflow job for this annotation

GitHub Actions / Go: Code sanity

func `(*moduleWrapper).CallInvalidMethod` is unused (unused)
method := "com.ubuntu.authd.pam.InvalidMethod"
tx, _ := m.ModuleTransaction.(*dbusmodule.Transaction)
return tx.BusObject().Call(method, dbus.FlagNoAutoStart).Err
}

// SimulateClientPanic forces the client to panic with the provided text.
func (m *moduleWrapper) SimulateClientPanic(text string) {

Check failure on line 35 in pam/integration-tests/cmd/exec-client/modulewrapper.go

View workflow job for this annotation

GitHub Actions / Go: Code sanity

func `(*moduleWrapper).SimulateClientPanic` is unused (unused)
panic(text)
Expand Down
4 changes: 4 additions & 0 deletions pam/integration-tests/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ func TestExecModule(t *testing.T) {
methodCalls: []cliMethodCall{{m: "ThisMethodDoesNotExist"}},
wantError: pam_test.ErrInvalidMethod,
},
"Error_when_calling_unknown_dbus_method": {
methodCalls: []cliMethodCall{{m: "CallInvalidMethod"}},
wantError: pam.ErrSystem,
},
"Error_when_argument_types_do_not_match_arguments": {
methodCalls: []cliMethodCall{{m: "SetItem", args: []any{"an-item", "value"}}},
wantError: pam_test.ErrArgumentTypeMismatch,
Expand Down
5 changes: 5 additions & 0 deletions pam/internal/dbusmodule/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func NewTransaction(ctx context.Context, address string, o ...TransactionOptions
return &Transaction{obj: obj}, cleanup, nil
}

// Bus gets the DBus object.

Check failure on line 70 in pam/internal/dbusmodule/transaction.go

View workflow job for this annotation

GitHub Actions / Go: Code sanity

exported: comment on exported method Transaction.BusObject should be of the form "BusObject ..." (revive)
func (tx *Transaction) BusObject() dbus.BusObject {
return tx.obj
}

// SetData allows to save any value in the module data that is preserved
// during the whole time the module is loaded.
func (tx *Transaction) SetData(key string, data any) error {
Expand Down

0 comments on commit 5dacb53

Please sign in to comment.