Exemple #1
0
    def new_item_commons(page, reporter, username, vaultname):
        userid = constants.get_user(username)[2]
        vaultid = constants.get_vaultsid(vaultname)
        constants.db_handler.reset_time()
        try:
            assert page.verify_on_vaults_page()
        except AssertionError:
            reporter.add_failure(10, "create new item test", "could not start", "initialization unsuccessful")
            raise AssertionError

        status = None
        try:
            status = constants.db_handler.get_user_vault_membership(userid, vaultid)
        except:
            reporter.add_failure(10, "create new item test",
                                 "expected user " + username + " to be a member of vault " + vaultname,
                                 "user was not a member of vault")
            raise AssertionError
        try:
            assert status.has_write() or status.has_admin()
        except AssertionError:
            reporter.add_failure(10, "create new item test",
                                 "expected user " + username + " to have read or write privileges in " + vaultname,
                                 "user did not have the correct privileges")
            raise AssertionError
Exemple #2
0
    def open_vault(self,vaultname):
        try:
            id = constants.get_vaultsid(vaultname)
        except KeyError:
            id=constants.db_handler.get_new_vault_id(vaultname)

        return self.open_vault_by_id(id)
Exemple #3
0
 def create_new_item_server(self, vaultname, itemname, iteminfo):
     #split in multiple lesser classes to better handle multiple object types
     try:
         self.open_vault(vaultname)
         v_id = constants.get_vaultsid(vaultname)
         self.driver.find_element_by_id('bar' + v_id + 'add').click()
         self.driver.find_element_by_id('templateid1').click()
         self.driver.find_element_by_id('cont' + v_id).click()
         self.driver.find_element_by_id('host').send_keys(itemname)
         self.driver.find_element_by_id('username').send_keys(iteminfo[1])
         if iteminfo[2] == '':
             self.driver.find_element_by_id('gen').click()
         else:
             self.driver.find_element_by_id('password').send_keys(
                 iteminfo[2])
         if iteminfo[3] == 'True':
             self.driver.find_element_by_id('password_alarm').click()
         self.driver.find_element_by_id('info').send_keys(iteminfo[4])
         self.driver.find_element_by_id('cryptedinfo').send_keys(
             iteminfo[5])
         self.driver.find_element_by_id('submitbutton').click()
         WebDriverWait(self.driver, 10).until(
             EC.invisibility_of_element_located((By.ID, "popupwindow")))
         WebDriverWait(self.driver, 10).until(
             EC.invisibility_of_element_located((By.ID, "waitwindow")))
     except:
         return False
     return True
Exemple #4
0
    def new_item_commons(page, reporter, username, vaultname):
        userid = constants.get_user(username)[2]
        vaultid = constants.get_vaultsid(vaultname)
        constants.db_handler.reset_time()
        try:
            assert page.verify_on_vaults_page()
        except AssertionError:
            reporter.add_failure(10, "create new item test", "could not start",
                                 "initialization unsuccessful")
            raise AssertionError

        status = None
        try:
            status = constants.db_handler.get_user_vault_membership(
                userid, vaultid)
        except:
            reporter.add_failure(
                10, "create new item test", "expected user " + username +
                " to be a member of vault " + vaultname,
                "user was not a member of vault")
            raise AssertionError
        try:
            assert status.has_write() or status.has_admin()
        except AssertionError:
            reporter.add_failure(
                10, "create new item test", "expected user " + username +
                " to have read or write privileges in " + vaultname,
                "user did not have the correct privileges")
            raise AssertionError
Exemple #5
0
    def open_vault(self, vaultname):
        try:
            id = constants.get_vaultsid(vaultname)
        except KeyError:
            id = constants.db_handler.get_new_vault_id(vaultname)

        return self.open_vault_by_id(id)
Exemple #6
0
    def create_new_server_item(page, reporter, username, vaultname, itemname):

        userid = constants.get_user(username)[2]
        vaultid = constants.get_vaultsid(vaultname)
        try:
            vault_tests.new_item_commons(page, reporter,username,vaultname)
        except AssertionError:
            return page

        #read itemdata from constants
        newitem = constants.get_newitem_server(itemname)

        try:
            assert page.create_new_item_server(vaultname,itemname,newitem)
        except:
            reporter.add_failure(10, "create new object test", "expected to create a new item", "item creation failed")
            return page

        i_id=constants.db_handler.get_new_created_item_in_vault_by_name(itemname, vaultid)

        try:
            assert constants.db_handler.expect_event_item_created(userid,i_id,vaultid)
        except:
            reporter.add_failure(10, "create new object test", "expected that creation of object "+itemname +" would be logged","objectcreation was not logged")
            return page


        reporter.add_success(10,"create new item test","object "+ itemname+ "created successfully")
        return page
