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)
def LoginLogout(self, options, skipLogoutTest=False): # Get session sessionOptions = SessionOptions(options) session = Session(sessionOptions) # Login, do something and then logout stub = session.stub # Not need. Auto login when getting stub: # session.Login() self.AuthenticatedAction(stub) session.Logout() if not skipLogoutTest: self.FailIfRemainAuthenticated(stub)