Skip to content

Commit

Permalink
Merge pull request #456 from airbnb/ryandeivert-classifier-convert-ty…
Browse files Browse the repository at this point in the history
…pe-bug

[lambda][rule] classifier nested type conversion bug
  • Loading branch information
ryandeivert authored Nov 8, 2017
2 parents d0de528 + b2a098e commit d0e31ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stream_alert/rule_processor/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _convert_type(cls, payload, schema):
if key == 'streamalert:envelope_keys' and not isinstance(payload[key], dict):
continue

cls._convert_type(payload[key], schema[key])
return cls._convert_type(payload[key], schema[key])

elif isinstance(value, list):
pass
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/stream_alert_rule_processor/test_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
# pylint: disable=protected-access
# pylint: disable=protected-access,too-many-public-methods
import json

from mock import call, patch
Expand Down Expand Up @@ -84,6 +84,19 @@ def test_convert_type_invalid_int(self, log_mock):
'key_01',
'NotInt')

@patch('logging.Logger.error')
def test_convert_type_invalid_nested(self, log_mock):
"""StreamClassifier - Convert Type, Invalid Nested Type"""
payload = {'key_01': '100', 'streamalert:envelope_keys': {'host': 'NotInt'}}
schema = {'key_01': 'integer', 'streamalert:envelope_keys': {'host': 'integer'}}

assert_false(self.classifier._convert_type(payload, schema))

log_mock.assert_called_with(
'Invalid schema. Value for key [%s] is not an int: %s',
'host',
'NotInt')

def test_convert_type_valid_float(self):
"""StreamClassifier - Convert Type, Valid Float"""
payload = {'key_01': '12.1'}
Expand Down

0 comments on commit d0e31ec

Please sign in to comment.