blob: 1560d552cf2ce4301a6248540b8639ccf3cc7219 (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package main
import (
"os"
"testing"
)
func TestCreateDomain(t *testing.T) {
d := VirtualDomain{Name: "example.org"}
if !d.CreateDomain() {
t.Fatal("Creating domain failed.")
}
}
func TestDomainExists(t *testing.T) {
d := VirtualDomain{Name: "blablabla"}
if d.DomainExists() {
t.Fatal("'" + d.Name + "' does not exists.")
}
d.Name = "example.org"
if !d.DomainExists() {
t.Fatal("'" + d.Name + "' should exist.")
}
}
func TestValidateDomain(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("Skipping test to avoid external network.")
}
d := VirtualDomain{Name: "blablabla"}
if d.ValidateDomain("blablabla") {
t.Fatal(d.Name + " is not a valid domain.")
}
d.Name = "dfalsdf.adfjalf.example.org"
if d.ValidateDomain("dfalsdf.adfjalf.example.org") {
t.Fatal("'" + d.Name + "' is not a valid domain.")
}
d.Name = "https://google.com"
if d.ValidateDomain("https://google.com") {
t.Fatal("'" + d.Name + "' is not a valid domain.")
}
d.Name = "google.com"
if d.ValidateDomain("wikipedia.de") {
t.Fatal("'" + d.Name + "' and wikipedia.de do not share IPs.")
}
d.Name = "localhost"
if !d.ValidateDomain("localhost") {
t.Fatal("'" + d.Name + "' is a valid domain.")
}
}
func TestValidateDomainMX(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("Skipping test to avoid external network.")
}
d := VirtualDomain{Name: "google.com"}
if d.ValidateDomainMX(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) {
t.Fatal("google.cm MX record doesn't point to this server.")
}
d.Name = "iamfabulous.de"
if !d.ValidateDomainMX(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) {
t.Fatal(os.Getenv("FREEMAIL_SMTP_MAILER_MX") + " MX should point to this server.")
}
}
func TestGetDomain(t *testing.T) {
domain := GetDomain("foo@example.org")
if domain != "example.org" {
t.Fatal("Can't get the domain from the adress.")
}
}
func TestGetPrimaryKey(t *testing.T) {
d := VirtualDomain{Name: "example.org"}
if d.GetPrimaryKey() != 1 {
t.Fatal("Primary key should be 1.")
}
}
|