Exemple #7
0
 def move_object(self,vaultname,objectname):
     a = self.mark_object(vaultname, objectname)
     if not a:
         return False
     try:
         self.driver.find_element_by_id('move_' + constants.get_vaultsid(vaultname)).click()
     except:
         return False
     return True
Exemple #8
0
 def move_object(self, vaultname, objectname):
     a = self.mark_object(vaultname, objectname)
     if not a:
         return False
     try:
         self.driver.find_element_by_id(
             'move_' + constants.get_vaultsid(vaultname)).click()
     except:
         return False
     return True
Exemple #9
0
 def close_vault(self,vaultname):
     try:
         id = constants.get_vaultsid(vaultname)
     except KeyError:
         id = constants.db_handler.get_new_vault_id(vaultname)
     try:
         v = self.driver.find_element_by_id("bartitle{}".format(id))
         if v.get_attribute('class') == 'bars _on':
             v.click()
     except:
         return False
     return True
Exemple #10
0
 def close_vault(self, vaultname):
     try:
         id = constants.get_vaultsid(vaultname)
     except KeyError:
         id = constants.db_handler.get_new_vault_id(vaultname)
     try:
         v = self.driver.find_element_by_id("bartitle{}".format(id))
         if v.get_attribute('class') == 'bars _on':
             v.click()
     except:
         return False
     return True
Exemple #11
0
    def paste_object(self,vaultname):
        try:
            self.open_vault(vaultname)
            try:
                vaultid = constants.get_vaultsid(vaultname)
            except KeyError:
                vaultid = constants.db_handler.get_new_vault_id(vaultname)
            self.driver.find_element_by_id('paste_{}'.format(vaultid)).click()
            Alert(self.driver).accept()
        except:
            return False
        #wait for waitwondow to disappear => wait for database to update
        WebDriverWait(self.driver, 10).until(EC.invisibility_of_element_located((By.ID, "waitwindow")))

        return True
Exemple #12
0
    def paste_object(self, vaultname):
        try:
            self.open_vault(vaultname)
            try:
                vaultid = constants.get_vaultsid(vaultname)
            except KeyError:
                vaultid = constants.db_handler.get_new_vault_id(vaultname)
            self.driver.find_element_by_id('paste_{}'.format(vaultid)).click()
            Alert(self.driver).accept()
        except:
            return False
        #wait for waitwondow to disappear => wait for database to update
        WebDriverWait(self.driver, 10).until(
            EC.invisibility_of_element_located((By.ID, "waitwindow")))

        return True
Exemple #13
0
    def mark_object(self,vaultname, objectname):
        try:
            self.close_vault(vaultname)
            self.open_vault(vaultname)
            vaultid = constants.get_vaultsid(vaultname)
            try:
                object= constants.get_object(objectname)
                o_id = object[0]
                o_type = object[2]
            except KeyError:
                o_id = constants.db_handler.get_new_created_item_in_vault_by_name(objectname,vaultid)
                o_type = constants.db_handler.get_new_object_type(o_id,vaultid)


            self.driver.find_element_by_id('mod_{}_{}_{}'.format(vaultid,o_type,o_id)).click()
        except:
            return False
        return True
Exemple #14
0
    def mark_object(self, vaultname, objectname):
        try:
            self.close_vault(vaultname)
            self.open_vault(vaultname)
            vaultid = constants.get_vaultsid(vaultname)
            try:
                object = constants.get_object(objectname)
                o_id = object[0]
                o_type = object[2]
            except KeyError:
                o_id = constants.db_handler.get_new_created_item_in_vault_by_name(
                    objectname, vaultid)
                o_type = constants.db_handler.get_new_object_type(
                    o_id, vaultid)

            self.driver.find_element_by_id('mod_{}_{}_{}'.format(
                vaultid, o_type, o_id)).click()
        except:
            return False
        return True
