resources_test.go 1.35 KB
Newer Older
ale's avatar
ale committed
1
2
3
4
5
6
7
8
package backend

import (
	"testing"

	"github.com/go-test/deep"
	"gopkg.in/ldap.v2"

9
	as "git.autistici.org/ai3/accountserver"
ale's avatar
ale committed
10
11
12
13
14
15
)

func TestEmailResource_FromLDAP(t *testing.T) {
	entry := ldap.NewEntry(
		"mail=test@investici.org,uid=test@investici.org,ou=People,dc=example,dc=com",
		map[string][]string{
ale's avatar
ale committed
16
17
18
19
20
21
22
			"objectClass":          []string{"top", "virtualMailUser"},
			"mail":                 []string{"test@investici.org"},
			"status":               []string{"active"},
			"host":                 []string{"host1"},
			"originalHost":         []string{"host1"},
			"mailAlternateAddress": []string{"test2@investici.org", "test3@investici.org"},
			"mailMessageStore":     []string{"test/store"},
ale's avatar
ale committed
23
24
25
26
		},
	)

	reg := newResourceRegistry()
27
	reg.register(as.ResourceTypeEmail, &emailResourceHandler{baseDN: "dc=example,dc=com"})
ale's avatar
ale committed
28
29
30
31
32
33

	r, err := reg.FromLDAP(entry)
	if err != nil {
		t.Fatal("FromLDAP", err)
	}

34
35
	expected := &as.Resource{
		ID:            as.NewResourceID("email", "test@investici.org", "test@investici.org"),
ale's avatar
ale committed
36
		Type:          "email",
ale's avatar
ale committed
37
38
39
40
		Name:          "test@investici.org",
		Status:        "active",
		Shard:         "host1",
		OriginalShard: "host1",
41
		Email: &as.Email{
ale's avatar
ale committed
42
43
44
45
46
47
48
49
			Aliases: []string{"test2@investici.org", "test3@investici.org"},
			Maildir: "test/store",
		},
	}
	if err := deep.Equal(r, expected); err != nil {
		t.Fatalf("bad result: %v", err)
	}
}