osel/events_test.go
Nate Johnston ca0e1ca769 Initial import of osel code
This is an initial import of the osel codebase.  The osel tool is a tool that
initiates external security scans (initially through Qualys) upon reciept of
AMQP events that indicate certain sensitive events have occurred, like a
security group rule change.

The commit history had to be thrown away because it contained some non-public
data, so I would like to call out the following contributors:

This uses go 1.10 and vgo for dependency management.

Co-Authored-By: Charles Bitter <Charles_Bitter@cable.comcast.com>
Co-Authored-By: Olivier Gagnon <Olivier_Gagnon@cable.comcast.com>
Co-Authored-By: Joseph Sleiman <Joseph_Sleiman@comcast.com>

Change-Id: Ib6abe2024fd91978b783ceee4cff8bb4678d7b15
2018-03-24 15:30:57 +00:00

62 lines
2.4 KiB
Go

package main
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseEventWillReturnAnEventStruct(t *testing.T) {
event, err := ParseEvent([]byte(securityGroupRuleCreateWithports))
assert.Nil(t, err)
assert.Equal(t, "main.Event", reflect.TypeOf(event).String(),
"ParseEvent should return an Event struct")
assert.Equal(t, "security_group_rule.create.end", event.EventData.EventType)
assert.Equal(t, "bca89c1b248e4aef9c69ece9e744cc54", event.EventData.UserID)
assert.Equal(t, "admin", event.EventData.UserName)
assert.Equal(t, "ada3b9b0dbac429f9361e803b54f5f32", event.EventData.TenantID)
assert.Equal(t, "VOIP", event.EventData.TenantName)
}
func TestParseEventWillCreateTheProperEventProcessor(t *testing.T) {
e, err := ParseEvent([]byte(securityGroupRuleCreateWithports))
assert.Nil(t, err)
//assert.Equal(t, "main.EventSecurityGroupRuleChange", reflect.TypeOf(e.Processor).String(),
// "ParseEvent should return the proper implementation of EventProcessor")
assert.Equal(t, EventSecurityGroupRuleChange{"sg_rule_add"}, e.Processor,
"ParseEvent should return the proper implementation of EventProcessor")
e, err = ParseEvent([]byte(securityGroupRuleDeleteWithIcmpAndCider))
assert.Nil(t, err)
assert.Equal(t, "main.EventSecurityGroupRuleChange", reflect.TypeOf(e.Processor).String(),
"ParseEvent should return the proper implementation of EventProcessor")
// _, eventProcessor, err = ParseEvent([]byte(portCreateWhenCreatingInstance))
// assert.Nil(t, err)
// assert.Equal(t, "main.EventPortChange", reflect.TypeOf(eventProcessor).String(),
// "ParseEvent should return the proper implementation of EventProcessor")
}
// func TestPortCreateEvent(t *testing.T) {
// fakeOpenStack := connectFakeOpenstack()
// event, eventProcessor, err := ParseEvent([]byte(portCreateWhenCreatingInstance))
// assert.Nil(t, err)
// eventProcessor.FillExtraData(&event, fakeOpenStack)
//}
func TestEventSecurityGroupRuleCreateEvent(t *testing.T) {
fakeOpenStack := connectFakeOpenstack()
event, err := ParseEvent([]byte(securityGroupRuleCreateWithports))
assert.Nil(t, err)
event.Processor.FillExtraData(&event, fakeOpenStack)
}
func TestEventSecurityGroupRuleDeleteEvent(t *testing.T) {
fakeOpenStack := connectFakeOpenstack()
event, err := ParseEvent([]byte(securityGroupRuleDeleteWithIcmpAndCider))
assert.Nil(t, err)
event.Processor.FillExtraData(&event, fakeOpenStack)
}