summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-01-25 02:19:29 -0500
committerMason Reed <mason@vector35.com>2025-01-25 02:19:29 -0500
commit26ed2cdfb13591c63a52e978ead5eae0b6acb0c4 (patch)
treeb9a6af3bdf15e2b1a46e5ad84ae05f7b722c6829
parente2bd9eae7b5d9eab93b59e481bfa2afbdf875dab (diff)
Fix collaboration support checks in rust unit tests
-rw-r--r--rust/src/collaboration.rs10
-rw-r--r--rust/tests/collaboration.rs20
2 files changed, 20 insertions, 10 deletions
diff --git a/rust/src/collaboration.rs b/rust/src/collaboration.rs
index 1dce8104..e173afaa 100644
--- a/rust/src/collaboration.rs
+++ b/rust/src/collaboration.rs
@@ -36,6 +36,16 @@ use crate::string::{BnStrCompatible, BnString};
// TODO: on what functions need to have been called prior? I feel like we should make the user have to pull
// TODO: the data because they have a greater understanding of where the function is being called from.
+/// Check whether the client has collaboration support.
+///
+/// Call this if you intend on providing divergent behavior, as otherwise you will likely
+/// crash calling collaboration APIs on unsupported builds of Binary Ninja.
+pub fn has_collaboration_support() -> bool {
+ let mut count = 0;
+ let value = unsafe { BNCollaborationGetRemotes(&mut count) };
+ !value.is_null()
+}
+
/// Get the single actively connected Remote (for ux simplification), if any
pub fn active_remote() -> Option<Ref<Remote>> {
let value = unsafe { BNCollaborationGetActiveRemote() };
diff --git a/rust/tests/collaboration.rs b/rust/tests/collaboration.rs
index 48da859a..7c2a2aae 100644
--- a/rust/tests/collaboration.rs
+++ b/rust/tests/collaboration.rs
@@ -1,5 +1,5 @@
use binaryninja::binary_view::BinaryViewExt;
-use binaryninja::collaboration::{NoNameChangeset, Remote, RemoteFileType, RemoteProject};
+use binaryninja::collaboration::{has_collaboration_support, NoNameChangeset, Remote, RemoteFileType, RemoteProject};
use binaryninja::headless::Session;
use binaryninja::symbol::{SymbolBuilder, SymbolType};
use rstest::*;
@@ -47,11 +47,11 @@ fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, cb: T) {
#[rstest]
fn test_connection(_session: &Session) {
- let remotes = binaryninja::collaboration::known_remotes();
- if remotes.is_empty() {
- eprintln!("No known remotes, skipping test...");
+ if !has_collaboration_support() {
+ eprintln!("No collaboration support, skipping test...");
return;
}
+ let remotes = binaryninja::collaboration::known_remotes();
let remote = remotes.iter().next().expect("No known remotes!");
assert!(remote.connect().is_ok(), "Failed to connect to remote");
remote
@@ -62,11 +62,11 @@ fn test_connection(_session: &Session) {
#[rstest]
fn test_project_creation(_session: &Session) {
- let remotes = binaryninja::collaboration::known_remotes();
- if remotes.is_empty() {
- eprintln!("No known remotes, skipping test...");
+ if !has_collaboration_support() {
+ eprintln!("No collaboration support, skipping test...");
return;
}
+ let remotes = binaryninja::collaboration::known_remotes();
let remote = remotes.iter().next().expect("No known remotes!");
temp_project_scope(&remote, |project| {
// Create the file than verify it by opening and checking contents.
@@ -142,11 +142,11 @@ fn test_project_creation(_session: &Session) {
#[rstest]
fn test_project_sync(_session: &Session) {
- let remotes = binaryninja::collaboration::known_remotes();
- if remotes.is_empty() {
- eprintln!("No known remotes, skipping test...");
+ if !has_collaboration_support() {
+ eprintln!("No collaboration support, skipping test...");
return;
}
+ let remotes = binaryninja::collaboration::known_remotes();
let remote = remotes.iter().next().expect("No known remotes!");
temp_project_scope(&remote, |project| {
// Open a view so that we can upload it.