def test_add_authorized_key_duplicate(self): """If the key already exists in the, it's not added again.""" authorized_keys_path = self.tempdir / 'authorized-keys' add_authorized_key('key 1', authorized_keys_path) add_authorized_key('key 1', authorized_keys_path) self.assertEqual(['key 1'], authorized_keys_path.read_text().splitlines())
def test_add_authorized_key_multiple(self): """Existing keys are preserved.""" authorized_keys_path = self.tempdir / 'authorized-keys' add_authorized_key('key 1', authorized_keys_path) add_authorized_key('key 2', authorized_keys_path) self.assertEqual(['key 1', 'key 2'], authorized_keys_path.read_text().splitlines())
def add_authorized_key(ssh_keys): remote_public_key = ssh_keys.get_remote('public-ssh-key') hookenv.log("Adding key: " + remote_public_key) ssh.add_authorized_key(remote_public_key, utils.get_paths()['authorized-keys']) ssh_peer = {ssh_keys.get_remote('private-address'): remote_public_key} utils.update_config(config_path=utils.get_paths()['config'], new_ssh_peers=ssh_peer) ssh_keys.remove_state(ssh_keys.states.new_remote_public_key)
def test_add_authorized_key_whitespace(self): """Whitespace gets stripped before adding the key.""" authorized_keys_path = self.tempdir / 'authorized-keys' add_authorized_key('\nkey 1\n', authorized_keys_path) self.assertEqual(['key 1'], authorized_keys_path.read_text().splitlines())
def test_add_authorized_key(self): """add_authorized_key() adds the given key.""" authorized_keys_path = self.tempdir / 'authorized-keys' add_authorized_key('key 1', authorized_keys_path) self.assertEqual(['key 1'], authorized_keys_path.read_text().splitlines())