def test_vectrix_output_bad_asset_type2(): bad_asset = [{ "type": "aws_s3_Bucket", # Resources aren't allowed to be PascalCase "id": "arn:aws:s3:::sample-id", "display_name": "Bucket: Sample ID", "link": "https://localhost.com", "metadata": { "aws_s3_bucket_name": { "priority": 50, "value": "sample-id" } } }] with pytest.raises(ValueError) as excinfo: vectrix.output(assets=bad_asset, issues=correct_issue, events=correct_event) assert 'asset type service and resource instantiations are required to follow camelCase for multiple words' == str( excinfo.value).split(".")[0]
def test_vectrix_output_bad_asset_type(): bad_asset = [{ "type": "Aws_s3_bucket", # Vendors aren't allowed to be caps "id": "arn:aws:s3:::sample-id", "display_name": "Bucket: Sample ID", "link": "https://localhost.com", "metadata": { "aws_s3_bucket_name": { "priority": 50, "value": "sample-id" } } }] with pytest.raises(ValueError) as excinfo: vectrix.output(assets=bad_asset, issues=correct_issue, events=correct_event) assert 'asset type vendor instantiation is required to be all lowercase' == str( excinfo.value).split(".")[0]
def test_vectrix_output_bad_asset_display_name(): bad_asset = [{ "type": "aws_s3_bucket", "id": "arn:aws:s3:::sample-id", "display_name": "Sample ID", # Display names need to be key/values denoted by colons "link": "https://localhost.com", "metadata": { "aws_s3_bucket_name": { "priority": 50, "value": "sample-id" } } }] with pytest.raises(ValueError) as excinfo: vectrix.output(assets=bad_asset, issues=correct_issue, events=correct_event) assert "asset dict key 'display_name' requires a colon that separates a key and value" == str( excinfo.value).split(".")[0]
def test_vectrix_output_bad_metadata_link(): bad_asset_metadata = [{ "type": "aws_s3_bucket", "id": "arn:aws:s3:::sample-id", "display_name": "Bucket: Sample ID", "link": "https://localhost.com", "metadata": { "aws_s3_bucket_name": { "priority": -1, "value": "sample-id", "link": "http://insecure-link.com" } } }] with pytest.raises(ValueError) as excinfo: vectrix.output(assets=bad_asset_metadata, issues=correct_issue, events=correct_event) assert "Only secure links are allowed in metadata elements (HTTPS)" == str( excinfo.value).split(".")[0]
def test_vectrix_output_bad_metadata_value_2(): bad_asset_metadata = [{ "type": "aws_s3_bucket", "id": "arn:aws:s3:::sample-id", "display_name": "Bucket: Sample ID", "link": "https://localhost.com", "metadata": { "aws_s3_bucket_name": { # Priority is only allowed to be between -1 and 100 (inclusive) "priority": -2, "value": [{"sample-id"}] } } }] with pytest.raises(ValueError) as excinfo: vectrix.output(assets=bad_asset_metadata, issues=correct_issue, events=correct_event) assert "metadata element aws_s3_bucket_name key 'value' can be list, but each element in the list has to be 'str'" == str( excinfo.value).split(".")[0]
def test_vectrix_output_disallowed_event_key(): bad_event_key = [{ "type": "aws_s3_bucket", "event": "S3 Bucket Created", "event_time": 1596843510, "display_name": "Bucket: Storage Bucket created", "metadata": { "aws_s3_bucket_name": { "priority": -1, "value": "sample-id" }, "aws_s3_bucket_arn": { "priority": -1, "value": "sample-id" } } }] with pytest.raises(ValueError) as excinfo: vectrix.output(assets=correct_asset, issues=correct_issue, events=bad_event_key) assert "event dict does not allow key 'type'" == str( excinfo.value).split(".")[0]
def test_vectrix_output(): vectrix.output(assets=correct_asset, issues=correct_issue, events=correct_event)
def test_vectrix_output_allow_typed_input(): vectrix.output(assets=[TestAsset()] + correct_asset, issues=[TestIssue()] + correct_issue, events=[TestEvent()] + correct_event)