-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_test.go
56 lines (46 loc) · 1.24 KB
/
connection_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
package gomailman
import (
"bytes"
"net/http"
"strings"
"testing"
)
const (
baseURL = "http://localhost:8001/3.1"
username = "restadmin"
password = "restpass"
)
func TestConnectionBasicAuthRejected(t *testing.T) {
conn, err := NewConnection(baseURL, "jimmer", password)
if err != nil {
t.Fatalf("Connection failed to create: %s", err)
}
res, err := conn.do(http.MethodGet, "system/versions", bytes.NewBuffer(nil))
if err != nil {
t.Fatalf("Connection request failed: %s", err)
}
b := bytes.NewBuffer(nil)
b.ReadFrom(res.Body)
result := b.String()
if !strings.Contains(result, "401 Unauthorized") {
t.Error("Basic authentication was sucessful expected 401 Unauthorized")
}
}
func TestConnectionNilUsername(t *testing.T) {
_, err := NewConnection(baseURL, "", password)
if err == nil {
t.Error("Connection successfully created with blank username")
}
}
func TestConnectionNilPassword(t *testing.T) {
_, err := NewConnection(baseURL, username, "")
if err == nil {
t.Error("Connection successfully created with blank password")
}
}
func TestConnectionNilUsernamePassword(t *testing.T) {
_, err := NewConnection(baseURL, "", "")
if err == nil {
t.Error("Connection successfully created with blank username and password")
}
}