Exemple #15
0
 def create_new_item_server(self,vaultname,itemname,iteminfo):
     #split in multiple lesser classes to better handle multiple object types
     try:
         self.open_vault(vaultname)
         v_id = constants.get_vaultsid(vaultname)
         self.driver.find_element_by_id('bar'+v_id+'add').click()
         self.driver.find_element_by_id('templateid1').click()
         self.driver.find_element_by_id('cont'+v_id).click()
         self.driver.find_element_by_id('host').send_keys(itemname)
         self.driver.find_element_by_id('username').send_keys(iteminfo[1])
         if iteminfo[2] == '':
             self.driver.find_element_by_id('gen').click()
         else:
             self.driver.find_element_by_id('password').send_keys(iteminfo[2])
         if iteminfo[3] == 'True':
             self.driver.find_element_by_id('password_alarm').click()
         self.driver.find_element_by_id('info').send_keys(iteminfo[4])
         self.driver.find_element_by_id('cryptedinfo').send_keys(iteminfo[5])
         self.driver.find_element_by_id('submitbutton').click()
         WebDriverWait(self.driver, 10).until(EC.invisibility_of_element_located((By.ID, "popupwindow")))
         WebDriverWait(self.driver, 10).until(EC.invisibility_of_element_located((By.ID, "waitwindow")))
     except:
         return False
     return True
Exemple #16
0
    def create_new_server_item(page, reporter, username, vaultname, itemname):

        userid = constants.get_user(username)[2]
        vaultid = constants.get_vaultsid(vaultname)
        try:
            vault_tests.new_item_commons(page, reporter, username, vaultname)
        except AssertionError:
            return page

        #read itemdata from constants
        newitem = constants.get_newitem_server(itemname)

        try:
            assert page.create_new_item_server(vaultname, itemname, newitem)
        except:
            reporter.add_failure(10, "create new object test",
                                 "expected to create a new item",
                                 "item creation failed")
            return page

        i_id = constants.db_handler.get_new_created_item_in_vault_by_name(
            itemname, vaultid)

        try:
            assert constants.db_handler.expect_event_item_created(
                userid, i_id, vaultid)
        except:
            reporter.add_failure(
                10, "create new object test",
                "expected that creation of object " + itemname +
                " would be logged", "objectcreation was not logged")
            return page

        reporter.add_success(10, "create new item test",
                             "object " + itemname + "created successfully")
        return page
Exemple #17
0
    def try_leave_vault_as_last_admin(page, reporter, username, vaultname):

        try:
            assert page.verify_on_vaults_page()
        except AssertionError:
            reporter.add_failure(22, "try to leave vault as last admin", "could not start, not on the vaults page",
                             "initialization unsuccessful")
            return page
        try:
            userid = constants.get_user(username)[2]
            vaultid = constants.get_vaultsid(vaultname)

            assert constants.db_handler.get_user_vault_membership(userid,vaultid).has_admin()
        except AssertionError:
            reporter.add_failure(22, "try to leave vault as last admin",
                                 "Expected {} to be admin member of {}".format(username, vaultname),
                                 "Could not verify this")
            return page
        except:
            reporter.add_failure(22, "try to leave vault as last admin",
                                 "Could not find user {} or vault {} in the database".format(username, vaultname),
                                 "expected to be able to find them")
            return page

        try:
            nr = constants.db_handler.number_of_admins(vaultid)
            assert nr == 1
        except AssertionError:
            reporter.add_failure(22, "try to leave vault as last admin",
                                 "Expected only {} to be the only admin in {}".format(username, vaultname),
                                 "Found that there were {} admins in {} in total".format(nr, vaultname))
            return page
        try:
            assert page.leave_vault(userid,vaultid)
        except AssertionError:
            reporter.add_failure(22, "try to leave vault as last admin",
                                 "Expected to be able to go through the entire leave-vault procedure for vault {}".format(
                                     vaultname), "Failed to do so")
            return page

        try:
            assert page.verify_on_vaults_page()
        except AssertionError:

            reporter.add_failure(22, "try to leave vault as last admin", "Expected to be on vaults page","Could not verify this")
            return page

        try:
            assert page.driver.find_element_by_id("errorwindow").text == "Last admin cannot be deleted - all object will be lost forever"
        except AssertionError:
            reporter.add_failure(22, "try to leave vault as last admin", "Expected to find error message on page", "Could not")
            return page

        try:
            assert constants.db_handler.number_of_admins(vaultid) == 1
            assert constants.db_handler.get_user_vault_membership(userid,vaultid).has_admin()
        except AssertionError:
            reporter.add_failure(22, "try to leave vault as last admin",
                         "Expected {} to remain the only admin member of {}".format(username, vaultname),
                         "could not verify this")
            return page
        reporter.add_success(22, "try to leave vault as last admin","Tried to leave vault {} as last admin member {} - leaving vault function did not go through, as expected".format(vaultname,username))
        return page
