1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
# SPDX-FileCopyrightText: 2018-2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
import unittest
from lxml import etree
from gvm.errors import GvmError, GvmResponseError, GvmServerError
from gvm.transforms import CheckCommandTransform
class CheckCommandTransformTestCase(unittest.TestCase):
def test_no_status_transform(self):
transform = CheckCommandTransform()
with self.assertRaises(GvmError):
transform(b"<foo/>")
def test_no_success_300status_transform(self):
transform = CheckCommandTransform()
root = etree.Element("foo_response")
root.set("status", "300")
root.set("status_text", "Foo error")
response = etree.tostring(root)
with self.assertRaises(GvmError):
transform(response)
def test_no_success_400status_transform(self):
transform = CheckCommandTransform()
root = etree.Element("foo_response")
root.set("status", "400")
root.set("status_text", "Foo error")
response = etree.tostring(root)
with self.assertRaises(GvmResponseError):
transform(response)
def test_no_success_500status_transform(self):
transform = CheckCommandTransform()
root = etree.Element("foo_response")
root.set("status", "500")
root.set("status_text", "Foo error")
response = etree.tostring(root)
with self.assertRaises(GvmServerError):
transform(response)
def test_success_response(self):
transform = CheckCommandTransform()
root = etree.Element("foo_response")
root.set("status", "200")
response = etree.tostring(root)
self.assertEqual(transform(response), b'<foo_response status="200"/>')
|