Listen for events and forward to external security scanning services.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

events_test.go 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "reflect"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestParseEventWillReturnAnEventStruct(t *testing.T) {
  8. event, err := ParseEvent([]byte(securityGroupRuleCreateWithports))
  9. assert.Nil(t, err)
  10. assert.Equal(t, "main.Event", reflect.TypeOf(event).String(),
  11. "ParseEvent should return an Event struct")
  12. assert.Equal(t, "security_group_rule.create.end", event.EventData.EventType)
  13. assert.Equal(t, "bca89c1b248e4aef9c69ece9e744cc54", event.EventData.UserID)
  14. assert.Equal(t, "admin", event.EventData.UserName)
  15. assert.Equal(t, "ada3b9b0dbac429f9361e803b54f5f32", event.EventData.TenantID)
  16. assert.Equal(t, "VOIP", event.EventData.TenantName)
  17. }
  18. func TestParseEventWillCreateTheProperEventProcessor(t *testing.T) {
  19. e, err := ParseEvent([]byte(securityGroupRuleCreateWithports))
  20. assert.Nil(t, err)
  21. //assert.Equal(t, "main.EventSecurityGroupRuleChange", reflect.TypeOf(e.Processor).String(),
  22. // "ParseEvent should return the proper implementation of EventProcessor")
  23. assert.Equal(t, EventSecurityGroupRuleChange{"sg_rule_add"}, e.Processor,
  24. "ParseEvent should return the proper implementation of EventProcessor")
  25. e, err = ParseEvent([]byte(securityGroupRuleDeleteWithIcmpAndCider))
  26. assert.Nil(t, err)
  27. assert.Equal(t, "main.EventSecurityGroupRuleChange", reflect.TypeOf(e.Processor).String(),
  28. "ParseEvent should return the proper implementation of EventProcessor")
  29. // _, eventProcessor, err = ParseEvent([]byte(portCreateWhenCreatingInstance))
  30. // assert.Nil(t, err)
  31. // assert.Equal(t, "main.EventPortChange", reflect.TypeOf(eventProcessor).String(),
  32. // "ParseEvent should return the proper implementation of EventProcessor")
  33. }
  34. // func TestPortCreateEvent(t *testing.T) {
  35. // fakeOpenStack := connectFakeOpenstack()
  36. // event, eventProcessor, err := ParseEvent([]byte(portCreateWhenCreatingInstance))
  37. // assert.Nil(t, err)
  38. // eventProcessor.FillExtraData(&event, fakeOpenStack)
  39. //}
  40. func TestEventSecurityGroupRuleCreateEvent(t *testing.T) {
  41. fakeOpenStack := connectFakeOpenstack()
  42. event, err := ParseEvent([]byte(securityGroupRuleCreateWithports))
  43. assert.Nil(t, err)
  44. event.Processor.FillExtraData(&event, fakeOpenStack)
  45. }
  46. func TestEventSecurityGroupRuleDeleteEvent(t *testing.T) {
  47. fakeOpenStack := connectFakeOpenstack()
  48. event, err := ParseEvent([]byte(securityGroupRuleDeleteWithIcmpAndCider))
  49. assert.Nil(t, err)
  50. event.Processor.FillExtraData(&event, fakeOpenStack)
  51. }