Exemple #18
0
    def delete_vault_with_objects(page, reporter, username, vaultname):
        #page = page_vaults.PageVaults()
        try:
            assert page.verify_on_vaults_page()
        except AssertionError:
            reporter.add_failure(19, "delete vault and its content",
                                 "could not start, not on the vaults page",
                                 "initialization unsuccessful")
            return page
        try:
            userid = constants.get_user(username)[2]
            vaultid = constants.get_vaultsid(vaultname)

            assert constants.db_handler.get_user_vault_membership(
                userid, vaultid).has_admin()
        except AssertionError:
            reporter.add_failure(
                19, "delete vault and its content",
                "Expected {} to be admin member of {}".format(
                    username, vaultname), "Could not verify this")
            return page
        except:
            reporter.add_failure(
                19, "delete vault and its content",
                "Could not find user {} or vault {} in the database".format(
                    username, vaultname), "expected to be able to find them")
            return page

        #get all object id:s and names [i,n]
        objects = constants.db_handler.get_all_objects_in_vault(vaultid)
        #delete all objects in vault
        if objects:
            try:
                assert page.delete_all_objects_in_vault(vaultid)
            except AssertionError:
                reporter.add_failure(
                    19, "delete vault and its content",
                    "Expected to be able to delete all objects in {}".format(
                        vaultname), "Could not verify this")
                return page
            #verify deletion
            for o in objects:
                try:
                    assert constants.db_handler.expect_event_object_deleted(
                        userid, vaultid, o[0], o[1])
                except AssertionError:
                    reporter.add_failure(
                        19, "delete vault and its content",
                        "Expected to be able to find deletion events for all objects in vault {}"
                        .format(vaultname), "Could not")
                    return page
        #---end if objects

        #Delete vault
        try:
            assert page.delete_vault(vaultid)
        except AssertionError:
            reporter.add_failure(
                19, "delete vault and its content",
                "Expected to be able to go through the delete-vault procedure for vault {}"
                .format(vaultname), "Could not verify this")
            return page

        #Verify vault deleted:
        try:
            assert page.verify_on_vaults_page()
            assert page.verify_vault_deleted(vaultid)
        except AssertionError:
            reporter.add_failure(
                19, "delete vault and its content",
                "Expected to be able to verify {} to be deleted".format(
                    vaultname), "could not verify")
            return page

        #Verify in database
        try:
            assert constants.db_handler.expect_event_vault_deleted(
                userid, vaultid, vaultname)
        except AssertionError:
            reporter.add_failure(
                19, "delete vault and its content",
                "Expected to be able to verify in database that vault {} was deleted"
                .format(vaultname), "could not verify")
            return page

        #Success
        reporter.add_success(
            19, "delete vault and its content",
            "vault {} and its content has been deleted as expected".format(
                vaultname))
        return page
