Exemplo n.º 1
0
    def test_SaveSessionFile(self):
        options = AnObject()
        options.server = self.host
        options.username = self.user
        options.password = self.password
        options.savesessionfile = self.sessionFile

        sessionOptions = SessionOptions(options)
        session = Session(sessionOptions)

        session.Login()
        stub = session.stub
        session.Logout()

        # Make sure session file exists and readable by user only
        if sys.platform == "win32":
            # Windows os.stat().st_mode always returns og rw
            # TODO: Use some other way to test
            pass
        else:
            st = os.stat(options.savesessionfile)
            if (st.st_mode & (stat.S_IRWXG | stat.S_IRWXO)) != 0:
                raise Exception("Session file is world readable!!!")

        # Should remain authenticated after logout
        self.AuthenticatedAction(stub)

        # Close this session
        del session

        # Test session file is usable
        options = AnObject()
        options.sessionfile = self.sessionFile
        self.LoginLogout(options, skipLogoutTest=True)
Exemplo n.º 2
0
    def test_SessionFile_Already_Loggedout(self):
        session = self.GetValidRootSession()
        stub = session.stub

        # Save lwp cookie
        session._SaveCookieFile(self.sessionFile, stub.cookie)

        # Logout. See what will happen...
        session.Logout()

        # Load cookie
        options = AnObject()
        options.sessionfile = self.sessionFile

        sessionOptions = SessionOptions(options)
        session = Session(sessionOptions)
        session.Login()
        self.FailIfRemainAuthenticated(session.stub)
Exemplo n.º 3
0
class DummyHandler(CLIHandler):
   def __init__(self, host, username, pwd):
      CLIHandler.__init__(self)
      opts = Values({
            'server' : host,
            'portnumber' : 443,
            'username' : username,
            'password' : pwd
            })
      sessionOptions = SessionOptions(opts)
      self.session = Session(sessionOptions)
      self.session.Login()

   def ParseArgs(self, method, args):
      argStream = ArgStream(args)
      parameters = {}
      while not argStream.Empty():
         arg = argStream.Pop()
         if self._IsOption(arg) and (not arg == "-" or arg == "--"):
            # Split "="
            splitOption = arg.split('=', 1)
            if len(splitOption) > 1 and splitOption[1]:
               argStream.Push(splitOption[1])
            option = splitOption[0]
            (param, val) = self._ParseCLIParameter(method, option, argStream)

            # Store parameters. Only array type can be duplicated
            valSet = parameters.setdefault(param.name, val)
            if valSet is not val:
               if issubclass(param.vmomiInfo.type, VmomiSupport.Array):
                  valSet += val
               else:
                  message = "Duplicated option " + option
                  raise NamespaceError(message)
         else:
            # Got  leftover option
            # For this version, do not allow leftover options
            message = "Invalid option " + arg
            raise NamespaceError(message)

      return parameters