11use std:: { collections:: HashMap , sync:: Arc } ;
22
3+ #[ cfg( feature = "gnome" ) ]
34use base64:: Engine ;
45use oo7:: { Secret , crypto, dbus} ;
56use zbus:: zvariant:: { ObjectPath , Optional , Value } ;
67
7- use crate :: {
8- gnome:: {
9- prompter:: { PromptType , Properties , Reply } ,
10- secret_exchange,
11- } ,
12- service:: Service ,
8+ #[ cfg( feature = "gnome" ) ]
9+ use crate :: gnome:: {
10+ prompter:: { PromptType , Properties , Reply } ,
11+ secret_exchange,
1312} ;
13+ use crate :: service:: Service ;
1414
1515/// Helper to create a peer-to-peer connection pair using Unix socket
1616async fn create_p2p_connection ( )
@@ -40,6 +40,7 @@ pub(crate) struct TestServiceSetup {
4040 pub server_public_key : Option < oo7:: Key > ,
4141 pub keyring_secret : Option < oo7:: Secret > ,
4242 pub aes_key : Option < Arc < oo7:: Key > > ,
43+ #[ cfg( feature = "gnome" ) ]
4344 pub mock_prompter : MockPrompterService ,
4445}
4546
@@ -71,12 +72,14 @@ impl TestServiceSetup {
7172 let server = Service :: run_with_connection ( server_conn. clone ( ) , secret. clone ( ) ) . await ?;
7273
7374 // Create and serve the mock prompter
74- let mock_prompter = MockPrompterService :: new ( ) ;
75- client_conn
76- . object_server ( )
77- . at ( "/org/gnome/keyring/Prompter" , mock_prompter. clone ( ) )
78- . await ?;
79-
75+ #[ cfg( feature = "gnome" ) ]
76+ {
77+ let mock_prompter = MockPrompterService :: new ( ) ;
78+ client_conn
79+ . object_server ( )
80+ . at ( "/org/gnome/keyring/Prompter" , mock_prompter. clone ( ) )
81+ . await ?;
82+ } ;
8083 // Give the server a moment to fully initialize
8184 tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
8285
@@ -96,6 +99,7 @@ impl TestServiceSetup {
9699 collections,
97100 server_public_key,
98101 aes_key : None ,
102+ #[ cfg( feature = "gnome" ) ]
99103 mock_prompter,
100104 } )
101105 }
@@ -114,11 +118,14 @@ impl TestServiceSetup {
114118 let server = Service :: run_with_connection ( server_conn. clone ( ) , secret. clone ( ) ) . await ?;
115119
116120 // Create and serve the mock prompter
117- let mock_prompter = MockPrompterService :: new ( ) ;
118- client_conn
119- . object_server ( )
120- . at ( "/org/gnome/keyring/Prompter" , mock_prompter. clone ( ) )
121- . await ?;
121+ #[ cfg( feature = "gnome" ) ]
122+ {
123+ let mock_prompter = MockPrompterService :: new ( ) ;
124+ client_conn
125+ . object_server ( )
126+ . at ( "/org/gnome/keyring/Prompter" , mock_prompter. clone ( ) )
127+ . await ?;
128+ } ;
122129
123130 // Give the server a moment to fully initialize
124131 tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
@@ -147,6 +154,7 @@ impl TestServiceSetup {
147154 collections,
148155 server_public_key,
149156 aes_key : Some ( Arc :: new ( aes_key) ) ,
157+ #[ cfg( feature = "gnome" ) ]
150158 mock_prompter,
151159 } )
152160 }
@@ -173,11 +181,14 @@ impl TestServiceSetup {
173181 let discovered = service. discover_keyrings ( secret. clone ( ) ) . await ?;
174182 service. initialize ( server_conn, discovered, false ) . await ?;
175183
176- let mock_prompter = MockPrompterService :: new ( ) ;
177- client_conn
178- . object_server ( )
179- . at ( "/org/gnome/keyring/Prompter" , mock_prompter. clone ( ) )
180- . await ?;
184+ #[ cfg( feature = "gnome" ) ]
185+ {
186+ let mock_prompter = MockPrompterService :: new ( ) ;
187+ client_conn
188+ . object_server ( )
189+ . at ( "/org/gnome/keyring/Prompter" , mock_prompter. clone ( ) )
190+ . await ?;
191+ } ;
181192
182193 tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 50 ) ) . await ;
183194
@@ -197,6 +208,7 @@ impl TestServiceSetup {
197208 collections,
198209 server_public_key,
199210 aes_key : None ,
211+ #[ cfg( feature = "gnome" ) ]
200212 mock_prompter,
201213 } )
202214 }
@@ -206,6 +218,7 @@ impl TestServiceSetup {
206218///
207219/// This simulates the GNOME System Prompter for testing without requiring
208220/// the actual GNOME keyring prompter service to be running.
221+ #[ cfg( feature = "gnome" ) ]
209222#[ derive( Debug , Clone ) ]
210223pub ( crate ) struct MockPrompterService {
211224 /// The password to use for unlock prompts (simulates user input)
@@ -216,6 +229,7 @@ pub(crate) struct MockPrompterService {
216229 password_queue : Arc < tokio:: sync:: Mutex < Vec < oo7:: Secret > > > ,
217230}
218231
232+ #[ cfg( feature = "gnome" ) ]
219233impl MockPrompterService {
220234 pub fn new ( ) -> Self {
221235 Self {
@@ -237,6 +251,7 @@ impl MockPrompterService {
237251 }
238252}
239253
254+ #[ cfg( feature = "gnome" ) ]
240255#[ zbus:: interface( name = "org.gnome.keyring.internal.Prompter" ) ]
241256impl MockPrompterService {
242257 async fn begin_prompting (
0 commit comments