Пример #1
0
    def test_api_add_computer_invalidPassword(self):
        '''
    tests add computer from request with an invalid password
    '''
        pref.setAttr(pref.CONFIG_PUBLIC_SSH_KEY, "dafsdfas")

        params = {
            pref.getNoCheck(pref.REQ_VAR_BODY): {
                pref.getNoCheck(pref.REQ_VAR_OP):
                pref.getAttrName(
                    pref.getNoCheck(pref.OPERATION_MANAGE_COMPUTERS)),
                pref.getNoCheck(pref.REQ_VAR_DATA): {
                    pref.getNoCheck(pref.REQ_VAR_FUNC_OP):
                    pref.getNoCheck(pref.TABLE_OP_ADD),
                    pref.getNoCheck(pref.REQ_VAR_DATA): {
                        pref.getNoCheck(pref.REQ_VAR_NICK_NAME):
                        "Larry's Computer",
                        pref.getNoCheck(pref.REQ_VAR_DESC): "ITS MAH COMPUTER",
                        pref.getNoCheck(pref.REQ_VAR_USERNAME): "root",
                        pref.getNoCheck(pref.REQ_VAR_PASSWORD):
                        "NOT MY PASSWORD",
                        pref.getNoCheck(pref.REQ_VAR_IP): "localhost",
                        pref.getNoCheck(pref.REQ_VAR_IS_ADMIN): False
                    }
                }
            }
        }
        rv = self.c.post('/api', json=params)
        self.assertEqual(rv.get_json()["Error"]["code"], 50)
Пример #2
0
    def test_addComputerWrongIP(self):
        '''tries to add a computer with the wrong password'''

        pref.setAttr(pref.CONFIG_PUBLIC_SSH_KEY, "asdfasdfasd")
        error = ssh.sshConnection.addNewComputer("69.69.69.69", self.username,
                                                 "WRONGPASSWORD!@##@!")
        self.assertEqual(error, pref.getError(pref.ERROR_CONNECTION_FAILED))
Пример #3
0
def mockApp() -> app.test_client_class:
    pref.setAttr(pref.CONFIG_SCRIPT_PATH, "tests/res/data/scripts/")
    pref.setAttr(pref.CONFIG_SCRIPT_LOG_PATH, "tests/res/data/scriptLogs/")

    c = app.test_client()
    with c.session_transaction() as sess:
        sess[pref.getNoCheck(pref.REQ_VAR_USER_ID)] = 1
    return c
Пример #4
0
 def test_addComputerNonexistentUser(self):
     '''
 Tries to add a computer on a server with a user that doesn't exist
 '''
     pref.setAttr(pref.CONFIG_PUBLIC_SSH_KEY, "asdfasdfasd")
     error = ssh.sshConnection.addNewComputer(self.ip, "Wrong_User",
                                              "WRONGPASSWORD!@##@!")
     self.assertEqual(error,
                      pref.getError(pref.ERROR_SSH_AUTHENTICATION_FAILED))
Пример #5
0
 def test_addComputerScripDNE(self):
     '''
 Tries to add a computer on a server with a user that doesn't exist
 '''
     pref.setAttr(pref.CONFIG_PUBLIC_SSH_KEY, "asdfasdfasd")
     pref.setAttr(pref.CONFIG_ADD_COMPUTER_SCRIPT, "DNE")
     error = ssh.sshConnection.addNewComputer(self.ip, self.username,
                                              "WRONGPASSWORD!@##@!")
     self.assertEqual(error,
                      pref.getError(pref.ERROR_SSH_AUTHENTICATION_FAILED))
