forked from fbiering/goipa
/
ipa_test.go
64 lines (49 loc) · 1.24 KB
/
ipa_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2018 Andrew E. Bruno. All rights reserved.
// Use of this source code is governed by a BSD style
// license that can be found in the LICENSE file.
package ipa
import (
"fmt"
"os"
"testing"
)
func newTestClientUserPassword() *Client {
host := os.Getenv("GOIPA_TEST_HOST")
username := os.Getenv("GOIPA_TEST_USER")
password := os.Getenv("GOIPA_TEST_PASSWD")
realm := os.Getenv("GOIPA_TEST_REALM")
c := NewClient(host, realm)
err := c.Login(username, password)
if err != nil {
panic(err)
}
return c
}
func newTestClientKeytab() *Client {
host := os.Getenv("GOIPA_TEST_HOST")
keytab := os.Getenv("GOIPA_TEST_KEYTAB")
username := os.Getenv("GOIPA_TEST_KTUSER")
realm := os.Getenv("GOIPA_TEST_REALM")
c := NewClient(host, realm)
err := c.LoginWithKeytab(keytab, username)
if err != nil {
panic(err)
}
return c
}
func TestPing(t *testing.T) {
user := os.Getenv("GOIPA_TEST_USER")
realm := os.Getenv("GOIPA_TEST_REALM")
c := newTestClientUserPassword()
res, err := c.Ping()
if err != nil {
t.Fatal(err)
}
princ := fmt.Sprintf("%s@%s", user, realm)
if princ != res.Principal {
t.Errorf("Wrong principal: got %s expected %s", res.Principal, princ)
}
if len(c.SessionID()) == 0 {
t.Errorf("SessionID not set")
}
}