transaction_test: Add more authentication tests to run as user
So that it's possible also to verify an info text conversation
This commit is contained in:
2
test-services/deny-service
Normal file
2
test-services/deny-service
Normal file
@@ -0,0 +1,2 @@
|
||||
# Custom stack to deny permit, independent of the user name/pass
|
||||
auth requisite pam_deny.so
|
||||
3
test-services/echo-service
Normal file
3
test-services/echo-service
Normal file
@@ -0,0 +1,3 @@
|
||||
# Custom stack to always permit, independent of the user name/pass
|
||||
auth optional pam_echo.so This is an info message for user %u on %s
|
||||
auth required pam_permit.so
|
||||
@@ -204,6 +204,46 @@ func TestPAM_ConfDir_FailNoServiceOrUnsupported(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPAM_ConfDir_InfoMessage(t *testing.T) {
|
||||
u, _ := user.Current()
|
||||
var infoText string
|
||||
tx, err := StartConfDir("echo-service", u.Username,
|
||||
ConversationFunc(func(s Style, msg string) (string, error) {
|
||||
switch s {
|
||||
case TextInfo:
|
||||
infoText = msg
|
||||
return "", nil
|
||||
}
|
||||
return "", errors.New("unexpected")
|
||||
}), "test-services")
|
||||
if err != nil {
|
||||
t.Fatalf("start #error: %v", err)
|
||||
}
|
||||
err = tx.Authenticate(0)
|
||||
if err != nil {
|
||||
t.Fatalf("authenticate #error: %v", err)
|
||||
}
|
||||
if infoText != "This is an info message for user " + u.Username + " on echo-service" {
|
||||
t.Fatalf("Unexpected info message: %v", infoText)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPAM_ConfDir_Deny(t *testing.T) {
|
||||
u, _ := user.Current()
|
||||
tx, err := StartConfDir("deny-service", u.Username, Credentials{}, "test-services")
|
||||
if err != nil {
|
||||
t.Fatalf("start #error: %v", err)
|
||||
}
|
||||
err = tx.Authenticate(0)
|
||||
if err == nil {
|
||||
t.Fatalf("authenticate #expected an error")
|
||||
}
|
||||
s := err.Error()
|
||||
if len(s) == 0 {
|
||||
t.Fatalf("error #expected an error message")
|
||||
}
|
||||
}
|
||||
|
||||
func TestItem(t *testing.T) {
|
||||
tx, _ := StartFunc("passwd", "test", func(s Style, msg string) (string, error) {
|
||||
return "", nil
|
||||
|
||||
Reference in New Issue
Block a user