Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-gb committed Jan 8, 2025
1 parent b0baf87 commit 33d4a51
Showing 1 changed file with 155 additions and 0 deletions.
155 changes: 155 additions & 0 deletions tests/plugins/test_valid_oid.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,123 @@ def test_rocky(self):
results[0].message,
)

def test_openeuler_ok(self):
path = Path("some/file.nasl")
content = (
' script_oid("1.3.6.1.4.1.25623.1.1.16.2022.123");\n'
' script_family("openEuler Local Security Checks");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckValidOID(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 0)

def test_openeuler_not_ok(self):
path = Path("some/file.nasl")
content = (
' script_oid("1.3.6.1.4.1.25623.1.1.16.2022.123");\n'
' script_family("HCE Local Security Checks");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckValidOID(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 1)

self.assertIsInstance(results[0], LinterError)
self.assertEqual(
(
"script_oid() is using an OID that is reserved for "
"openEuler '1.3.6.1.4.1.25623.1.1.16.2022.123'"
),
results[0].message,
)

def test_hce_ok(self):
path = Path("some/file.nasl")
content = (
' script_oid("1.3.6.1.4.1.25623.1.1.17.2022.123");\n'
' script_family("HCE Local Security Checks");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckValidOID(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 0)

def test_hce_not_ok(self):
path = Path("some/file.nasl")
content = (
' script_oid("1.3.6.1.4.1.25623.1.1.17.2022.123");\n'
' script_family("openEuler Local Security Checks");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckValidOID(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 1)

self.assertIsInstance(results[0], LinterError)
self.assertEqual(
(
"script_oid() is using an OID that is reserved for "
"HCE '1.3.6.1.4.1.25623.1.1.17.2022.123'"
),
results[0].message,
)

def test_opensuse_ok(self):
path = Path("some/file.nasl")
content = (
' script_oid("1.3.6.1.4.1.25623.1.1.18.2022.123");\n'
' script_family("openSUSE Local Security Checks");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckValidOID(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 0)

def test_opensuse_not_ok(self):
path = Path("some/file.nasl")
content = (
' script_oid("1.3.6.1.4.1.25623.1.1.18.2022.123");\n'
' script_family("HCE Local Security Checks");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckValidOID(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 1)

self.assertIsInstance(results[0], LinterError)
self.assertEqual(
(
"script_oid() is using an OID that is reserved for "
"openSUSE '1.3.6.1.4.1.25623.1.1.18.2022.123'"
),
results[0].message,
)

def test_unknown(self):
path = Path("some/file.nasl")
content = (
Expand Down Expand Up @@ -757,3 +874,41 @@ def test_script_name__product_firefox(self):
),
results[0].message,
)

def test_script_family__product_microsoft_ok(self):
path = Path("some/file.nasl")
content = (
' script_oid("1.3.6.1.4.1.25623.1.3.11571.0.5019966.494846484649555554514651545348");'
"\n"
' script_family("Windows : Microsoft Bulletins");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckValidOID(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 0)

def test_script_family__product_microsoft_not_ok(self):
path = Path("some/file.nasl")
content = (
' script_oid("1.3.6.1.4.1.25623.1.3.11571.0.5019966.494846484649555554514651545348");'
"\n"
' script_family("Windows : Microsoft");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckValidOID(fake_context)

results = list(plugin.run())
self.assertIsInstance(results[0], LinterError)
self.assertEqual(
(
"script_oid() is using an OID that is reserved for 'Windows' "
"(1.3.6.1.4.1.25623.1.3.11571.0.5019966.494846484649555554514651545348)"
),
results[0].message,
)

0 comments on commit 33d4a51

Please sign in to comment.