28 lines
785 B
Go
28 lines
785 B
Go
package sqlserverproxy
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/binary"
|
|
"linkport/internal/model"
|
|
"testing"
|
|
)
|
|
|
|
func TestTDSTimingSkipsLoginAndWaitsForEndOfMessage(t *testing.T) {
|
|
var wire []byte
|
|
for _, flags := range []byte{1, 0, 1} {
|
|
header := []byte{4, flags, 0, 9, 0, 0, 1, 0}
|
|
binary.BigEndian.PutUint16(header[2:], 9)
|
|
wire = append(wire, append(header, 'x')...)
|
|
}
|
|
var q model.ExecutionQueue
|
|
q.Start("sql_batch")
|
|
var got []model.Execution
|
|
ctx := model.WithExecutionObserver(context.Background(), func(e model.Execution) { got = append(got, e) })
|
|
var out bytes.Buffer
|
|
relayMeasured(ctx, &out, bytes.NewReader(wire), &q)
|
|
if !bytes.Equal(out.Bytes(), wire) || len(got) != 1 || got[0].Operation != "sql_batch" {
|
|
t.Fatal("wrong response timing or modified TDS")
|
|
}
|
|
}
|