diff options
author | Michael Steinert <[email protected]> | 2015-04-09 11:37:39 -0500 |
---|---|---|
committer | Michael Steinert <[email protected]> | 2015-04-09 11:37:39 -0500 |
commit | b4414b73f07d47068171a386ebcc51ce124958f8 (patch) | |
tree | 9a9709a50d899c5d619257995667bfceba95ed24 /transaction_test.go | |
parent | c88b34e980257134650b21769d5f386390ea8372 (diff) |
Improve test coverage
Diffstat (limited to 'transaction_test.go')
-rw-r--r-- | transaction_test.go | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/transaction_test.go b/transaction_test.go index 3826bf4..16dc8ad 100644 --- a/transaction_test.go +++ b/transaction_test.go @@ -3,6 +3,7 @@ package pam import ( "errors" "os/user" + "runtime" "testing" ) @@ -21,6 +22,15 @@ func TestPAM_001(t *testing.T) { if err != nil { t.Fatalf("authenticate #error: %v", err) } + err = tx.AcctMgmt(Silent) + if err != nil { + t.Fatalf("acct_mgmt #error: %v", err) + } + err = tx.SetCred(Silent | EstablishCred) + if err != nil { + t.Fatalf("setcred #error: %v", err) + } + runtime.GC() } func TestPAM_002(t *testing.T) { @@ -44,6 +54,7 @@ func TestPAM_002(t *testing.T) { if err != nil { t.Fatalf("authenticate #error: %v", err) } + runtime.GC() } type Credentials struct { @@ -78,6 +89,7 @@ func TestPAM_003(t *testing.T) { if err != nil { t.Fatalf("authenticate #error: %v", err) } + runtime.GC() } func TestPAM_004(t *testing.T) { @@ -96,6 +108,69 @@ func TestPAM_004(t *testing.T) { if err != nil { t.Fatalf("authenticate #error: %v", err) } + runtime.GC() +} + +func TestPAM_005(t *testing.T) { + u, _ := user.Current() + if u.Uid != "0" { + t.Skip("run this test as root") + } + tx, err := StartFunc("passwd", "test", func(s Style, msg string) (string, error) { + return "secret", nil + }) + if err != nil { + t.Fatalf("start #error: %v", err) + } + err = tx.ChangeAuthTok(Silent) + if err != nil { + t.Fatalf("chauthtok #error: %v", err) + } + runtime.GC() +} + +func TestPAM_006(t *testing.T) { + u, _ := user.Current() + if u.Uid != "0" { + t.Skip("run this test as root") + } + tx, err := StartFunc("passwd", u.Username, func(s Style, msg string) (string, error) { + return "secret", nil + }) + if err != nil { + t.Fatalf("start #error: %v", err) + } + err = tx.OpenSession(Silent) + if err != nil { + t.Fatalf("open_session #error: %v", err) + } + err = tx.CloseSession(Silent) + if err != nil { + t.Fatalf("close_session #error: %v", err) + } + runtime.GC() +} + +func TestPAM_007(t *testing.T) { + u, _ := user.Current() + if u.Uid != "0" { + t.Skip("run this test as root") + } + tx, err := StartFunc("", "test", func(s Style, msg string) (string, error) { + return "", errors.New("Sorry, it didn't work") + }) + if err != nil { + t.Fatalf("start #error: %v", err) + } + err = tx.Authenticate(0) + if err == nil { + t.Fatalf("authenticate #expected an error", err) + } + s := err.Error() + if len(s) == 0 { + t.Fatalf("error #expected an error message") + } + runtime.GC() } func TestItem(t *testing.T) { @@ -130,6 +205,7 @@ func TestItem(t *testing.T) { if s != "root" { t.Fatalf("getitem #error: expected root, got %v", s) } + runtime.GC() } func TestEnv(t *testing.T) { @@ -161,7 +237,12 @@ func TestEnv(t *testing.T) { } } - s := tx.GetEnv("VAL1") + s := tx.GetEnv("VAL0") + if s != "" { + t.Fatalf("getenv #error: expected \"\", got %v", s) + } + + s = tx.GetEnv("VAL1") if s != "1" { t.Fatalf("getenv #error: expected 1, got %v", s) } @@ -191,4 +272,5 @@ func TestEnv(t *testing.T) { if m["VAL3"] != "3" { t.Fatalf("getenvlist #error: expected 3, got %v", m["VAL1"]) } + runtime.GC() } |