Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

handshake_frame_test.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package obfuscation
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/suite"
  5. )
  6. type HandshakeFrameTestSuite struct {
  7. suite.Suite
  8. frame handshakeFrame
  9. reverted handshakeFrame
  10. }
  11. func (h *HandshakeFrameTestSuite) SetupSuite() {
  12. for i := range hfLen {
  13. h.frame.data[i] = byte(i + 1)
  14. h.reverted.data[i] = byte(hfLen - i)
  15. }
  16. }
  17. func (h *HandshakeFrameTestSuite) TestKey() {
  18. key := h.frame.key()
  19. h.EqualValues(8+1, key[0])
  20. h.EqualValues(8+hfLenKey, key[len(key)-1])
  21. h.Len(key, hfLenKey)
  22. }
  23. func (h *HandshakeFrameTestSuite) TestIV() {
  24. iv := h.frame.iv()
  25. h.EqualValues(40+1, iv[0])
  26. h.EqualValues(40+hfLenIV, iv[len(iv)-1])
  27. h.Len(iv, hfLenIV)
  28. }
  29. func (h *HandshakeFrameTestSuite) TestConnectionType() {
  30. connectionType := h.frame.connectionType()
  31. h.EqualValues(56+1, connectionType[0])
  32. h.EqualValues(56+hfLenConnectionType, connectionType[len(connectionType)-1])
  33. h.Len(connectionType, hfLenConnectionType)
  34. }
  35. func (h *HandshakeFrameTestSuite) TestDCSlice() {
  36. dcSlice := h.frame.dcSlice()
  37. h.EqualValues(61, dcSlice[0])
  38. h.EqualValues(61+1, dcSlice[1])
  39. h.Len(dcSlice, 2)
  40. }
  41. func (h *HandshakeFrameTestSuite) TestDC() {
  42. h.Equal(15933, h.frame.dc())
  43. }
  44. func (h *HandshakeFrameTestSuite) TestRevert() {
  45. fr := h.frame
  46. fr.revert()
  47. h.Equal(h.reverted.key(), fr.key())
  48. h.Equal(h.reverted.iv(), fr.iv())
  49. }
  50. func TestHandshakeFrame(t *testing.T) {
  51. t.Parallel()
  52. suite.Run(t, &HandshakeFrameTestSuite{})
  53. }