-
Notifications
You must be signed in to change notification settings - Fork 18
/
address_test.go
111 lines (94 loc) · 3.36 KB
/
address_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package proton_test
import (
"context"
"testing"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/go-proton-api/server"
"github.com/stretchr/testify/require"
)
func TestAddress_DisplayName(t *testing.T) {
s := server.New()
defer s.Close()
// Create a user on the server.
userID, _, err := s.CreateUser("user", []byte("pass"))
require.NoError(t, err)
addr1, err := s.CreateAddress(userID, "[email protected]", []byte("pass"))
require.NoError(t, err)
require.NoError(t, s.ChangeAddressDisplayName(userID, addr1, "User 1"))
addr2, err := s.CreateAddress(userID, "[email protected]", []byte("pass"))
require.NoError(t, err)
require.NoError(t, s.ChangeAddressDisplayName(userID, addr2, "User 2"))
require.NoError(t, err)
m := proton.New(
proton.WithHostURL(s.GetHostURL()),
proton.WithTransport(proton.InsecureTransport()),
)
defer m.Close()
// Create one session for the user.
c, auth, err := m.NewClientWithLogin(context.Background(), "user", []byte("pass"))
require.NoError(t, err)
require.Equal(t, userID, auth.UserID)
// Get addresses for the user.
addrs, err := c.GetAddresses(context.Background())
require.NoError(t, err)
for _, addr := range addrs {
switch addr.ID {
case addr1:
require.Equal(t, addr.Email, "[email protected]")
require.Equal(t, addr.DisplayName, "User 1")
case addr2:
require.Equal(t, addr.Email, "[email protected]")
require.Equal(t, addr.DisplayName, "User 2")
}
}
}
func TestAddress_Types(t *testing.T) {
s := server.New()
defer s.Close()
// Create a user on the server.
userID, _, err := s.CreateUser("user", []byte("pass"))
require.NoError(t, err)
id2, err := s.CreateAddress(userID, "[email protected]", []byte("pass"))
require.NoError(t, err)
require.NoError(t, s.ChangeAddressType(userID, id2, proton.AddressTypeAlias))
id3, err := s.CreateAddress(userID, "[email protected]", []byte("pass"))
require.NoError(t, err)
require.NoError(t, s.ChangeAddressType(userID, id3, proton.AddressTypeCustom))
id4, err := s.CreateAddress(userID, "[email protected]", []byte("pass"))
require.NoError(t, err)
require.NoError(t, s.ChangeAddressType(userID, id4, proton.AddressTypePremium))
id5, err := s.CreateAddress(userID, "[email protected]", []byte("pass"))
require.NoError(t, err)
require.NoError(t, s.ChangeAddressType(userID, id5, proton.AddressTypeExternal))
m := proton.New(
proton.WithHostURL(s.GetHostURL()),
proton.WithTransport(proton.InsecureTransport()),
)
defer m.Close()
// Create one session for the user.
c, auth, err := m.NewClientWithLogin(context.Background(), "user", []byte("pass"))
require.NoError(t, err)
require.Equal(t, userID, auth.UserID)
// Get addresses for the user.
addrs, err := c.GetAddresses(context.Background())
require.NoError(t, err)
for _, addr := range addrs {
switch addr.ID {
case id2:
require.Equal(t, addr.Email, "[email protected]")
require.Equal(t, addr.Type, proton.AddressTypeAlias)
case id3:
require.Equal(t, addr.Email, "[email protected]")
require.Equal(t, addr.Type, proton.AddressTypeCustom)
case id4:
require.Equal(t, addr.Email, "[email protected]")
require.Equal(t, addr.Type, proton.AddressTypePremium)
case id5:
require.Equal(t, addr.Email, "[email protected]")
require.Equal(t, addr.Type, proton.AddressTypeExternal)
default:
require.Equal(t, addr.Email, "[email protected]")
require.Equal(t, addr.Type, proton.AddressTypeOriginal)
}
}
}