move gotd fork into repo. (#111)

- 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
This commit is contained in:
Adam Van Ymeren
2025-06-27 20:03:37 -07:00
committed by GitHub
parent 0952df0244
commit 7a04f298d2
19264 changed files with 1539697 additions and 84 deletions
+104
View File
@@ -0,0 +1,104 @@
package session
import (
"bytes"
"encoding/base64"
"testing"
"github.com/stretchr/testify/require"
"go.mau.fi/mautrix-telegram/pkg/gotd/crypto"
)
func repeat(i int) []byte {
return bytes.Repeat([]byte{'a'}, i)
}
var (
testKey = repeat(256)
ipv4 = append([]byte("\x02\xc0\xa8\x00\x01\x01\xbb"), testKey...)
ipv6 = append([]byte("\x02 \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xbb"), testKey...)
)
func TestStringSession(t *testing.T) {
var key crypto.Key
copy(key[:], testKey)
authKey := key.WithID()
based := func(data []byte) string {
return "1" + base64.URLEncoding.EncodeToString(data)
}
tests := []struct {
name string
hx string
want *Data
wantErr bool
}{
{"IPv4", based(ipv4), &Data{
DC: 2,
Addr: "192.168.0.1:443",
AuthKey: authKey.Value[:],
AuthKeyID: authKey.ID[:],
}, false},
{"IPv6", based(ipv6),
&Data{
DC: 2,
Addr: "[2001:db8::]:443",
AuthKey: authKey.Value[:],
AuthKeyID: authKey.ID[:],
}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Log(tt.hx)
got, err := TelethonSession(tt.hx)
if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tt.want, got)
}
})
}
}
func Test_decodeStringSession(t *testing.T) {
var key crypto.Key
copy(key[:], testKey)
authKey := key.WithID()
tests := []struct {
name string
data []byte
want *Data
wantErr bool
}{
{"TooSmall", repeat(1), nil, true},
{"InvalidLength", repeat(267), nil, true},
{"TooBig", repeat(276), nil, true},
{"IPv4", ipv4, &Data{
DC: 2,
Addr: "192.168.0.1:443",
AuthKey: authKey.Value[:],
AuthKeyID: authKey.ID[:],
}, false},
{"IPv6", ipv6, &Data{
DC: 2,
Addr: "[2001:db8::]:443",
AuthKey: authKey.Value[:],
AuthKeyID: authKey.ID[:],
}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := decodeStringSession(tt.data)
if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tt.want, got)
}
})
}
}