Пример #6
0
def createMockDB():
    '''
  creates a db for unit test
  saved in the file tests/res/unittest.db
  '''

    pref.setAttr(pref.CONFIG_DB_PATH, "tests/res/unittest.db")
    scriptLogTable.ScriptLogTable.createTable()
    scriptTable.ScriptTable.createTable()
    computerTable.ComputerTable.createTable()
    userTable.UserTable.createTable()
    def test_setAttrAndReset(self):

        #check that the value is correct to start
        err, unknownErr = pref.get(pref.ERROR_UNKNOWN)
        self.assertEqual(
            pref.getError(pref.ERROR_UNKNOWN).code, unknownErr.code)
        self.assertEqual(pref.Success.code, err.code)

        #set new value
        err = pref.setAttr(pref.ERROR_UNKNOWN, "error")
        self.assertEqual(pref.Success.code, err.code)

        #check new value
        err, unknownErr = pref.get(pref.ERROR_UNKNOWN)
        self.assertEqual("error", unknownErr)
        self.assertEqual(pref.Success.code, err.code)

        #reset config
        pref.resetConfig()

        #check that the value was reset
        err, unknownErr = pref.get(pref.ERROR_UNKNOWN)
        self.assertEqual(
            pref.getError(pref.ERROR_UNKNOWN).code, unknownErr.code)
        self.assertEqual(pref.Success.code, err.code)
    def test_setAttrInDict(self):
        err = pref.setAttr(pref.ERROR_UNKNOWN, "error")
        self.assertEqual(pref.Success.code, err.code)

        err, unknownErr = pref.get(pref.ERROR_UNKNOWN)
        self.assertEqual("error", unknownErr)
        self.assertEqual(pref.Success.code, err.code)
    def test_setAttr(self):
        err = pref.setAttr(pref.CONFIG_LOGIN_ENDPOINT, "/login2")
        self.assertEqual(pref.Success.code, err.code)

        err, login = pref.get(pref.CONFIG_LOGIN_ENDPOINT)
        self.assertEqual("/login2", login)
        self.assertEqual(pref.Success.code, err.code)
Пример #10
0
    def test_connectionNoSSHKey(self):
        '''
    Basic test just testing a non-working connection of the ip and username given
    it will use a nonexistant sshkey in /DNE/NOPE
    '''

        #Create ssh connection
        conn = ssh.sshConnection(self.computer, self.user, self.script)

        #sets a nonexistant key
        pref.setAttr(pref.CONFIG_PRIVATE_SSH_KEY, "/DNE/NOPE")

        #Connect to computer
        err = conn.connect()

        #Test for no error
        self.assertEqual(err, pref.getError(pref.ERROR_CANT_FIND_SSH_KEY))
Пример #11
0
    def test_connectionInvalidSSHKey(self):
        '''
    Basic test just testing a non-working connection of the ip and username given
    it will use a invalid sshkey in tests/res/invalidKey
    '''

        #Create ssh connection
        conn = ssh.sshConnection(self.computer, self.user, self.script)

        #sets a nonexistant key
        pref.setAttr(pref.CONFIG_PRIVATE_SSH_KEY, "tests/res/InvalidKey")

        #Connect to computer
        err = conn.connect()

        #Test for no error
        self.assertEqual(err,
                         pref.getError(pref.ERROR_SSH_AUTHENTICATION_FAILED))
Пример #12
0
 def test_addComputerEmptyPublicSSHKey(self):
     '''tries to add a computer with an empty static key'''
     pref.setAttr(pref.CONFIG_PUBLIC_SSH_KEY, "")
     error = ssh.sshConnection.addNewComputer(self.ip, self.username,
                                              "WRONGPASSWORD!@##@!")
     self.assertEqual(error, pref.getError(pref.ERROR_EMPTY_SSH_PUBLIC_KEY))
Пример #13
0
def clearDB():
    pref.setAttr(pref.CONFIG_DB_PATH, "tests/res/unittest.db")
    scriptLogTable.ScriptLogTable.deleteTable()
    scriptTable.ScriptTable.deleteTable()
    computerTable.ComputerTable.deleteTable()
    userTable.UserTable.deleteTable()
Пример #14
0
 def setUp(self):
     pref.setAttr(
         pref.CONFIG_DB_PATH, "tests/res/unittest.db"
     )  # work on seperate clean database so as to not mess up test data in base db
     pref.setAttr(pref.CONFIG_SCRIPT_PATH, "tests/res/data/scripts/")
     pref.setAttr(pref.CONFIG_SCRIPT_LOG_PATH, "tests/res/data/scriptLogs/")