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
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

init_test.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package obfuscation_test
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "fmt"
  6. "os"
  7. "path/filepath"
  8. "strings"
  9. "github.com/stretchr/testify/require"
  10. "github.com/stretchr/testify/suite"
  11. )
  12. type snapshotBytes struct {
  13. data []byte
  14. }
  15. func (s snapshotBytes) MarshalText() ([]byte, error) {
  16. if len(s.data) == 0 {
  17. return nil, nil
  18. }
  19. return []byte(base64.RawStdEncoding.EncodeToString(s.data)), nil
  20. }
  21. func (s *snapshotBytes) UnmarshalText(data []byte) error {
  22. val, err := base64.RawStdEncoding.DecodeString(string(data))
  23. if err != nil {
  24. return fmt.Errorf("cannot unmarshal %v: %w", len(val), err)
  25. }
  26. s.data = val
  27. return nil
  28. }
  29. type ObfuscatedSnapshot struct {
  30. Secret snapshotBytes `json:"secret"`
  31. Frame snapshotBytes `json:"frame"`
  32. DC int16 `json:"dc"`
  33. Encrypted struct {
  34. Text snapshotBytes `json:"text"`
  35. Cipher snapshotBytes `json:"cipher"`
  36. } `json:"encrypted"`
  37. Decrypted struct {
  38. Text snapshotBytes `json:"text"`
  39. Cipher snapshotBytes `json:"cipher"`
  40. } `json:"decrypted"`
  41. }
  42. type SnapshotTestSuite struct {
  43. suite.Suite
  44. snapshots map[string]*ObfuscatedSnapshot
  45. }
  46. func (s *SnapshotTestSuite) Setup(dirname, namePrefix string) {
  47. s.snapshots = make(map[string]*ObfuscatedSnapshot)
  48. files, err := os.ReadDir("testdata")
  49. require.NoError(s.T(), err)
  50. for _, v := range files {
  51. if !strings.HasPrefix(v.Name(), namePrefix) {
  52. continue
  53. }
  54. filename := filepath.Join("testdata", v.Name())
  55. contents, err := os.ReadFile(filename)
  56. require.NoError(s.T(), err)
  57. value := &ObfuscatedSnapshot{}
  58. require.NoError(s.T(), json.Unmarshal(contents, value))
  59. s.snapshots[v.Name()] = value
  60. }
  61. }