Exemple #1
0
 def test_no_existing_file(self):
     path = "/tmp/this_file_does_not_exists_known_hosts"
     key = 'example.com ssh-rsa AAAAetc\n'
     diff = compute_diff(path, found_line=None, replace_or_add=False, state='present', key=key)
     self.assertEqual(diff, {
         'before_header': '/dev/null',
         'after_header': path,
         'before': '',
         'after': 'example.com ssh-rsa AAAAetc\n',
     })
Exemple #2
0
 def test_key_removal_no_change(self):
     path = self._create_file(
         'two.example.com ssh-rsa BBBBetc\n'
     )
     key = 'one.example.com ssh-rsa AAAAetc\n'
     diff = compute_diff(path, found_line=None, replace_or_add=False, state='absent', key=key)
     self.assertEqual(diff, {
         'before_header': path,
         'after_header': path,
         'before': 'two.example.com ssh-rsa BBBBetc\n',
         'after': 'two.example.com ssh-rsa BBBBetc\n',
     })
Exemple #3
0
 def test_key_change(self):
     path = self._create_file(
         'one.example.com ssh-rsa AAAaetc\n'
         'two.example.com ssh-rsa BBBBetc\n'
     )
     key = 'one.example.com ssh-rsa AAAAetc\n'
     diff = compute_diff(path, found_line=1, replace_or_add=True, state='present', key=key)
     self.assertEqual(diff, {
         'before_header': path,
         'after_header': path,
         'before': 'one.example.com ssh-rsa AAAaetc\ntwo.example.com ssh-rsa BBBBetc\n',
         'after': 'two.example.com ssh-rsa BBBBetc\none.example.com ssh-rsa AAAAetc\n',
     })
 def test_no_existing_file(self):
     path = tempfile.mktemp(prefix='ansible-test-', suffix='-known_hosts')
     key = 'example.com ssh-rsa AAAAetc\n'
     diff = compute_diff(path,
                         found_line=None,
                         replace_or_add=False,
                         state='present',
                         key=key)
     self.assertEqual(
         diff, {
             'before_header': '/dev/null',
             'after_header': path,
             'before': '',
             'after': 'example.com ssh-rsa AAAAetc\n',
         })