summaryrefslogtreecommitdiff
path: root/transaction_test.go
diff options
context:
space:
mode:
authorMichael Steinert <[email protected]>2015-03-29 11:25:00 -0500
committerMichael Steinert <[email protected]>2015-03-29 11:25:00 -0500
commit9c771166c9fb45cfa72779c356962f51022a6903 (patch)
tree5e71a54944eb9fbee940db70bc1c38d457a37d55 /transaction_test.go
parentb380319c58ed6bf1023f8e58f78f593fa28c234b (diff)
Add a test suite
Diffstat (limited to 'transaction_test.go')
-rw-r--r--transaction_test.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/transaction_test.go b/transaction_test.go
new file mode 100644
index 0000000..a1b7050
--- /dev/null
+++ b/transaction_test.go
@@ -0,0 +1,82 @@
+package pam
+
+import (
+ "errors"
+ "testing"
+)
+
+func TestPAM_001(t *testing.T) {
+ tx, err := StartFunc("", "test", func(s Style, msg string) (string, error) {
+ return "secret", nil
+ })
+ if err != nil {
+ t.Fatalf("start #error: %v", err)
+ }
+ err = tx.Authenticate(0)
+ if err != nil {
+ t.Fatalf("authenticate #error: %v", err)
+ }
+}
+
+func TestPAM_002(t *testing.T) {
+ tx, err := StartFunc("", "", func(s Style, msg string) (string, error) {
+ switch s {
+ case PromptEchoOn:
+ return "test", nil
+ case PromptEchoOff:
+ return "secret", nil
+ }
+ return "", errors.New("unexpected")
+ })
+ if err != nil {
+ t.Fatalf("start #error: %v", err)
+ }
+ err = tx.Authenticate(0)
+ if err != nil {
+ t.Fatalf("authenticate #error: %v", err)
+ }
+}
+
+type Credentials struct {
+ User string
+ Password string
+}
+
+func (c Credentials) RespondPAM(s Style, msg string) (string, error) {
+ switch s {
+ case PromptEchoOn:
+ return c.User, nil
+ case PromptEchoOff:
+ return c.Password, nil
+ }
+ return "", errors.New("unexpected")
+}
+
+func TestPAM_003(t *testing.T) {
+ c := Credentials{
+ User: "test",
+ Password: "secret",
+ }
+ tx, err := Start("", "", c)
+ if err != nil {
+ t.Fatalf("start #error: %v", err)
+ }
+ err = tx.Authenticate(0)
+ if err != nil {
+ t.Fatalf("authenticate #error: %v", err)
+ }
+}
+
+func TestPAM_004(t *testing.T) {
+ c := Credentials{
+ Password: "secret",
+ }
+ tx, err := Start("", "test", c)
+ if err != nil {
+ t.Fatalf("start #error: %v", err)
+ }
+ err = tx.Authenticate(0)
+ if err != nil {
+ t.Fatalf("authenticate #error: %v", err)
+ }
+}