Exemple #19
0
    def delete_vault_with_objects(page, reporter, username, vaultname):
        #page = page_vaults.PageVaults()
        try:
            assert page.verify_on_vaults_page()
        except AssertionError:
            reporter.add_failure(19, "delete vault and its content", "could not start, not on the vaults page",
                                 "initialization unsuccessful")
            return page
        try:
            userid = constants.get_user(username)[2]
            vaultid = constants.get_vaultsid(vaultname)

            assert constants.db_handler.get_user_vault_membership(userid, vaultid).has_admin()
        except AssertionError:
            reporter.add_failure(19, "delete vault and its content",
                                 "Expected {} to be admin member of {}".format(username, vaultname),
                                 "Could not verify this")
            return page
        except:
            reporter.add_failure(19, "delete vault and its content",
                                 "Could not find user {} or vault {} in the database".format(username, vaultname),
                                 "expected to be able to find them")
            return page

        #get all object id:s and names [i,n]
        objects = constants.db_handler.get_all_objects_in_vault(vaultid)
        #delete all objects in vault
        if objects:
            try:
                assert page.delete_all_objects_in_vault(vaultid)
            except AssertionError:
                reporter.add_failure(19, "delete vault and its content","Expected to be able to delete all objects in {}".format(vaultname),"Could not verify this")
                return page
            #verify deletion
            for o in objects:
                try:
                    assert constants.db_handler.expect_event_object_deleted(userid,vaultid,o[0],o[1])
                except AssertionError:
                    reporter.add_failure(19, "delete vault and its content",
                                 "Expected to be able to find deletion events for all objects in vault {}".format(vaultname),
                                         "Could not")
                    return page
        #---end if objects

        #Delete vault
        try:
            assert page.delete_vault(vaultid)
        except AssertionError:
            reporter.add_failure(19, "delete vault and its content",
                                 "Expected to be able to go through the delete-vault procedure for vault {}".format(
                                     vaultname), "Could not verify this")
            return page

        #Verify vault deleted:
        try:
            assert page.verify_on_vaults_page()
            assert page.verify_vault_deleted(vaultid)
        except AssertionError:
            reporter.add_failure(19, "delete vault and its content","Expected to be able to verify {} to be deleted".format(vaultname),"could not verify")
            return page

        #Verify in database
        try:
            assert constants.db_handler.expect_event_vault_deleted(userid,vaultid,vaultname)
        except AssertionError:
            reporter.add_failure(19, "delete vault and its content",
                                 "Expected to be able to verify in database that vault {} was deleted".format(
                                     vaultname), "could not verify")
            return page

        #Success
        reporter.add_success(19, "delete vault and its content",
                             "vault {} and its content has been deleted as expected".format(vaultname))
        return page
Exemple #20
0
    def try_leave_vault_as_last_admin(page, reporter, username, vaultname):

        try:
            assert page.verify_on_vaults_page()
        except AssertionError:
            reporter.add_failure(22, "try to leave vault as last admin",
                                 "could not start, not on the vaults page",
                                 "initialization unsuccessful")
            return page
        try:
            userid = constants.get_user(username)[2]
            vaultid = constants.get_vaultsid(vaultname)

            assert constants.db_handler.get_user_vault_membership(
                userid, vaultid).has_admin()
        except AssertionError:
            reporter.add_failure(
                22, "try to leave vault as last admin",
                "Expected {} to be admin member of {}".format(
                    username, vaultname), "Could not verify this")
            return page
        except:
            reporter.add_failure(
                22, "try to leave vault as last admin",
                "Could not find user {} or vault {} in the database".format(
                    username, vaultname), "expected to be able to find them")
            return page

        try:
            nr = constants.db_handler.number_of_admins(vaultid)
            assert nr == 1
        except AssertionError:
            reporter.add_failure(
                22, "try to leave vault as last admin",
                "Expected only {} to be the only admin in {}".format(
                    username, vaultname),
                "Found that there were {} admins in {} in total".format(
                    nr, vaultname))
            return page
        try:
            assert page.leave_vault(userid, vaultid)
        except AssertionError:
            reporter.add_failure(
                22, "try to leave vault as last admin",
                "Expected to be able to go through the entire leave-vault procedure for vault {}"
                .format(vaultname), "Failed to do so")
            return page

        try:
            assert page.verify_on_vaults_page()
        except AssertionError:

            reporter.add_failure(22, "try to leave vault as last admin",
                                 "Expected to be on vaults page",
                                 "Could not verify this")
            return page

        try:
            assert page.driver.find_element_by_id(
                "errorwindow"
            ).text == "Last admin cannot be deleted - all object will be lost forever"
        except AssertionError:
            reporter.add_failure(22, "try to leave vault as last admin",
                                 "Expected to find error message on page",
                                 "Could not")
            return page

        try:
            assert constants.db_handler.number_of_admins(vaultid) == 1
            assert constants.db_handler.get_user_vault_membership(
                userid, vaultid).has_admin()
        except AssertionError:
            reporter.add_failure(
                22, "try to leave vault as last admin",
                "Expected {} to remain the only admin member of {}".format(
                    username, vaultname), "could not verify this")
            return page
        reporter.add_success(
            22, "try to leave vault as last admin",
            "Tried to leave vault {} as last admin member {} - leaving vault function did not go through, as expected"
            .format(vaultname, username))
        return page