Beispiel #1
0
def create_connection():
    """
           **Creates the connection*
           This function allows user to create a connection with openvas manager using gvm. The UnixSocketConnection function
           takes as a parameter a path that leads to openvasmd socket file (/var/run/openvasmd.sock) that exists in the VM that runs OpenVAS manager.
           Read rights must be granted (sudo chmod a+rwx openvasmd.sock)

           :return: The connection that gives access to the OpenVAS interface.
       """

    subprocess.call(["sudo", "./config.sh"])
    connection = UnixSocketConnection(path='/var/run/gvmd.sock')
    # transform = EtreeTransform()
    gmp = Gmp(connection)

    # version = gmp.get_version()
    gmp.authenticate('admin', 'admin')

    return gmp
Beispiel #2
0
class GmpAuthenticateTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.gmp = Gmp(self.connection)

    def test_missing_username(self):
        with self.assertRaises(RequiredArgument):
            self.gmp.authenticate(None, 'foo')

        with self.assertRaises(RequiredArgument):
            self.gmp.authenticate('', 'foo')

    def test_missing_password(self):
        with self.assertRaises(RequiredArgument):
            self.gmp.authenticate('bar', None)

        with self.assertRaises(RequiredArgument):
            self.gmp.authenticate('bar', '')

    def test_authentication_success(self):
        self.assertFalse(self.gmp.is_authenticated())

        self.gmp.authenticate('foo', 'bar')

        self.connection.send.has_been_called_with(
            '<authenticate>'
            '<credentials>'
            '<username>foo</username>'
            '<password>bar</password>'
            '</credentials>'
            '</authenticate>'
        )

        self.assertTrue(self.gmp.is_authenticated())

    def test_authentication_failure(self):
        self.connection.read.return_value(
            '<authentication_response status="400" status_text="Auth failed"/>'
        )

        self.assertFalse(self.gmp.is_authenticated())

        self.gmp.authenticate('foo', 'bar')

        self.connection.send.has_been_called_with(
            '<authenticate>'
            '<credentials>'
            '<username>foo</username>'
            '<password>bar</password>'
            '</credentials>'
            '</authenticate>'
        )

        self.assertFalse(self.gmp.is_authenticated())