Integration test for confdir handling.
Add tests to cover StartConfDir with custom services path.
This commit is contained in:
2
my-service
Normal file
2
my-service
Normal file
@@ -0,0 +1,2 @@
|
||||
# Custom stack to always permit, independent of the user name/pass
|
||||
auth required pam_permit.so
|
||||
@@ -166,6 +166,50 @@ func TestPAM_007(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPAM_ConfDir(t *testing.T) {
|
||||
u, _ := user.Current()
|
||||
if u.Uid != "0" {
|
||||
t.Skip("run this test as root")
|
||||
}
|
||||
c := Credentials{
|
||||
// the custom service always permits even with wrong password.
|
||||
Password: "wrongsecret",
|
||||
}
|
||||
tx, err := StartConfDir("my-service", "test", c, ".")
|
||||
if !CheckPamHasStartConfdir() {
|
||||
if err == nil {
|
||||
t.Fatalf("start should have errored out as pam_start_confdir is not available: %v", err)
|
||||
}
|
||||
// nothing else we do, we don't support it.
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("start #error: %v", err)
|
||||
}
|
||||
err = tx.Authenticate(0)
|
||||
if err != nil {
|
||||
t.Fatalf("authenticate #error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPAM_ConfDir_FailNoServiceOrUnsupported(t *testing.T) {
|
||||
u, _ := user.Current()
|
||||
if u.Uid != "0" {
|
||||
t.Skip("run this test as root")
|
||||
}
|
||||
c := Credentials{
|
||||
Password: "secret",
|
||||
}
|
||||
_, err := StartConfDir("does-not-exists", "test", c, ".")
|
||||
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