1
1
use std:: { io:: Write , process:: Stdio } ;
2
2
use tokio:: process:: Command ;
3
3
use tracing:: { instrument, trace, warn} ;
4
- use uv_redacted:: DisplaySafeUrlRef ;
4
+ use uv_redacted:: DisplaySafeUrl ;
5
5
use uv_warnings:: warn_user_once;
6
6
7
7
use crate :: credentials:: Credentials ;
@@ -36,11 +36,7 @@ impl KeyringProvider {
36
36
/// Returns [`None`] if no password was found for the username or if any errors
37
37
/// are encountered in the keyring backend.
38
38
#[ instrument( skip_all, fields( url = % url. to_string( ) , username) ) ]
39
- pub async fn fetch (
40
- & self ,
41
- url : DisplaySafeUrlRef < ' _ > ,
42
- username : Option < & str > ,
43
- ) -> Option < Credentials > {
39
+ pub async fn fetch ( & self , url : & DisplaySafeUrl , username : Option < & str > ) -> Option < Credentials > {
44
40
// Validate the request
45
41
debug_assert ! (
46
42
url. host_str( ) . is_some( ) ,
@@ -229,7 +225,7 @@ mod tests {
229
225
let keyring = KeyringProvider :: empty ( ) ;
230
226
// Panics due to debug assertion; returns `None` in production
231
227
let result = std:: panic:: AssertUnwindSafe (
232
- keyring. fetch ( DisplaySafeUrlRef :: from ( & url) , Some ( "user" ) ) ,
228
+ keyring. fetch ( DisplaySafeUrl :: ref_cast ( & url) , Some ( "user" ) ) ,
233
229
)
234
230
. catch_unwind ( )
235
231
. await ;
@@ -242,7 +238,7 @@ mod tests {
242
238
let keyring = KeyringProvider :: empty ( ) ;
243
239
// Panics due to debug assertion; returns `None` in production
244
240
let result = std:: panic:: AssertUnwindSafe (
245
- keyring. fetch ( DisplaySafeUrlRef :: from ( & url) , Some ( url. username ( ) ) ) ,
241
+ keyring. fetch ( DisplaySafeUrl :: ref_cast ( & url) , Some ( url. username ( ) ) ) ,
246
242
)
247
243
. catch_unwind ( )
248
244
. await ;
@@ -255,7 +251,7 @@ mod tests {
255
251
let keyring = KeyringProvider :: empty ( ) ;
256
252
// Panics due to debug assertion; returns `None` in production
257
253
let result = std:: panic:: AssertUnwindSafe (
258
- keyring. fetch ( DisplaySafeUrlRef :: from ( & url) , Some ( url. username ( ) ) ) ,
254
+ keyring. fetch ( DisplaySafeUrl :: ref_cast ( & url) , Some ( url. username ( ) ) ) ,
259
255
)
260
256
. catch_unwind ( )
261
257
. await ;
@@ -265,7 +261,7 @@ mod tests {
265
261
#[ tokio:: test]
266
262
async fn fetch_url_no_auth ( ) {
267
263
let url = Url :: parse ( "https://example.com" ) . unwrap ( ) ;
268
- let url = DisplaySafeUrlRef :: from ( & url) ;
264
+ let url = DisplaySafeUrl :: ref_cast ( & url) ;
269
265
let keyring = KeyringProvider :: empty ( ) ;
270
266
let credentials = keyring. fetch ( url, Some ( "user" ) ) ;
271
267
assert ! ( credentials. await . is_none( ) ) ;
@@ -277,7 +273,7 @@ mod tests {
277
273
let keyring = KeyringProvider :: dummy ( [ ( url. host_str ( ) . unwrap ( ) , "user" , "password" ) ] ) ;
278
274
assert_eq ! (
279
275
keyring
280
- . fetch( DisplaySafeUrlRef :: from ( & url) , Some ( "user" ) )
276
+ . fetch( DisplaySafeUrl :: ref_cast ( & url) , Some ( "user" ) )
281
277
. await ,
282
278
Some ( Credentials :: basic(
283
279
Some ( "user" . to_string( ) ) ,
@@ -287,7 +283,7 @@ mod tests {
287
283
assert_eq ! (
288
284
keyring
289
285
. fetch(
290
- DisplaySafeUrlRef :: from ( & url. join( "test" ) . unwrap( ) ) ,
286
+ DisplaySafeUrl :: ref_cast ( & url. join( "test" ) . unwrap( ) ) ,
291
287
Some ( "user" )
292
288
)
293
289
. await ,
@@ -303,7 +299,7 @@ mod tests {
303
299
let url = Url :: parse ( "https://example.com" ) . unwrap ( ) ;
304
300
let keyring = KeyringProvider :: dummy ( [ ( "other.com" , "user" , "password" ) ] ) ;
305
301
let credentials = keyring
306
- . fetch ( DisplaySafeUrlRef :: from ( & url) , Some ( "user" ) )
302
+ . fetch ( DisplaySafeUrl :: ref_cast ( & url) , Some ( "user" ) )
307
303
. await ;
308
304
assert_eq ! ( credentials, None ) ;
309
305
}
@@ -318,7 +314,7 @@ mod tests {
318
314
assert_eq ! (
319
315
keyring
320
316
. fetch(
321
- DisplaySafeUrlRef :: from ( & url. join( "foo" ) . unwrap( ) ) ,
317
+ DisplaySafeUrl :: ref_cast ( & url. join( "foo" ) . unwrap( ) ) ,
322
318
Some ( "user" )
323
319
)
324
320
. await ,
@@ -329,7 +325,7 @@ mod tests {
329
325
) ;
330
326
assert_eq ! (
331
327
keyring
332
- . fetch( DisplaySafeUrlRef :: from ( & url) , Some ( "user" ) )
328
+ . fetch( DisplaySafeUrl :: ref_cast ( & url) , Some ( "user" ) )
333
329
. await ,
334
330
Some ( Credentials :: basic(
335
331
Some ( "user" . to_string( ) ) ,
@@ -339,7 +335,7 @@ mod tests {
339
335
assert_eq ! (
340
336
keyring
341
337
. fetch(
342
- DisplaySafeUrlRef :: from ( & url. join( "bar" ) . unwrap( ) ) ,
338
+ DisplaySafeUrl :: ref_cast ( & url. join( "bar" ) . unwrap( ) ) ,
343
339
Some ( "user" )
344
340
)
345
341
. await ,
@@ -355,7 +351,7 @@ mod tests {
355
351
let url = Url :: parse ( "https://example.com" ) . unwrap ( ) ;
356
352
let keyring = KeyringProvider :: dummy ( [ ( url. host_str ( ) . unwrap ( ) , "user" , "password" ) ] ) ;
357
353
let credentials = keyring
358
- . fetch ( DisplaySafeUrlRef :: from ( & url) , Some ( "user" ) )
354
+ . fetch ( DisplaySafeUrl :: ref_cast ( & url) , Some ( "user" ) )
359
355
. await ;
360
356
assert_eq ! (
361
357
credentials,
@@ -370,7 +366,7 @@ mod tests {
370
366
async fn fetch_url_no_username ( ) {
371
367
let url = Url :: parse ( "https://example.com" ) . unwrap ( ) ;
372
368
let keyring = KeyringProvider :: dummy ( [ ( url. host_str ( ) . unwrap ( ) , "user" , "password" ) ] ) ;
373
- let credentials = keyring. fetch ( DisplaySafeUrlRef :: from ( & url) , None ) . await ;
369
+ let credentials = keyring. fetch ( DisplaySafeUrl :: ref_cast ( & url) , None ) . await ;
374
370
assert_eq ! (
375
371
credentials,
376
372
Some ( Credentials :: basic(
@@ -385,14 +381,14 @@ mod tests {
385
381
let url = Url :: parse ( "https://example.com" ) . unwrap ( ) ;
386
382
let keyring = KeyringProvider :: dummy ( [ ( url. host_str ( ) . unwrap ( ) , "foo" , "password" ) ] ) ;
387
383
let credentials = keyring
388
- . fetch ( DisplaySafeUrlRef :: from ( & url) , Some ( "bar" ) )
384
+ . fetch ( DisplaySafeUrl :: ref_cast ( & url) , Some ( "bar" ) )
389
385
. await ;
390
386
assert_eq ! ( credentials, None ) ;
391
387
392
388
// Still fails if we have `foo` in the URL itself
393
389
let url =
Url :: parse ( "https://[email protected] " ) . unwrap ( ) ;
394
390
let credentials = keyring
395
- . fetch ( DisplaySafeUrlRef :: from ( & url) , Some ( "bar" ) )
391
+ . fetch ( DisplaySafeUrl :: ref_cast ( & url) , Some ( "bar" ) )
396
392
. await ;
397
393
assert_eq ! ( credentials, None ) ;
398
394
}
0 commit comments