Refactor checker logic to integrate context handling in MTProxy checks. Update error handling to utilize tgquick for response verification, replacing previous waitPostPayload function. Simplify error messages for closed connections.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package tgquick
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPopRI_RoundTrip(t *testing.T) {
|
||||
payload := []byte{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
enc, err := randomizedIntermediateEncode(payload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var acc []byte
|
||||
acc = append(acc, enc...)
|
||||
got, ok := popRI(&acc)
|
||||
if !ok || len(acc) != 0 {
|
||||
t.Fatalf("popRI: ok=%v rest=%d", ok, len(acc))
|
||||
}
|
||||
if string(got) != string(payload) {
|
||||
t.Fatalf("payload mismatch: %v vs %v", got, payload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsResPQ(t *testing.T) {
|
||||
nonce := make([]byte, 16)
|
||||
// resPQ: constructor + nonce(16) + server_nonce(16) + pq bytes + Vector<long>
|
||||
msgData := make([]byte, 4+16+16+4+4)
|
||||
binary.LittleEndian.PutUint32(msgData, tlResPQ)
|
||||
copy(msgData[4:20], nonce)
|
||||
copy(msgData[20:36], nonce)
|
||||
// pq empty, fingerprints empty
|
||||
if !isResPQ(wrapUnencrypted(msgData)) {
|
||||
t.Fatal("expected resPQ")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user