2018-02-01 03:07:59 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
# Copyright (c) 2017 Mozilla Corporation
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), "../../../mq/plugins"))
|
|
|
|
from cloudtrail import message
|
|
|
|
|
|
|
|
|
|
|
|
class TestCloudtrailPlugin():
|
|
|
|
def setup(self):
|
|
|
|
self.plugin = message()
|
|
|
|
|
2018-02-01 22:02:30 +03:00
|
|
|
def test_nonexistent_source(self):
|
2018-02-01 03:07:59 +03:00
|
|
|
msg = {
|
2018-02-01 22:02:30 +03:00
|
|
|
'category': 'someother',
|
2018-02-01 03:07:59 +03:00
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
assert retmessage == msg
|
|
|
|
assert retmeta == {}
|
|
|
|
|
2018-02-01 22:02:30 +03:00
|
|
|
def test_incorrect_source(self):
|
2018-02-01 03:07:59 +03:00
|
|
|
msg = {
|
2018-02-01 22:02:30 +03:00
|
|
|
'source': 'someother',
|
2018-02-01 03:07:59 +03:00
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
assert retmessage == msg
|
|
|
|
assert retmeta == {}
|
|
|
|
|
|
|
|
def test_iamInstanceProfile(self):
|
|
|
|
msg = {
|
2018-02-01 22:02:30 +03:00
|
|
|
'source': 'cloudtrail',
|
2018-02-01 03:07:59 +03:00
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'iamInstanceProfile': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
2018-02-01 22:02:30 +03:00
|
|
|
'source': 'cloudtrail',
|
2018-02-01 03:07:59 +03:00
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'iamInstanceProfile': {
|
2018-02-01 03:10:53 +03:00
|
|
|
'raw_value': 'astringvalue',
|
2018-02-01 03:07:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|
|
|
|
|
|
|
|
def test_attribute(self):
|
|
|
|
msg = {
|
2018-02-01 22:02:30 +03:00
|
|
|
'source': 'cloudtrail',
|
2018-02-01 03:07:59 +03:00
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'attribute': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
2018-02-01 22:02:30 +03:00
|
|
|
'source': 'cloudtrail',
|
2018-02-01 03:07:59 +03:00
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'attribute': {
|
2018-02-01 03:10:53 +03:00
|
|
|
'raw_value': 'astringvalue',
|
2018-02-01 03:07:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|
2018-02-07 20:43:58 +03:00
|
|
|
|
|
|
|
def test_description(self):
|
|
|
|
msg = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'description': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'description': {
|
|
|
|
'raw_value': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|
2018-02-13 23:53:43 +03:00
|
|
|
|
|
|
|
def test_filter(self):
|
|
|
|
msg = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'filter': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'filter': {
|
|
|
|
'raw_value': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|
|
|
|
|
|
|
|
def test_role(self):
|
|
|
|
msg = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'responseelements': {
|
|
|
|
'role': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'responseelements': {
|
|
|
|
'role': {
|
|
|
|
'raw_value': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|
|
|
|
|
|
|
|
def test_additionaleventdata(self):
|
|
|
|
msg = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'additionaleventdata': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'additionaleventdata': {
|
|
|
|
'raw_value': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|
|
|
|
|
|
|
|
def test_serviceeventdetails(self):
|
|
|
|
msg = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'serviceeventdetails': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'serviceeventdetails': {
|
|
|
|
'raw_value': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|
2018-02-14 20:07:40 +03:00
|
|
|
|
|
|
|
def test_rule(self):
|
|
|
|
msg = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'rule': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'requestparameters': {
|
|
|
|
'rule': {
|
|
|
|
'raw_value': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|
|
|
|
|
|
|
|
def test_subnets(self):
|
|
|
|
msg = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'responseelements': {
|
|
|
|
'subnets': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
|
|
|
|
|
|
|
expected_message = {
|
|
|
|
'source': 'cloudtrail',
|
|
|
|
'details': {
|
|
|
|
'responseelements': {
|
|
|
|
'subnets': {
|
|
|
|
'raw_value': 'astringvalue',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert retmessage == expected_message
|
|
|
|
assert retmeta == {}
|