func TestThrift_GapInStream_response(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"thrift", "thriftdetailed"}) } var thrift Thrift thrift.Init(true, nil) thrift.Idl = thriftIdlForTesting(t, ` exception InvalidOperation { 1: i32 what, 2: string why } service Test { i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch), } `) thrift.PublishQueue = make(chan *ThriftTransaction, 10) tcptuple := testTcpTuple() req := createTestPacket(t, "800100010000000963616c63756c6174650000000008000"+ "1000000010c00020800010000000108000200000000080003000000040000") // missing last few bytes repl := createTestPacket(t, "800100020000000963616c63756c617465000000000c00"+ "01080001000000040b00020000001243616e6e6f742064697669646520") private := protos.ProtocolData(new(thriftPrivateData)) private = thrift.Parse(req, tcptuple, 0, private) private = thrift.Parse(repl, tcptuple, 1, private) private, drop := thrift.GapInStream(tcptuple, 1, 5, private) if drop == false { t.Error("GapInStream returned drop=false") } trans := expectThriftTransaction(t, thrift) // The exception is not captured, but otherwise the values from the request // are correct if trans.Request.Method != "calculate" || trans.Request.Params != "(logid: 1, w: (1: 1, 2: 0, 3: 4))" || trans.Reply.ReturnValue != "" || trans.Reply.Exceptions != `` || trans.Reply.HasException || trans.Request.Service != "Test" || trans.Reply.Notes[0] != "Packet loss while capturing the response" { t.Error("trans.Reply.Exceptions", trans.Reply.Exceptions) t.Error("trans.Reply.HasException", trans.Reply.HasException) } }
// Test that loss of data during the response (but not at the beginning) // don't cause the whole transaction to be dropped. func Test_gap_in_response(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"mysql", "mysqldetailed"}) } mysql := MysqlModForTests() // request and response from tests/pcaps/mysql_result_long.pcap // select * from test req_data, err := hex.DecodeString( "130000000373656c656374202a20" + "66726f6d2074657374") assert.Nil(t, err) resp_data, err := hex.DecodeString( "0100000103240000020364656604" + "74657374047465737404746573740161" + "01610c3f000b00000003000000000024" + "00000303646566047465737404746573" + "740474657374016201620c3f000b0000" + "00030000000000240000040364656604" + "74657374047465737404746573740163" + "01630c2100fd020000fd000000000005" + "000005fe000022000a00000601310131" + "0548656c6c6f0a000007013201320548" + "656c6c6f0601000801330133fcff004c" + "6f72656d20497073756d206973207369" + "6d706c792064756d6d79207465787420" + "6f6620746865207072696e74696e6720" + "616e64207479706573657474696e6720" + "696e6475737472792e204c6f72656d20") assert.Nil(t, err) tcptuple := testTcpTuple() req := protos.Packet{Payload: req_data} resp := protos.Packet{Payload: resp_data} private := protos.ProtocolData(new(mysqlPrivateData)) private = mysql.Parse(&req, tcptuple, 0, private) private = mysql.Parse(&resp, tcptuple, 1, private) logp.Debug("mysql", "Now sending gap..") private, drop := mysql.GapInStream(tcptuple, 1, 10, private) assert.Equal(t, true, drop) trans := expectTransaction(t, mysql) assert.NotNil(t, trans) assert.Equal(t, trans["notes"], []string{"Packet loss while capturing the response"}) }
// Test that loss of data during the response (but not at the beginning) // don't cause the whole transaction to be dropped. func Test_gap_in_response(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"pgsql", "pgsqldetailed"}) } pgsql := PgsqlModForTests() // request and response from tests/pcaps/pgsql_request_response.pcap // select * from test req_data, err := hex.DecodeString( "510000001873656c656374202a20" + "66726f6d20746573743b00") assert.Nil(t, err) // response is incomplete resp_data, err := hex.DecodeString( "5400000042000361000000410900" + "0100000413ffffffffffff0000620000" + "004009000200000413ffffffffffff00" + "00630000004009000300000413ffffff" + "ffffff0000440000001b000300000003" + "6d6561000000036d6562000000036d65" + "63440000001e0003000000046d656131" + "000000046d656231000000046d656331" + "440000001e0003000000046d65613200") assert.Nil(t, err) tcptuple := testTcpTuple() req := protos.Packet{Payload: req_data} resp := protos.Packet{Payload: resp_data} private := protos.ProtocolData(new(pgsqlPrivateData)) private = pgsql.Parse(&req, tcptuple, 0, private) private = pgsql.Parse(&resp, tcptuple, 1, private) logp.Debug("pgsql", "Now sending gap..") private, drop := pgsql.GapInStream(tcptuple, 1, 10, private) assert.Equal(t, true, drop) trans := expectTransaction(t, pgsql) assert.NotNil(t, trans) assert.Equal(t, trans["notes"], []string{"Packet loss while capturing the response"}) }
func TestThrift_GapInStream_request(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"thrift", "thriftdetailed"}) } var thrift Thrift thrift.Init(true, nil) thrift.Idl = thriftIdlForTesting(t, ` exception InvalidOperation { 1: i32 what, 2: string why } service Test { i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch), } `) thrift.PublishQueue = make(chan *ThriftTransaction, 10) tcptuple := testTcpTuple() // missing bytes from the request req := createTestPacket(t, "800100010000000963616c63756c6174") repl := createTestPacket(t, "800100020000000963616c63756c617465000000000c00"+ "01080001000000040b00020000001243616e6e6f742064697669646520627920300000") private := protos.ProtocolData(new(thriftPrivateData)) private = thrift.Parse(req, tcptuple, 0, private) private, drop := thrift.GapInStream(tcptuple, 0, 5, private) private = thrift.Parse(repl, tcptuple, 1, private) if drop == false { t.Error("GapInStream returned drop=false") } // packet loss in requests should result in no transaction select { case trans := <-thrift.PublishQueue: t.Error("Expected no transaction but got one:", trans) default: // ok } }
func Test_gap_in_body_http1dot0_fin(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"http", "httpdetailed"}) } http := HttpModForTests() data1 := []byte("GET / HTTP/1.0\r\n\r\n") data2 := []byte("HTTP/1.0 200 OK\r\n" + "Date: Tue, 14 Aug 2012 22:31:45 GMT\r\n" + "Expires: -1\r\n" + "Cache-Control: private, max-age=0\r\n" + "Content-Type: text/html; charset=UTF-8\r\n" + "Content-Encoding: gzip\r\n" + "Server: gws\r\n" + "X-XSS-Protection: 1; mode=block\r\n" + "X-Frame-Options: SAMEORIGIN\r\n" + "\r\n" + "xxxxxxxxxxxxxxxxxxxx") tcptuple := testTcpTuple() req := protos.Packet{Payload: data1} resp := protos.Packet{Payload: data2} private := protos.ProtocolData(new(httpPrivateData)) private = http.Parse(&req, tcptuple, 0, private) private = http.ReceivedFin(tcptuple, 0, private) private = http.Parse(&resp, tcptuple, 1, private) logp.Debug("http", "Now sending gap..") private, drop := http.GapInStream(tcptuple, 1, 10, private) assert.Equal(t, false, drop) private = http.ReceivedFin(tcptuple, 1, private) trans := expectTransaction(t, http) assert.NotNil(t, trans) assert.Equal(t, trans["notes"], []string{"Packet loss while capturing the response"}) }
// Test simple request / response. func TestSimpleFindLimit1(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"mongodb", "mongodbdetailed"}) } mongodb := MongodbModForTests() // request and response from tests/pcaps/mongo_one_row.pcap req_data, err := hex.DecodeString( "320000000a000000ffffffffd4070000" + "00000000746573742e72667374617572" + "616e7473000000000001000000050000" + "0000") assert.Nil(t, err) resp_data, err := hex.DecodeString( "020200004a0000000a00000001000000" + "08000000000000000000000000000000" + "01000000de010000075f696400558beb" + "b45f075665d2ae862703616464726573" + "730069000000026275696c64696e6700" + "05000000313030370004636f6f726400" + "1b000000013000e6762ff7c97652c001" + "3100d5b14ae9996c4440000273747265" + "657400100000004d6f72726973205061" + "726b2041766500027a6970636f646500" + "060000003130343632000002626f726f" + "756768000600000042726f6e78000263" + "756973696e65000700000042616b6572" + "79000467726164657300eb0000000330" + "002b00000009646174650000703d8544" + "01000002677261646500020000004100" + "1073636f72650002000000000331002b" + "0000000964617465000044510a410100" + "00026772616465000200000041001073" + "636f72650006000000000332002b0000" + "00096461746500009cda693c01000002" + "6772616465000200000041001073636f" + "7265000a000000000333002b00000009" + "646174650000ccb8cd33010000026772" + "616465000200000041001073636f7265" + "0009000000000334002b000000096461" + "7465000014109d2e0100000267726164" + "65000200000042001073636f7265000e" + "0000000000026e616d6500160000004d" + "6f72726973205061726b2042616b6520" + "53686f70000272657374617572616e74" + "5f696400090000003330303735343435" + "0000") assert.Nil(t, err) tcptuple := testTcpTuple() req := protos.Packet{Payload: req_data} resp := protos.Packet{Payload: resp_data} private := protos.ProtocolData(new(mongodbPrivateData)) private = mongodb.Parse(&req, tcptuple, 0, private) private = mongodb.Parse(&resp, tcptuple, 1, private) trans := expectTransaction(t, mongodb) assert.Equal(t, "OK", trans["status"]) assert.Equal(t, "find", trans["method"]) assert.Equal(t, "mongodb", trans["type"]) logp.Debug("mongodb", "Trans: %v", trans) }