Ejemplo n.º 1
0
 def set_ssh(user_content, sshKey=None):  # Set SSH key to user.
     r1 = None
     if sshKey is None:
         logger.debug("About to generate an ssh key for the user: %s" %
                      user_content['email'])
         sshKey = Helper.generate_sshpub_key()
     postURL = settings.ICE_EM_URL + '/v1/engmgr/users/ssh'
     logger.debug("Post user URL: " + postURL)
     headers = dict()  # Create header for post request.
     headers['Content-type'] = 'application/json'
     headers['Authorization'] = user_content['session_token']
     post_data = dict()  # Create JSON data for post request.
     post_data['ssh_key'] = sshKey
     try:
         r1 = requests.post(
             postURL, json=post_data, headers=headers, verify=False)
         Helper.internal_assert(r1.status_code, 200)
         logger.debug(
             "SSH Key was added successfully")
         if not APIBridge.is_gitlab_ready(user_content):
             raise
         return sshKey
     except BaseException:
         if r1 is None:
             logger.error("Failed to add public SSH key.")
         else:
             logger.error(
                 "POST request failed to add SSH key to user, " +
                 "see response >>> %s %s" %
                 (r1.status_code, r1.reason))
         raise
Ejemplo n.º 2
0
    def add_ssh_key(is_negative=False):
        logger.debug("About to add an SSH Key in modal window")
        try:  # Add SSH Key from modal window and return key value.
            Wait.text_by_name(Constants.Dashboard.Wizard.AddSSHKey.Title.NAME,
                              Constants.Dashboard.Wizard.AddSSHKey.Title.TEXT)
            # Generate an SSH Public Key.
            sshKey = Helper.generate_sshpub_key()
            if is_negative:
                sshKey = sshKey[8:]
            Enter.text_by_name("key", sshKey)

            # Check that the submit button exists.
            Wait.text_by_css(
                Constants.SubmitButton.CSS,
                Constants.Dashboard.Wizard.AddSSHKey.Title.TEXT)

            Click.css(Constants.SubmitButton.CSS)  # Click on submit button.
            if is_negative:
                Wait.text_by_id(
                    Constants.Toast.ID,
                    Constants.Dashboard.Avatar.Account
                    .SSHKey.UpdateFailed.TEXT)
            else:
                Wait.name_to_dissappear(
                    Constants.Dashboard.Wizard.AddSSHKey.Title.NAME)
                logger.debug("SSH Key added via modal window.")
            return sshKey
        # If failed - count the failure and add the error to list of errors.
        except Exception as e:
            errorMsg = "Failed to add an SSH Key in " +\
                "the modal window. Exception=" + \
                str(e)
            raise Exception(errorMsg)
Ejemplo n.º 3
0
 def update_account(user_content):
     r1 = None
     token = APIUser.login_user(user_content['email'])
     user_content['session_token'] = 'token ' + token
     sshKey = Helper.generate_sshpub_key()
     putURL = settings.ICE_EM_URL + '/v1/engmgr/users/account'
     logger.debug("Put user URL: " + putURL)
     headers = dict()  # Create header for put request.
     headers['Content-type'] = 'application/json'
     headers['Authorization'] = user_content['session_token']
 #   headers['Authorization'] = user_content['activation_token']
     put_data = dict()  # Create JSON data for put request.
     user_content['vendor'] = user_content['company']['name']
     if user_content['vendor'] == "AT&T":
         put_data['company'] = "AT&T"
     else:
         put_data['company'] = user_content['vendor']
     put_data['email'] = user_content['email']
     put_data['full_name'] = user_content['full_name']
     put_data['password'] = ""
     put_data['phone_number'] = "+1201" + \
         Helper.rand_string("randomNumber", 6)
     put_data['ssh_key'] = sshKey
     try:
         r1 = requests.put(
             putURL, json=put_data, headers=headers, verify=False)
         Helper.internal_assert(r1.status_code, 200)
         logger.debug(
             "SSH Key was added successfully to user " +
             user_content['full_name'])
         if not APIBridge.is_gitlab_ready(user_content):
             raise
         return sshKey
     except BaseException:
         if r1 is None:
             logger.error("Failed to add public SSH key to user.")
         else:
             logger.error(
                 "PUT request failed to add SSH key to user, see " +
                 "response >>> %s %s \n %s" %
                 (r1.status_code, r1.reason, str(
                     r1.content, 'utf-8')))
         raise
Ejemplo n.º 4
0
 def test_ssh_key_invalid(self):
     Frontend.Overview.click_on_vf(self.user_content)
     validSSHKey = Helper.generate_sshpub_key()
     invalidSSHKey = validSSHKey[8:]
     logger.debug(invalidSSHKey)
     Frontend.User.set_ssh_key_from_account(invalidSSHKey, is_negative=True)
Ejemplo n.º 5
0
 def test_ssh_key_valid(self):
     validSSHKey = Helper.generate_sshpub_key()
     logger.debug(validSSHKey)
     Frontend.User.set_ssh_key_from_account(validSSHKey)