示例#1
0
 def test_non_secret_keys_are_not_masked(self):
     prompter = configure.InteractivePrompter()
     prompter.get_value(current_value='mycurrentvalue',
                        config_name='not_a_secret_key',
                        prompt_text='Enter value')
     # We should also not display the entire priate key.
     prompt_text = self.stdout.getvalue()
     self.assertIn('mycurrentvalue', prompt_text)
     self.assertRegexpMatches(prompt_text, r'\[mycurrentvalue\]')
示例#2
0
 def test_private_key_is_masked(self):
     prompter = configure.InteractivePrompter()
     prompter.get_value(current_value='mysupersecretkey',
                        config_name=CDP_PRIVATE_KEY_KEY_NAME,
                        prompt_text='Private Key')
     # We should also not display the entire private key.
     prompt_text = self.stdout.getvalue()
     self.assertNotIn('mysupersecretkey', prompt_text)
     self.assertRegexpMatches(prompt_text, r'\[\*\*\*\*.*\]')
示例#3
0
 def test_access_key_not_masked_when_none(self):
     self.mock_raw_input.return_value = 'foo'
     prompter = configure.InteractivePrompter()
     response = prompter.get_value(current_value=None,
                                   config_name=CDP_ACCESS_KEY_ID_KEY_NAME,
                                   prompt_text='Access key')
     # First we should return the value from raw_input.
     self.assertEqual(response, 'foo')
     prompt_text = self.stdout.getvalue()
     self.assertIn('[None]', prompt_text)
示例#4
0
    def test_user_hits_enter_returns_none(self):
        # If a user hits enter, then raw_input returns the empty string.
        self.mock_raw_input.return_value = ''

        prompter = configure.InteractivePrompter()
        response = prompter.get_value(current_value=None,
                                      config_name=CDP_ACCESS_KEY_ID_KEY_NAME,
                                      prompt_text='Access key')
        # We convert the empty string to None to indicate that there
        # was no input.
        self.assertIsNone(response)
示例#5
0
 def test_access_key_is_masked(self):
     self.mock_raw_input.return_value = 'foo'
     prompter = configure.InteractivePrompter()
     response = prompter.get_value(current_value='myaccesskey',
                                   config_name=CDP_ACCESS_KEY_ID_KEY_NAME,
                                   prompt_text='Access key')
     # First we should return the value from raw_input.
     self.assertEqual(response, 'foo')
     # We should also not display the entire access key.
     prompt_text = self.stdout.getvalue()
     self.assertNotIn('myaccesskey', prompt_text)
     self.assertRegexpMatches(prompt_text, r'\[\*\*\*\*.*\]')
示例#6
0
    def test_compat_input_flushes_after_each_prompt(self):
        # Clear out the default patch
        self.stdout_patch.stop()

        # Create a mock stdout to record flush calls and replace stdout_patch
        self.stdout = mock.Mock()
        self.stdout_patch = mock.patch('sys.stdout', self.stdout)
        self.stdout_patch.start()

        # Make sure flush called at least once
        prompter = configure.InteractivePrompter()
        prompter.get_value(current_value='foo',
                           config_name='bar',
                           prompt_text='baz')
        self.assertTrue(self.stdout.flush.called)

        # Make sure flush is called after *every* prompt
        self.stdout.reset_mock()
        prompter.get_value(current_value='foo2',
                           config_name='bar2',
                           prompt_text='baz2')
        self.assertTrue(self.stdout.flush.called)