def test_public(self): self.assertEqual(check_data_writable(), []) # This will generate new key key = get_gpg_public_key() self.assertIsNotNone(key) # Check cache access self.assertEqual(key, get_gpg_public_key())
def test_ssh_generate(self): self.assertEqual(check_data_writable(), []) response = self.client.get(reverse('admin:ssh')) self.assertContains(response, 'Generate SSH key') response = self.client.post(reverse('admin:ssh'), {'action': 'generate'}) self.assertContains(response, 'Created new SSH key')
def test_ssh_generate(self): self.assertEqual(check_data_writable(), []) response = self.client.get(reverse('admin:ssh')) self.assertContains(response, 'Generate SSH key') response = self.client.post( reverse('admin:ssh'), {'action': 'generate'} ) self.assertContains(response, 'Created new SSH key')
def test_get(self): self.assertEqual(check_data_writable(), []) # This will generate new key key = get_gpg_sign_key() self.assertIsNotNone(key) # Check cache access self.assertEqual(key, get_gpg_sign_key()) # Check empty cache cache.delete('gpg-key-id') self.assertEqual(key, get_gpg_sign_key())
def test_create_ssh_wrapper(self): self.assertEqual(check_data_writable(), []) filename = get_wrapper_filename() create_ssh_wrapper() with open(filename, 'r') as handle: data = handle.read() self.assertTrue(ssh_file('known_hosts') in data) self.assertTrue(ssh_file('id_rsa') in data) self.assertTrue(settings.DATA_DIR in data) self.assertTrue(os.access(filename, os.X_OK)) # Second run should not touch the file timestamp = os.stat(filename).st_mtime create_ssh_wrapper() self.assertEqual(timestamp, os.stat(filename).st_mtime)
def test_create_ssh_wrapper(self): self.assertEqual(check_data_writable(), []) filename = get_wrapper_filename() create_ssh_wrapper() with open(filename, 'r') as handle: data = handle.read() self.assertTrue(ssh_file('known_hosts') in data) self.assertTrue(ssh_file('id_rsa') in data) self.assertTrue(settings.DATA_DIR in data) self.assertTrue( os.access(filename, os.X_OK) ) # Second run should not touch the file timestamp = os.stat(filename).st_mtime create_ssh_wrapper() self.assertEqual(timestamp, os.stat(filename).st_mtime)
def test_ssh_add(self): self.assertEqual(check_data_writable(), []) try: oldpath = os.environ['PATH'] os.environ['PATH'] = ':'.join( (get_test_file(''), os.environ['PATH'])) # Verify there is button for adding response = self.client.get(reverse('admin:ssh')) self.assertContains(response, 'Add host key') # Add the key response = self.client.post(reverse('admin:ssh'), { 'action': 'add-host', 'host': 'github.com' }) self.assertContains(response, 'Added host key for github.com') finally: os.environ['PATH'] = oldpath # Check the file contains it hostsfile = os.path.join(settings.DATA_DIR, 'ssh', 'known_hosts') with open(hostsfile) as handle: self.assertIn('github.com', handle.read())
def test_ssh_add(self): self.assertEqual(check_data_writable(), []) try: oldpath = os.environ['PATH'] os.environ['PATH'] = ':'.join( (get_test_file(''), os.environ['PATH']) ) # Verify there is button for adding response = self.client.get(reverse('admin:ssh')) self.assertContains(response, 'Add host key') # Add the key response = self.client.post( reverse('admin:ssh'), {'action': 'add-host', 'host': 'github.com'} ) self.assertContains(response, 'Added host key for github.com') finally: os.environ['PATH'] = oldpath # Check the file contains it hostsfile = os.path.join(settings.DATA_DIR, 'ssh', 'known_hosts') with open(hostsfile) as handle: self.assertIn('github.com', handle.read())
def test_parse(self): self.assertEqual(check_data_writable(), []) shutil.copy(TEST_HOSTS, os.path.join(settings.DATA_DIR, 'ssh')) hosts = get_host_keys() self.assertEqual(len(hosts), 50)
def test_generate(self): self.assertEqual(check_data_writable(), []) self.assertIsNone(get_gpg_key()) key = generate_gpg_key() self.assertIsNotNone(key) self.assertEqual(key, get_gpg_key())
def test_parse(self): self.assertEqual(check_data_writable(), []) shutil.copy(TEST_HOSTS, os.path.join(settings.DATA_DIR, 'ssh')) hosts = get_host_keys() self.assertEqual(len(hosts), 50)