7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package tdesktop
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
|
)
|
|
|
|
func Test_mtpAuthorization_deserialize(t *testing.T) {
|
|
testData := []uint8{
|
|
0x00, 0x00, 0x00, 0x4b, // dbiMtpAuthorization
|
|
0x00, 0x00, 0x05, 0x30, // mainLength
|
|
0xff, 0xff, 0xff, 0xff, // legacyUserId
|
|
0xff, 0xff, 0xff, 0xff, // legacyMainDcId
|
|
0x00, 0x00, 0x00, 0x00, 0x12, 0x73, 0xab, 0x45, // UserID = 309570373
|
|
0x00, 0x00, 0x00, 0x02, // DC = 2
|
|
0x00, 0x00, 0x00, 0x05, // 5 keys.
|
|
}
|
|
maxCut := len(testData) + 16
|
|
for i := byte(0); i < 5; i++ {
|
|
testData = append(testData, 0, 0, 0, i) // DC ID as BigEndian uint32
|
|
key := bytes.Repeat([]byte{i}, 256)
|
|
testData = append(testData, key...)
|
|
}
|
|
|
|
t.Run("OK", func(t *testing.T) {
|
|
a := require.New(t)
|
|
var m MTPAuthorization
|
|
a.NoError(m.deserialize(&qtReader{buf: bin.Buffer{Buf: testData}}))
|
|
a.Equal(uint64(309570373), m.UserID)
|
|
a.Equal(2, m.MainDC)
|
|
a.Len(m.Keys, 5)
|
|
for i := 0; i < 5; i++ {
|
|
a.Equal(m.Keys[i][0], uint8(i))
|
|
}
|
|
})
|
|
t.Run("WrongID", func(t *testing.T) {
|
|
a := require.New(t)
|
|
var m MTPAuthorization
|
|
a.Error(m.deserialize(&qtReader{buf: bin.Buffer{Buf: make([]byte, 4)}}))
|
|
})
|
|
|
|
for i := 0; i < maxCut; i += 4 {
|
|
t.Run(fmt.Sprintf("EOFAfter%d", i), func(t *testing.T) {
|
|
a := require.New(t)
|
|
var m MTPAuthorization
|
|
a.Error(m.deserialize(&qtReader{buf: bin.Buffer{Buf: testData[:i]}}))
|
|
})
|
|
}
|
|
}
|