mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-13 17:12:05 -04:00
groupware: port tests to Stalwart 0.16.7
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -532,6 +532,7 @@ func (w *HttpWsClientFactory) connect(ctx context.Context, sessionProvider func(
|
||||
|
||||
h := http.Header{}
|
||||
w.auth(ctx, username, logger, h)
|
||||
w.logger.Trace().Str("username", log.SafeString(username)).Str("url", log.SafeString(u.String())).Msgf("connecting")
|
||||
c, res, err := w.dialer.DialContext(ctx, u.String(), h)
|
||||
if err != nil {
|
||||
return nil, "", endpoint, jmapError(err, JmapErrorFailedToEstablishWssConnection)
|
||||
|
||||
@@ -59,8 +59,8 @@ func TestAddressBooks(t *testing.T) {
|
||||
},
|
||||
func(orig AddressBook) AddressBookChange {
|
||||
return AddressBookChange{
|
||||
Description: ptr(orig.Description + " (changed)"),
|
||||
IsSubscribed: ptr(!orig.IsSubscribed),
|
||||
Description: new(orig.Description + " (changed)"),
|
||||
IsSubscribed: new(!orig.IsSubscribed),
|
||||
}
|
||||
},
|
||||
func(t *testing.T, orig AddressBook, _ AddressBookChange, changed AddressBook) {
|
||||
@@ -85,7 +85,7 @@ func TestContacts(t *testing.T) {
|
||||
defer s.Close()
|
||||
|
||||
user := pickUser()
|
||||
session := s.Session(user.name)
|
||||
session := s.Session(user.email)
|
||||
ctx := s.Context(session)
|
||||
|
||||
accountId, addressbookId, expectedContactCardsById, boxes, err := s.fillContacts(t, count, session, ctx, user)
|
||||
@@ -213,8 +213,8 @@ func TestContacts(t *testing.T) {
|
||||
now := time.Now().Truncate(time.Duration(1) * time.Second).UTC()
|
||||
for _, event := range expectedContactCardsById {
|
||||
change := ContactCardChange{
|
||||
Language: ptr("xyz"),
|
||||
Updated: ptr(now),
|
||||
Language: new("xyz"),
|
||||
Updated: new(now),
|
||||
}
|
||||
result, err := s.client.UpdateContactCard(accountId, event.Id, change, ctx)
|
||||
require.NoError(err)
|
||||
@@ -359,7 +359,7 @@ func (s *StalwartTest) fillContacts( //NOSONAR
|
||||
user User,
|
||||
) (AccountId, string, map[string]ContactCard, ContactsBoxes, error) {
|
||||
require := require.New(t)
|
||||
c, err := NewTestJmapClient(session, user.name, user.password, true, true)
|
||||
c, err := NewTestJmapClient(session, user.email, user.password, true, true)
|
||||
require.NoError(err)
|
||||
defer c.Close()
|
||||
|
||||
@@ -401,11 +401,11 @@ func (s *StalwartTest) fillContacts( //NOSONAR
|
||||
|
||||
card := ContactCardChange{
|
||||
Type: jscontact.ContactCardType,
|
||||
Version: ptr(jscontact.JSContactVersion_1_0),
|
||||
Version: new(jscontact.JSContactVersion_1_0),
|
||||
AddressBookIds: toBoolPtrMap([]string{addressbookId}),
|
||||
ProdId: &productName,
|
||||
Language: &language,
|
||||
Kind: ptr(jscontact.ContactCardKindIndividual),
|
||||
Kind: new(jscontact.ContactCardKindIndividual),
|
||||
Name: &nameObj,
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ func TestCalendars(t *testing.T) { //NOSONAR
|
||||
},
|
||||
func(orig Calendar) CalendarChange {
|
||||
return CalendarChange{
|
||||
Description: ptr(orig.Description + " (changed)"),
|
||||
IsSubscribed: ptr(!orig.IsSubscribed),
|
||||
Description: new(orig.Description + " (changed)"),
|
||||
IsSubscribed: new(!orig.IsSubscribed),
|
||||
}
|
||||
},
|
||||
func(t *testing.T, orig Calendar, _ CalendarChange, changed Calendar) {
|
||||
@@ -75,7 +75,7 @@ func TestEvents(t *testing.T) {
|
||||
defer s.Close()
|
||||
|
||||
user := pickUser()
|
||||
session := s.Session(user.name)
|
||||
session := s.Session(user.email)
|
||||
ctx := s.Context(session)
|
||||
|
||||
accountId, calendarId, expectedEventsById, boxes, err := s.fillEvents(t, count, ctx, user)
|
||||
@@ -178,7 +178,7 @@ func TestEvents(t *testing.T) {
|
||||
for _, event := range expectedEventsById {
|
||||
change := CalendarEventChange{
|
||||
EventChange: jscalendar.EventChange{
|
||||
Status: ptr(jscalendar.StatusCancelled),
|
||||
Status: new(jscalendar.StatusCancelled),
|
||||
ObjectChange: jscalendar.ObjectChange{
|
||||
Sequence: uintPtr(99),
|
||||
ShowWithoutTime: truep,
|
||||
@@ -382,7 +382,7 @@ func (s *StalwartTest) fillEvents( //NOSONAR
|
||||
user User,
|
||||
) (AccountId, string, map[string]CalendarEvent, EventsBoxes, error) {
|
||||
require := require.New(t)
|
||||
c, err := NewTestJmapClient(ctx.Session, user.name, user.password, true, true)
|
||||
c, err := NewTestJmapClient(ctx.Session, user.email, user.password, true, true)
|
||||
require.NoError(err)
|
||||
defer c.Close()
|
||||
|
||||
@@ -467,7 +467,7 @@ func (s *StalwartTest) fillEvents( //NOSONAR
|
||||
EventChange: jscalendar.EventChange{
|
||||
Type: jscalendar.EventType,
|
||||
Start: jscalendar.LocalDateTime(start),
|
||||
Duration: ptr(jscalendar.Duration(duration)),
|
||||
Duration: new(jscalendar.Duration(duration)),
|
||||
Status: &status,
|
||||
ObjectChange: jscalendar.ObjectChange{
|
||||
CommonObjectChange: jscalendar.CommonObjectChange{
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestEmails(t *testing.T) {
|
||||
defer s.Close()
|
||||
|
||||
user := pickUser()
|
||||
session := s.Session(user.name)
|
||||
session := s.Session(user.email)
|
||||
ctx := s.Context(session)
|
||||
|
||||
accountId := session.PrimaryAccounts.Mail
|
||||
@@ -59,9 +59,11 @@ func TestEmails(t *testing.T) {
|
||||
result, err := s.client.GetIdentities(accountId, []string{}, ctx)
|
||||
require.NoError(err)
|
||||
require.Equal(session.State, result.GetSessionState())
|
||||
require.Len(result.Payload.List, 1)
|
||||
require.Equal(user.email, result.Payload.List[0].Email)
|
||||
require.Equal(user.description, result.Payload.List[0].Name)
|
||||
require.Len(result.Payload.List, 2)
|
||||
emailMatches := structs.Filter(result.Payload.List, func(i Identity) bool { return i.Email == user.email })
|
||||
require.Len(emailMatches, 1)
|
||||
aliasMatches := structs.Filter(result.Payload.List, func(i Identity) bool { return i.Email == user.alias })
|
||||
require.Len(aliasMatches, 1)
|
||||
}
|
||||
|
||||
{
|
||||
@@ -122,7 +124,7 @@ func TestSendingEmails(t *testing.T) {
|
||||
defer s.Close()
|
||||
|
||||
from := pickUser()
|
||||
session := s.Session(from.name)
|
||||
session := s.Session(from.email)
|
||||
ctx := s.Context(session)
|
||||
accountId := session.PrimaryAccounts.Mail
|
||||
|
||||
@@ -131,7 +133,7 @@ func TestSendingEmails(t *testing.T) {
|
||||
others := structs.Filter(users[:], func(u User) bool { return u.name != from.name })
|
||||
to = others[rand.Intn(len(others))]
|
||||
}
|
||||
toSession := s.Session(to.name)
|
||||
toSession := s.Session(to.email)
|
||||
toAccountId := toSession.PrimaryAccounts.Mail
|
||||
|
||||
var cc User
|
||||
@@ -139,7 +141,7 @@ func TestSendingEmails(t *testing.T) {
|
||||
others := structs.Filter(users[:], func(u User) bool { return u.name != from.name && u.name != to.name })
|
||||
cc = others[rand.Intn(len(others))]
|
||||
}
|
||||
ccSession := s.Session(cc.name)
|
||||
ccSession := s.Session(cc.email)
|
||||
ccAccountId := ccSession.PrimaryAccounts.Mail
|
||||
|
||||
var mailboxPerRole map[string]Mailbox
|
||||
@@ -190,8 +192,10 @@ func TestSendingEmails(t *testing.T) {
|
||||
{
|
||||
result, err := s.client.GetIdentities(accountId, []string{}, ctx)
|
||||
require.NoError(err)
|
||||
require.NotEmpty(result.Payload.List)
|
||||
identity = result.Payload.List[0]
|
||||
require.Len(result.Payload.List, 2)
|
||||
matchesAlias := structs.Filter(result.Payload.List, func(i Identity) bool { return i.Email == from.alias })
|
||||
require.Len(matchesAlias, 1)
|
||||
identity = matchesAlias[0]
|
||||
}
|
||||
|
||||
create := EmailChange{
|
||||
@@ -270,7 +274,7 @@ func TestSendingEmails(t *testing.T) {
|
||||
require.Equal(sub.UndoStatus, UndoStatusPending) // this *might* be fragile: if the server is fast enough, would we get "final" here?
|
||||
require.Empty(sub.DsnBlobIds)
|
||||
require.Empty(sub.MdnBlobIds)
|
||||
require.Equal(from.email, sub.Envelope.MailFrom.Email)
|
||||
require.Equal(from.alias, sub.Envelope.MailFrom.Email)
|
||||
require.Nil(sub.Envelope.MailFrom.Parameters)
|
||||
require.Len(sub.Envelope.RcptTo, 2)
|
||||
require.Contains(sub.Envelope.RcptTo, Address{Email: to.email})
|
||||
@@ -325,7 +329,7 @@ func TestSendingEmails(t *testing.T) {
|
||||
require.Equal(1, mailbox.TotalEmails)
|
||||
}
|
||||
}
|
||||
require.NotEmpty(inboxId, "failed to find the Mailbox with the 'inbox' role for %v", r.user.name)
|
||||
require.NotEmpty(inboxId, "failed to find the Mailbox with the 'inbox' role for %v", r.user.email)
|
||||
}
|
||||
|
||||
result, err := s.client.QueryEmails([]AccountId{r.accountId}, EmailFilterCondition{InMailbox: inboxId}, 0, 0, true, 0, rctx)
|
||||
@@ -538,7 +542,7 @@ func (s *StalwartTest) fillEmailsWithImap(folder string, count int, empty bool,
|
||||
}
|
||||
}(c)
|
||||
|
||||
if err = c.Login(user.name, user.password).Wait(); err != nil {
|
||||
if err = c.Login(user.email, user.password).Wait(); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
@@ -586,7 +590,7 @@ func (s *StalwartTest) fillEmailsWithImap(folder string, count int, empty bool,
|
||||
domain := addressParts[0][2]
|
||||
|
||||
toName := displayName
|
||||
toAddress := fmt.Sprintf("%s@%s", user.name, domain)
|
||||
toAddress := fmt.Sprintf("%s@%s", user.email, domain)
|
||||
ccName1 := "Team Lead"
|
||||
ccAddress1 := fmt.Sprintf("lead@%s", domain)
|
||||
ccName2 := "Coworker"
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestWs(t *testing.T) {
|
||||
defer s.Close()
|
||||
|
||||
user := pickUser()
|
||||
session := s.Session(user.name)
|
||||
session := s.Session(user.email)
|
||||
ctx := s.Context(session)
|
||||
|
||||
mailAccountId := session.PrimaryAccounts.Mail
|
||||
@@ -77,7 +77,7 @@ func TestWs(t *testing.T) {
|
||||
_, inboxFolder = s.findInbox(t, mailAccountId, ctx)
|
||||
}
|
||||
|
||||
l := &testWsPushListener{t: t, username: user.name, logger: s.logger, mailAccountId: mailAccountId}
|
||||
l := &testWsPushListener{t: t, username: user.email, logger: s.logger, mailAccountId: mailAccountId}
|
||||
s.client.AddWsPushListener(l)
|
||||
|
||||
require.Equal(uint32(0), l.calls.Load())
|
||||
|
||||
@@ -575,7 +575,7 @@ func (e Exemplar) MailboxInbox() (Mailbox, string, string) {
|
||||
Id: e.MailboxInboxId,
|
||||
Name: "Inbox",
|
||||
Role: JmapMailboxRoleInbox,
|
||||
SortOrder: ptr(0),
|
||||
SortOrder: new(0),
|
||||
TotalEmails: 1291,
|
||||
UnreadEmails: 82,
|
||||
TotalThreads: 891,
|
||||
@@ -600,7 +600,7 @@ func (e Exemplar) MailboxInboxProjects() (Mailbox, string, string) {
|
||||
Id: e.MailboxProjectId,
|
||||
ParentId: e.MailboxInboxId,
|
||||
Name: "Projects",
|
||||
SortOrder: ptr(0),
|
||||
SortOrder: new(0),
|
||||
TotalEmails: 112,
|
||||
UnreadEmails: 3,
|
||||
TotalThreads: 85,
|
||||
@@ -625,7 +625,7 @@ func (e Exemplar) MailboxDrafts() (Mailbox, string, string) {
|
||||
Id: e.MailboxDraftsId,
|
||||
Name: "Drafts",
|
||||
Role: JmapMailboxRoleDrafts,
|
||||
SortOrder: ptr(0),
|
||||
SortOrder: new(0),
|
||||
TotalEmails: 12,
|
||||
UnreadEmails: 1,
|
||||
TotalThreads: 12,
|
||||
@@ -650,7 +650,7 @@ func (e Exemplar) MailboxSent() (Mailbox, string, string) {
|
||||
Id: e.MailboxSentId,
|
||||
Name: "Sent Items",
|
||||
Role: JmapMailboxRoleSent,
|
||||
SortOrder: ptr(0),
|
||||
SortOrder: new(0),
|
||||
TotalEmails: 1621,
|
||||
UnreadEmails: 0,
|
||||
TotalThreads: 1621,
|
||||
@@ -675,7 +675,7 @@ func (e Exemplar) MailboxJunk() (Mailbox, string, string) {
|
||||
Id: e.MailboxJunkId,
|
||||
Name: "Junk Mail",
|
||||
Role: JmapMailboxRoleJunk,
|
||||
SortOrder: ptr(0),
|
||||
SortOrder: new(0),
|
||||
TotalEmails: 251,
|
||||
UnreadEmails: 0,
|
||||
TotalThreads: 251,
|
||||
@@ -700,7 +700,7 @@ func (e Exemplar) MailboxDeleted() (Mailbox, string, string) {
|
||||
Id: e.MailboxDeletedId,
|
||||
Name: "Deleted Items",
|
||||
Role: JmapMailboxRoleTrash,
|
||||
SortOrder: ptr(0),
|
||||
SortOrder: new(0),
|
||||
TotalEmails: 99,
|
||||
UnreadEmails: 0,
|
||||
TotalThreads: 91,
|
||||
@@ -918,7 +918,7 @@ func (e Exemplar) AddressBook() AddressBook {
|
||||
|
||||
func (e Exemplar) AddressBookChange() AddressBookChange {
|
||||
return AddressBookChange{
|
||||
Description: ptr("A different name"),
|
||||
Description: new("A different name"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2325,9 +2325,9 @@ func (e Exemplar) CalendarEventSearchResults() CalendarEventSearchResults {
|
||||
return CalendarEventSearchResults{
|
||||
Results: []CalendarEvent{ev},
|
||||
CanCalculateChanges: true,
|
||||
Position: ptr(uint(3)),
|
||||
Limit: ptr(uint(10)),
|
||||
Total: ptr(uint(4)),
|
||||
Position: new(uint(3)),
|
||||
Limit: new(uint(10)),
|
||||
Total: new(uint(4)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2337,8 +2337,8 @@ func (e Exemplar) ContactCardSearchResults() ContactCardSearchResults {
|
||||
return ContactCardSearchResults{
|
||||
Results: []ContactCard{c1, c2},
|
||||
CanCalculateChanges: true,
|
||||
Position: ptr(uint(3)),
|
||||
Limit: ptr(uint(10)),
|
||||
Total: ptr(uint(4)),
|
||||
Position: new(uint(3)),
|
||||
Limit: new(uint(10)),
|
||||
Total: new(uint(4)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,14 +394,10 @@ func mapPairs[K comparable, L, R any](left map[K]L, right map[K]R) map[K]pair[L,
|
||||
}
|
||||
|
||||
var (
|
||||
truep = ptr(true)
|
||||
falsep = ptr(false)
|
||||
truep = new(true)
|
||||
falsep = new(false)
|
||||
)
|
||||
|
||||
func ptr[T any | string | int | uint | bool](t T) *T {
|
||||
return &t
|
||||
}
|
||||
|
||||
func identity1[T any](t T) T {
|
||||
return t
|
||||
}
|
||||
@@ -410,7 +406,7 @@ func list[T Foo, GETRESP GetResponse[T]](r GETRESP) []T { return r.GetList() }
|
||||
func getid[T Idable](r T) string { return r.GetId() }
|
||||
|
||||
func uintPtr[T int | uint](i T) *uint {
|
||||
return ptr(uint(i))
|
||||
return new(uint(i))
|
||||
}
|
||||
|
||||
func valueIf[T any | uint | int | bool](value *T, condition bool) *T {
|
||||
|
||||
Reference in New Issue
Block a user