|
| 1 | +package generators |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/stretchr/testify/require" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +// refer example of https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs-records-examples.html#flow-log-example-accepted-rejected |
| 10 | +const acceptedVPC = "2 123456789010 eni-1235b8ca123456789 172.31.16.139 172.31.16.21 20641 22 6 20 4249 1418530010 1418530070 ACCEPT OK" |
| 11 | +const rejectedVPC = "2 123456789010 eni-1235b8ca123456789 172.31.9.69 172.31.9.12 49761 3389 6 20 4249 1418530010 1418530070 REJECT OK" |
| 12 | + |
| 13 | +func Test_buildVPC(t *testing.T) { |
| 14 | + t.Run("Validate AWS documented VPC - Accepted", func(t *testing.T) { |
| 15 | + line := buildVPCLogLine(vpcCustomizer{ |
| 16 | + Version: 2, |
| 17 | + AccountID: "123456789010", |
| 18 | + InterfaceID: "eni-1235b8ca123456789", |
| 19 | + SrcAddr: "172.31.16.139", |
| 20 | + DstAddr: "172.31.16.21", |
| 21 | + SrcPort: 20641, |
| 22 | + DstPort: 22, |
| 23 | + Protocol: 6, |
| 24 | + Packets: 20, |
| 25 | + Bytes: 4249, |
| 26 | + Start: 1418530010, |
| 27 | + End: 1418530070, |
| 28 | + Action: "ACCEPT", |
| 29 | + LogStatus: "OK", |
| 30 | + }) |
| 31 | + |
| 32 | + require.Equal(t, acceptedVPC, strings.TrimSpace(line)) |
| 33 | + }) |
| 34 | + |
| 35 | + t.Run("Validate AWS documented VPC - Accepted", func(t *testing.T) { |
| 36 | + line := buildVPCLogLine(vpcCustomizer{ |
| 37 | + Version: 2, |
| 38 | + AccountID: "123456789010", |
| 39 | + InterfaceID: "eni-1235b8ca123456789", |
| 40 | + SrcAddr: "172.31.9.69", |
| 41 | + DstAddr: "172.31.9.12", |
| 42 | + SrcPort: 49761, |
| 43 | + DstPort: 3389, |
| 44 | + Protocol: 6, |
| 45 | + Packets: 20, |
| 46 | + Bytes: 4249, |
| 47 | + Start: 1418530010, |
| 48 | + End: 1418530070, |
| 49 | + Action: "REJECT", |
| 50 | + LogStatus: "OK", |
| 51 | + }) |
| 52 | + |
| 53 | + require.Equal(t, rejectedVPC, strings.TrimSpace(line)) |
| 54 | + }) |
| 55 | +} |
0 commit comments