diff options
| author | Jae-Heon Ji <32578710+jaeheonji@users.noreply.github.com> | 2023-08-12 22:35:42 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-12 15:35:42 +0200 |
| commit | c8ddb23297e2f4fc900b8286d57e2808ae6a4fdb (patch) | |
| tree | c96d26c8bfc24172374aefe88624b78c6890663f /zellij-server/src/plugins | |
| parent | docs(changelog): protobuffers (diff) | |
| download | sl0ppij-c8ddb23297e2f4fc900b8286d57e2808ae6a4fdb.tar.gz sl0ppij-c8ddb23297e2f4fc900b8286d57e2808ae6a4fdb.tar.xz sl0ppij-c8ddb23297e2f4fc900b8286d57e2808ae6a4fdb.zip | |
feat: add plugin permission system (#2624)
* WIP: add exaple of permission ui
* feat: add request permission ui
* feat: add caching permission in memory
* feat: add permission check
* feat: add file caching
* fix: changes request
* feat(ui): new status bar mode (#2619)
* supermode prototype
* fix integration tests
* fix tests
* style(fmt): rustfmt
* docs(changelog): status-bar supermode
* fix(rendering): occasional glitches while resizing (#2621)
* docs(changelog): resize glitches fix
* chore(version): bump development version
* Fix colored pane frames in mirrored sessions (#2625)
* server/panes/tiled: Fix colored frames
in mirrored sessions. Colored frames were previously ignored because
they were treated like floating panes when rendering tiled panes.
* CHANGELOG: Add PR #2625
* server/tab/unit: Fix unit tests for server.
* fix(sessions): use custom lists of adjectives and nouns for generating session names (#2122)
* Create custom lists of adjectives and nouns for generating session names
* move word lists to const slices
* add logic to retry name generation
* refactor
- reuse the name generator
- iterator instead of for loop
---------
Co-authored-by: Thomas Linford <linford.t@gmail.com>
* docs(changelog): generate session names with custom words list
* feat(plugins): make plugins configurable (#2646)
* work
* make every plugin entry point configurable
* make integration tests pass
* make e2e tests pass
* add test for plugin configuration
* add test snapshot
* add plugin config parsing test
* cleanups
* style(fmt): rustfmt
* style(comment): remove commented code
* docs(changelog): configurable plugins
* style(fmt): rustfmt
* touch up ui
* fix: don't save permission data in memory
* feat: load cached permission
* test: add example test (WIP)
* fix: issue event are always denied
* test: update snapshot
* apply formatting
* refactor: update default cache function
* test: add more new test
* apply formatting
* Revert "apply formatting"
This reverts commit a4e93703fbfdb6865131daa1c8b90fc5c36ab25e.
* apply format
* fix: update cache path
* apply format
* fix: cache path
* fix: update log level
* test for github workflow
* Revert "test for github workflow"
This reverts commit 01eff3bc5d1627a4e60bc6dac8ebe5500bc5b56e.
* refactor: permission cache
* fix(test): permission grant/deny race condition
* style(fmt): rustfmt
* style(fmt): rustfmt
* configure permissions
* permission denied test
* snapshot
* add ui for small plugins
* style(fmt): rustfmt
* some cleanups
---------
Co-authored-by: Aram Drevekenin <aram@poor.dev>
Co-authored-by: har7an <99636919+har7an@users.noreply.github.com>
Co-authored-by: Kyle Sutherland-Cash <kyle.sutherlandcash@gmail.com>
Co-authored-by: Thomas Linford <linford.t@gmail.com>
Co-authored-by: Thomas Linford <tlinford@users.noreply.github.com>
Diffstat (limited to 'zellij-server/src/plugins')
10 files changed, 1426 insertions, 308 deletions
diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs index f36bdc2d..4bef0683 100644 --- a/zellij-server/src/plugins/mod.rs +++ b/zellij-server/src/plugins/mod.rs @@ -18,7 +18,7 @@ use crate::{pty::PtyInstruction, thread_bus::Bus, ClientId, ServerInstruction}; use wasm_bridge::WasmBridge; use zellij_utils::{ - data::{Event, EventType, PluginCapabilities}, + data::{Event, EventType, PermissionStatus, PermissionType, PluginCapabilities}, errors::{prelude::*, ContextType, PluginContext}, input::{ command::TerminalAction, @@ -79,6 +79,13 @@ pub enum PluginInstruction { String, // serialized payload ), PluginSubscribedToEvents(PluginId, ClientId, HashSet<EventType>), + PermissionRequestResult( + PluginId, + Option<ClientId>, + Vec<PermissionType>, + PermissionStatus, + Option<PathBuf>, + ), Exit, } @@ -105,6 +112,9 @@ impl From<&PluginInstruction> for PluginContext { PluginInstruction::PluginSubscribedToEvents(..) => { PluginContext::PluginSubscribedToEvents }, + PluginInstruction::PermissionRequestResult(..) => { + PluginContext::PermissionRequestResult + }, } } } @@ -287,6 +297,30 @@ pub(crate) fn plugin_thread_main( } } }, + PluginInstruction::PermissionRequestResult( + plugin_id, + client_id, + permissions, + status, + cache_path, + ) => { + if let Err(e) = wasm_bridge.cache_plugin_permissions( + plugin_id, + client_id, + permissions, + status, + cache_path, + ) { + log::error!("{}", e); + } + + let updates = vec![( + Some(plugin_id), + client_id, + Event::PermissionRequestResult(status), + )]; + wasm_bridge.update_plugins(updates)?; + }, PluginInstruction::Exit => { wasm_bridge.cleanup(); break; diff --git a/zellij-server/src/plugins/plugin_loader.rs b/zellij-server/src/plugins/plugin_loader.rs index 92a4c048..ea0c2b6a 100644 --- a/zellij-server/src/plugins/plugin_loader.rs +++ b/zellij-server/src/plugins/plugin_loader.rs @@ -188,6 +188,7 @@ impl<'a> PluginLoader<'a> { display_loading_stage!(end, loading_indication, senders, plugin_id); Ok(()) } + pub fn add_client( client_id: ClientId, plugin_dir: PathBuf, @@ -613,6 +614,19 @@ impl<'a> PluginLoader<'a> { } start_function.call(&[]).with_context(err_context)?; + plugin_map.lock().unwrap().insert( + self.plugin_id, + self.client_id, + Arc::new(Mutex::new(RunningPlugin::new( + main_user_instance, + main_user_env, + self.size.rows, + self.size.cols, + ))), + subscriptions.clone(), + workers, + ); + let protobuf_plugin_configuration: ProtobufPluginConfiguration = self .plugin .userspace_configuration @@ -640,18 +654,6 @@ impl<'a> PluginLoader<'a> { self.senders, self.plugin_id ); - plugin_map.lock().unwrap().insert( - self.plugin_id, - self.client_id, - Arc::new(Mutex::new(RunningPlugin::new( - main_user_instance, - main_user_env, - self.size.rows, - self.size.cols, - ))), - subscriptions.clone(), - workers, - ); display_loading_stage!( indicate_writing_plugin_to_cache_success, self.loading_indication, @@ -764,13 +766,13 @@ impl<'a> PluginLoader<'a> { }) .with_context(err_context)?; let wasi = wasi_env.import_object(&module).with_context(err_context)?; - let mut mut_plugin = self.plugin.clone(); mut_plugin.set_tab_index(self.tab_index); let plugin_env = PluginEnv { plugin_id: self.plugin_id, client_id: self.client_id, plugin: mut_plugin, + permissions: Arc::new(Mutex::new(None)), senders: self.senders.clone(), wasi_env, plugin_own_data_dir: self.plugin_own_data_dir.clone(), diff --git a/zellij-server/src/plugins/plugin_map.rs b/zellij-server/src/plugins/plugin_map.rs index 2f7454c7..0cf26943 100644 --- a/zellij-server/src/plugins/plugin_map.rs +++ b/zellij-server/src/plugins/plugin_map.rs @@ -11,7 +11,6 @@ use wasmer_wasi::WasiEnv; use crate::{thread_bus::ThreadSenders, ClientId}; use zellij_utils::async_channel::Sender; -use zellij_utils::errors::prelude::*; use zellij_utils::{ data::EventType, data::PluginCapabilities, @@ -20,6 +19,7 @@ use zellij_utils::{ input::plugins::PluginConfig, ipc::ClientAttributes, }; +use zellij_utils::{data::PermissionType, errors::prelude::*}; // the idea here is to provide atomicity when adding/removing plugins from the map (eg. when a new // client connects) but to also allow updates/renders not to block each other @@ -193,6 +193,7 @@ pub type Subscriptions = HashSet<EventType>; pub struct PluginEnv { pub plugin_id: PluginId, pub plugin: PluginConfig, + pub permissions: Arc<Mutex<Option<HashSet<PermissionType>>>>, pub senders: ThreadSenders, pub wasi_env: WasiEnv, pub tab_index: usize, @@ -215,6 +216,10 @@ impl PluginEnv { self.plugin_id ) } + + pub fn set_permissions(&mut self, permissions: HashSet<PermissionType>) { + self.permissions.lock().unwrap().replace(permissions); + } } #[derive(Eq, PartialEq, Hash)] diff --git a/zellij-server/src/plugins/unit/plugin_tests.rs b/zellij-server/src/plugins/unit/plugin_tests.rs index 663ca94e..e995a07b 100644 --- a/zellij-server/src/plugins/unit/plugin_tests.rs +++ b/zellij-server/src/plugins/unit/plugin_tests.rs @@ -6,9 +6,10 @@ use std::collections::BTreeMap; use std::path::PathBuf; use tempfile::tempdir; use wasmer::Store; -use zellij_utils::data::{Event, Key, PluginCapabilities}; +use zellij_utils::data::{Event, Key, PermissionStatus, PermissionType, PluginCapabilities}; use zellij_utils::errors::ErrorContext; use zellij_utils::input::layout::{Layout, PluginUserConfiguration, RunPlugin, RunPluginLocation}; +use zellij_utils::input::permission::PermissionCache; use zellij_utils::input::plugins::PluginsConfig; use zellij_utils::ipc::ClientAttributes; use zellij_utils::lazy_static::lazy_static; @@ -52,6 +53,157 @@ macro_rules! log_actions_in_thread { }; } +macro_rules! grant_permissions_and_log_actions_in_thread { + ( $arc_mutex_log:expr, $exit_event:path, $receiver:expr, $exit_after_count:expr, $permission_type:expr, $cache_path:expr, $plugin_thread_sender:expr, $client_id:expr ) => { + std::thread::Builder::new() + .name("fake_screen_thread".to_string()) + .spawn({ + let log = $arc_mutex_log.clone(); + let mut exit_event_count = 0; + let cache_path = $cache_path.clone(); + let plugin_thread_sender = $plugin_thread_sender.clone(); + move || loop { + let (event, _err_ctx) = $receiver + .recv() + .expect("failed to receive event on channel"); + match event { + $exit_event(..) => { + exit_event_count += 1; + log.lock().unwrap().push(event); + if exit_event_count == $exit_after_count { + break; + } + }, + ScreenInstruction::RequestPluginPermissions(_, plugin_permission) => { + if plugin_permission.permissions.contains($permission_type) { + let _ = plugin_thread_sender.send( + PluginInstruction::PermissionRequestResult( + 0, + Some($client_id), + plugin_permission.permissions, + PermissionStatus::Granted, + Some(cache_path.clone()), + ), + ); + } else { + let _ = plugin_thread_sender.send( + PluginInstruction::PermissionRequestResult( + 0, + Some($client_id), + plugin_permission.permissions, + PermissionStatus::Denied, + Some(cache_path.clone()), + ), + ); + } + }, + _ => { + log.lock().unwrap().push(event); + }, + } + } + }) + .unwrap() + }; +} + +macro_rules! deny_permissions_and_log_actions_in_thread { + ( $arc_mutex_log:expr, $exit_event:path, $receiver:expr, $exit_after_count:expr, $permission_type:expr, $cache_path:expr, $plugin_thread_sender:expr, $client_id:expr ) => { + std::thread::Builder::new() + .name("fake_screen_thread".to_string()) + .spawn({ + let log = $arc_mutex_log.clone(); + let mut exit_event_count = 0; + let cache_path = $cache_path.clone(); + let plugin_thread_sender = $plugin_thread_sender.clone(); + move || loop { + let (event, _err_ctx) = $receiver + .recv() + .expect("failed to receive event on channel"); + match event { + $exit_event(..) => { + exit_event_count += 1; + log.lock().unwrap().push(event); + if exit_event_count == $exit_after_count { + break; + } + }, + ScreenInstruction::RequestPluginPermissions(_, plugin_permission) => { + let _ = plugin_thread_sender.send( + PluginInstruction::PermissionRequestResult( + 0, + Some($client_id), + plugin_permission.permissions, + PermissionStatus::Denied, + Some(cache_path.clone()), + ), + ); + break; + }, + _ => { + log.lock().unwrap().push(event); + }, + } + } + }) + .unwrap() + }; +} + +macro_rules! grant_permissions_and_log_actions_in_thread_naked_variant { + ( $arc_mutex_log:expr, $exit_event:path, $receiver:expr, $exit_after_count:expr, $permission_type:expr, $cache_path:expr, $plugin_thread_sender:expr, $client_id:expr ) => { + std::thread::Builder::new() + .name("fake_screen_thread".to_string()) + .spawn({ + let log = $arc_mutex_log.clone(); + let mut exit_event_count = 0; + let cache_path = $cache_path.clone(); + let plugin_thread_sender = $plugin_thread_sender.clone(); + move || loop { + let (event, _err_ctx) = $receiver + .recv() + .expect("failed to receive event on channel"); + match event { + $exit_event => { + exit_event_count += 1; + log.lock().unwrap().push(event); + if exit_event_count == $exit_after_count { + break; + } + }, + ScreenInstruction::RequestPluginPermissions(_, plugin_permission) => { + if plugin_permission.permissions.contains($permission_type) { + let _ = plugin_thread_sender.send( + PluginInstruction::PermissionRequestResult( + 0, + Some($client_id), + plugin_permission.permissions, + PermissionStatus::Granted, + Some(cache_path.clone()), + ), + ); + } else { + let _ = plugin_thread_sender.send( + PluginInstruction::PermissionRequestResult( + 0, + Some($client_id), + plugin_permission.permissions, + PermissionStatus::Denied, + Some(cache_path.clone()), + ), + ); + } + }, + _ => { + log.lock().unwrap().push(event); + }, + } + } + }) + .unwrap() + }; +} + macro_rules! log_actions_in_thread_naked_variant { ( $arc_mutex_log:expr, $exit_event:path, $receiver:expr, $exit_after_count:expr ) => { std::thread::Builder::new() @@ -167,14 +319,14 @@ fn create_plugin_thread_with_server_receiver( ) -> ( SenderWithContext<PluginInstruction>, Receiver<(ServerInstruction, ErrorContext)>, + Receiver<(ScreenInstruction, ErrorContext)>, Box<dyn FnMut()>, ) { let zellij_cwd = zellij_cwd.unwrap_or_else(|| PathBuf::from(".")); let (to_server, server_receiver): ChannelWithContext<ServerInstruction> = channels::bounded(50); let to_server = SenderWithContext::new(to_server); - let (to_screen, _screen_receiver): ChannelWithContext<ScreenInstruction> = - channels::unbounded(); + let (to_screen, screen_receiver): ChannelWithContext<ScreenInstruction> = channels::unbounded(); let to_screen = SenderWithContext::new(to_screen); let (to_plugin, plugin_receiver): ChannelWithContext<PluginInstruction> = channels::unbounded(); @@ -240,7 +392,12 @@ fn create_plugin_thread_with_server_receiver( // the plugin cache } }; - (to_plugin, server_receiver, Box::new(teardown)) + ( + to_plugin, + server_receiver, + screen_receiver, + Box::new(teardown), + ) } fn create_plugin_thread_with_pty_receiver( @@ -248,6 +405,7 @@ fn create_plugin_thread_with_pty_receiver( ) -> ( SenderWithContext<PluginInstruction>, Receiver<(PtyInstruction, ErrorContext)>, + Receiver<(ScreenInstruction, ErrorContext)>, Box<dyn FnMut()>, ) { let zellij_cwd = zellij_cwd.unwrap_or_else(|| PathBuf::from(".")); @@ -255,8 +413,7 @@ fn create_plugin_thread_with_pty_receiver( channels::bounded(50); let to_server = SenderWithContext::new(to_server); - let (to_screen, _screen_receiver): ChannelWithContext<ScreenInstruction> = - channels::unbounded(); + let (to_screen, screen_receiver): ChannelWithContext<ScreenInstruction> = channels::unbounded(); let to_screen = SenderWithContext::new(to_screen); let (to_plugin, plugin_receiver): ChannelWithContext<PluginInstruction> = channels::unbounded(); @@ -322,7 +479,7 @@ fn create_plugin_thread_with_pty_receiver( // the plugin cache } }; - (to_plugin, pty_receiver, Box::new(teardown)) + (to_plugin, pty_receiver, screen_receiver, Box::new(teardown)) } lazy_static! { @@ -344,6 +501,9 @@ pub fn load_new_plugin_from_hd() { // message (this is what the fixture plugin does) // we then listen on our mock screen receiver to make sure we got a PluginBytes instruction // that contains said render, and assert against it + let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(None); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -359,11 +519,15 @@ pub fn load_new_plugin_from_hd() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::PluginBytes, screen_receiver, - 2 + 2, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -403,8 +567,12 @@ pub fn load_new_plugin_from_hd() { #[test] #[ignore] pub fn plugin_workers() { + let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its + // destructor removes the directory let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(None); let plugin_should_float = Some(false); + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let plugin_title = Some("test_plugin".to_owned()); let run_plugin = RunPlugin { _allow_exec_host_cmd: false, @@ -418,11 +586,15 @@ pub fn plugin_workers() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::PluginBytes, screen_receiver, - 3 + 3, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -465,8 +637,12 @@ pub fn plugin_workers() { #[test] #[ignore] pub fn plugin_workers_persist_state() { + let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its + // destructor removes the directory let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(None); let plugin_should_float = Some(false); + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let plugin_title = Some("test_plugin".to_owned()); let run_plugin = RunPlugin { _allow_exec_host_cmd: false, @@ -480,11 +656,15 @@ pub fn plugin_workers_persist_state() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::PluginBytes, screen_receiver, - 5 + 5, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -603,6 +783,7 @@ pub fn switch_to_mode_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -619,11 +800,82 @@ pub fn switch_to_mode_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ChangeMode, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); + + let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); + let _ = plugin_thread_sender.send(PluginInstruction::Load( + plugin_should_float, + plugin_title, + run_plugin, + tab_index, + client_id, + size, + )); + let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( + None, + Some(client_id), + Event::Key(Key::Char('a')), // this triggers a SwitchToMode(Tab) command in the fixture + // plugin + )])); + std::thread::sleep(std::time::Duration::from_millis(100)); + screen_thread.join().unwrap(); // this might take a while if the cache is cold + teardown(); + let switch_to_mode_event = received_screen_instructions + .lock() + .unwrap() + .iter() + .find_map(|i| { + if let ScreenInstruction::ChangeMode(..) = i { + Some(i.clone()) + } else { + None + } + }) + .clone(); + assert_snapshot!(format!("{:#?}", switch_to_mode_event)); +} + +#[test] +#[ignore] +pub fn switch_to_mode_plugin_command_permission_denied() { + let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its + // destructor removes the directory + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, screen_receiver, mut teardown) = + create_plugin_thread(Some(plugin_host_folder)); + let plugin_should_float = Some(false); + let plugin_title = Some("test_plugin".to_owned()); + let run_plugin = RunPlugin { + _allow_exec_host_cmd: false, + location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)), + configuration: Default::default(), + }; + let tab_index = 1; + let client_id = 1; + let size = Size { + cols: 121, + rows: 20, + }; + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let screen_thread = deny_permissions_and_log_actions_in_thread!( + received_screen_instructions, + ScreenInstruction::ChangeMode, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -665,6 +917,7 @@ pub fn new_tabs_with_layout_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -681,11 +934,15 @@ pub fn new_tabs_with_layout_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::NewTab, screen_receiver, - 2 + 2, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -741,6 +998,7 @@ pub fn new_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -757,11 +1015,15 @@ pub fn new_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::NewTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -803,6 +1065,7 @@ pub fn go_to_next_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -819,11 +1082,15 @@ pub fn go_to_next_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::SwitchTabNext, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -864,6 +1131,7 @@ pub fn go_to_previous_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -880,11 +1148,15 @@ pub fn go_to_previous_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::SwitchTabPrev, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -925,6 +1197,7 @@ pub fn resize_focused_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -941,11 +1214,15 @@ pub fn resize_focused_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::Resize, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -986,6 +1263,7 @@ pub fn resize_focused_pane_with_direction_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1002,11 +1280,15 @@ pub fn resize_focused_pane_with_direction_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::Resize, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1047,6 +1329,7 @@ pub fn focus_next_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1063,11 +1346,15 @@ pub fn focus_next_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::FocusNextPane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1108,6 +1395,7 @@ pub fn focus_previous_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1124,11 +1412,15 @@ pub fn focus_previous_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::FocusPreviousPane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1169,6 +1461,7 @@ pub fn move_focus_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1185,11 +1478,15 @@ pub fn move_focus_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::MoveFocusLeft, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1230,6 +1527,7 @@ pub fn move_focus_or_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1246,11 +1544,15 @@ pub fn move_focus_or_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::MoveFocusLeftOrPreviousTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1291,6 +1593,7 @@ pub fn edit_scrollback_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1307,11 +1610,15 @@ pub fn edit_scrollback_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::EditScrollback, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1352,6 +1659,7 @@ pub fn write_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1368,11 +1676,15 @@ pub fn write_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::WriteCharacter, screen_receiver, - 1 + 1, + &PermissionType::WriteToStdin, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1413,6 +1725,7 @@ pub fn write_chars_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1429,11 +1742,15 @@ pub fn write_chars_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::WriteCharacter, screen_receiver, - 1 + 1, + &PermissionType::WriteToStdin, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1474,6 +1791,7 @@ pub fn toggle_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1490,11 +1808,15 @@ pub fn toggle_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ToggleTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1535,6 +1857,7 @@ pub fn move_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1551,11 +1874,15 @@ pub fn move_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::MovePane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1596,6 +1923,7 @@ pub fn move_pane_with_direction_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1612,11 +1940,15 @@ pub fn move_pane_with_direction_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::MovePaneLeft, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1657,6 +1989,7 @@ pub fn clear_screen_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1673,11 +2006,16 @@ pub fn clear_screen_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ClearScreen, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1689,6 +2027,7 @@ pub fn clear_screen_plugin_command() { client_id, size, )); + std::thread::sleep(std::time::Duration::from_millis(100)); let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( None, Some(client_id), @@ -1718,6 +2057,7 @@ pub fn scroll_up_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1734,11 +2074,16 @@ pub fn scroll_up_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ScrollUp, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1779,6 +2124,7 @@ pub fn scroll_down_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1795,11 +2141,15 @@ pub fn scroll_down_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ScrollDown, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1840,6 +2190,7 @@ pub fn scroll_to_top_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1856,11 +2207,15 @@ pub fn scroll_to_top_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ScrollToTop, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1901,6 +2256,7 @@ pub fn scroll_to_bottom_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1917,11 +2273,15 @@ pub fn scroll_to_bottom_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ScrollToBottom, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -1962,6 +2322,7 @@ pub fn page_scroll_up_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -1978,11 +2339,15 @@ pub fn page_scroll_up_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::PageScrollUp, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2023,6 +2388,7 @@ pub fn page_scroll_down_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2039,11 +2405,15 @@ pub fn page_scroll_down_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::PageScrollDown, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2084,6 +2454,7 @@ pub fn toggle_focus_fullscreen_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2100,11 +2471,15 @@ pub fn toggle_focus_fullscreen_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ToggleActiveTerminalFullscreen, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2145,6 +2520,7 @@ pub fn toggle_pane_frames_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2161,11 +2537,15 @@ pub fn toggle_pane_frames_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread_naked_variant!( + let screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( received_screen_instructions, ScreenInstruction::TogglePaneFrames, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2206,6 +2586,7 @@ pub fn toggle_pane_embed_or_eject_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2222,11 +2603,15 @@ pub fn toggle_pane_embed_or_eject_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::TogglePaneEmbedOrFloating, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2267,6 +2652,7 @@ pub fn undo_rename_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2283,11 +2669,15 @@ pub fn undo_rename_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::UndoRenamePane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2328,6 +2718,7 @@ pub fn close_focus_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2344,11 +2735,15 @@ pub fn close_focus_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::CloseFocusedPane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2389,6 +2784,7 @@ pub fn toggle_active_tab_sync_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2405,11 +2801,15 @@ pub fn toggle_active_tab_sync_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ToggleActiveSyncTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2450,6 +2850,7 @@ pub fn close_focused_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2466,11 +2867,15 @@ pub fn close_focused_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::CloseTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2511,6 +2916,7 @@ pub fn undo_rename_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2527,11 +2933,15 @@ pub fn undo_rename_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::UndoRenameTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2572,6 +2982,7 @@ pub fn previous_swap_layout_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2588,11 +2999,15 @@ pub fn previous_swap_layout_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::PreviousSwapLayout, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2633,6 +3048,7 @@ pub fn next_swap_layout_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2649,11 +3065,15 @@ pub fn next_swap_layout_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::NextSwapLayout, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2694,6 +3114,7 @@ pub fn go_to_tab_name_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2710,11 +3131,15 @@ pub fn go_to_tab_name_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::GoToTabName, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2755,6 +3180,7 @@ pub fn focus_or_create_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2771,11 +3197,15 @@ pub fn focus_or_create_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::GoToTabName, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2816,6 +3246,7 @@ pub fn go_to_tab() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2832,11 +3263,15 @@ pub fn go_to_tab() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::GoToTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2877,6 +3312,7 @@ pub fn start_or_reload_plugin() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -2893,11 +3329,15 @@ pub fn start_or_reload_plugin() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::StartOrReloadPluginPane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -2938,7 +3378,8 @@ pub fn quit_zellij_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, server_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, server_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_server_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -2954,12 +3395,23 @@ pub fn quit_zellij_plugin_command() { rows: 20, }; let received_server_instruction = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let server_thread = log_actions_in_thread!( received_server_instruction, ServerInstruction::ClientExit, server_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -2976,7 +3428,7 @@ pub fn quit_zellij_plugin_command() { Event::Key(Key::Char('8')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + server_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); let new_tab_event = received_server_instruction .lock() @@ -2999,7 +3451,8 @@ pub fn detach_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, server_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, server_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_server_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3015,12 +3468,23 @@ pub fn detach_plugin_command() { rows: 20, }; let received_server_instruction = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let server_thread = log_actions_in_thread!( received_server_instruction, ServerInstruction::DetachSession, server_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -3037,7 +3501,7 @@ pub fn detach_plugin_command() { Event::Key(Key::Char('l')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + server_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); let new_tab_event = received_server_instruction .lock() @@ -3060,7 +3524,8 @@ pub fn open_file_floating_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, pty_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, pty_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_pty_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3075,13 +3540,24 @@ pub fn open_file_floating_plugin_command() { cols: 121, rows: 20, }; - let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( - received_screen_instructions, + let received_pty_instructions = Arc::new(Mutex::new(vec![])); + let pty_thread = log_actions_in_thread!( + received_pty_instructions, PtyInstruction::SpawnTerminal, pty_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -3098,9 +3574,9 @@ pub fn open_file_floating_plugin_command() { Event::Key(Key::Ctrl('h')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + pty_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); - let new_tab_event = received_screen_instructions + let new_tab_event = received_pty_instructions .lock() .unwrap() .iter() @@ -3121,7 +3597,8 @@ pub fn open_file_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, pty_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, pty_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_pty_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3136,13 +3613,24 @@ pub fn open_file_plugin_command() { cols: 121, rows: 20, }; - let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( - received_screen_instructions, + let received_pty_instructions = Arc::new(Mutex::new(vec![])); + let pty_thread = log_actions_in_thread!( + received_pty_instructions, PtyInstruction::SpawnTerminal, pty_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -3159,9 +3647,9 @@ pub fn open_file_plugin_command() { Event::Key(Key::Ctrl('g')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + pty_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); - let new_tab_event = received_screen_instructions + let new_tab_event = received_pty_instructions .lock() .unwrap() .iter() @@ -3182,7 +3670,8 @@ pub fn open_file_with_line_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, pty_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, pty_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_pty_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3197,14 +3686,26 @@ pub fn open_file_with_line_plugin_command() { cols: 121, rows: 20, }; - let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( - received_screen_instructions, + let received_pty_instructions = Arc::new(Mutex::new(vec![])); + let pty_thread = log_actions_in_thread!( + received_pty_instructions, PtyInstruction::SpawnTerminal, pty_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); + let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( plugin_should_float, @@ -3220,9 +3721,9 @@ pub fn open_file_with_line_plugin_command() { Event::Key(Key::Ctrl('i')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + pty_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); - let new_tab_event = received_screen_instructions + let new_tab_event = received_pty_instructions .lock() .unwrap() .iter() @@ -3243,7 +3744,8 @@ pub fn open_file_with_line_floating_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, pty_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, pty_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_pty_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3258,13 +3760,24 @@ pub fn open_file_with_line_floating_plugin_command() { cols: 121, rows: 20, }; - let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( - received_screen_instructions, + let received_pty_instructions = Arc::new(Mutex::new(vec![])); + let pty_thread = log_actions_in_thread!( + received_pty_instructions, PtyInstruction::SpawnTerminal, pty_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -3281,9 +3794,9 @@ pub fn open_file_with_line_floating_plugin_command() { Event::Key(Key::Ctrl('j')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + pty_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); - let new_tab_event = received_screen_instructions + let new_tab_event = received_pty_instructions .lock() .unwrap() .iter() @@ -3304,7 +3817,8 @@ pub fn open_terminal_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, pty_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, pty_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_pty_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3319,13 +3833,24 @@ pub fn open_terminal_plugin_command() { cols: 121, rows: 20, }; - let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( - received_screen_instructions, + let received_pty_instructions = Arc::new(Mutex::new(vec![])); + let pty_thread = log_actions_in_thread!( + received_pty_instructions, PtyInstruction::SpawnTerminal, pty_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -3342,9 +3867,9 @@ pub fn open_terminal_plugin_command() { Event::Key(Key::Ctrl('k')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + pty_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); - let new_tab_event = received_screen_instructions + let new_tab_event = received_pty_instructions .lock() .unwrap() .iter() @@ -3365,7 +3890,8 @@ pub fn open_terminal_floating_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, pty_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, pty_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_pty_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3380,13 +3906,24 @@ pub fn open_terminal_floating_plugin_command() { cols: 121, rows: 20, }; - let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( - received_screen_instructions, + let received_pty_instructions = Arc::new(Mutex::new(vec![])); + let pty_thread = log_actions_in_thread!( + received_pty_instructions, PtyInstruction::SpawnTerminal, pty_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -3403,9 +3940,9 @@ pub fn open_terminal_floating_plugin_command() { Event::Key(Key::Ctrl('l')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + pty_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); - let new_tab_event = received_screen_instructions + let new_tab_event = received_pty_instructions .lock() .unwrap() .iter() @@ -3426,7 +3963,8 @@ pub fn open_command_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, pty_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, pty_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_pty_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3441,13 +3979,24 @@ pub fn open_command_pane_plugin_command() { cols: 121, rows: 20, }; - let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( - received_screen_instructions, + let received_pty_instructions = Arc::new(Mutex::new(vec![])); + let pty_thread = log_actions_in_thread!( + received_pty_instructions, PtyInstruction::SpawnTerminal, pty_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -3464,9 +4013,9 @@ pub fn open_command_pane_plugin_command() { Event::Key(Key::Ctrl('m')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + pty_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); - let new_tab_event = received_screen_instructions + let new_tab_event = received_pty_instructions .lock() .unwrap() .iter() @@ -3487,7 +4036,8 @@ pub fn open_command_pane_floating_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); - let (plugin_thread_sender, pty_receiver, mut teardown) = + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + let (plugin_thread_sender, pty_receiver, screen_receiver, mut teardown) = create_plugin_thread_with_pty_receiver(Some(plugin_host_folder)); let plugin_should_float = Some(false); let plugin_title = Some("test_plugin".to_owned()); @@ -3502,13 +4052,24 @@ pub fn open_command_pane_floating_plugin_command() { cols: 121, rows: 20, }; - let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( - received_screen_instructions, + let received_pty_instructions = Arc::new(Mutex::new(vec![])); + let pty_thread = log_actions_in_thread!( + received_pty_instructions, PtyInstruction::SpawnTerminal, pty_receiver, 1 ); + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let _screen_thread = grant_permissions_and_log_actions_in_thread_naked_variant!( + received_screen_instructions, + ScreenInstruction::Exit, + screen_receiver, + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id + ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); let _ = plugin_thread_sender.send(PluginInstruction::Load( @@ -3525,9 +4086,9 @@ pub fn open_command_pane_floating_plugin_command() { Event::Key(Key::Ctrl('n')), // this triggers the enent in the fixture plugin )])); std::thread::sleep(std::time::Duration::from_millis(100)); - screen_thread.join().unwrap(); // this might take a while if the cache is cold + pty_thread.join().unwrap(); // this might take a while if the cache is cold teardown(); - let new_tab_event = received_screen_instructions + let new_tab_event = received_pty_instructions .lock() .unwrap() .iter() @@ -3548,6 +4109,7 @@ pub fn switch_to_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -3564,11 +4126,15 @@ pub fn switch_to_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::GoToTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -3731,6 +4297,7 @@ pub fn close_terminal_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -3747,11 +4314,15 @@ pub fn close_terminal_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ClosePane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -3792,6 +4363,7 @@ pub fn close_plugin_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -3808,11 +4380,15 @@ pub fn close_plugin_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::ClosePane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -3853,6 +4429,7 @@ pub fn focus_terminal_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -3869,11 +4446,15 @@ pub fn focus_terminal_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::FocusPaneWithId, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -3914,6 +4495,7 @@ pub fn focus_plugin_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -3930,11 +4512,15 @@ pub fn focus_plugin_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::FocusPaneWithId, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -3975,6 +4561,7 @@ pub fn rename_terminal_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -3991,11 +4578,15 @@ pub fn rename_terminal_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::RenamePane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -4036,6 +4627,7 @@ pub fn rename_plugin_pane_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -4052,11 +4644,15 @@ pub fn rename_plugin_pane_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::RenamePane, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -4097,6 +4693,7 @@ pub fn rename_tab_plugin_command() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -4113,11 +4710,15 @@ pub fn rename_tab_plugin_command() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::RenameTab, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -4158,6 +4759,7 @@ pub fn send_configuration_to_plugins() { let temp_folder = tempdir().unwrap(); // placed explicitly in the test scope because its // destructor removes the directory let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); let (plugin_thread_sender, screen_receiver, mut teardown) = create_plugin_thread(Some(plugin_host_folder)); let plugin_should_float = Some(false); @@ -4183,11 +4785,15 @@ pub fn send_configuration_to_plugins() { rows: 20, }; let received_screen_instructions = Arc::new(Mutex::new(vec![])); - let screen_thread = log_actions_in_thread!( + let screen_thread = grant_permissions_and_log_actions_in_thread!( received_screen_instructions, ScreenInstruction::GoToTabName, screen_receiver, - 1 + 1, + &PermissionType::ChangeApplicationState, + cache_path, + plugin_thread_sender, + client_id ); let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); @@ -4224,3 +4830,226 @@ pub fn send_configuration_to_plugins() { .clone(); assert_snapshot!(format!("{:#?}", go_to_tab_event)); } + +#[test] +#[ignore] +pub fn request_plugin_permissions() { + let temp_folder = tempdir().unwrap(); + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let (plugin_thread_sender, screen_receiver, mut teardown) = + create_plugin_thread(Some(plugin_host_folder)); + let plugin_should_float = Some(false); + let plugin_title = Some("test_plugin".to_owned()); + let run_plugin = RunPlugin { + _allow_exec_host_cmd: false, + location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)), + configuration: Default::default(), + }; + let tab_index = 1; + let client_id = 1; + let size = Size { + cols: 121, + rows: 20, + }; + let received_screen_instructions = Arc::new(Mutex::new(vec![])); + let screen_thread = log_actions_in_thread!( + received_screen_instructions, + ScreenInstruction::RequestPluginPermissions, + screen_receiver, + 1 + ); + + let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); + let _ = plugin_thread_sender.send(PluginInstruction::Load( + plugin_should_float, + plugin_title, + run_plugin, + tab_index, + client_id, + size, + )); + let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( + None, + Some(client_id), + Event::Key(Key::Ctrl('1')), // this triggers the enent in the fixture plugin + )])); + std::thread::sleep(std::time::Duration::from_millis(100)); + screen_thread.join().unwrap(); // this might take a while if the cache is cold + teardown(); + let new_tab_event = received_screen_instructions + .lock() + .unwrap() + .iter() + .find_map(|i| { + if let ScreenInstruction::RequestPluginPermissions(_, plugin_permission) = i { + Some(plugin_permission.permissions.clone()) + } else { + None + } + }) + .clone(); + assert_snapshot!(format!("{:#?}", new_tab_event)); +} + +#[test] +#[ignore] +pub fn granted_permission_request_result() { + let temp_folder = tempdir().unwrap(); + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + + let (plugin_thread_sender, screen_receiver, mut teardown) = + create_plugin_thread(Some(plugin_host_folder)); + let plugin_should_float = Some(false); + let plugin_title = Some("test_plugin".to_owned()); + let run_plugin = RunPlugin { + _allow_exec_host_cmd: false, + location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)), + configuration: Default::default(), + }; + let tab_index = 1; + let client_id = 1; + let size = Size { + cols: 121, + rows: 20, + }; + + // here we create a fake screen thread that will send a PermissionStatus::Granted + // message for every permission request it gets + let screen_thread = std::thread::Builder::new() + .name("fake_screen_thread".to_string()) + .spawn({ + let cache_path = cache_path.clone(); + let plugin_thread_sender = plugin_thread_sender.clone(); + move || loop { + let (event, _err_ctx) = screen_receiver + .recv() + .expect("failed to receive event on channel"); + match event { + ScreenInstruction::RequestPluginPermissions(_, plugin_permission) => { + let _ = + plugin_thread_sender.send(PluginInstruction::PermissionRequestResult( + 0, + Some(client_id), + plugin_permission.permissions, + PermissionStatus::Granted, + Some(cache_path.clone()), + )); + break; + }, + ScreenInstruction::Exit => { + break; + }, + _ => {}, + } + } + }) + .unwrap(); + + let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); + let _ = plugin_thread_sender.send(PluginInstruction::Load( + plugin_should_float, + plugin_title, + run_plugin.clone(), + tab_index, + client_id, + size, + )); + let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( + None, + Some(client_id), + Event::Key(Key::Ctrl('1')), // this triggers the enent in the fixture plugin + )])); + screen_thread.join().unwrap(); + teardown(); + + let permission_cache = PermissionCache::from_path_or_default(Some(cache_path)); + let mut permissions = permission_cache + .get_permissions(run_plugin.location.to_string()) + .clone(); + let permissions = permissions.as_mut().map(|p| { + let mut permissions = p.clone(); + permissions.sort_unstable(); + permissions + }); + + assert_snapshot!(format!("{:#?}", permissions)); +} + +#[test] +#[ignore] +pub fn denied_permission_request_result() { + let temp_folder = tempdir().unwrap(); + let plugin_host_folder = PathBuf::from(temp_folder.path()); + let cache_path = plugin_host_folder.join("permissions_test.kdl"); + + let (plugin_thread_sender, screen_receiver, mut teardown) = + create_plugin_thread(Some(plugin_host_folder)); + let plugin_should_float = Some(false); + let plugin_title = Some("test_plugin".to_owned()); + let run_plugin = RunPlugin { + _allow_exec_host_cmd: false, + location: RunPluginLocation::File(PathBuf::from(&*PLUGIN_FIXTURE)), + configuration: Default::default(), + }; + let tab_index = 1; + let client_id = 1; + let size = Size { + cols: 121, + rows: 20, + }; + + // here we create a fake screen thread that will send a PermissionStatus::Granted + // message for every permission request it gets + let screen_thread = std::thread::Builder::new() + .name("fake_screen_thread".to_string()) + .spawn({ + let cache_path = cache_path.clone(); + let plugin_thread_sender = plugin_thread_sender.clone(); + move || loop { + let (event, _err_ctx) = screen_receiver + .recv() + .expect("failed to receive event on channel"); + match event { + ScreenInstruction::RequestPluginPermissions(_, plugin_permission) => { + let _ = + plugin_thread_sender.send(PluginInstruction::PermissionRequestResult( + 0, + Some(client_id), + plugin_permission.permissions, + PermissionStatus::Denied, + Some(cache_path.clone()), + )); + break; + }, + ScreenInstruction::Exit => { + break; + }, + _ => {}, + } + } + }) + .unwrap(); + + let _ = plugin_thread_sender.send(PluginInstruction::AddClient(client_id)); + let _ = plugin_thread_sender.send(PluginInstruction::Load( + plugin_should_float, + plugin_title, + run_plugin.clone(), + tab_index, + client_id, + size, + )); + let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( + None, + Some(client_id), + Event::Key(Key::Ctrl('1')), // this triggers the enent in the fixture plugin + )])); + screen_thread.join().unwrap(); + teardown(); + + let permission_cache = PermissionCache::from_path_or_default(Some(cache_path)); + let permissions = permission_cache.get_permissions(run_plugin.location.to_string()); + + assert_snapshot!(format!("{:#?}", permissions)); +} diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__denied_permission_request_result.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__denied_permission_request_result.snap new file mode 100644 index 00000000..d7dfeb16 --- /dev/null +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__denied_permission_request_result.snap @@ -0,0 +1,7 @@ +--- +source: zellij-server/src/plugins/./unit/plugin_tests.rs +expression: "format!(\"{:#?}\", permissions)" +--- +Some( + [], +) diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap new file mode 100644 index 00000000..beaa4adc --- /dev/null +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__granted_permission_request_result.snap @@ -0,0 +1,15 @@ +--- +source: zellij-server/src/plugins/./unit/plugin_tests.rs +assertion_line: 4864 +expression: "format!(\"{:#?}\", permissions)" +--- +Some( + [ + ReadApplicationState, + ChangeApplicationState, + OpenFiles, + RunCommands, + OpenTerminalsOrPlugins, + WriteToStdin, + ], +) diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__request_plugin_permissions.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__request_plugin_permissions.snap new file mode 100644 index 00000000..23fa6c22 --- /dev/null +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__request_plugin_permissions.snap @@ -0,0 +1,17 @@ +--- +source: zellij-server/src/plugins/./unit/plugin_tests.rs +assertion_line: 4767 +expression: "format!(\"{:#?}\", new_tab_event)" +--- +Some( + [ + ChangeApplicationState, + ReadApplicationState, + ReadApplicationState, + ChangeApplicationState, + OpenFiles, + RunCommands, + OpenTerminalsOrPlugins, + WriteToStdin, + ], +) diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__switch_to_mode_plugin_command_permission_denied.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__switch_to_mode_plugin_command_permission_denied.snap new file mode 100644 index 00000000..57afe877 --- /dev/null +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__switch_to_mode_plugin_command_permission_denied.snap @@ -0,0 +1,6 @@ +--- +source: zellij-server/src/plugins/./unit/plugin_tests.rs +assertion_line: 903 +expression: "format!(\"{:#?}\", switch_to_mode_event)" +--- +None diff --git a/zellij-server/src/plugins/wasm_bridge.rs b/zellij-server/src/plugins/wasm_bridge.rs index d6fcf1fc..5c3c7c0d 100644 --- a/zellij-server/src/plugins/wasm_bridge.rs +++ b/zellij-server/src/plugins/wasm_bridge.rs @@ -13,6 +13,8 @@ use std::{ }; use wasmer::{Instance, Module, Store, Value}; use zellij_utils::async_std::task::{self, JoinHandle}; +use zellij_utils::data::{PermissionStatus, PermissionType}; +use zellij_utils::input::permission::PermissionCache; use zellij_utils::notify_debouncer_full::{notify::RecommendedWatcher, Debouncer, FileIdMap}; use zellij_utils::plugin_api::event::ProtobufEvent; @@ -706,6 +708,44 @@ impl WasmBridge { }; } } + pub fn cache_plugin_permissions( + &mut self, + plugin_id: PluginId, + client_id: Option<ClientId>, + permissions: Vec<PermissionType>, + status: PermissionStatus, + cache_path: Option<PathBuf>, + ) -> Result<()> { + if let Some(running_plugin) = self + .plugin_map + .lock() + .unwrap() + .get_running_plugin(plugin_id, client_id) + { + let err_context = || format!("Failed to write plugin permission {plugin_id}"); + + let mut running_plugin = running_plugin.lock().unwrap(); + let permissions = if status == PermissionStatus::Granted { + permissions + } else { + vec![] + }; + + running_plugin + .plugin_env + .set_permissions(HashSet::from_iter(permissions.clone())); + + let mut permission_cache = PermissionCache::from_path_or_default(cache_path); + permission_cache.cache( + running_plugin.plugin_env.plugin.location.to_string(), + permissions, + ); + + permission_cache.write_to_file().with_context(err_context)?; + } + + Ok(()) + } } fn handle_plugin_successful_loading(senders: &ThreadSenders, plugin_id: PluginId) { @@ -728,6 +768,35 @@ fn handle_plugin_loading_failure( )); } +// TODO: move to permissions? +fn check_event_permission( + plugin_env: &PluginEnv, + event: &Event, +) -> (PermissionStatus, Option<PermissionType>) { + if plugin_env.plugin.is_builtin() { + // built-in plugins can do all the things because they're part of the application and + // there's no use to deny them anything + return (PermissionStatus::Granted, None); + } + let permission = match event { + Event::ModeUpdate(..) + | Event::TabUpdate(..) + | Event::PaneUpdate(..) + | Event::CopyToClipboard(..) + | Event::SystemClipboardFailure + | Event::InputReceived => PermissionType::ReadApplicationState, + _ => return (PermissionStatus::Granted, None), + }; + + if let Some(permissions) = plugin_env.permissions.lock().unwrap().as_ref() { + if permissions.contains(&permission) { + return (PermissionStatus::Granted, None); + } + } + + (PermissionStatus::Denied, Some(permission)) +} + pub fn apply_event_to_plugin( plugin_id: PluginId, client_id: ClientId, @@ -739,35 +808,48 @@ pub fn apply_event_to_plugin( plugin_bytes: &mut Vec<(PluginId, ClientId, Vec<u8>)>, ) -> Result<()> { let err_context = || format!("Failed to apply event to plugin {plugin_id}"); - let protobuf_event: ProtobufEvent = event - .clone() - .try_into() - .map_err(|e| anyhow!("Failed to convert to protobuf: {:?}", e))?; - let update = instance - .exports - .get_function("update") - .with_context(err_context)?; - wasi_write_object(&plugin_env.wasi_env, &protobuf_event.encode_to_vec()) - .with_context(err_context)?; - let update_return = update.call(&[]).with_context(err_context)?; - let should_render = match update_return.get(0) { - Some(Value::I32(n)) => *n == 1, - _ => false, - }; - - if rows > 0 && columns > 0 && should_render { - let rendered_bytes = instance - .exports - .get_function("render") - .map_err(anyError::new) - .and_then(|render| { - render - .call(&[Value::I32(rows as i32), Value::I32(columns as i32)]) + match check_event_permission(plugin_env, event) { + (PermissionStatus::Granted, _) => { + let protobuf_event: ProtobufEvent = event + .clone() + .try_into() + .map_err(|e| anyhow!("Failed to convert to protobuf: {:?}", e))?; + let update = instance + .exports + .get_function("update") + .with_context(err_context)?; + wasi_write_object(&plugin_env.wasi_env, &protobuf_event.encode_to_vec()) + .with_context(err_context)?; + let update_return = update.call(&[]).with_context(err_context)?; + let should_render = match update_return.get(0) { + Some(Value::I32(n)) => *n == 1, + _ => false, + }; + if rows > 0 && columns > 0 && should_render { + let rendered_bytes = instance + .exports + .get_function("render") .map_err(anyError::new) - }) - .and_then(|_| wasi_read_string(&plugin_env.wasi_env)) - .with_context(err_context)?; - plugin_bytes.push((plugin_id, client_id, rendered_bytes.as_bytes().to_vec())); + .and_then(|render| { + render + .call(&[Value::I32(rows as i32), Value::I32(columns as i32)]) + .map_err(anyError::new) + }) + .and_then(|_| wasi_read_string(&plugin_env.wasi_env)) + .with_context(err_context)?; + plugin_bytes.push((plugin_id, client_id, rendered_bytes.as_bytes().to_vec())); + } + }, + (PermissionStatus::Denied, permission) => { + log::error!( + "PluginId '{}' permission '{}' is not allowed - Event '{:?}' denied", + plugin_id, + permission + .map(|p| p.to_string()) + .unwrap_or("UNKNOWN".to_owned()), + EventType::from_str(&event.to_string()).with_context(err_context)? + ); + }, } Ok(()) } diff --git a/zellij-server/src/plugins/zellij_exports.rs b/zellij-server/src/plugins/zellij_exports.rs index 275de13e..f2effa19 100644 --- a/zellij-server/src/plugins/zellij_exports.rs +++ b/zellij-server/src/plugins/zellij_exports.rs @@ -8,12 +8,15 @@ use std::{ collections::{BTreeMap, HashSet}, path::PathBuf, process, + str::FromStr, sync::{Arc, Mutex}, thread, time::{Duration, Instant}, }; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; +use zellij_utils::data::{CommandType, PermissionStatus, PermissionType, PluginPermission}; +use zellij_utils::input::permission::PermissionCache; use url::Url; @@ -86,118 +89,134 @@ impl ForeignFunctionEnv { } fn host_run_plugin_command(env: &ForeignFunctionEnv) { + let err_context = || format!("failed to run plugin command {}", env.plugin_env.name()); wasi_read_bytes(&env.plugin_env.wasi_env) .and_then(|bytes| { let command: ProtobufPluginCommand = ProtobufPluginCommand::decode(bytes.as_slice())?; let command: PluginCommand = command .try_into() .map_err(|e| anyhow!("failed to convert serialized command: {}", e))?; - match command { - PluginCommand::Subscribe(event_list) => subscribe(env, event_list)?, - PluginCommand::Unsubscribe(event_list) => unsubscribe(env, event_list)?, - PluginCommand::SetSelectable(selectable) => set_selectable(env, selectable), - PluginCommand::GetPluginIds => get_plugin_ids(env), - PluginCommand::GetZellijVersion => get_zellij_version(env), - PluginCommand::OpenFile(file_to_open) => open_file(env, file_to_open), - PluginCommand::OpenFileFloating(file_to_open) => { - open_file_floating(env, file_to_open) + match check_command_permission(&env.plugin_env, &command) { + (PermissionStatus::Granted, _) => match command { + PluginCommand::Subscribe(event_list) => subscribe(env, event_list)?, + PluginCommand::Unsubscribe(event_list) => unsubscribe(env, event_list)?, + PluginCommand::SetSelectable(selectable) => set_selectable(env, selectable), + PluginCommand::GetPluginIds => get_plugin_ids(env), + PluginCommand::GetZellijVersion => get_zellij_version(env), + PluginCommand::OpenFile(file_to_open) => open_file(env, file_to_open), + PluginCommand::OpenFileFloating(file_to_open) => { + open_file_floating(env, file_to_open) + }, + PluginCommand::OpenTerminal(cwd) => open_terminal(env, cwd.path.try_into()?), + PluginCommand::OpenTerminalFloating(cwd) => { + open_terminal_floating(env, cwd.path.try_into()?) + }, + PluginCommand::OpenCommandPane(command_to_run) => { + open_command_pane(env, command_to_run) + }, + PluginCommand::OpenCommandPaneFloating(command_to_run) => { + open_command_pane_floating(env, command_to_run) + }, + PluginCommand::SwitchTabTo(tab_index) => switch_tab_to(env, tab_index), + PluginCommand::SetTimeout(seconds) => set_timeout(env, seconds), + PluginCommand::ExecCmd(command_line) => exec_cmd(env, command_line), + PluginCommand::PostMessageTo(plugin_message) => { + post_message_to(env, plugin_message)? + }, + PluginCommand::PostMessageToPlugin(plugin_message) => { + post_message_to_plugin(env, plugin_message)? + }, + PluginCommand::HideSelf => hide_self(env)?, + PluginCommand::ShowSelf(should_float_if_hidden) => { + show_self(env, should_float_if_hidden) + }, + PluginCommand::SwitchToMode(input_mode) => { + switch_to_mode(env, input_mode.try_into()?) + }, + PluginCommand::NewTabsWithLayout(raw_layout) => { + new_tabs_with_layout(env, &raw_layout)? + }, + PluginCommand::NewTab => new_tab(env), + PluginCommand::GoToNextTab => go_to_next_tab(env), + PluginCommand::GoToPreviousTab => go_to_previous_tab(env), + PluginCommand::Resize(resize_payload) => resize(env, resize_payload), + PluginCommand::ResizeWithDirection(resize_strategy) => { + resize_with_direction(env, resize_strategy) + }, + PluginCommand::FocusNextPane => focus_next_pane(env), + PluginCommand::FocusPreviousPane => focus_previous_pane(env), + PluginCommand::MoveFocus(direction) => move_focus(env, direction), + PluginCommand::MoveFocusOrTab(direction) => move_focus_or_tab(env, direction), + PluginCommand::Detach => detach(env), + PluginCommand::EditScrollback => edit_scrollback(env), + PluginCommand::Write(bytes) => write(env, bytes), + PluginCommand::WriteChars(chars) => write_chars(env, chars), + PluginCommand::ToggleTab => toggle_tab(env), + PluginCommand::MovePane => move_pane(env), + PluginCommand::MovePaneWithDirection(direction) => { + move_pane_with_direction(env, direction) + }, + PluginCommand::ClearScreen => clear_screen(env), + PluginCommand::ScrollUp => scroll_up(env), + PluginCommand::ScrollDown => scroll_down(env), + PluginCommand::ScrollToTop => scroll_to_top(env), + PluginCommand::ScrollToBottom => scroll_to_bottom(env), + PluginCommand::PageScrollUp => page_scroll_up(env), + PluginCommand::PageScrollDown => page_scroll_down(env), + PluginCommand::ToggleFocusFullscreen => toggle_focus_fullscreen(env), + PluginCommand::TogglePaneFrames => toggle_pane_frames(env), + PluginCommand::TogglePaneEmbedOrEject => toggle_pane_embed_or_eject(env), + PluginCommand::UndoRenamePane => undo_rename_pane(env), + PluginCommand::CloseFocus => close_focus(env), + PluginCommand::ToggleActiveTabSync => toggle_active_tab_sync(env), + PluginCommand::CloseFocusedTab => close_focused_tab(env), + PluginCommand::UndoRenameTab => undo_rename_tab(env), + PluginCommand::QuitZellij => quit_zellij(env), + PluginCommand::PreviousSwapLayout => previous_swap_layout(env), + PluginCommand::NextSwapLayout => next_swap_layout(env), + PluginCommand::GoToTabName(tab_name) => go_to_tab_name(env, tab_name), + PluginCommand::FocusOrCreateTab(tab_name) => focus_or_create_tab(env, tab_name), + PluginCommand::GoToTab(tab_index) => go_to_tab(env, tab_index), + PluginCommand::StartOrReloadPlugin(plugin_url) => { + start_or_reload_plugin(env, &plugin_url)? + }, + PluginCommand::CloseTerminalPane(terminal_pane_id) => { + close_terminal_pane(env, terminal_pane_id) + }, + PluginCommand::ClosePluginPane(plugin_pane_id) => { + close_plugin_pane(env, plugin_pane_id) + }, + PluginCommand::FocusTerminalPane(terminal_pane_id, should_float_if_hidden) => { + focus_terminal_pane(env, terminal_pane_id, should_float_if_hidden) + }, + PluginCommand::FocusPluginPane(plugin_pane_id, should_float_if_hidden) => { + focus_plugin_pane(env, plugin_pane_id, should_float_if_hidden) + }, + PluginCommand::RenameTerminalPane(terminal_pane_id, new_name) => { + rename_terminal_pane(env, terminal_pane_id, &new_name) + }, + PluginCommand::RenamePluginPane(plugin_pane_id, new_name) => { + rename_plugin_pane(env, plugin_pane_id, &new_name) + }, + PluginCommand::RenameTab(tab_index, new_name) => { + rename_tab(env, tab_index, &new_name) + }, + PluginCommand::ReportPanic(crash_payload) => report_panic(env, &crash_payload), + PluginCommand::RequestPluginPermissions(permissions) => { + request_permission(env, permissions)? + }, }, - PluginCommand::OpenTerminal(cwd) => open_terminal(env, cwd.path.try_into()?), - PluginCommand::OpenTerminalFloating(cwd) => { - open_terminal_floating(env, cwd.path.try_into()?) + (PermissionStatus::Denied, permission) => { + log::error!( + "Plugin '{}' permission '{}' denied - Command '{:?}' denied", + env.plugin_env.name(), + permission + .map(|p| p.to_string()) + .unwrap_or("UNKNOWN".to_owned()), + CommandType::from_str(&command.to_string()).with_context(err_context)? + ); }, - PluginCommand::OpenCommandPane(command_to_run) => { - open_command_pane(env, command_to_run) - }, - PluginCommand::OpenCommandPaneFloating(command_to_run) => { - open_command_pane_floating(env, command_to_run) - }, - PluginCommand::SwitchTabTo(tab_index) => switch_tab_to(env, tab_index), - PluginCommand::SetTimeout(seconds) => set_timeout(env, seconds), - PluginCommand::ExecCmd(command_line) => exec_cmd(env, command_line), - PluginCommand::PostMessageTo(plugin_message) => { - post_message_to(env, plugin_message)? - }, - PluginCommand::PostMessageToPlugin(plugin_message) => { - post_message_to_plugin(env, plugin_message)? - }, - PluginCommand::HideSelf => hide_self(env)?, - PluginCommand::ShowSelf(should_float_if_hidden) => { - show_self(env, should_float_if_hidden) - }, - PluginCommand::SwitchToMode(input_mode) => { - switch_to_mode(env, input_mode.try_into()?) - }, - PluginCommand::NewTabsWithLayout(raw_layout) => { - new_tabs_with_layout(env, &raw_layout)? - }, - PluginCommand::NewTab => new_tab(env), - PluginCommand::GoToNextTab => go_to_next_tab(env), - PluginCommand::GoToPreviousTab => go_to_previous_tab(env), - PluginCommand::Resize(resize_payload) => resize(env, resize_payload), - PluginCommand::ResizeWithDirection(resize_strategy) => { - resize_with_direction(env, resize_strategy) - }, - PluginCommand::FocusNextPane => focus_next_pane(env), - PluginCommand::FocusPreviousPane => focus_previous_pane(env), - PluginCommand::MoveFocus(direction) => move_focus(env, direction), - PluginCommand::MoveFocusOrTab(direction) => move_focus_or_tab(env, direction), - PluginCommand::Detach => detach(env), - PluginCommand::EditScrollback => edit_scrollback(env), - PluginCommand::Write(bytes) => write(env, bytes), - PluginCommand::WriteChars(chars) => write_chars(env, chars), - PluginCommand::ToggleTab => toggle_tab(env), - PluginCommand::MovePane => move_pane(env), - PluginCommand::MovePaneWithDirection(direction) => { - move_pane_with_direction(env, direction) - }, - PluginCommand::ClearScreen => clear_screen(env), - PluginCommand::ScrollUp => scroll_up(env), - PluginCommand::ScrollDown => scroll_down(env), - PluginCommand::ScrollToTop => scroll_to_top(env), - PluginCommand::ScrollToBottom => scroll_to_bottom(env), - PluginCommand::PageScrollUp => page_scroll_up(env), - PluginCommand::PageScrollDown => page_scroll_down(env), - PluginCommand::ToggleFocusFullscreen => toggle_focus_fullscreen(env), - PluginCommand::TogglePaneFrames => toggle_pane_frames(env), - PluginCommand::TogglePaneEmbedOrEject => toggle_pane_embed_or_eject(env), - PluginCommand::UndoRenamePane => undo_rename_pane(env), - PluginCommand::CloseFocus => close_focus(env), - PluginCommand::ToggleActiveTabSync => toggle_active_tab_sync(env), - PluginCommand::CloseFocusedTab => close_focused_tab(env), - PluginCommand::UndoRenameTab => undo_rename_tab(env), - PluginCommand::QuitZellij => quit_zellij(env), - PluginCommand::PreviousSwapLayout => previous_swap_layout(env), - PluginCommand::NextSwapLayout => next_swap_layout(env), - PluginCommand::GoToTabName(tab_name) => go_to_tab_name(env, tab_name), - PluginCommand::FocusOrCreateTab(tab_name) => focus_or_create_tab(env, tab_name), - PluginCommand::GoToTab(tab_index) => go_to_tab(env, tab_index), - PluginCommand::StartOrReloadPlugin(plugin_url) => { - start_or_reload_plugin(env, &plugin_url)? - }, - PluginCommand::CloseTerminalPane(terminal_pane_id) => { - close_terminal_pane(env, terminal_pane_id) - }, - PluginCommand::ClosePluginPane(plugin_pane_id) => { - close_plugin_pane(env, plugin_pane_id) - }, - PluginCommand::FocusTerminalPane(terminal_pane_id, should_float_if_hidden) => { - focus_terminal_pane(env, terminal_pane_id, should_float_if_hidden) - }, - PluginCommand::FocusPluginPane(plugin_pane_id, should_float_if_hidden) => { - focus_plugin_pane(env, plugin_pane_id, should_float_if_hidden) - }, - PluginCommand::RenameTerminalPane(terminal_pane_id, new_name) => { - rename_terminal_pane(env, terminal_pane_id, &new_name) - }, - PluginCommand::RenamePluginPane(plugin_pane_id, new_name) => { - rename_plugin_pane(env, plugin_pane_id, &new_name) - }, - PluginCommand::RenameTab(tab_index, new_name) => { - rename_tab(env, tab_index, &new_name) - }, - PluginCommand::ReportPanic(crash_payload) => report_panic(env, &crash_payload), - } + }; Ok(()) }) .with_context(|| format!("failed to run plugin command {}", env.plugin_env.name())) @@ -255,6 +274,30 @@ fn set_selectable(env: &ForeignFunctionEnv, selectable: bool) { } } +fn request_permission(env: &ForeignFunctionEnv, permissions: Vec<PermissionType>) -> Result<()> { + if PermissionCache::from_path_or_default(None) + .check_permissions(env.plugin_env.plugin.location.to_string(), &permissions) + { + return env + .plugin_env + .senders + .send_to_plugin(PluginInstruction::PermissionRequestResult( + env.plugin_env.plugin_id, + Some(env.plugin_env.client_id), + permissions.to_vec(), + PermissionStatus::Granted, + None, + )); + } + + env.plugin_env + .senders + .send_to_screen(ScreenInstruction::RequestPluginPermissions( + env.plugin_env.plugin_id, + PluginPermission::new(env.plugin_env.plugin.location.to_string(), permissions), + )) +} + fn get_plugin_ids(env: &ForeignFunctionEnv) { let ids = PluginIds { plugin_id: env.plugin_env.plugin_id, @@ -1001,3 +1044,81 @@ pub fn wasi_read_bytes(wasi_env: &WasiEnv) -> Result<Vec<u8>> { .and_then(|string| serde_json::from_str(&string).map_err(anyError::new)) .with_context(|| format!("failed to deserialize object from WASI env '{wasi_env:?}'")) } + +// TODO: move to permissions? +fn check_command_permission( + plugin_env: &PluginEnv, + command: &PluginCommand, +) -> (PermissionStatus, Option<PermissionType>) { + if plugin_env.plugin.is_builtin() { + // built-in plugins can do all the things because they're part of the application and + // there's no use to deny them anything + return (PermissionStatus::Granted, None); + } + let permission = match command { + PluginCommand::OpenFile(..) | PluginCommand::OpenFileFloating(..) => { + PermissionType::OpenFiles + }, + PluginCommand::OpenTerminal(..) + | PluginCommand::StartOrReloadPlugin(..) + | PluginCommand::OpenTerminalFloating(..) => PermissionType::OpenTerminalsOrPlugins, + PluginCommand::OpenCommandPane(..) + | PluginCommand::OpenCommandPaneFloating(..) + | PluginCommand::ExecCmd(..) => PermissionType::RunCommands, + PluginCommand::Write(..) | PluginCommand::WriteChars(..) => PermissionType::WriteToStdin, + PluginCommand::SwitchTabTo(..) + | PluginCommand::SwitchToMode(..) + | PluginCommand::NewTabsWithLayout(..) + | PluginCommand::NewTab + | PluginCommand::GoToNextTab + | PluginCommand::GoToPreviousTab + | PluginCommand::Resize(..) + | PluginCommand::ResizeWithDirection(..) + | PluginCommand::FocusNextPane + | PluginCommand::MoveFocus(..) + | PluginCommand::MoveFocusOrTab(..) + | PluginCommand::Detach + | PluginCommand::EditScrollback + | PluginCommand::ToggleTab + | PluginCommand::MovePane + | PluginCommand::MovePaneWithDirection(..) + | PluginCommand::ClearScreen + | PluginCommand::ScrollUp + | PluginCommand::ScrollDown + | PluginCommand::ScrollToTop + | PluginCommand::ScrollToBottom + | PluginCommand::PageScrollUp + | PluginCommand::PageScrollDown + | PluginCommand::ToggleFocusFullscreen + | PluginCommand::TogglePaneFrames + | PluginCommand::TogglePaneEmbedOrEject + | PluginCommand::UndoRenamePane + | PluginCommand::CloseFocus + | PluginCommand::ToggleActiveTabSync + | PluginCommand::CloseFocusedTab + | PluginCommand::UndoRenameTab + | PluginCommand::QuitZellij + | PluginCommand::PreviousSwapLayout + | PluginCommand::NextSwapLayout + | PluginCommand::GoToTabName(..) + | PluginCommand::FocusOrCreateTab(..) + | PluginCommand::GoToTab(..) + | PluginCommand::CloseTerminalPane(..) + | PluginCommand::ClosePluginPane(..) + | PluginCommand::FocusTerminalPane(..) + | PluginCommand::FocusPluginPane(..) + | PluginCommand::RenameTerminalPane(..) + | PluginCommand::RenamePluginPane(..) + | PluginCommand::RenameTab(..) => PermissionType::ChangeApplicationState, + _ => return (PermissionStatus::Granted, None), + }; + + log::info!("plugin permissions: {:?}", plugin_env.permissions); + if let Some(permissions) = plugin_env.permissions.lock().unwrap().as_ref() { + if permissions.contains(&permission) { + return (PermissionStatus::Granted, None); + } + } + + (PermissionStatus::Denied, Some(permission)) +} |
