def setUp(self): auth_token = util.get_auth_token() self.telnet = util.telnet_emulator() self.telnet.write('%s %s\n' % (util.AUTH, auth_token)) util.wait_on_windows() if (not util.check_read_until( self.telnet.read_until(util.OK, util.TIMEOUT_S))): sys.exit(-1)
def _auth_user_for_emulator_console(self): """Authorization user.""" auth_token = util.get_auth_token() self.telnet = util.telnet_emulator() self.telnet.write('%s %s\n' % (util.AUTH, auth_token)) util.wait_on_windows() if (not util.check_read_until( self.telnet.read_until(util.OK, util.TIMEOUT_S))): sys.exit(-1)
def test_auth_token_file_exists(self): """Test command for: auth <auth_token>. TT ID: a808dfe9-b0ff-4b77-9db5-24d8b2aa44ea Test steps: 1. Launch an emulator avd 2. From command prompt, run: telnet localhost <port> 3. verify 1 4. Exist emulator console Verify: 1. .emulator_console_auth_token file is created in home folder """ print 'Running test: %s' % (inspect.stack()[0][3]) self.telnet = util.telnet_emulator() assert os.path.isfile(util.TOKEN_PATH) util.exit_emulator_console(self.telnet)
def test_auth_without_authorization(self): """Test command for: auth <auth_token>. TT ID: a808dfe9-b0ff-4b77-9db5-24d8b2aa44ea Test steps: 1. Launch an emulator avd 2. From command prompt, run: telnet localhost <port> 3. Run: help, verify 1 4. Exist emulator console Verify: 1. Short help information is displayed. """ print 'Running test: %s' % (inspect.stack()[0][3]) self.telnet = util.telnet_emulator() self._verify_auth_command_by_enter_help_command( util.REGEX_HELP_DISPLAY_NO_AUTH) util.exit_emulator_console(self.telnet)
def test_auth_empty_auth_token_file(self): """Test command for: auth <auth_token>. TT ID: a808dfe9-b0ff-4b77-9db5-24d8b2aa44ea Test steps: 0. Save valid auth token, and empty the contents of auth token file 1. Launch an emulator avd 2. From command prompt, run: telnet localhost <port> 3. Run: help, verify 1 4. Reset auth token file 5. Exist emulator console Verify: 1. Emulator authentication is skipped and emulator console is usable (Here, we run help command to check.) """ print 'Running test: %s' % (inspect.stack()[0][3]) # save auth token value and empty contents of auth token file valid_auth_token = util.get_auth_token() try: f = open(util.TOKEN_PATH, 'w') f.close() # telnet and verify self.telnet = util.telnet_emulator() self._verify_auth_command_by_enter_help_command( util.REGEX_HELP_DISPLAY_AUTH) # reset auth token file f = open(util.TOKEN_PATH, 'w') f.write(valid_auth_token) f.close() util.exit_emulator_console(self.telnet) except IOError as e: print 'IOError on auth token file.' finally: print( 'The failure on resetting auth token file back will affact other ' 'tests running after this test. Hence, reset it again when ' 'failure happens.') f = open(util.TOKEN_PATH, 'w') f.write(valid_auth_token) f.close()
def test_auth_user_with_random_auth_token(self): """Test command for: auth <auth_token>. TT ID: a808dfe9-b0ff-4b77-9db5-24d8b2aa44ea Test steps: 1. Launch an emulator avd 2. From command prompt, run: telnet localhost <port> 3. Run: help, verify 1 4. Run: auth <random_auth_token>, verify 1 5. Exist emulator console Verify: 1. User is not authorized, and warning message is displayed. """ print 'Running test: %s' % (inspect.stack()[0][3]) self.telnet = util.telnet_emulator() self._auth_user_for_emulator_console(util.CMD_RANDOM_AUTH_TOKEN, AUTH_ERROR_OUTPUT) util.exit_emulator_console(self.telnet)
def test_auth_user_with_empty_auth_token(self): """Test command for: auth <auth_token>. TT ID: a808dfe9-b0ff-4b77-9db5-24d8b2aa44ea Test steps: 1. Launch an emulator avd 2. From command prompt, run: telnet localhost <port> 3. Run: help, verify 1 4. Run: auth <empty_string>, verify 1 5. Exist emulator console Verify: 1. User is not authorized, and "missing authentication token" is displayed. """ print 'Running test: %s' % (inspect.stack()[0][3]) self.telnet = util.telnet_emulator() self._auth_user_for_emulator_console(util.CMD_EMPTY_AUTH_TOKEN, AUTH_TOKEN_MISSING_OUTPUT) util.exit_emulator_console(self.telnet)
def test_auth_user_with_valid_auth_token(self): """Test command for: auth <auth_token>. TT ID: a808dfe9-b0ff-4b77-9db5-24d8b2aa44ea Test steps: 1. Launch an emulator avd 2. From command prompt, run: telnet localhost <port> 3. Run: help, verify 1 4. Run: auth <valid auth token>, verify 1 5. Run: help, verify 2 6. Exist emulator console Verify: 1. User is not authorized 2. The full help commands information is displayed """ print 'Running test: %s' % (inspect.stack()[0][3]) self.telnet = util.telnet_emulator() auth_token = util.get_auth_token() valid_auth_cmd = '%s %s\n' % (util.AUTH, auth_token) self._auth_user_for_emulator_console(valid_auth_cmd, AUTH_OUTPUT) self._verify_auth_command_by_enter_help_command( util.REGEX_HELP_DISPLAY_AUTH) util.exit_emulator_console(self.telnet)