st2client/tests/unit/test_auth.py
def runTest(self, mock_gp):
        '''Test 'st2 login' functionality with interactive password entry
        '''

        expected_username = self.TOKEN['user']
        args = ['--config', self.CONFIG_FILE, 'login', expected_username]

        mock_gp.getpass.return_value = 'Password1!'

        self.shell.run(args)

        expected_kwargs = {
            'headers': {'content-type': 'application/json'},
            'auth': ('st2admin', 'Password1!')
        }
        requests.post.assert_called_with('http://127.0.0.1:9100/tokens', '{}', **expected_kwargs)

        with open(self.CONFIG_FILE, 'r') as config_file:
            for line in config_file.readlines():
                # Make sure certain values are not present
                self.assertFalse('password' in line)
                self.assertFalse('olduser' in line)

                # Make sure configured username is what we expect
                if 'username' in line:
                    self.assertEquals(line.split(' ')[2][:-1], expected_username)

            # validate token was created
            self.assertTrue(os.path.isfile('%stoken-%s' % (self.DOTST2_PATH, expected_username)))

        # Validate token is sent on subsequent requests to st2 API
        args = ['--config', self.CONFIG_FILE, 'pack', 'list']
        self.shell.run(args)

        expected_kwargs = {
            'headers': {
                'X-Auth-Token': self.TOKEN['token']
            },
            'params': {}
        }
        requests.get.assert_called_with('http://127.0.0.1:9101/v1/packs', **expected_kwargs)
Test 'st2 login' functionality with interactive password entry
        
Test 'st2 login' functionality with interactive password entry
Test ' st2 login ' functionality with interactive password entry
def runTest(self, mock_gp):
        expected_username = self.TOKEN['user']
        args = ['--config', self.CONFIG_FILE, 'login', expected_username]
        mock_gp.getpass.return_value = 'Password1!'
        self.shell.run(args)
        expected_kwargs = {
            'headers': {'content-type': 'application/json'},
            'auth': ('st2admin', 'Password1!')
        }
        requests.post.assert_called_with('http://127.0.0.1:9100/tokens', '{}', **expected_kwargs)
        with open(self.CONFIG_FILE, 'r') as config_file:
            for line in config_file.readlines():
                self.assertFalse('password' in line)
                self.assertFalse('olduser' in line)
                if 'username' in line:
                    self.assertEquals(line.split(' ')[2][:-1], expected_username)
            self.assertTrue(os.path.isfile('%stoken-%s' % (self.DOTST2_PATH, expected_username)))
        args = ['--config', self.CONFIG_FILE, 'pack', 'list']
        self.shell.run(args)
        expected_kwargs = {
            'headers': {
                'X-Auth-Token': self.TOKEN['token']
            },
            'params': {}
        }
        requests.get.assert_called_with('http://127.0.0.1:9101/v1/packs', **expected_kwargs)
def runTest ( self , mock_gp ) : expected_username = self . TOKEN [ 'user' ] args = [ '--config' , self . CONFIG_FILE , 'login' , expected_username ] mock_gp . getpass . return_value = 'Password1!' self . shell . run ( args ) expected_kwargs = { 'headers' : { 'content-type' : 'application/json' } , 'auth' : ( 'st2admin' , 'Password1!' ) } requests . post . assert_called_with ( 'http://127.0.0.1:9100/tokens' , '{}' , ** expected_kwargs ) with open ( self . CONFIG_FILE , 'r' ) as config_file : for line in config_file . readlines ( ) : self . assertFalse ( 'password' in line ) self . assertFalse ( 'olduser' in line ) if 'username' in line : self . assertEquals ( line . split ( ' ' ) [ 2 ] [ : - 1 ] , expected_username ) self . assertTrue ( os . path . isfile ( '%stoken-%s' % ( self . DOTST2_PATH , expected_username ) ) ) args = [ '--config' , self . CONFIG_FILE , 'pack' , 'list' ] self . shell . run ( args ) expected_kwargs = { 'headers' : { 'X-Auth-Token' : self . TOKEN [ 'token' ] } , 'params' : { } } requests . get . assert_called_with ( 'http://127.0.0.1:9101/v1/packs' , ** expected_kwargs )
Test 'st2 login' functionality with interactive password entry
Test ' st2 login ' functionality with interactive password entry
'''Test 'st2 login' functionality with interactive password entry
        ''' # Make sure certain values are not present # Make sure configured username is what we expect # validate token was created # Validate token is sent on subsequent requests to st2 API
self
mock_gp