Skip to content

Commit

Permalink
Merge branch 'main' into better_marshal_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwb authored Nov 14, 2023
2 parents 126257d + 784b47c commit 42cf450
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# level: WARNING
# start_line: 10
# end_line: 10
# start_column: 0
# end_column: 14
import json


Expand Down
5 changes: 5 additions & 0 deletions tests/unit/rules/python/stdlib/json/examples/json_load.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# level: WARNING
# start_line: 11
# end_line: 11
# start_column: 0
# end_column: 9
import json
from io import StringIO

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/rules/python/stdlib/json/examples/json_loads.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# level: WARNING
# start_line: 9
# end_line: 9
# start_column: 0
# end_column: 10
import json


Expand Down
62 changes: 15 additions & 47 deletions tests/unit/rules/python/stdlib/json/test_json_load.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright 2023 Secure Saurce LLC
import os

from parameterized import parameterized

from precli.core.level import Level
from precli.rules import Rule
from tests.unit.rules.python import test_case


RULE_ID = "PRE0008"


class JsonLoadTests(test_case.TestCase):
def setUp(self):
super().setUp()
self.rule_id = "PRE0008"
self.base_path = os.path.join(
"tests",
"unit",
Expand All @@ -23,55 +23,23 @@ def setUp(self):
)

def test_json_load_rule_meta(self):
rule = Rule.get_by_id(RULE_ID)
self.assertEqual(RULE_ID, rule.id)
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("deserialization_of_untrusted_data", rule.name)
self.assertEqual(
f"https://docs.securesauce.dev/rules/{RULE_ID}", rule.help_url
f"https://docs.securesauce.dev/rules/{self.rule_id}", rule.help_url
)
self.assertEqual(True, rule.default_config.enabled)
self.assertEqual(Level.WARNING, rule.default_config.level)
self.assertEqual(-1.0, rule.default_config.rank)
self.assertEqual("502", rule.cwe.cwe_id)

def test_json_jsondecoder_decode(self):
results = self.parser.parse(
os.path.join(self.base_path, "json_jsondecoder_decode.py")
)
self.assertEqual(1, len(results))
result = results[0]
self.assertEqual(RULE_ID, result.rule_id)
self.assertEqual(5, result.location.start_line)
self.assertEqual(5, result.location.end_line)
self.assertEqual(0, result.location.start_column)
self.assertEqual(14, result.location.end_column)
self.assertEqual(Level.WARNING, result.level)
self.assertEqual(-1.0, result.rank)

def test_json_load(self):
results = self.parser.parse(
os.path.join(self.base_path, "json_load.py")
)
self.assertEqual(1, len(results))
result = results[0]
self.assertEqual(RULE_ID, result.rule_id)
self.assertEqual(6, result.location.start_line)
self.assertEqual(6, result.location.end_line)
self.assertEqual(0, result.location.start_column)
self.assertEqual(9, result.location.end_column)
self.assertEqual(Level.WARNING, result.level)
self.assertEqual(-1.0, result.rank)

def test_json_loads(self):
results = self.parser.parse(
os.path.join(self.base_path, "json_loads.py")
)
self.assertEqual(1, len(results))
result = results[0]
self.assertEqual(RULE_ID, result.rule_id)
self.assertEqual(4, result.location.start_line)
self.assertEqual(4, result.location.end_line)
self.assertEqual(0, result.location.start_column)
self.assertEqual(10, result.location.end_column)
self.assertEqual(Level.WARNING, result.level)
self.assertEqual(-1.0, result.rank)
@parameterized.expand(
[
"json_jsondecoder_decode",
"json_load",
"json_loads",
]
)
def test(self, filename):
self.check(filename)

0 comments on commit 42cf450

Please sign in to comment.