// Initializes logp if the verbose flag was set. func configureLogp() { oneTimeLogpInit.Do(func() { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"eventlog", "eventlog_detail"}) logp.Info("DEBUG enabled for eventlog.") } else { logp.LogInit(logp.LOG_WARNING, "", false, true, []string{}) } }) }
// Initializes logp if the verbose flag was set. func configureLogp() { oneTimeLogpInit.Do(func() { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"eventlog"}) logp.Info("DEBUG enabled for eventlog.") } else { logp.LogInit(logp.LOG_WARNING, "", false, true, []string{}) } // Clear the event log before starting. log, _ := elog.Open(sourceName) eventlogging.ClearEventLog(eventlogging.Handle(log.Handle), "") log.Close() }) }
func TestOneHost503Resp(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"elasticsearch"}) } index := fmt.Sprintf("packetbeat-unittest-%d", os.Getpid()) body := map[string]interface{}{ "user": "******", "post_date": "2009-11-15T14:12:12", "message": "trying out", } server := ElasticsearchMock(503, []byte("Something wrong happened")) client := NewClient(server.URL, "", nil, nil, "", "") params := map[string]string{ "refresh": "true", } _, _, err := client.Index(index, "test", "1", params, body) if err == nil { t.Errorf("Index() should return error.") } if !strings.Contains(err.Error(), "503 Service Unavailable") { t.Errorf("Should return <503 Service Unavailable> instead of %v", err) } }
func TestAmqp_RecoverMethod(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() amqp.sendRequest = true data, err := hex.DecodeString("01000100000005003c006e01ce") assert.Nil(t, err) data2, err := hex.DecodeString("01000100000004003c006fce") assert.Nil(t, err) tcptuple := testTCPTuple() req := protos.Packet{Payload: data} private := protos.ProtocolData(new(amqpPrivateData)) private = amqp.Parse(&req, tcptuple, 0, private) req = protos.Packet{Payload: data2} amqp.Parse(&req, tcptuple, 1, private) trans := expectTransaction(t, amqp) assert.Equal(t, "basic.recover", trans["method"]) assert.Equal(t, "basic.recover", trans["request"]) assert.Equal(t, "amqp", trans["type"]) assert.Equal(t, common.OK_STATUS, trans["status"]) assert.Equal(t, common.MapStr{"requeue": true}, trans["amqp"]) }
func TestAmqp_GetEmptyMethod(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() amqp.sendRequest = true data, err := hex.DecodeString("01000100000013003c004600000b526f626269" + "654b65616e6501ce") assert.Nil(t, err) data2, err := hex.DecodeString("01000100000005003c004800ce") assert.Nil(t, err) tcptuple := testTCPTuple() req := protos.Packet{Payload: data} private := protos.ProtocolData(new(amqpPrivateData)) private = amqp.Parse(&req, tcptuple, 0, private) req = protos.Packet{Payload: data2} amqp.Parse(&req, tcptuple, 1, private) trans := expectTransaction(t, amqp) assert.Equal(t, "basic.get-empty", trans["method"]) assert.Equal(t, "basic.get RobbieKeane", trans["request"]) assert.Equal(t, "amqp", trans["type"]) assert.Equal(t, common.OK_STATUS, trans["status"]) }
func TestAmqp_NoWaitQueueDeleteMethod(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() amqp.sendRequest = true data, err := hex.DecodeString("010001000000120032002800000a546573745468" + "6f6d617304ce") assert.Nil(t, err) tcptuple := testTCPTuple() req := protos.Packet{Payload: data} private := protos.ProtocolData(new(amqpPrivateData)) amqp.Parse(&req, tcptuple, 0, private) trans := expectTransaction(t, amqp) assert.Equal(t, "queue.delete", trans["method"]) assert.Equal(t, "queue.delete TestThomas", trans["request"]) assert.Equal(t, "amqp", trans["type"]) fields, ok := trans["amqp"].(common.MapStr) if !ok { t.Errorf("Field should be present") } assert.Equal(t, true, fields["no-wait"]) assert.Equal(t, false, fields["if-empty"]) assert.Equal(t, false, fields["if-unused"]) assert.Equal(t, "TestThomas", fields["queue"]) }
func TestAmqp_ExchangeDeletion(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() data, err := hex.DecodeString("010001000000100028001400000844656c65746" + "54d6501ce") assert.Nil(t, err) stream := &amqpStream{data: data, message: new(amqpMessage)} m := stream.message ok, complete := amqp.amqpMessageParser(stream) if !ok { t.Errorf("Parsing returned error") } if !complete { t.Errorf("Message should be complete") } assert.Equal(t, "exchange.delete", m.method) assert.Equal(t, "DeleteMe", m.fields["exchange"]) assert.Equal(t, "DeleteMe", m.request) assert.Equal(t, true, m.fields["if-unused"]) assert.Equal(t, false, m.fields["no-wait"]) }
func TestAmqp_ExchangeDeclaration(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() data, err := hex.DecodeString("0100010000001c0028000a00000a6c6f67735f746f7" + "0696305746f7069630200000000ce") assert.Nil(t, err) stream := &amqpStream{data: data, message: new(amqpMessage)} m := stream.message ok, complete := amqp.amqpMessageParser(stream) if !ok { t.Errorf("Parsing returned error") } if !complete { t.Errorf("Message should be complete") } assert.Equal(t, "exchange.declare", m.method) assert.Equal(t, "logs_topic", m.fields["exchange"]) assert.Equal(t, "logs_topic", m.request) assert.Equal(t, true, m.fields["durable"]) assert.Equal(t, false, m.fields["passive"]) assert.Equal(t, false, m.fields["no-wait"]) assert.Equal(t, "topic", m.fields["exchange-type"]) _, exists := m.fields["arguments"].(common.MapStr) if exists { t.Errorf("Arguments field should not be present") } }
func TestAmqp_ConnectionCloseNoError(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() amqp.hideConnectionInformation = false data, err := hex.DecodeString("01000000000012000a003200c8076b74687862616900000000ce") assert.Nil(t, err) data2, err := hex.DecodeString("01000000000004000a0033ce") assert.Nil(t, err) tcptuple := testTCPTuple() req := protos.Packet{Payload: data} private := protos.ProtocolData(new(amqpPrivateData)) private = amqp.Parse(&req, tcptuple, 0, private) req = protos.Packet{Payload: data2} amqp.Parse(&req, tcptuple, 1, private) trans := expectTransaction(t, amqp) assert.Equal(t, "connection.close", trans["method"]) assert.Equal(t, "amqp", trans["type"]) assert.Equal(t, common.OK_STATUS, trans["status"]) assert.Nil(t, trans["notes"]) fields, ok := trans["amqp"].(common.MapStr) assert.True(t, ok) code, ok := fields["reply-code"].(uint16) assert.True(t, ok) assert.Equal(t, uint16(200), code) }
func TestUseType(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode. Requires Kafka") } if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"kafka"}) } id := strconv.Itoa(rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int()) logType := fmt.Sprintf("log-type-%s", id) kafka := newTestKafkaOutput(t, "", true) event := common.MapStr{ "@timestamp": common.Time(time.Now()), "host": "test-host", "type": logType, "message": id, } if err := kafka.PublishEvent(nil, testOptions, event); err != nil { t.Fatal(err) } messages := testReadFromKafkaTopic(t, logType, 1, 5*time.Second) if assert.Len(t, messages, 1) { msg := messages[0] logp.Debug("kafka", "%s: %s", msg.Key, msg.Value) assert.Contains(t, string(msg.Value), id) } }
func TestMissingFields(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"*"}) } yml := []map[string]interface{}{ map[string]interface{}{ "include_fields": map[string]interface{}{ "equals": map[string]string{ "type": "process", }, }, }, } config := filter.FilterPluginConfig{} for _, rule := range yml { c := map[string]common.Config{} for name, ruleYml := range rule { ruleConfig, err := common.NewConfigFrom(ruleYml) assert.Nil(t, err) c[name] = *ruleConfig } config = append(config, c) } _, err := filter.New(config) assert.NotNil(t, err) }
func TestOneHost500Resp(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"elasticsearch"}) } index := fmt.Sprintf("packetbeat-unittest-%d", os.Getpid()) body := map[string]interface{}{ "user": "******", "post_date": "2009-11-15T14:12:12", "message": "trying out", } server := ElasticsearchMock(http.StatusInternalServerError, []byte("Something wrong happened")) client := newTestClient(server.URL) err := client.Connect(1 * time.Second) if err != nil { t.Fatalf("Failed to connect: %v", err) } params := map[string]string{ "refresh": "true", } _, _, err = client.Index(index, "test", "1", params, body) if err == nil { t.Errorf("Index() should return error.") } if !strings.Contains(err.Error(), "500 Internal Server Error") { t.Errorf("Should return <500 Internal Server Error> instead of %v", err) } }
func TestOneHostSuccessResp(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"elasticsearch"}) } index := fmt.Sprintf("packetbeat-unittest-%d", os.Getpid()) body := map[string]interface{}{ "user": "******", "post_date": "2009-11-15T14:12:12", "message": "trying out", } expectedResp, _ := json.Marshal(QueryResult{Ok: true, Index: index, Type: "test", ID: "1", Version: 1, Created: true}) server := ElasticsearchMock(200, expectedResp) client := newTestClient(server.URL) params := map[string]string{ "refresh": "true", } _, resp, err := client.Index(index, "test", "1", params, body) if err != nil { t.Errorf("Index() returns error: %s", err) } if !resp.Created { t.Errorf("Index() fails: %s", resp) } }
func TestMySQLParser_simpleUpdateResponse(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"mysqldetailed"}) } data := []byte("300000010001000100000028526f7773206d6174636865643a203120204368616e6765643a203120205761726e696e67733a2030") message, err := hex.DecodeString(string(data)) if err != nil { t.Errorf("Failed to decode hex string") } stream := &MysqlStream{data: message, message: new(MysqlMessage)} ok, complete := mysqlMessageParser(stream) if !ok { t.Errorf("Parsing returned error") } if !complete { t.Errorf("Expecting a complete message") } if stream.message.IsRequest { t.Errorf("Failed to parse MySQL Query response") } if !stream.message.IsOK || stream.message.IsError { t.Errorf("Failed to true, true, parse MySQL Query response") } if stream.message.AffectedRows != 1 { t.Errorf("Failed to get the number of affected rows") } if stream.message.Size != 52 { t.Errorf("Wrong message size %d", stream.message.Size) } }
func BenchmarkIcmpProcessICMPv4(b *testing.B) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"icmp", "icmpdetailed"}) } results := &publish.ChanTransactions{make(chan common.MapStr, 10)} icmp, err := New(true, results, common.NewConfig()) if err != nil { b.Error("Failed to create ICMP processor") return } icmpRequestData := createICMPv4Layer(b, "08"+"00"+"0000"+"ffff"+"0001") packetRequestData := new(protos.Packet) icmpResponseData := createICMPv4Layer(b, "00"+"00"+"0000"+"ffff"+"0001") packetResponseData := new(protos.Packet) b.ResetTimer() for n := 0; n < b.N; n++ { icmp.ProcessICMPv4(nil, icmpRequestData, packetRequestData) icmp.ProcessICMPv4(nil, icmpResponseData, packetResponseData) client := icmp.results.(*publish.ChanTransactions) <-client.Channel } }
func TestAmqp_QueueDeclaration(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() data, err := hex.DecodeString("0100010000001a0032000a00000e5468697320697" + "3206120544553541800000000ce") assert.Nil(t, err) stream := &amqpStream{data: data, message: new(amqpMessage)} m := stream.message ok, complete := amqp.amqpMessageParser(stream) if !ok { t.Errorf("Parsing returned error") } if !complete { t.Errorf("Message should be complete") } assert.Equal(t, "This is a TEST", m.fields["queue"]) assert.Equal(t, false, m.fields["passive"]) assert.Equal(t, false, m.fields["durable"]) assert.Equal(t, false, m.fields["exclusive"]) assert.Equal(t, true, m.fields["auto-delete"]) assert.Equal(t, true, m.fields["no-wait"]) _, exists := m.fields["arguments"].(common.MapStr) if exists { t.Errorf("Arguments field should not be present") } }
func TestAmqp_ChannelCloseErrorMethod(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() data, err := hex.DecodeString("0100010000009000140028019685505245434f4e444" + "954494f4e5f4641494c4544202d20696e6571756976616c656e74206172672027617574" + "6f5f64656c6574652720666f722065786368616e676520277465737445786368616e676" + "52720696e2076686f737420272f273a207265636569766564202774727565272062757" + "42063757272656e74206973202766616c7365270028000ace") assert.Nil(t, err) data2, err := hex.DecodeString("0100010000000400280033ce") assert.Nil(t, err) tcptuple := testTCPTuple() req := protos.Packet{Payload: data} private := protos.ProtocolData(new(amqpPrivateData)) private = amqp.Parse(&req, tcptuple, 0, private) req = protos.Packet{Payload: data2} amqp.Parse(&req, tcptuple, 1, private) trans := expectTransaction(t, amqp) assert.Equal(t, "channel.close", trans["method"]) assert.Equal(t, "amqp", trans["type"]) assert.Equal(t, common.ERROR_STATUS, trans["status"]) assert.Nil(t, trans["notes"]) }
// Test parsing an incomplete pgsql response func TestPgsqlParser_incomplete_response(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"pgsql", "pgsqldetailed"}) } pgsql := pgsqlModForTests() data := []byte( "54000000420003610000004009000100000413ffffffffffff0000620000004009000200000413ffffffffffff0000630000004009000300000413ffffffffffff0000" + "440000001b0003000000036d6561000000036d6562000000036d6563" + "440000001e0003000000046d656131000000046d656231000000046d656331" + "440000001e0003000000046d") message, err := hex.DecodeString(string(data)) if err != nil { t.Error("Failed to decode hex string") } stream := &pgsqlStream{data: message, message: new(pgsqlMessage)} ok, complete := pgsql.pgsqlMessageParser(stream) if !ok { t.Error("Parsing returned error") } if complete { t.Error("Expecting an incomplete message") } }
func TestAmqp_MultipleBodyFrames(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() amqp.sendRequest = true data, err := hex.DecodeString("0100010000000e003c00280000000568656c6c6f00ce" + "02000100000021003c0000000000000000002a80400a746578742f706c61696e00000000" + "56a22873ce030001000000202a2a2a68656c6c6f2049206c696b6520746f207075626c69" + "736820626967206dce") assert.Nil(t, err) data2, err := hex.DecodeString("0300010000000a657373616765732a2a2ace") assert.Nil(t, err) tcptuple := testTCPTuple() req := protos.Packet{Payload: data} private := protos.ProtocolData(new(amqpPrivateData)) private = amqp.Parse(&req, tcptuple, 0, private) req = protos.Packet{Payload: data2} amqp.Parse(&req, tcptuple, 0, private) trans := expectTransaction(t, amqp) assert.Equal(t, "basic.publish", trans["method"]) assert.Equal(t, "***hello I like to publish big messages***", trans["request"]) }
func testAsyncLBFailSendWithoutActiveConnection(t *testing.T, events []eventInfo) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"*"}) } errFail := errors.New("fail connect") mode, _ := NewAsyncConnectionMode( []AsyncProtocolClient{ &mockClient{ connected: false, close: closeOK, connect: alwaysFailConnect(errFail), }, &mockClient{ connected: false, close: closeOK, connect: alwaysFailConnect(errFail), }, }, false, 2, 100*time.Millisecond, 100*time.Millisecond, 1*time.Second, ) testMode(t, mode, testNoOpts, events, signals(false), nil) }
func TestAmqp_BasicConsume(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() data, err := hex.DecodeString("01000100000028003c001400000e4957616e74" + "546f436f6e73756d650d6d6973746572436f6e73756d650300000000ce") assert.Nil(t, err) stream := &amqpStream{data: data, message: new(amqpMessage)} m := stream.message ok, complete := amqp.amqpMessageParser(stream) if !ok { t.Errorf("Parsing returned error") } if !complete { t.Errorf("Message should be complete") } assert.Equal(t, "basic.consume", m.method) assert.Equal(t, "IWantToConsume", m.fields["queue"]) assert.Equal(t, "misterConsume", m.fields["consumer-tag"]) assert.Equal(t, true, m.fields["no-ack"]) assert.Equal(t, false, m.fields["exclusive"]) assert.Equal(t, true, m.fields["no-local"]) assert.Equal(t, false, m.fields["no-wait"]) _, exists := m.fields["arguments"].(common.MapStr) if exists { t.Errorf("Arguments field should not be present") } }
func testAsyncLBFlakyGuaranteed2(t *testing.T, events []eventInfo) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"*"}) } var collected [][]common.MapStr err := errors.New("flaky") mode, _ := NewAsyncConnectionMode( []AsyncProtocolClient{ &mockClient{ connected: true, close: closeOK, connect: connectOK, asyncPublish: asyncFailStartWith(50, err, asyncCollectPublish(&collected)), }, &mockClient{ connected: true, close: closeOK, connect: connectOK, asyncPublish: asyncFailStartWith(50, err, asyncCollectPublish(&collected)), }, }, false, 3, 1*time.Nanosecond, 1*time.Millisecond, 4*time.Millisecond, ) testMode(t, mode, testGuaranteed, events, signals(true), &collected) }
//this method is exclusive to RabbitMQ func TestAmqp_ExchangeBind(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() data, err := hex.DecodeString("0100010000001c0028001e0000057465737431" + "057465737432044d5346540000000000ce") assert.Nil(t, err) stream := &amqpStream{data: data, message: new(amqpMessage)} m := stream.message ok, complete := amqp.amqpMessageParser(stream) if !ok { t.Errorf("Parsing returned error") } if !complete { t.Errorf("Message should be complete") } assert.Equal(t, "exchange.bind", m.method) assert.Equal(t, "test1", m.fields["destination"]) assert.Equal(t, "test2", m.fields["source"]) assert.Equal(t, "MSFT", m.fields["routing-key"]) assert.Equal(t, "test2 test1", m.request) assert.Equal(t, false, m.fields["no-wait"]) _, exists := m.fields["arguments"].(common.MapStr) if exists { t.Errorf("Arguments field should not be present") } }
func TestHttpParser_eatBody_connclose(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"http", "httpdetailed"}) } http := httpModForTests() http.parserConfig.sendHeaders = true http.parserConfig.sendAllHeaders = true data := []byte("HTTP/1.1 200 ok\r\n" + "user-agent: curl/7.35.0\r\n" + "host: localhost:9000\r\n" + "accept: */*\r\n" + "authorization: Company 1\r\n" + "connection: close\r\n" + "\r\n" + "0123456789") st := &stream{data: data, message: new(message)} ok, complete := testParseStream(http, st, 0) assert.True(t, ok) assert.False(t, complete) assert.Equal(t, st.bodyReceived, 10) ok, complete = testParseStream(http, st, 5) assert.True(t, ok) assert.False(t, complete) assert.Equal(t, st.bodyReceived, 15) ok, complete = testParseStream(http, st, 5) assert.True(t, ok) assert.False(t, complete) assert.Equal(t, st.bodyReceived, 20) }
func TestAmqp_RejectMessage(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() amqp.sendRequest = true data, err := hex.DecodeString("0100010000000d003c005a000000000000000101ce") assert.Nil(t, err) tcptuple := testTCPTuple() req := protos.Packet{Payload: data} private := protos.ProtocolData(new(amqpPrivateData)) //method frame amqp.Parse(&req, tcptuple, 0, private) trans := expectTransaction(t, amqp) assert.Equal(t, "basic.reject", trans["method"]) assert.Equal(t, "basic.reject 1", trans["request"]) assert.Equal(t, "amqp", trans["type"]) assert.Equal(t, common.ERROR_STATUS, trans["status"]) fields, ok := trans["amqp"].(common.MapStr) if !ok { t.Errorf("Field should be present") } assert.Equal(t, true, fields["multiple"]) }
func TestHttpParser_301_response(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"http"}) } data := "HTTP/1.1 301 Moved Permanently\r\n" + "Date: Sun, 29 Sep 2013 16:53:59 GMT\r\n" + "Server: Apache\r\n" + "Location: http://www.hotnews.ro/\r\n" + "Vary: Accept-Encoding\r\n" + "Content-Length: 290\r\n" + "Connection: close\r\n" + "Content-Type: text/html; charset=iso-8859-1\r\n" + "\r\n" + "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" + "<html><head>\r\n" + "<title>301 Moved Permanently</title>\r\n" + "</head><body>\r\n" + "<h1>Moved Permanently</h1>\r\n" + "<p>The document has moved <a href=\"http://www.hotnews.ro/\">here</a>.</p>\r\n" + "<hr>\r\n" + "<address>Apache Server at hotnews.ro Port 80</address>\r\n" + "</body></html>" msg, ok, complete := testParse(nil, data) assert.True(t, ok) assert.True(t, complete) assert.Equal(t, 290, msg.contentLength) }
func TestAmqp_GetMethod(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() amqp.sendRequest = true amqp.sendResponse = true data, err := hex.DecodeString("0100010000000f003c0046000007546573744" + "7657401ce") assert.Nil(t, err) data2, err := hex.DecodeString("0100010000001a003c00470000000000000001" + "0000075465737447657400000001ce02000100000019003c000000000000000000" + "1280000a746578742f706c61696ece03000100000012476574206d6520696620796" + "f752064617265ce") assert.Nil(t, err) tcptuple := testTCPTuple() req := protos.Packet{Payload: data} private := protos.ProtocolData(new(amqpPrivateData)) private = amqp.Parse(&req, tcptuple, 0, private) req = protos.Packet{Payload: data2} amqp.Parse(&req, tcptuple, 1, private) trans := expectTransaction(t, amqp) assert.Equal(t, "basic.get", trans["method"]) assert.Equal(t, "basic.get TestGet", trans["request"]) assert.Equal(t, "amqp", trans["type"]) assert.Equal(t, common.OK_STATUS, trans["status"]) assert.Equal(t, "Get me if you dare", trans["response"]) }
func TestHttpParser_censorPasswordPOST(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"http", "httpdetailed"}) } http := httpModForTests() http.hideKeywords = []string{"password"} http.parserConfig.sendHeaders = true http.parserConfig.sendAllHeaders = true data1 := "POST /users/login HTTP/1.1\r\n" + "HOST: www.example.com\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + "Content-Length: 28\r\n" + "\r\n" + "username=ME&password=secret\r\n" tp := newTestParser(http, data1) msg, ok, complete := tp.parse() assert.True(t, ok) assert.True(t, complete) rawMsg := tp.stream.data[tp.stream.message.start:tp.stream.message.end] path, params, err := http.extractParameters(msg, rawMsg) assert.Nil(t, err) assert.Equal(t, "/users/login", path) assert.False(t, strings.Contains(params, "secret")) }
func TestAmqp_GetTable(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"}) } amqp := amqpModForTests() data, err := hex.DecodeString("010001000000890032000a00000a5465737448656164" + "657218000000730974696d657374616d70540000000055f7e40903626974620507646563" + "696d616c440500ec49050568656c6c6f530000001f4869206461726c696e6720c3aac3aa" + "c3aac3aac3aac3aac3aae697a5e69cac06646f75626c656440453e100cbd7da405666c6f" + "6174664124cccd04626f6f6c7401ce") assert.Nil(t, err) stream := &amqpStream{data: data, message: new(amqpMessage)} ok, complete := amqp.amqpMessageParser(stream) m := stream.message if !ok { t.Errorf("Parsing returned error") } if !complete { t.Errorf("Message should be complete") } args, ok := m.fields["arguments"].(common.MapStr) if !ok { t.Errorf("Field should be present") } double, ok := args["double"].(float64) if !ok { t.Errorf("Field should be present") } else if ok && double != 42.4848648 { t.Errorf("Wrong argument") } float, ok := args["float"].(float32) if !ok { t.Errorf("Field should be present") } else if ok && float != 10.3 { t.Errorf("Wrong argument") } argByte, ok := args["bit"].(int8) if !ok { t.Errorf("Field should be present") } else if ok && argByte != 5 { t.Errorf("Wrong argument") } assert.Equal(t, "Hi darling êêêêêêê日本", args["hello"]) assert.Equal(t, true, args["bool"]) assert.Equal(t, "154.85189", args["decimal"]) assert.Equal(t, "queue.declare", m.method) assert.Equal(t, false, m.fields["durable"]) assert.Equal(t, true, m.fields["no-wait"]) assert.Equal(t, true, m.fields["auto-delete"]) assert.Equal(t, false, m.fields["exclusive"]) //assert.Equal(t, "September 15 11:25:29 2015", args["timestamp"]) assert.Equal(t, "TestHeader", m.request) }
func TestThriftIdl_thriftReadFiles(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"thrift", "thriftdetailed"}) } idl := thriftIdlForTesting(t, ` /* simple test */ service Test { i32 add(1:i32 num1, 2: i32 num2) } `) methods_map := idl.MethodsByName if len(methods_map) == 0 { t.Error("Empty methods_map") } m, exists := methods_map["add"] if !exists || m.Service == nil || m.Method == nil || m.Service.Name != "Test" || m.Method.Name != "add" { t.Error("Bad data:", m) } if *m.Params[1] != "num1" || *m.Params[2] != "num2" { t.Error("Bad params", m.Params) } if len(m.Exceptions) != 0 { t.Error("Non empty exceptions", m.Exceptions) } }