summaryrefslogtreecommitdiff
path: root/transaction_test.go
diff options
context:
space:
mode:
authorMike Steinert <[email protected]>2022-09-17 16:16:24 -0500
committerGitHub <[email protected]>2022-09-17 16:16:24 -0500
commit313ea6f3baf83aaff875512dbd9905cb07537d84 (patch)
tree48a583e8773fbb8111e457b1997e211a067532b5 /transaction_test.go
parentf401703daf29acc07acb7d078755f4eb0bcd6e8c (diff)
parent376af17c468ef14f63444c5d1e5c157c7bb7ce1c (diff)
Merge pull request #5 from didrocks/start_confdirv1.1.0
Allow to define confdir
Diffstat (limited to 'transaction_test.go')
-rw-r--r--transaction_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/transaction_test.go b/transaction_test.go
index 2da45ab..c56edf2 100644
--- a/transaction_test.go
+++ b/transaction_test.go
@@ -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