11use binaryninja:: binary_view:: BinaryViewExt ;
2- use binaryninja:: collaboration:: {
3- has_collaboration_support, NoNameChangeset , Remote , RemoteFileType , RemoteProject ,
4- } ;
2+ use binaryninja:: collaboration:: { NoNameChangeset , Remote , RemoteFileType , RemoteProject } ;
53use binaryninja:: headless:: Session ;
4+ use binaryninja:: rc:: Ref ;
65use binaryninja:: symbol:: { SymbolBuilder , SymbolType } ;
76use rstest:: * ;
87use serial_test:: serial;
8+ use std:: env;
99use std:: path:: PathBuf ;
1010
11- #[ fixture]
12- #[ once]
13- fn session ( ) -> Session {
14- Session :: new ( ) . expect ( "Failed to initialize session" )
15- }
16-
17- // TODO: This cannot run in CI, as headless does not have collaboration, we should gate this.
1811// TODO: Why cant we create_project for the same project name? why does that fail.
19-
2012// TODO: Remote connection / disconnection is NOT thread safe, the core needs to lock on each.
2113// TODO: Because of this we run these tests serially, this isnt _really_ an issue for real code, as
2214// TODO: Real code shouldnt be trying to connect to the same remote on multiple threads.
@@ -28,6 +20,13 @@ fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, project_name: &str
2820 // TODO: have connected by the time this errors out. Maybe?
2921 let _ = remote. connect ( ) ;
3022 }
23+
24+ if let Ok ( home_dir) = env:: var ( "HOME" ) . or_else ( |_| env:: var ( "USERPROFILE" ) ) {
25+ eprintln ! ( "Current user directory: {}" , home_dir) ;
26+ } else {
27+ eprintln ! ( "Unable to determine the current user directory." ) ;
28+ }
29+
3130 let project = remote
3231 . create_project ( project_name, "Test project for test purposes" )
3332 . expect ( "Failed to create project" ) ;
@@ -56,15 +55,26 @@ fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, project_name: &str
5655 . expect ( "Failed to delete project" ) ;
5756}
5857
58+ /// Get the selected remote to test with.
59+ fn selected_remote ( ) -> Option < Ref < Remote > > {
60+ // If the user has initialized with a enterprise server we might already have an active remote.
61+ match binaryninja:: collaboration:: active_remote ( ) {
62+ Some ( remote) => Some ( remote) ,
63+ None => {
64+ let remotes = binaryninja:: collaboration:: known_remotes ( ) ;
65+ remotes. iter ( ) . next ( ) . map ( |r| r. clone ( ) )
66+ }
67+ }
68+ }
69+
5970#[ rstest]
6071#[ serial]
61- fn test_connection ( _session : & Session ) {
62- if !has_collaboration_support ( ) {
63- eprintln ! ( "No collaboration support, skipping test..." ) ;
72+ fn test_connection ( ) {
73+ let _session = Session :: new ( ) . expect ( "Failed to initialize session" ) ;
74+ let Some ( remote) = selected_remote ( ) else {
75+ eprintln ! ( "No known remotes, skipping test..." ) ;
6476 return ;
65- }
66- let remotes = binaryninja:: collaboration:: known_remotes ( ) ;
67- let remote = remotes. iter ( ) . next ( ) . expect ( "No known remotes!" ) ;
77+ } ;
6878 assert ! ( remote. connect( ) . is_ok( ) , "Failed to connect to remote" ) ;
6979 remote
7080 . disconnect ( )
@@ -74,13 +84,12 @@ fn test_connection(_session: &Session) {
7484
7585#[ rstest]
7686#[ serial]
77- fn test_project_creation ( _session : & Session ) {
78- if !has_collaboration_support ( ) {
79- eprintln ! ( "No collaboration support, skipping test..." ) ;
87+ fn test_project_creation ( ) {
88+ let _session = Session :: new ( ) . expect ( "Failed to initialize session" ) ;
89+ let Some ( remote) = selected_remote ( ) else {
90+ eprintln ! ( "No known remotes, skipping test..." ) ;
8091 return ;
81- }
82- let remotes = binaryninja:: collaboration:: known_remotes ( ) ;
83- let remote = remotes. iter ( ) . next ( ) . expect ( "No known remotes!" ) ;
92+ } ;
8493 temp_project_scope ( & remote, "test_creation" , |project| {
8594 // Create the file than verify it by opening and checking contents.
8695 let created_file = project
@@ -155,13 +164,12 @@ fn test_project_creation(_session: &Session) {
155164
156165#[ rstest]
157166#[ serial]
158- fn test_project_sync ( _session : & Session ) {
159- if !has_collaboration_support ( ) {
160- eprintln ! ( "No collaboration support, skipping test..." ) ;
167+ fn test_project_sync ( ) {
168+ let _session = Session :: new ( ) . expect ( "Failed to initialize session" ) ;
169+ let Some ( remote) = selected_remote ( ) else {
170+ eprintln ! ( "No known remotes, skipping test..." ) ;
161171 return ;
162- }
163- let remotes = binaryninja:: collaboration:: known_remotes ( ) ;
164- let remote = remotes. iter ( ) . next ( ) . expect ( "No known remotes!" ) ;
172+ } ;
165173 temp_project_scope ( & remote, "test_sync" , |project| {
166174 // Open a view so that we can upload it.
167175 let out_dir = env ! ( "OUT_DIR" ) . parse :: < PathBuf > ( ) . unwrap ( ) ;
0 commit comments