An easy-to-host PDS on the ATProtocol, MacOS. Grandma-approved.

fmt: format code with clippy fixes and allow dead_code on http_client (MM-89)

authored by malpercio.dev and committed by

Tangled 111a155d d256b101

+103 -58
+1
crates/relay/src/app.rs
··· 77 77 pub struct AppState { 78 78 pub config: Arc<Config>, 79 79 pub db: sqlx::SqlitePool, 80 + #[allow(dead_code)] 80 81 pub http_client: Client, 81 82 } 82 83
+5 -6
crates/relay/src/db/mod.rs
··· 734 734 let pool = in_memory_pool().await; 735 735 run_migrations(&pool).await.unwrap(); 736 736 737 - let plan: Vec<(i64, i64, i64, String)> = sqlx::query_as( 738 - "EXPLAIN QUERY PLAN SELECT * FROM devices WHERE account_id = 'acct1'", 739 - ) 740 - .fetch_all(&pool) 741 - .await 742 - .unwrap(); 737 + let plan: Vec<(i64, i64, i64, String)> = 738 + sqlx::query_as("EXPLAIN QUERY PLAN SELECT * FROM devices WHERE account_id = 'acct1'") 739 + .fetch_all(&pool) 740 + .await 741 + .unwrap(); 743 742 744 743 let detail = plan 745 744 .iter()
+97 -52
crates/relay/src/routes/create_mobile_account.rs
··· 263 263 .inspect_err(|e| { 264 264 tracing::error!(error = %e, "failed to classify claim code status"); 265 265 }) 266 - .map_err(|_| { 267 - ApiError::new(ErrorCode::InternalError, "failed to create account") 268 - })?; 266 + .map_err(|_| ApiError::new(ErrorCode::InternalError, "failed to create account"))?; 269 267 270 268 return Err(match row { 271 269 Some((Some(_),)) => ApiError::new( 272 270 ErrorCode::ClaimCodeRedeemed, 273 271 "claim code has already been redeemed", 274 272 ), 275 - _ => ApiError::new( 276 - ErrorCode::NotFound, 277 - "claim code is invalid or has expired", 278 - ), 273 + _ => ApiError::new(ErrorCode::NotFound, "claim code is invalid or has expired"), 279 274 }); 280 275 } 281 276 ··· 359 354 ); 360 355 } 361 356 if msg.contains("pending_accounts.handle") { 362 - return ApiError::new( 363 - ErrorCode::HandleTaken, 364 - "this handle is already claimed", 365 - ); 357 + return ApiError::new(ErrorCode::HandleTaken, "this handle is already claimed"); 366 358 } 367 359 // Unknown unique constraint — log the name so it surfaces in traces. 368 360 tracing::error!( ··· 438 430 .unwrap(); 439 431 440 432 assert_eq!(response.status(), StatusCode::CREATED); 441 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 433 + let body = axum::body::to_bytes(response.into_body(), 4096) 434 + .await 435 + .unwrap(); 442 436 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 443 437 444 - assert!(json["accountId"].as_str().is_some(), "accountId must be present"); 445 - assert!(json["deviceId"].as_str().is_some(), "deviceId must be present"); 446 - assert!(json["deviceToken"].as_str().is_some(), "deviceToken must be present"); 447 - assert!(json["sessionToken"].as_str().is_some(), "sessionToken must be present"); 438 + assert!( 439 + json["accountId"].as_str().is_some(), 440 + "accountId must be present" 441 + ); 442 + assert!( 443 + json["deviceId"].as_str().is_some(), 444 + "deviceId must be present" 445 + ); 446 + assert!( 447 + json["deviceToken"].as_str().is_some(), 448 + "deviceToken must be present" 449 + ); 450 + assert!( 451 + json["sessionToken"].as_str().is_some(), 452 + "sessionToken must be present" 453 + ); 448 454 assert_eq!(json["nextStep"], "did_creation"); 449 455 } 450 456 ··· 458 464 .await 459 465 .unwrap(); 460 466 461 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 467 + let body = axum::body::to_bytes(response.into_body(), 4096) 468 + .await 469 + .unwrap(); 462 470 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 463 471 464 472 uuid::Uuid::parse_str(json["accountId"].as_str().unwrap()) ··· 477 485 .await 478 486 .unwrap(); 479 487 480 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 488 + let body = axum::body::to_bytes(response.into_body(), 4096) 489 + .await 490 + .unwrap(); 481 491 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 482 492 483 493 for field in ["deviceToken", "sessionToken"] { 484 494 let token = json[field].as_str().unwrap(); 485 495 assert!( 486 - token.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_'), 496 + token 497 + .chars() 498 + .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_'), 487 499 "{field} must be base64url without padding; got: {token}" 488 500 ); 489 501 assert_eq!( ··· 507 519 .unwrap(); 508 520 509 521 assert_eq!(response.status(), StatusCode::CREATED); 510 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 522 + let body = axum::body::to_bytes(response.into_body(), 4096) 523 + .await 524 + .unwrap(); 511 525 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 512 526 513 527 let account_id = json["accountId"].as_str().unwrap(); ··· 528 542 assert_eq!(code, claim_code); 529 543 530 544 // devices row 531 - let (dev_account_id, platform, public_key): (String, String, String) = sqlx::query_as( 532 - "SELECT account_id, platform, public_key FROM devices WHERE id = ?", 533 - ) 534 - .bind(device_id) 535 - .fetch_one(&db) 536 - .await 537 - .expect("devices row must exist"); 545 + let (dev_account_id, platform, public_key): (String, String, String) = 546 + sqlx::query_as("SELECT account_id, platform, public_key FROM devices WHERE id = ?") 547 + .bind(device_id) 548 + .fetch_one(&db) 549 + .await 550 + .expect("devices row must exist"); 538 551 539 552 assert_eq!(dev_account_id, account_id); 540 553 assert_eq!(platform, "ios"); ··· 571 584 .await 572 585 .unwrap(); 573 586 574 - assert!(redeemed_at.is_some(), "claim code must have redeemed_at set"); 587 + assert!( 588 + redeemed_at.is_some(), 589 + "claim code must have redeemed_at set" 590 + ); 575 591 } 576 592 577 593 #[tokio::test] ··· 588 604 .await 589 605 .unwrap(); 590 606 591 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 607 + let body = axum::body::to_bytes(response.into_body(), 4096) 608 + .await 609 + .unwrap(); 592 610 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 593 611 594 612 let device_id = json["deviceId"].as_str().unwrap(); 595 613 let account_id = json["accountId"].as_str().unwrap(); 596 614 597 615 // device token hash 598 - let device_token_bytes = 599 - URL_SAFE_NO_PAD.decode(json["deviceToken"].as_str().unwrap()).unwrap(); 616 + let device_token_bytes = URL_SAFE_NO_PAD 617 + .decode(json["deviceToken"].as_str().unwrap()) 618 + .unwrap(); 600 619 let expected_device_hash: String = Sha256::digest(&device_token_bytes) 601 620 .iter() 602 621 .map(|b| format!("{b:02x}")) ··· 608 627 .fetch_one(&db) 609 628 .await 610 629 .unwrap(); 611 - assert_eq!(stored_device_hash, expected_device_hash, "device_token_hash mismatch"); 630 + assert_eq!( 631 + stored_device_hash, expected_device_hash, 632 + "device_token_hash mismatch" 633 + ); 612 634 613 635 // session token hash 614 - let session_token_bytes = 615 - URL_SAFE_NO_PAD.decode(json["sessionToken"].as_str().unwrap()).unwrap(); 636 + let session_token_bytes = URL_SAFE_NO_PAD 637 + .decode(json["sessionToken"].as_str().unwrap()) 638 + .unwrap(); 616 639 let expected_session_hash: String = Sha256::digest(&session_token_bytes) 617 640 .iter() 618 641 .map(|b| format!("{b:02x}")) 619 642 .collect(); 620 643 621 - let (stored_session_hash,): (String,) = sqlx::query_as( 622 - "SELECT token_hash FROM pending_sessions WHERE account_id = ?", 623 - ) 624 - .bind(account_id) 625 - .fetch_one(&db) 626 - .await 627 - .unwrap(); 628 - assert_eq!(stored_session_hash, expected_session_hash, "session token_hash mismatch"); 644 + let (stored_session_hash,): (String,) = 645 + sqlx::query_as("SELECT token_hash FROM pending_sessions WHERE account_id = ?") 646 + .bind(account_id) 647 + .fetch_one(&db) 648 + .await 649 + .unwrap(); 650 + assert_eq!( 651 + stored_session_hash, expected_session_hash, 652 + "session token_hash mismatch" 653 + ); 629 654 } 630 655 631 656 // ── Claim code errors ───────────────────────────────────────────────────── ··· 641 666 .unwrap(); 642 667 643 668 assert_eq!(response.status(), StatusCode::NOT_FOUND); 644 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 669 + let body = axum::body::to_bytes(response.into_body(), 4096) 670 + .await 671 + .unwrap(); 645 672 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 646 673 assert_eq!(json["error"]["code"], "NOT_FOUND"); 647 674 } ··· 670 697 .unwrap(); 671 698 672 699 assert_eq!(response.status(), StatusCode::NOT_FOUND); 673 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 700 + let body = axum::body::to_bytes(response.into_body(), 4096) 701 + .await 702 + .unwrap(); 674 703 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 675 704 assert_eq!(json["error"]["code"], "NOT_FOUND"); 676 705 } ··· 699 728 .unwrap(); 700 729 701 730 assert_eq!(second.status(), StatusCode::CONFLICT); 702 - let body = axum::body::to_bytes(second.into_body(), 4096).await.unwrap(); 731 + let body = axum::body::to_bytes(second.into_body(), 4096) 732 + .await 733 + .unwrap(); 703 734 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 704 735 assert_eq!(json["error"]["code"], "CLAIM_CODE_REDEEMED"); 705 736 } ··· 775 806 .unwrap(); 776 807 777 808 assert_eq!(response.status(), StatusCode::CONFLICT); 778 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 809 + let body = axum::body::to_bytes(response.into_body(), 4096) 810 + .await 811 + .unwrap(); 779 812 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 780 813 assert_eq!(json["error"]["code"], "HANDLE_TAKEN"); 781 814 ··· 843 876 .unwrap(); 844 877 845 878 assert_eq!(response.status(), StatusCode::CONFLICT); 846 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 879 + let body = axum::body::to_bytes(response.into_body(), 4096) 880 + .await 881 + .unwrap(); 847 882 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 848 883 assert_eq!(json["error"]["code"], "ACCOUNT_EXISTS"); 849 884 } ··· 905 940 .unwrap(); 906 941 907 942 assert_eq!(response.status(), StatusCode::CONFLICT); 908 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 943 + let body = axum::body::to_bytes(response.into_body(), 4096) 944 + .await 945 + .unwrap(); 909 946 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 910 947 assert_eq!(json["error"]["code"], "HANDLE_TAKEN"); 911 948 } ··· 922 959 .unwrap(); 923 960 924 961 assert_eq!(response.status(), StatusCode::BAD_REQUEST); 925 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 962 + let body = axum::body::to_bytes(response.into_body(), 4096) 963 + .await 964 + .unwrap(); 926 965 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 927 966 assert_eq!(json["error"]["code"], "INVALID_CLAIM"); 928 967 } ··· 954 993 .unwrap(); 955 994 956 995 assert_eq!(response.status(), StatusCode::BAD_REQUEST); 957 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 996 + let body = axum::body::to_bytes(response.into_body(), 4096) 997 + .await 998 + .unwrap(); 958 999 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 959 1000 assert_eq!(json["error"]["code"], "INVALID_CLAIM"); 960 1001 } ··· 973 1014 .unwrap(); 974 1015 975 1016 assert_eq!(response.status(), StatusCode::BAD_REQUEST); 976 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 1017 + let body = axum::body::to_bytes(response.into_body(), 4096) 1018 + .await 1019 + .unwrap(); 977 1020 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 978 1021 assert_eq!(json["error"]["code"], "INVALID_CLAIM"); 979 1022 } ··· 1019 1062 .unwrap(); 1020 1063 1021 1064 assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR); 1022 - let body = axum::body::to_bytes(response.into_body(), 4096).await.unwrap(); 1065 + let body = axum::body::to_bytes(response.into_body(), 4096) 1066 + .await 1067 + .unwrap(); 1023 1068 let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); 1024 1069 assert_eq!(json["error"]["code"], "INTERNAL_ERROR"); 1025 1070 }