Exemple #1
0
 def test_remove_comment_from_key(self):
     key_string = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsEctmRR8YdO+nnZauPqhhsvOn6c30szVe1Gqmc6kM8/Wi9XS+dUKAL12iuQTrkuFCY6wvmfLG9ACIV8b1ZXxOxE3G5Q+0FvGJMHCdKL0b2fDCLiDNpcg22xOb4QaXggJaXR+M8yxNn5I+LIKpSA6vP6HEYKxm3aHQyrYDhy7WuJ8L/BUw+cAxDa0+y9l9ZuKwv5IdNTwU/WdQWeBXiLyhEV6Pcnx6pTDjgJqtnTHePQ/Cm/pedIYoeamFZwWkabnoTPZPiKa+ATLNXXOBzvcV32f2EFW7957TodpL1Yhg/WPDcD/2ypGWgmtUmWhYxJhXAactaTiZni+nhVjEi9zmQ== [email protected] on paras"
     result = SshKey.remove_comment_from_key_string(key_string)
     count = len(result.split())
     self.assertEquals(count, 2)
     key_string = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsEctmRR8YdO+nnZauPqhhsvOn6c30szVe1Gqmc6kM8/Wi9XS+dUKAL12iuQTrkuFCY6wvmfLG9ACIV8b1ZXxOxE3G5Q+0FvGJMHCdKL0b2fDCLiDNpcg22xOb4QaXggJaXR+M8yxNn5I+LIKpSA6vP6HEYKxm3aHQyrYDhy7WuJ8L/BUw+cAxDa0+y9l9ZuKwv5IdNTwU/WdQWeBXiLyhEV6Pcnx6pTDjgJqtnTHePQ/Cm/pedIYoeamFZwWkabnoTPZPiKa+ATLNXXOBzvcV32f2EFW7957TodpL1Yhg/WPDcD/2ypGWgmtUmWhYxJhXAactaTiZni+nhVjEi9zmQ=="
     result = SshKey.remove_comment_from_key_string(key_string)
     count = len(result.split())
     self.assertEquals(count, 2)
 def test_remove_comment_from_key(self):
     key_string = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsEctmRR8YdO+nnZauPqhhsvOn6c30szVe1Gqmc6kM8/Wi9XS+dUKAL12iuQTrkuFCY6wvmfLG9ACIV8b1ZXxOxE3G5Q+0FvGJMHCdKL0b2fDCLiDNpcg22xOb4QaXggJaXR+M8yxNn5I+LIKpSA6vP6HEYKxm3aHQyrYDhy7WuJ8L/BUw+cAxDa0+y9l9ZuKwv5IdNTwU/WdQWeBXiLyhEV6Pcnx6pTDjgJqtnTHePQ/Cm/pedIYoeamFZwWkabnoTPZPiKa+ATLNXXOBzvcV32f2EFW7957TodpL1Yhg/WPDcD/2ypGWgmtUmWhYxJhXAactaTiZni+nhVjEi9zmQ== [email protected] on paras"
     result = SshKey.remove_comment_from_key_string(key_string)
     count = len(result.split())
     self.assertEquals(count, 2)
     key_string = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsEctmRR8YdO+nnZauPqhhsvOn6c30szVe1Gqmc6kM8/Wi9XS+dUKAL12iuQTrkuFCY6wvmfLG9ACIV8b1ZXxOxE3G5Q+0FvGJMHCdKL0b2fDCLiDNpcg22xOb4QaXggJaXR+M8yxNn5I+LIKpSA6vP6HEYKxm3aHQyrYDhy7WuJ8L/BUw+cAxDa0+y9l9ZuKwv5IdNTwU/WdQWeBXiLyhEV6Pcnx6pTDjgJqtnTHePQ/Cm/pedIYoeamFZwWkabnoTPZPiKa+ATLNXXOBzvcV32f2EFW7957TodpL1Yhg/WPDcD/2ypGWgmtUmWhYxJhXAactaTiZni+nhVjEi9zmQ=="
     result = SshKey.remove_comment_from_key_string(key_string)
     count = len(result.split())
     self.assertEquals(count, 2)        
    def _do_save(self, req, user):
        """
        Save ssh key into database
        """
        if not req.args.get('ssh_key'):
            add_warning(req, _('Failed to add SSH key: Key is required'))
            return user

        ssh_key = req.args.get('ssh_key')
        ssh_key = SshKey.remove_comment_from_key_string(ssh_key)

        if not SshKey.validate_key_string(ssh_key):
            add_warning(req, _('Failed to add SSH key: invalid SSH key, key must be in open ssh format'))
            return user

        description = req.args.get('description')
        if len(description) > 200:
            add_warning(req, _('Failed to add SSH key: Too long description'))
            return user

        key_store = CQDESshKeyStore.instance()
        user_id = user.id

        if key_store.add_ssh_key(user_id, ssh_key, description):
            add_notice(req, _('New SSH key added (please allow 5 minutes for replication)'))
            return user

        add_warning(req, _('Failed to add SSH key: Server error'))
        return user
    def _do_save(self, req, user):
        """
        Save ssh key into database
        """
        if not req.args.get('ssh_key'):
            add_warning(req, _('Failed to add SSH key: Key is required'))
            return user

        ssh_key = req.args.get('ssh_key')
        ssh_key = SshKey.remove_comment_from_key_string(ssh_key)

        if not SshKey.validate_key_string(ssh_key):
            add_warning(
                req,
                _('Failed to add SSH key: invalid SSH key, key must be in open ssh format'
                  ))
            return user

        description = req.args.get('description')
        if len(description) > 200:
            add_warning(req, _('Failed to add SSH key: Too long description'))
            return user

        key_store = CQDESshKeyStore.instance()
        user_id = user.id

        if key_store.add_ssh_key(user_id, ssh_key, description):
            add_notice(
                req,
                _('New SSH key added (please allow 5 minutes for replication)')
            )
            return user

        add_warning(req, _('Failed to add SSH key: Server error'))
        return user
Exemple #5
0
 def test_remove_comment_from_key_error(self):
     key_string = None
     result = SshKey.remove_comment_from_key_string(key_string)
     self.assertEquals(result, None)
 def test_remove_comment_from_key_error(self):
     key_string = None
     result = SshKey.remove_comment_from_key_string(key_string)
     self.assertEquals(result, None)