From 5c7fb67cbaad79ee30e8a504cc9404181266cc31 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Wed, 16 Apr 2025 10:41:02 +0300 Subject: [PATCH 01/36] migrate to axum --- Cargo.lock | 2607 +++++++++++------ Cargo.toml | 42 +- .../2025-02-28-071855_add_email/down.sql | 3 + migrations/2025-02-28-071855_add_email/up.sql | 3 + src/api/account.rs | 10 +- src/api/activity.rs | 92 +- src/api/auth.rs | 352 ++- src/api/friends.rs | 52 +- src/api/leaderboards.rs | 98 +- src/api/mod.rs | 16 +- src/api/oauth.rs | 61 +- src/api/search.rs | 8 +- src/api/stats.rs | 7 +- src/api/users.rs | 108 +- src/auth/mod.rs | 150 +- src/auth/secured_access.rs | 1 + src/database/activity.rs | 6 +- src/database/auth.rs | 75 +- src/database/leaderboards.rs | 4 +- src/database/mod.rs | 34 +- src/error.rs | 53 +- src/main.rs | 365 ++- src/models.rs | 30 +- src/ratelimiter.rs | 129 +- src/requests.rs | 58 - src/schema.rs | 1 + src/state.rs | 39 + src/tests/account.rs | 32 +- src/tests/activity.rs | 106 +- src/tests/auth.rs | 77 +- src/tests/friends.rs | 54 +- src/tests/leaderboards.rs | 71 +- src/tests/macros.rs | 128 +- src/tests/mod.rs | 149 +- src/utils.rs | 19 +- 35 files changed, 3035 insertions(+), 2005 deletions(-) create mode 100644 migrations/2025-02-28-071855_add_email/down.sql create mode 100644 migrations/2025-02-28-071855_add_email/up.sql delete mode 100644 src/requests.rs create mode 100644 src/state.rs diff --git a/Cargo.lock b/Cargo.lock index 98ddf24..5c4d9de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,242 +1,57 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] -name = "actix-codec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" -dependencies = [ - "bitflags 2.5.0", - "bytes", - "futures-core", - "futures-sink", - "memchr", - "pin-project-lite", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "actix-cors" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0346d8c1f762b41b458ed3145eea914966bb9ad20b9be0d6d463b20d45586370" -dependencies = [ - "actix-utils", - "actix-web", - "derive_more", - "futures-util", - "log", - "once_cell", - "smallvec", -] - -[[package]] -name = "actix-http" -version = "3.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb9843d84c775696c37d9a418bbb01b932629d01870722c0f13eb3f95e2536d" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "actix-tls", - "actix-utils", - "ahash", - "base64 0.22.1", - "bitflags 2.5.0", - "brotli", - "bytes", - "bytestring", - "derive_more", - "encoding_rs", - "flate2", - "futures-core", - "h2", - "http 0.2.12", - "httparse", - "httpdate", - "itoa", - "language-tags", - "local-channel", - "mime", - "percent-encoding", - "pin-project-lite", - "rand", - "sha1", - "smallvec", - "tokio", - "tokio-util", - "tracing", - "zstd", -] - -[[package]] -name = "actix-macros" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" -dependencies = [ - "quote", - "syn 2.0.66", -] - -[[package]] -name = "actix-router" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" -dependencies = [ - "bytestring", - "cfg-if", - "http 0.2.12", - "regex", - "regex-lite", - "serde", - "tracing", -] - -[[package]] -name = "actix-rt" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28f32d40287d3f402ae0028a9d54bef51af15c8769492826a69d28f81893151d" -dependencies = [ - "futures-core", - "tokio", -] - -[[package]] -name = "actix-server" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb13e7eef0423ea6eab0e59f6c72e7cb46d33691ad56a726b3cd07ddec2c2d4" -dependencies = [ - "actix-rt", - "actix-service", - "actix-utils", - "futures-core", - "futures-util", - "mio", - "socket2", - "tokio", - "tracing", -] - -[[package]] -name = "actix-service" -version = "2.0.2" +name = "addr2line" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b894941f818cfdc7ccc4b9e60fa7e53b5042a2e8567270f9147d5591893373a" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ - "futures-core", - "paste", - "pin-project-lite", + "gimli", ] [[package]] -name = "actix-tls" -version = "3.4.0" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac453898d866cdbecdbc2334fe1738c747b4eba14a677261f2b768ba05329389" -dependencies = [ - "actix-rt", - "actix-service", - "actix-utils", - "futures-core", - "http 0.2.12", - "http 1.1.0", - "impl-more", - "pin-project-lite", - "tokio", - "tokio-rustls", - "tokio-util", - "tracing", - "webpki-roots", -] +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] -name = "actix-utils" -version = "3.0.1" +name = "aead" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88a1dcdff1466e3c2488e1cb5c36a71822750ad43839937f85d2f4d9f8b705d8" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ - "local-waker", - "pin-project-lite", + "crypto-common", + "generic-array", ] [[package]] -name = "actix-web" -version = "4.6.0" +name = "aes" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1cf67dadb19d7c95e5a299e2dda24193b89d5d4f33a3b9800888ede9e19aa32" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ - "actix-codec", - "actix-http", - "actix-macros", - "actix-router", - "actix-rt", - "actix-server", - "actix-service", - "actix-tls", - "actix-utils", - "actix-web-codegen", - "ahash", - "bytes", - "bytestring", "cfg-if", - "cookie", - "derive_more", - "encoding_rs", - "futures-core", - "futures-util", - "itoa", - "language-tags", - "log", - "mime", - "once_cell", - "pin-project-lite", - "regex", - "regex-lite", - "serde", - "serde_json", - "serde_urlencoded", - "smallvec", - "socket2", - "time", - "url", -] - -[[package]] -name = "actix-web-codegen" -version = "4.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1f50ebbb30eca122b188319a4398b3f7bb4a8cdf50ecfb73bfc6a3c3ce54f5" -dependencies = [ - "actix-router", - "proc-macro2", - "quote", - "syn 2.0.66", + "cipher", + "cpufeatures", ] [[package]] -name = "addr2line" -version = "0.21.0" +name = "aes-gcm" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" dependencies = [ - "gimli", + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", ] -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "ahash" version = "0.8.11" @@ -244,10 +59,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "getrandom", "once_cell", "version_check", - "zerocopy", + "zerocopy 0.7.35", ] [[package]] @@ -260,19 +74,10 @@ dependencies = [ ] [[package]] -name = "alloc-no-stdlib" -version = "2.0.4" +name = "allocator-api2" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" - -[[package]] -name = "alloc-stdlib" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" -dependencies = [ - "alloc-no-stdlib", -] +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "android-tzdata" @@ -302,87 +107,131 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.80" +version = "0.1.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] -name = "atty" -version = "0.2.14" +name = "atomic-waker" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] -name = "awc" -version = "3.5.0" +name = "axum" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe6b67e44fb95d1dc9467e3930383e115f9b4ed60ca689db41409284e967a12d" +checksum = "de45108900e1f9b9242f7f2e254aa3e2c029c921c258fe9e6b4217eeebd54288" dependencies = [ - "actix-codec", - "actix-http", - "actix-rt", - "actix-service", - "actix-tls", - "actix-utils", - "base64 0.22.1", + "axum-core", + "axum-macros", "bytes", - "cfg-if", - "cookie", - "derive_more", - "futures-core", + "form_urlencoded", "futures-util", - "h2", - "http 0.2.12", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", "itoa", - "log", + "matchit", + "memchr", "mime", "percent-encoding", "pin-project-lite", - "rand", - "rustls", + "rustversion", "serde", "serde_json", + "serde_path_to_error", "serde_urlencoded", + "sync_wrapper", "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-extra" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45bf463831f5131b7d3c756525b305d40f1185b688565648a92e1392ca35713d" +dependencies = [ + "axum", + "axum-core", + "bytes", + "cookie", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "serde", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64" version = "0.22.1" @@ -391,21 +240,15 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bitflags" -version = "1.3.2" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" [[package]] name = "blake2" @@ -425,32 +268,11 @@ dependencies = [ "generic-array", ] -[[package]] -name = "brotli" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", - "brotli-decompressor", -] - -[[package]] -name = "brotli-decompressor" -version = "4.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a45bd2e4095a8b518033b128020dd4a55aab1c0a381ba4404a472630f4bc362" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", -] - [[package]] name = "bumpalo" -version = "3.16.0" +version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" [[package]] name = "byteorder" @@ -460,28 +282,17 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "bytestring" -version = "1.3.1" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d80203ea6b29df88012294f62733de21cfeab47f17b41af3a38bc30a03ee72" -dependencies = [ - "bytes", -] +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cc" -version = "1.0.98" +version = "1.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" dependencies = [ - "jobserver", - "libc", - "once_cell", + "shlex", ] [[package]] @@ -492,9 +303,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" dependencies = [ "android-tzdata", "iana-time-zone", @@ -502,55 +313,74 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.5", + "windows-link", ] [[package]] -name = "convert_case" -version = "0.4.0" +name = "chumsky" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eebd66744a15ded14960ab4ccdbfb51ad3b81f51f3f04a80adac98c985396c9" +dependencies = [ + "hashbrown 0.14.5", + "stacker", +] + +[[package]] +name = "cipher" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] [[package]] name = "cookie" -version = "0.16.2" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" +checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" dependencies = [ + "aes-gcm", + "base64", "percent-encoding", + "rand 0.8.5", + "subtle", "time", "version_check", ] [[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - -[[package]] -name = "cpufeatures" -version = "0.2.12" +name = "core-foundation" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ + "core-foundation-sys", "libc", ] [[package]] -name = "crc32fast" -version = "1.4.2" +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" dependencies = [ - "cfg-if", + "libc", ] [[package]] name = "crossbeam-utils" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crypto-common" @@ -559,70 +389,101 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", + "rand_core 0.6.4", "typenum", ] [[package]] -name = "dashmap" -version = "5.5.3" +name = "ctr" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", + "cipher", ] [[package]] -name = "deadpool" -version = "0.9.5" +name = "darling" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "421fe0f90f2ab22016f32a9881be5134fdd71c65298917084b0c7477cbc3856e" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" dependencies = [ - "async-trait", - "deadpool-runtime", - "num_cpus", - "retain_mut", - "tokio", + "darling_core", + "darling_macro", ] [[package]] -name = "deadpool-runtime" -version = "0.1.4" +name = "darling_core" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" - -[[package]] -name = "deranged" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" dependencies = [ - "powerfmt", + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", ] [[package]] -name = "derive_more" -version = "0.99.17" +name = "darling_macro" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ - "convert_case", - "proc-macro2", + "darling_core", "quote", - "rustc_version", - "syn 1.0.109", + "syn", +] + +[[package]] +name = "dashmap" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + +[[package]] +name = "deadpool" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ed5957ff93768adf7a65ab167a17835c3d2c3c50d084fe305174c112f468e2f" +dependencies = [ + "deadpool-runtime", + "num_cpus", + "tokio", +] + +[[package]] +name = "deadpool-runtime" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" + +[[package]] +name = "deranged" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +dependencies = [ + "powerfmt", ] [[package]] name = "diesel" -version = "2.1.6" +version = "2.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff236accb9a5069572099f0b350a92e9560e8e63a9b8d546162f4a5e03026bb2" +checksum = "34d3950690ba3a6910126162b47e775e203006d4242a15de912bec6c0a695153" dependencies = [ - "bitflags 2.5.0", + "bitflags", "byteorder", "chrono", "diesel_derives", @@ -632,9 +493,9 @@ dependencies = [ [[package]] name = "diesel-async" -version = "0.4.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acada1517534c92d3f382217b485db8a8638f111b0e3f2a2a8e26165050f77be" +checksum = "51a307ac00f7c23f526a04a77761a0519b9f0eb2838ebf5b905a58580095bdcb" dependencies = [ "async-trait", "deadpool", @@ -647,23 +508,24 @@ dependencies = [ [[package]] name = "diesel_derives" -version = "2.1.4" +version = "2.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14701062d6bed917b5c7103bdffaee1e4609279e240488ad24e7bd979ca6866c" +checksum = "a93958254b70bea63b4187ff73d10180599d9d8d177071b7f91e6da4e0c0ad55" dependencies = [ "diesel_table_macro_syntax", + "dsl_auto_type", "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] name = "diesel_table_macro_syntax" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" +checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" dependencies = [ - "syn 2.0.66", + "syn", ] [[package]] @@ -677,45 +539,83 @@ dependencies = [ "subtle", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dotenv" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +[[package]] +name = "dsl_auto_type" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139ae9aca7527f85f26dd76483eb38533fd84bd571065da1739656ef71c5ff5b" +dependencies = [ + "darling", + "either", + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "either" -version = "1.12.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] -name = "encoding_rs" -version = "0.8.34" +name = "email-encoding" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +checksum = "9298e6504d9b9e780ed3f7dfd43a61be8cd0e09eb07f7706a945b0072b6670b6" dependencies = [ - "cfg-if", + "base64", + "memchr", ] [[package]] -name = "env_logger" -version = "0.9.3" +name = "email_address" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +checksum = "e079f19b08ca6239f47f8ba8509c11cf3ea30095831f7fed61441475edd8c449" + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", + "cfg-if", ] [[package]] name = "equivalent" -version = "1.0.1" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] [[package]] name = "fallible-iterator" @@ -724,14 +624,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] -name = "flate2" -version = "1.0.30" +name = "fastrand" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" -dependencies = [ - "crc32fast", - "miniz_oxide", -] +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fnv" @@ -739,6 +635,27 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -750,9 +667,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -765,9 +682,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -775,15 +692,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -792,32 +709,32 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -827,9 +744,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -861,47 +778,74 @@ checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", + "wasm-bindgen", +] + +[[package]] +name = "ghash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +dependencies = [ + "opaque-debug", + "polyval", ] [[package]] name = "gimli" -version = "0.28.1" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "governor" -version = "0.6.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a7f542ee6b35af73b06abc0dad1c1bae89964e4e253bc4b587b91c9637867b" +checksum = "3cbe789d04bf14543f03c4b60cd494148aa79438c8440ae7d81a7778147745c3" dependencies = [ "cfg-if", "dashmap", - "futures", + "futures-sink", "futures-timer", - "no-std-compat", + "futures-util", + "getrandom 0.3.2", + "hashbrown 0.15.2", "nonzero_ext", "parking_lot", "portable-atomic", "quanta", - "rand", + "rand 0.9.0", "smallvec", "spinning_top", + "web-time", ] [[package]] name = "h2" -version = "0.3.26" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +checksum = "75249d144030531f8dee69fe9cea04d3edf809a017ae445e2abdff6629e86633" dependencies = [ + "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "futures-util", - "http 0.2.12", + "http", "indexmap", "slab", "tokio", @@ -914,16 +858,28 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "hashbrown" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ - "libc", + "allocator-api2", + "equivalent", + "foldhash", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -939,11 +895,22 @@ dependencies = [ "digest", ] +[[package]] +name = "hostname" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56f203cd1c76362b69e3863fd987520ac36cf70a8c92627449b2f64a8cf7d65" +dependencies = [ + "cfg-if", + "libc", + "windows-link", +] + [[package]] name = "http" -version = "0.2.12" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" dependencies = [ "bytes", "fnv", @@ -951,21 +918,33 @@ dependencies = [ ] [[package]] -name = "http" -version = "1.1.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "fnv", - "itoa", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", ] [[package]] name = "httparse" -version = "1.8.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "httpdate" @@ -974,21 +953,90 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] -name = "humantime" -version = "2.1.0" +name = "hyper" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "libc", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", + "log", "wasm-bindgen", "windows-core", ] @@ -1002,93 +1050,253 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", ] [[package]] -name = "impl-more" -version = "0.1.6" +name = "idna_adapter" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206ca75c9c03ba3d4ace2460e57b189f39f43de612c2f85836e65c929701bb2d" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] [[package]] name = "indexmap" -version = "2.2.6" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.2", ] [[package]] -name = "itertools" -version = "0.10.5" +name = "inout" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" dependencies = [ - "either", + "generic-array", ] [[package]] -name = "itoa" -version = "1.0.11" +name = "ipnet" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] -name = "jobserver" -version = "0.1.31" +name = "itertools" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" dependencies = [ - "libc", + "either", ] +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ + "once_cell", "wasm-bindgen", ] [[package]] -name = "language-tags" -version = "0.3.2" +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lettre" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" +checksum = "759bc2b8eabb6a30b235d6f716f7f36479f4b38cbe65b8747aefee51f89e8437" +dependencies = [ + "async-trait", + "base64", + "chumsky", + "email-encoding", + "email_address", + "fastrand", + "futures-io", + "futures-util", + "hostname", + "httpdate", + "idna", + "mime", + "native-tls", + "nom", + "percent-encoding", + "quoted_printable", + "socket2", + "tokio", + "tokio-native-tls", + "tracing", + "url", +] [[package]] name = "libc" -version = "0.2.155" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] -name = "local-channel" -version = "0.1.5" +name = "linux-raw-sys" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8" -dependencies = [ - "futures-core", - "futures-sink", - "local-waker", -] +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] -name = "local-waker" -version = "0.1.4" +name = "litemap" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487" +checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" [[package]] name = "lock_api" @@ -1102,9 +1310,24 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" [[package]] name = "md-5" @@ -1118,9 +1341,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -1130,30 +1353,49 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.7.3" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" dependencies = [ - "adler", + "adler2", ] [[package]] name = "mio" -version = "0.8.11" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.52.0", +] + +[[package]] +name = "native-tls" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" dependencies = [ "libc", "log", - "wasi", - "windows-sys 0.48.0", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] -name = "no-std-compat" -version = "0.4.1" +name = "nom" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] [[package]] name = "nonzero_ext" @@ -1161,45 +1403,111 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] -name = "num-traits" -version = "0.2.19" +name = "openssl" +version = "0.10.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" dependencies = [ - "autocfg", + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "openssl-macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ - "hermit-abi 0.3.9", - "libc", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "object" -version = "0.32.2" +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "openssl-sys" +version = "0.9.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "8288979acd84749c744a9014b4382d42b8f7b2592847b5afb2ed29e5d16ede07" dependencies = [ - "memchr", + "cc", + "libc", + "pkg-config", + "vcpkg", ] [[package]] -name = "once_cell" -version = "1.19.0" +name = "overload" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking_lot" @@ -1219,9 +1527,9 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.1", + "redox_syscall", "smallvec", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1231,16 +1539,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" dependencies = [ "base64ct", - "rand_core", + "rand_core 0.6.4", "subtle", ] -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - [[package]] name = "percent-encoding" version = "2.3.1" @@ -1249,47 +1551,47 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "phf" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" dependencies = [ "phf_shared", ] [[package]] name = "phf_shared" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" dependencies = [ "siphasher", ] [[package]] name = "pin-project" -version = "1.1.5" +version = "1.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.5" +version = "1.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pin-utils" @@ -1299,39 +1601,51 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "polyval" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", +] [[package]] name = "portable-atomic" -version = "1.6.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" [[package]] name = "postgres-protocol" -version = "0.6.6" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b6c5ef183cd3ab4ba005f1ca64c21e8bd97ce4699cfea9e8d9a2c4958ca520" +checksum = "76ff0abab4a9b844b93ef7b81f1efc0a366062aaef2cd702c76256b5dc075c54" dependencies = [ - "base64 0.21.7", + "base64", "byteorder", "bytes", "fallible-iterator", "hmac", "md-5", "memchr", - "rand", + "rand 0.9.0", "sha2", "stringprep", ] [[package]] name = "postgres-types" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d2234cdee9408b523530a9b6d2d6b373d1db34f6a8e51dc03ded1828d7fb67c" +checksum = "613283563cd90e1dfc3518d548caee47e0e725455ed619881f5cf21f36de4b48" dependencies = [ "bytes", "fallible-iterator", @@ -1346,43 +1660,67 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy 0.8.24", +] [[package]] name = "proc-macro2" -version = "1.0.84" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] +[[package]] +name = "psm" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58e5423e24c18cc840e1c98370b3993c6649cd1678b4d24318bcf0a083cbe88" +dependencies = [ + "cc", +] + [[package]] name = "quanta" -version = "0.12.3" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5" +checksum = "3bd1fe6824cea6538803de3ff1bc0cf3949024db3d43c9643024bfb33a807c0e" dependencies = [ "crossbeam-utils", "libc", "once_cell", "raw-cpuid", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "web-sys", "winapi", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] +[[package]] +name = "quoted_printable" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "640c9bd8497b02465aeef5375144c26062e0dcd5939dfcbb0f5db76cb8c17c73" + +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + [[package]] name = "rand" version = "0.8.5" @@ -1390,8 +1728,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.3", + "zerocopy 0.8.24", ] [[package]] @@ -1401,7 +1750,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.3", ] [[package]] @@ -1410,104 +1769,135 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.15", ] [[package]] -name = "raw-cpuid" -version = "11.0.2" +name = "rand_core" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e29830cbb1290e404f24c73af91c5d8d631ce7e128691e9477556b540cd01ecd" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "bitflags 2.5.0", + "getrandom 0.3.2", ] [[package]] -name = "redox_syscall" -version = "0.4.1" +name = "raw-cpuid" +version = "11.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "c6df7ab838ed27997ba19a4664507e6f82b41fe6e20be42929332156e5e85146" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] name = "redox_syscall" -version = "0.5.1" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" dependencies = [ - "bitflags 2.5.0", + "bitflags", ] [[package]] name = "regex" -version = "1.10.4" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", ] [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", + "regex-syntax 0.6.29", ] [[package]] -name = "regex-lite" -version = "0.1.5" +name = "regex-automata" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b661b2f27137bdbc16f00eda72866a92bb28af1753ffbd56744fb6e2e9cd8e" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.5", +] [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] -name = "retain_mut" -version = "0.1.9" +name = "regex-syntax" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4389f1d5789befaf6029ebd9f7dac4af7f7e3d61b69d4f30e2ac02b57e7712b0" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] -name = "ring" -version = "0.16.20" +name = "reqwest" +version = "0.12.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +checksum = "d19c46a6fdd48bc4dab94b6103fccc55d34c67cc0ad04653aad4ea2a07cd7bbb" dependencies = [ - "cc", - "libc", + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", "web-sys", - "winapi", + "windows-registry", ] [[package]] name = "ring" -version = "0.17.8" +version = "0.17.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom", + "getrandom 0.2.15", "libc", - "spin 0.9.8", - "untrusted 0.9.0", + "untrusted", "windows-sys 0.52.0", ] @@ -1518,40 +1908,85 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustc_version" -version = "0.4.0" +name = "rustix" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" dependencies = [ - "semver", + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.59.0", ] [[package]] name = "rustls" -version = "0.20.9" +version = "0.23.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +checksum = "df51b5869f3a441595eac5e8ff14d486ff285f7b8c0df8770e49c3b56351f0f0" dependencies = [ - "log", - "ring 0.16.20", - "sct", - "webpki", + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" + +[[package]] +name = "rustls-webpki" +version = "0.103.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", ] +[[package]] +name = "rustversion" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + [[package]] name = "ryu" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "schannel" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" +dependencies = [ + "windows-sys 0.59.0", +] [[package]] name = "scoped-futures" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1473e24c637950c9bd38763220bea91ec3e095a89f672bbd7a10d03e77ba467" +checksum = "1b24aae2d0636530f359e9d5ef0c04669d11c5e756699b27a6a6d845d8329091" dependencies = [ - "cfg-if", - "pin-utils", + "pin-project-lite", ] [[package]] @@ -1561,73 +1996,89 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] -name = "sct" -version = "0.7.1" +name = "security-framework" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", ] [[package]] -name = "semver" -version = "1.0.23" +name = "security-framework-sys" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] name = "serde" -version = "1.0.203" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] [[package]] -name = "serde_urlencoded" -version = "0.7.1" +name = "serde_path_to_error" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a" dependencies = [ - "form_urlencoded", "itoa", - "ryu", "serde", ] [[package]] -name = "sha1" -version = "0.10.6" +name = "serde_spanned" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ - "cfg-if", - "cpufeatures", - "digest", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", ] [[package]] @@ -1642,19 +2093,25 @@ dependencies = [ ] [[package]] -name = "signal-hook-registry" -version = "1.4.2" +name = "sharded-slab" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" dependencies = [ - "libc", + "lazy_static", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "siphasher" -version = "0.3.11" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slab" @@ -1667,39 +2124,46 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.2" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" [[package]] name = "socket2" -version = "0.5.7" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" dependencies = [ "libc", "windows-sys 0.52.0", ] [[package]] -name = "spin" -version = "0.5.2" +name = "spinning_top" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "d96d2d1d716fb500937168cc09353ffdc7a012be8475ac7308e1bdf0e3923300" +dependencies = [ + "lock_api", +] [[package]] -name = "spin" -version = "0.9.8" +name = "stable_deref_trait" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] -name = "spinning_top" -version = "0.3.0" +name = "stacker" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96d2d1d716fb500937168cc09353ffdc7a012be8475ac7308e1bdf0e3923300" +checksum = "601f9201feb9b09c00266478bf459952b9ef9a6b94edb2f21eba14ab681a60a9" dependencies = [ - "lock_api", + "cc", + "cfg-if", + "libc", + "psm", + "windows-sys 0.59.0", ] [[package]] @@ -1713,17 +2177,23 @@ dependencies = [ "unicode-properties", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" dependencies = [ "proc-macro2", "quote", @@ -1731,82 +2201,131 @@ dependencies = [ ] [[package]] -name = "syn" -version = "2.0.66" +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "unicode-ident", + "syn", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", ] [[package]] -name = "termcolor" -version = "1.4.1" +name = "tempfile" +version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf" dependencies = [ - "winapi-util", + "fastrand", + "getrandom 0.3.2", + "once_cell", + "rustix", + "windows-sys 0.59.0", ] [[package]] -name = "testaustime-rs" +name = "testaustime" version = "0.3.1" dependencies = [ - "actix-cors", - "actix-web", "argon2", - "awc", + "axum", + "axum-extra", "chrono", "dashmap", "diesel", "diesel-async", "dotenv", - "env_logger", "futures", "futures-util", "governor", - "http 0.2.12", + "http", + "http-body-util", "itertools", - "log", - "rand", + "lettre", + "mime", + "rand 0.9.0", "regex", + "reqwest", "serde", "serde_derive", "serde_json", "thiserror", + "tokio", "toml", + "tower", + "tower-http", "tracing", - "tracing-actix-web", + "tracing-futures", + "tracing-subscriber", "url", ] [[package]] name = "thiserror" -version = "1.0.61" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", ] [[package]] name = "time" -version = "0.3.36" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" dependencies = [ "deranged", "itoa", @@ -1819,25 +2338,35 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" dependencies = [ "num-conv", "time-core", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" dependencies = [ "tinyvec_macros", ] @@ -1850,26 +2379,46 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.44.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" dependencies = [ "backtrace", "bytes", "libc", "mio", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "socket2", - "windows-sys 0.48.0", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", ] [[package]] name = "tokio-postgres" -version = "0.7.10" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d340244b32d920260ae7448cb72b6e238bddc3d4f7603394e7dd46ed8e48f5b8" +checksum = "6c95d533c83082bb6490e0189acaa0bbeef9084e60471b696ca6988cd0541fb0" dependencies = [ "async-trait", "byteorder", @@ -1884,7 +2433,7 @@ dependencies = [ "pin-project-lite", "postgres-protocol", "postgres-types", - "rand", + "rand 0.9.0", "socket2", "tokio", "tokio-util", @@ -1893,20 +2442,19 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.23.4" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b" dependencies = [ "rustls", "tokio", - "webpki", ] [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" dependencies = [ "bytes", "futures-core", @@ -1917,95 +2465,202 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.11" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" dependencies = [ "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", ] [[package]] -name = "tracing" -version = "0.1.40" +name = "toml_datetime" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ - "log", + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", "pin-project-lite", - "tracing-attributes", - "tracing-core", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", ] [[package]] -name = "tracing-actix-web" +name = "tower-http" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d725b8fa6ef307b3f4856913523337de45c47cc79271bafd7acfb39559e3a2da" +checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" dependencies = [ - "actix-web", - "pin-project", + "bitflags", + "bytes", + "http", + "http-body", + "pin-project-lite", + "tower-layer", + "tower-service", "tracing", - "uuid", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ + "matchers", + "nu-ansi-term", "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "unicode-properties" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4259d9d4425d9f0661581b804cb85fe66a4c631cadd8f490d1c13a35d5d9291" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" [[package]] -name = "untrusted" -version = "0.7.1" +name = "universal-hash" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] [[package]] name = "untrusted" @@ -2015,9 +2670,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.0" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna", @@ -2025,19 +2680,43 @@ dependencies = [ ] [[package]] -name = "uuid" -version = "1.8.0" +name = "utf16_iter" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" -dependencies = [ - "getrandom", -] +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] [[package]] name = "wasi" @@ -2045,6 +2724,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + [[package]] name = "wasite" version = "0.1.0" @@ -2053,34 +2741,48 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", + "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.66", + "syn", "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2088,59 +2790,53 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] -name = "webpki" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" -dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", -] - -[[package]] -name = "webpki-roots" -version = "0.22.6" +name = "web-time" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" dependencies = [ - "webpki", + "js-sys", + "wasm-bindgen", ] [[package]] name = "whoami" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" +checksum = "6994d13118ab492c3c80c1f81928718159254c53c472bf9ce36f8dae4add02a7" dependencies = [ - "redox_syscall 0.4.1", + "redox_syscall", "wasite", "web-sys", ] @@ -2162,36 +2858,88 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "winapi-util" -version = "0.1.8" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" dependencies = [ - "windows-sys 0.52.0", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings 0.4.0", ] [[package]] -name = "winapi-x86_64-pc-windows-gnu" +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-registry" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" +dependencies = [ + "windows-result", + "windows-strings 0.3.1", + "windows-targets 0.53.0", +] [[package]] -name = "windows-core" -version = "0.52.0" +name = "windows-result" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" dependencies = [ - "windows-targets 0.52.5", + "windows-link", ] [[package]] -name = "windows-sys" -version = "0.48.0" +name = "windows-strings" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" dependencies = [ - "windows-targets 0.48.5", + "windows-link", ] [[package]] @@ -2200,174 +2948,285 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" [[package]] name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + +[[package]] +name = "winnow" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63d3fcd9bba44b03821e7d699eeee959f3126dcc4aa8e4ae18ec617c2a5cea10" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags", +] + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive 0.7.35", +] [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" dependencies = [ - "zerocopy-derive", + "zerocopy-derive 0.8.24", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn", ] [[package]] -name = "zstd" -version = "0.13.1" +name = "zerocopy-derive" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d789b1514203a1120ad2429eae43a7bd32b90976a7bb8a05f7ec02fa88cc23a" +checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" dependencies = [ - "zstd-safe", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "zstd-safe" -version = "7.1.0" +name = "zerofrom" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd99b45c6bc03a018c8b8a86025678c87e55526064e38f9df301989dce7ec0a" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" dependencies = [ - "zstd-sys", + "zerofrom-derive", ] [[package]] -name = "zstd-sys" -version = "2.0.10+zstd.1.5.6" +name = "zerofrom-derive" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ - "cc", - "pkg-config", + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index 4d14f8f..f7d36df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "testaustime-rs" +name = "testaustime" version = "0.3.1" edition = "2021" authors = ["Ville Järvinen ", "Luukas Pörtfors "] @@ -7,40 +7,46 @@ authors = ["Ville Järvinen ", "Luukas Pörtfors , } -#[post("/account/settings")] pub async fn change_settings( - settings: web::Json, userid: SecuredUserIdentity, db: DatabaseWrapper, -) -> Result { + settings: Json, +) -> Result { if let Some(public_profile) = settings.public_profile { db.change_visibility(userid.identity.id, public_profile) .await?; }; - Ok(HttpResponse::Ok()) + Ok(StatusCode::OK) } diff --git a/src/api/activity.rs b/src/api/activity.rs index 779217b..2d6f8ad 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -1,21 +1,22 @@ -use actix_web::{ - error::*, - web::{self, Data, Json}, - HttpResponse, Responder, -}; +use std::sync::Arc; + +use axum::{extract::State, response::IntoResponse, Json}; use chrono::{Duration, Local}; use dashmap::DashMap; -use serde_derive::Deserialize; +use http::StatusCode; +use serde::Deserialize; use crate::{ - api::auth::SecuredUserIdentity, database::DatabaseWrapper, error::TimeError, models::UserId, - requests::*, + api::auth::SecuredUserIdentity, + database::DatabaseWrapper, + error::TimeError, + models::{HeartBeat, UserId}, }; pub type HeartBeatMemoryStore = DashMap; #[derive(Deserialize)] -pub struct RenameRequest { +pub struct ActivityRenameRequest { from: String, to: String, } @@ -25,14 +26,12 @@ pub struct HideRequest { target_project: String, hidden: bool, } - -#[post("/update")] pub async fn update( user: UserId, - heartbeat: Json, db: DatabaseWrapper, - heartbeats: Data, -) -> Result { + heartbeats: State>, + Json(heartbeat): Json, +) -> Result { if let Some(project) = &heartbeat.project_name { if project.len() > 64 { return Err(TimeError::InvalidLength( @@ -72,29 +71,20 @@ pub async fn update( // If the user sends a heartbeat but maximum activity duration has been exceeded, // end session and start new db.add_activity(user.id, current_heartbeat, start, duration) - .await - .map_err(ErrorInternalServerError)?; + .await?; heartbeats.insert( user.id, - ( - heartbeat.into_inner(), - Local::now().naive_local(), - Duration::seconds(0), - ), + (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(HttpResponse::Ok().body(0i32.to_string())) + Ok(0i32.to_string()) } else { // Extend current coding session if heartbeat matches and it has been under the maximum duration of a break heartbeats.insert( user.id, - ( - heartbeat.into_inner(), - start, - curtime.signed_duration_since(start), - ), + (heartbeat, start, curtime.signed_duration_since(start)), ); - Ok(HttpResponse::Ok().body(curtime.signed_duration_since(start).to_string())) + Ok(curtime.signed_duration_since(start).to_string()) } } else { // Flush current session and start new session if heartbeat changes @@ -103,41 +93,32 @@ pub async fn update( } db.add_activity(user.id, current_heartbeat, start, duration) - .await - .map_err(ErrorInternalServerError)?; + .await?; heartbeats.insert( user.id, - ( - heartbeat.into_inner(), - Local::now().naive_local(), - Duration::seconds(0), - ), + (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(HttpResponse::Ok().body(0i32.to_string())) + + Ok(0i32.to_string()) } } None => { // If the user has not sent a heartbeat during this session heartbeats.insert( user.id, - ( - heartbeat.into_inner(), - Local::now().naive_local(), - Duration::seconds(0), - ), + (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(HttpResponse::Ok().body(0.to_string())) + Ok(0.to_string()) } } } -#[post("/flush")] pub async fn flush( user: UserId, db: DatabaseWrapper, - heartbeats: Data, -) -> Result { + heartbeats: State>, +) -> Result { if let Some(heartbeat) = heartbeats.get(&user.id) { let (inner_heartbeat, start, duration) = heartbeat.to_owned(); drop(heartbeat); @@ -145,48 +126,45 @@ pub async fn flush( db.add_activity(user.id, inner_heartbeat, start, duration) .await?; } - Ok(HttpResponse::Ok().finish()) + Ok(StatusCode::OK) } -#[delete("/delete")] pub async fn delete( user: SecuredUserIdentity, db: DatabaseWrapper, body: String, -) -> Result { +) -> Result { let deleted = db .delete_activity( user.identity.id, - body.parse::().map_err(ErrorBadRequest)?, + body.parse::().map_err(|_| TimeError::BadId)?, ) .await?; if deleted { - Ok(HttpResponse::Ok().finish()) + Ok(StatusCode::OK) } else { Err(TimeError::BadId) } } -#[post("/rename")] pub async fn rename_project( user: UserId, db: DatabaseWrapper, - body: Json, -) -> Result { + body: Json, +) -> Result { let renamed = db.rename_project(user.id, &body.from, &body.to).await?; - Ok(web::Json(json!({ "affected_activities": renamed }))) + Ok(Json(json!({ "affected_activities": renamed }))) } -#[post("/hide")] pub async fn hide_project( user: UserId, db: DatabaseWrapper, body: Json, -) -> Result { +) -> Result { let renamed = db .set_project_hidden(user.id, &body.target_project, body.hidden) .await?; - Ok(web::Json(json!({ "affected_activities": renamed }))) + Ok(Json(json!({ "affected_activities": renamed }))) } diff --git a/src/api/auth.rs b/src/api/auth.rs index eaa8a89..9afc335 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -1,50 +1,83 @@ -use std::{future::Future, pin::Pin}; +use std::{ + net::{IpAddr, SocketAddr}, + sync::Arc, +}; -use actix_web::{ - dev::{ConnectionInfo, Payload}, - error::*, - web::{Data, Json}, - FromRequest, HttpMessage, HttpRequest, HttpResponse, Responder, +use axum::{ + extract::{ConnectInfo, FromRequestParts, State}, + response::IntoResponse, + Json, +}; +use chrono::{Duration, Local}; +use http::{header::FORWARDED, request::Parts, HeaderMap, StatusCode}; +use lettre::{ + message::header::ContentType, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, }; +use serde::{Deserialize, Serialize}; use crate::{ auth::{secured_access::SecuredAccessTokenStorage, Authentication}, database::DatabaseWrapper, error::TimeError, models::{SecuredAccessTokenResponse, SelfUser, UserId, UserIdentity}, - requests::*, - RegisterLimiter, + utils::{generate_password_reset_token, validate_email}, + PasswordReset, PasswordResetState, RegisterLimiter, }; -impl FromRequest for UserId { - type Error = TimeError; - type Future = Pin>>>; - - fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future { - let auth = req.extensions().get::().cloned().unwrap(); - Box::pin(async move { - if let Authentication::AuthToken(user) = auth { - Ok(UserId { id: user.id }) - } else { - Err(TimeError::Unauthorized) - } - }) +#[derive(Deserialize)] +pub struct UsernameChangeRequest { + pub new: String, +} + +#[derive(Deserialize)] +pub struct EmailChangeRequest { + pub new: String, +} + +#[derive(Deserialize)] +pub struct PasswordChangeRequest { + pub old: String, + pub new: String, +} + +#[derive(Deserialize, Debug)] +pub struct LoginRequest { + pub username: String, + pub password: String, +} + +#[derive(Deserialize, Debug)] +pub struct RegisterRequest { + pub username: String, + pub email: Option, + pub password: String, +} + +impl FromRequestParts for UserId { + type Rejection = TimeError; + + async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { + let auth = parts.extensions.get::().cloned().unwrap(); + + if let Authentication::AuthToken(user) = auth { + Ok(UserId { id: user.id }) + } else { + Err(TimeError::Unauthorized) + } } } -impl FromRequest for UserIdentity { - type Error = TimeError; - type Future = Pin>>>; +impl FromRequestParts for UserIdentity { + type Rejection = TimeError; - fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future { - let auth = req.extensions().get::().cloned().unwrap(); - Box::pin(async move { - if let Authentication::AuthToken(user) = auth { - Ok(user) - } else { - Err(TimeError::Unauthorized) - } - }) + async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result { + let auth = parts.extensions.get::().cloned().unwrap(); + + if let Authentication::AuthToken(user) = auth { + Ok(user) + } else { + Err(TimeError::Unauthorized) + } } } @@ -52,19 +85,17 @@ pub struct SecuredUserIdentity { pub identity: UserIdentity, } -impl FromRequest for SecuredUserIdentity { - type Error = TimeError; - type Future = Pin>>>; +impl FromRequestParts for SecuredUserIdentity { + type Rejection = TimeError; - fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future { - let auth = req.extensions().get::().cloned().unwrap(); - Box::pin(async move { - if let Authentication::SecuredAuthToken(user) = auth { - Ok(SecuredUserIdentity { identity: user }) - } else { - Err(TimeError::UnauthroizedSecuredAccess) - } - }) + async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result { + let auth = parts.extensions.get::().cloned().unwrap(); + + if let Authentication::SecuredAccessToken(user) = auth { + Ok(SecuredUserIdentity { identity: user }) + } else { + Err(TimeError::UnauthroizedSecuredAccess) + } } } @@ -72,29 +103,29 @@ pub struct UserIdentityOptional { pub identity: Option, } -impl FromRequest for UserIdentityOptional { - type Error = TimeError; - type Future = Pin>>>; - - fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future { - let auth = req.extensions().get::().cloned().unwrap(); - Box::pin(async move { - if let Authentication::AuthToken(user) = auth { - Ok(UserIdentityOptional { - identity: Some(user), - }) - } else { - Ok(UserIdentityOptional { identity: None }) - } - }) +impl FromRequestParts for UserIdentityOptional +where + S: Send + Sync, +{ + type Rejection = TimeError; + + async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { + let auth = parts.extensions.get::().cloned().unwrap(); + + if let Authentication::AuthToken(user) = auth { + Ok(UserIdentityOptional { + identity: Some(user), + }) + } else { + Ok(UserIdentityOptional { identity: None }) + } } } -#[post("/auth/login")] pub async fn login( - data: Json, db: DatabaseWrapper, -) -> Result { + data: Json, +) -> Result { if data.password.len() > 128 { return Err(TimeError::InvalidLength( "Password cannot be longer than 128 characters".to_string(), @@ -109,34 +140,33 @@ pub async fn login( } } -#[post("/auth/securedaccess")] pub async fn get_secured_access_token( - data: Json, - secured_access_storage: Data, + State(secured_access_storage): State>, db: DatabaseWrapper, -) -> Result { + data: Json, +) -> Result { if data.password.len() > 128 { return Err(TimeError::InvalidLength( "Password cannot be longer than 128 characters".to_string(), )); } - match db + if let Ok(Some(user)) = db .verify_user_password(&data.username, &data.password) .await { - Ok(Some(user)) => Ok(Json(SecuredAccessTokenResponse { + Ok(Json(SecuredAccessTokenResponse { token: secured_access_storage.create_token(user.id), - })), - _ => Err(TimeError::InvalidCredentials), + })) + } else { + Err(TimeError::InvalidCredentials) } } -#[post("/auth/regenerate")] pub async fn regenerate( user: SecuredUserIdentity, db: DatabaseWrapper, -) -> Result { +) -> Result { db.regenerate_token(user.identity.id) .await .inspect_err(|e| error!("{}", e)) @@ -146,35 +176,44 @@ pub async fn regenerate( }) } -#[post("/auth/register")] pub async fn register( - conn_info: ConnectionInfo, - data: Json, + State(rls): State>, + ConnectInfo(conn_info): ConnectInfo, + headers: HeaderMap, db: DatabaseWrapper, - rls: Data, -) -> Result { + Json(data): Json, +) -> Result { if data.password.len() < 8 || data.password.len() > 128 { return Err(TimeError::InvalidLength( "Password has to be between 8 and 128 characters long".to_string(), )); } - if !super::REGEX.with(|r| r.is_match(&data.username)) { + if !super::VALID_NAME_REGEX.is_match(&data.username) { return Err(TimeError::BadUsername); } - if db.get_user_by_name(&data.username).await.is_ok() { - return Err(TimeError::UserExists); + if data.email.as_ref().is_some_and(|e| validate_email(e)) { + return Err(TimeError::InvalidEmail); + } + + let username = data.username.clone(); + if db.get_user_by_name(&username).await.is_ok() { + return Err(TimeError::UsernameTaken); } let ip = if rls.limit_by_peer_ip { - conn_info.peer_addr().ok_or(TimeError::UnknownError)? + conn_info.ip() } else { - conn_info - .realip_remote_addr() - .ok_or(TimeError::UnknownError)? + let header = headers + .get("x-forwarded-for") + .or_else(|| headers.get(FORWARDED)); + + header + .and_then(|ip| ip.to_str().ok().and_then(|ip| ip.parse::().ok())) + .unwrap_or(conn_info.ip()) }; - if let Some(res) = rls.storage.get(ip) { + if let Some(res) = rls.storage.get(&ip.to_string()) { if chrono::Local::now() .naive_local() .signed_duration_since(*res) @@ -185,7 +224,7 @@ pub async fn register( } let res = db - .new_testaustime_user(&data.username, &data.password) + .new_testaustime_user(&data.username, &data.password, data.email.as_deref()) .await?; rls.storage @@ -194,49 +233,144 @@ pub async fn register( Ok(Json(res)) } -#[post("/auth/changeusername")] -pub async fn changeusername( +pub async fn change_username( user: SecuredUserIdentity, - data: Json, db: DatabaseWrapper, -) -> Result { + Json(data): Json, +) -> Result { if data.new.len() < 2 || data.new.len() > 32 { return Err(TimeError::InvalidLength( "Username is not between 2 and 32 chars".to_string(), )); } - if !super::REGEX.with(|r| r.is_match(&data.new)) { + + if !super::VALID_NAME_REGEX.is_match(&data.new) { return Err(TimeError::BadUsername); } - if db.get_user_by_name(&data.new).await.is_ok() { - return Err(TimeError::UserExists); + let result = db.change_username(user.identity.id, &data.new).await; + + if result.as_ref().is_err_and(|e| e.is_unique_violation()) { + return Err(TimeError::UsernameTaken); } - let user = db.get_user_by_id(user.identity.id).await?; - db.change_username(user.id, &data.new).await?; - Ok(HttpResponse::Ok().finish()) + result.map(|_| StatusCode::OK) } -#[post("/auth/changepassword")] -pub async fn changepassword( +pub async fn change_email( + user: SecuredUserIdentity, + db: DatabaseWrapper, + Json(data): Json, +) -> Result { + if !validate_email(&data.new) { + return Err(TimeError::InvalidEmail); + } + + let result = db.change_email(user.identity.id, data.new).await; + + if result.as_ref().is_err_and(|e| e.is_unique_violation()) { + return Err(TimeError::EmailTaken); + } + + result.map(|_| StatusCode::OK) +} + +pub async fn change_password( user: UserIdentity, - data: Json, db: DatabaseWrapper, -) -> Result { - if data.new.len() < 8 || data.new.len() > 128 { + Json(body): Json, +) -> Result { + if body.new.len() < 8 || body.new.len() > 128 { return Err(TimeError::InvalidLength( "Password has to be between 8 and 128 characters long".to_string(), )); } - let old = data.old.to_owned(); - let tuser = db.get_testaustime_user_by_id(user.id).await?; - let k = db.verify_user_password(&user.username, &old).await?; - if k.is_some() || tuser.password.iter().all(|n| *n == 0) { - db.change_password(user.id, &data.new) - .await - .map(|_| HttpResponse::Ok().finish()) + + let testaustime_user = db.get_testaustime_user_by_id(user.id).await?; + let k = db.verify_user_password(&user.username, &body.old).await?; + + if k.is_some() || testaustime_user.password.iter().all(|n| *n == 0) { + db.change_password(user.id, &body.new).await?; + Ok(StatusCode::OK) } else { Err(TimeError::Unauthorized) } } + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PasswordResetRequest { + pub email: String, +} + +pub async fn request_password_reset( + db: DatabaseWrapper, + State(password_resets): State>, + State(relay): State>, + Json(body): Json, +) -> Result { + let Some(user) = db.get_user_by_email(&body.email).await? else { + return Ok(StatusCode::OK); + }; + + let Some(ref email) = user.email else { + return Ok(StatusCode::OK); + }; + + let token = generate_password_reset_token(); + + let message = Message::builder() + .from("Testaustime ".parse().unwrap()) + .to(format!("{} <{}>", user.username, email).parse().map_err(|_| TimeError::InvalidEmail)?) + .subject("Testaustime password reset") + .header(ContentType::TEXT_PLAIN) + .body(format!("Here is your testaustime password reset link: https://testaustime.fi/reset_password?token={}", token)).unwrap(); + + tokio::spawn(async move { + if let Err(err) = relay.send(message).await { + error!("{}", err); + }; + }); + + debug!("Sent password reset of user {} to {}", user.username, email); + + password_resets.storage.insert( + token, + PasswordReset { + expires: Local::now().naive_local() + Duration::minutes(30), + user, + }, + ); + + Ok(StatusCode::OK) +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PasswordResetCompletionRequest { + password: String, + token: String, +} + +pub async fn reset_password( + db: DatabaseWrapper, + State(password_resets): State>, + Json(body): Json, +) -> Result { + let Some(reset) = password_resets.storage.get(&body.token) else { + return Err(TimeError::InvalidPasswordResetToken); + }; + + if reset.expires > Local::now().naive_local() { + db.change_password(reset.user.id, &body.password).await?; + debug!("Changed password for user {}", reset.user.username); + + drop(reset); + password_resets.storage.remove(&body.token); + + Ok(StatusCode::OK) + } else { + drop(reset); + password_resets.storage.remove(&body.token); + + Err(TimeError::ExpiredPasswordResetToken) + } +} diff --git a/src/api/friends.rs b/src/api/friends.rs index b5f888b..45101ae 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -1,9 +1,9 @@ -use actix_web::{ - error::*, - web::{self, Data}, - HttpResponse, Responder, -}; +use std::sync::Arc; + +use axum::{extract::State, response::IntoResponse, Json}; use diesel::result::DatabaseErrorKind; +use http::StatusCode; +use serde::Deserialize; use crate::{ api::{activity::HeartBeatMemoryStore, auth::SecuredUserIdentity}, @@ -12,15 +12,19 @@ use crate::{ models::{CurrentActivity, FriendWithTimeAndStatus, UserId}, }; -#[post("/friends/add")] +#[derive(Deserialize, Debug)] +pub struct FriendRequest { + pub code: String, +} + pub async fn add_friend( user: UserId, - body: String, db: DatabaseWrapper, - heartbeats: Data, -) -> Result { + State(heartbeats): State>, + Json(body): Json, +) -> Result { match db - .add_friend(user.id, body.trim().trim_start_matches("ttfc_").to_string()) + .add_friend(user.id, body.code.trim_start_matches("ttfc_").to_string()) .await { // This is not correct @@ -52,17 +56,16 @@ pub async fn add_friend( }), }; - Ok(web::Json(friend_with_time)) + Ok(Json(friend_with_time)) } } } -#[get("/friends/list")] pub async fn get_friends( user: UserId, db: DatabaseWrapper, - heartbeats: Data, -) -> Result { + State(heartbeats): State>, +) -> Result { let friends = db .get_friends_with_time(user.id) .await @@ -86,31 +89,34 @@ pub async fn get_friends( }) .collect::>(); - Ok(web::Json(friends)) + Ok(Json(friends)) } -#[post("/friends/regenerate")] pub async fn regenerate_friend_code( user: SecuredUserIdentity, db: DatabaseWrapper, -) -> Result { +) -> Result { db.regenerate_friend_code(user.identity.id) .await .inspect_err(|e| error!("{}", e)) - .map(|code| web::Json(json!({ "friend_code": code }))) + .map(|code| Json(json!({ "friend_code": code }))) +} + +#[derive(Debug, Clone, Deserialize)] +pub struct RemoveFriendRequest { + name: String, } -#[delete("/friends/remove")] pub async fn remove( user: SecuredUserIdentity, db: DatabaseWrapper, - body: String, -) -> Result { - let friend = db.get_user_by_name(&body).await?; + Json(body): Json, +) -> Result { + let friend = db.get_user_by_name(&body.name).await?; let deleted = db.remove_friend(user.identity.id, friend.id).await?; if deleted { - Ok(HttpResponse::Ok().finish()) + Ok(StatusCode::OK) } else { Err(TimeError::BadId) } diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 39d03f3..2918749 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -1,9 +1,6 @@ -use actix_web::{ - error::*, - web::{self, Json, Path}, - HttpResponse, Responder, -}; -use diesel::result::DatabaseErrorKind; +use axum::{extract::Path, response::IntoResponse, Json}; +use diesel::result::{DatabaseErrorKind, Error as DieselError}; +use http::StatusCode; use serde::{Deserialize, Serialize}; use crate::{ @@ -25,13 +22,12 @@ pub struct LeaderboardUser { pub user: String, } -#[post("/leaderboards/create")] pub async fn create_leaderboard( creator: UserId, - body: Json, db: DatabaseWrapper, -) -> Result { - if !super::REGEX.with(|r| r.is_match(&body.name)) { + body: Json, +) -> Result { + if !super::VALID_NAME_REGEX.is_match(&body.name) { return Err(TimeError::BadLeaderboardName); } @@ -40,11 +36,11 @@ pub async fn create_leaderboard( } match db.create_leaderboard(creator.id, &body.name).await { - Ok(code) => Ok(web::Json(json!({ "invite_code": code }))), + Ok(code) => Ok(Json(json!({ "invite_code": code }))), Err(e) => { error!("{}", e); Err(match e { - TimeError::DieselError(diesel::result::Error::DatabaseError( + TimeError::DieselError(DieselError::DatabaseError( DatabaseErrorKind::UniqueViolation, .., )) => TimeError::LeaderboardExists, @@ -54,50 +50,47 @@ pub async fn create_leaderboard( } } -#[get("/leaderboards/{name}")] pub async fn get_leaderboard( user: UserId, - path: Path<(String,)>, + Path(name): Path, db: DatabaseWrapper, -) -> Result { +) -> Result { let lid = db - .get_leaderboard_id_by_name(&path.0) + .get_leaderboard_id_by_name(&name) .await .map_err(|_| TimeError::LeaderboardNotFound)?; if db.is_leaderboard_member(user.id, lid).await? { - let board = db.get_leaderboard(&path.0).await?; - Ok(web::Json(board)) + let board = db.get_leaderboard(&name).await?; + Ok(Json(board)) } else { Err(TimeError::Unauthorized) } } -#[delete("/leaderboards/{name}")] pub async fn delete_leaderboard( user: SecuredUserIdentity, - path: Path<(String,)>, + Path(name): Path, db: DatabaseWrapper, -) -> Result { +) -> Result { let lid = db - .get_leaderboard_id_by_name(&path.0) + .get_leaderboard_id_by_name(&name) .await .map_err(|_| TimeError::LeaderboardNotFound)?; if db.is_leaderboard_admin(user.identity.id, lid).await? { - db.delete_leaderboard(&path.0).await?; - Ok(HttpResponse::Ok().finish()) + db.delete_leaderboard(&name).await?; + Ok(StatusCode::OK) } else { Err(TimeError::Unauthorized) } } -#[post("/leaderboards/join")] pub async fn join_leaderboard( user: UserId, - body: Json, db: DatabaseWrapper, -) -> Result { + body: Json, +) -> Result { match db .add_user_to_leaderboard(user.id, body.invite.trim().trim_start_matches("ttlic_")) .await @@ -105,28 +98,27 @@ pub async fn join_leaderboard( Err(e) => { error!("{}", e); Err(match e { - TimeError::DieselError(diesel::result::Error::DatabaseError( + TimeError::DieselError(DieselError::DatabaseError( DatabaseErrorKind::UniqueViolation, .., )) => TimeError::AlreadyMember, - TimeError::DieselError(diesel::result::Error::NotFound) => { + TimeError::DieselError(DieselError::NotFound) => { TimeError::LeaderboardNotFound } _ => e, }) } - Ok(leaderboard) => Ok(web::Json(json!(leaderboard))), + Ok(leaderboard) => Ok(Json(json!(leaderboard))), } } -#[post("/leaderboards/{name}/leave")] pub async fn leave_leaderboard( user: SecuredUserIdentity, - path: Path<(String,)>, + Path(name): Path, db: DatabaseWrapper, -) -> Result { +) -> Result { let lid = db - .get_leaderboard_id_by_name(&path.0) + .get_leaderboard_id_by_name(&name) .await .map_err(|_| TimeError::LeaderboardNotFound)?; @@ -140,21 +132,20 @@ pub async fn leave_leaderboard( .remove_user_from_leaderboard(lid, user.identity.id) .await? { - Ok(HttpResponse::Ok().finish()) + Ok(StatusCode::OK) } else { Err(TimeError::NotMember) } } -#[post("/leaderboards/{name}/promote")] pub async fn promote_member( user: SecuredUserIdentity, - path: Path<(String,)>, + Path(name): Path, db: DatabaseWrapper, promotion: Json, -) -> Result { +) -> Result { let lid = db - .get_leaderboard_id_by_name(&path.0) + .get_leaderboard_id_by_name(&name) .await .map_err(|_| TimeError::LeaderboardNotFound)?; @@ -168,7 +159,7 @@ pub async fn promote_member( .promote_user_to_leaderboard_admin(lid, newadmin.id) .await? { - Ok(HttpResponse::Ok().finish()) + Ok(StatusCode::OK) } else { // FIXME: This is not correct Err(TimeError::NotMember) @@ -178,15 +169,14 @@ pub async fn promote_member( } } -#[post("/leaderboards/{name}/demote")] pub async fn demote_member( user: SecuredUserIdentity, - path: Path<(String,)>, + Path(name): Path, db: DatabaseWrapper, demotion: Json, -) -> Result { +) -> Result { let lid = db - .get_leaderboard_id_by_name(&path.0) + .get_leaderboard_id_by_name(&name) .await .map_err(|_| TimeError::LeaderboardNotFound)?; @@ -200,7 +190,7 @@ pub async fn demote_member( .demote_user_to_leaderboard_member(lid, oldadmin.id) .await? { - Ok(HttpResponse::Ok().finish()) + Ok(StatusCode::OK) } else { // FIXME: This is not correct Err(TimeError::NotMember) @@ -210,15 +200,14 @@ pub async fn demote_member( } } -#[post("/leaderboards/{name}/kick")] pub async fn kick_member( user: SecuredUserIdentity, - path: Path<(String,)>, + Path(name): Path, db: DatabaseWrapper, kick: Json, -) -> Result { +) -> Result { let lid = db - .get_leaderboard_id_by_name(&path.0) + .get_leaderboard_id_by_name(&name) .await .map_err(|_| TimeError::LeaderboardNotFound)?; @@ -231,26 +220,25 @@ pub async fn kick_member( db.remove_user_from_leaderboard(lid, kmember.id) .await .map_err(|_| TimeError::NotMember)?; - Ok(HttpResponse::Ok().finish()) + Ok(StatusCode::OK) } else { Err(TimeError::Unauthorized) } } -#[post("/leaderboards/{name}/regenerate")] pub async fn regenerate_invite( user: SecuredUserIdentity, - path: Path<(String,)>, + Path(name): Path, db: DatabaseWrapper, -) -> Result { +) -> Result { let lid = db - .get_leaderboard_id_by_name(&path.0) + .get_leaderboard_id_by_name(&name) .await .map_err(|_| TimeError::LeaderboardNotFound)?; if db.is_leaderboard_admin(user.identity.id, lid).await? { let code = db.regenerate_leaderboard_invite(lid).await?; - Ok(web::Json(json!({ "invite_code": code }))) + Ok(Json(json!({ "invite_code": code }))) } else { Err(TimeError::Unauthorized) } diff --git a/src/api/mod.rs b/src/api/mod.rs index afd13ed..e940465 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,4 +1,7 @@ -use actix_web::{HttpResponse, Responder}; +use std::sync::LazyLock; + +use axum::response::IntoResponse; +use http::StatusCode; use regex::Regex; pub mod account; @@ -12,11 +15,10 @@ pub mod search; pub mod stats; pub mod users; -thread_local! { - pub static REGEX: Regex = Regex::new("^[[:word:]]{2,32}$").unwrap(); -} +pub static VALID_NAME_REGEX: LazyLock = LazyLock::new(|| { + Regex::new("^[[:word:]]{2,32}$").unwrap() +}); -#[get("/health")] -async fn health() -> impl Responder { - HttpResponse::Ok() +pub async fn health() -> impl IntoResponse { + StatusCode::OK } diff --git a/src/api/oauth.rs b/src/api/oauth.rs index d9d9a90..ceb6964 100644 --- a/src/api/oauth.rs +++ b/src/api/oauth.rs @@ -1,18 +1,17 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::LazyLock}; -use actix_web::{ - cookie::Cookie, - error::*, - web::{Data, Query}, - HttpResponse, Responder, +use axum::{ + extract::Query, + response::{IntoResponse, Redirect}, }; -use awc::Client; +use axum_extra::extract::{cookie::Cookie, CookieJar}; +use reqwest::Client; use serde_derive::Deserialize; use crate::{database::DatabaseWrapper, error::TimeError}; #[derive(Deserialize)] -struct TokenExchangeRequest { +pub struct TokenExchangeRequest { code: String, } @@ -43,26 +42,33 @@ struct TestausIdPlatformInfo { id: String, } -#[get("/auth/callback")] -async fn callback( - request: Query, - client: Data, - oauth_client: Data, +static CLIENT_INFO: LazyLock = LazyLock::new(|| { + toml::from_str(&std::fs::read_to_string("settings.toml").expect("Missing settings.toml")) + .expect("Invalid Toml in settings.toml") +}); + +pub async fn callback( db: DatabaseWrapper, -) -> Result { + jar: CookieJar, + request: Query, +) -> Result { if request.code.chars().any(|c| !c.is_alphanumeric()) { return Err(TimeError::BadCode); } + // Maybe store in state? + let client = Client::new(); + let res = client .post("http://id.testausserveri.fi/api/v1/token") - .insert_header(("content-type", "application/x-www-form-urlencoded")) - .send_form(&HashMap::from([ + .header("content-type", "application/x-www-form-urlencoded") + .form(&HashMap::from([ ("code", &request.code), - ("redirect_uri", &oauth_client.redirect_uri), - ("client_id", &oauth_client.id), - ("client_secret", &oauth_client.secret), + ("redirect_uri", &CLIENT_INFO.redirect_uri), + ("client_id", &CLIENT_INFO.id), + ("client_secret", &CLIENT_INFO.secret), ])) + .send() .await .unwrap() .json::() @@ -71,7 +77,7 @@ async fn callback( let res = client .get("http://id.testausserveri.fi/api/v1/me") - .insert_header(("Authorization", format!("Bearer {}", res.token))) + .header("Authorization", format!("Bearer {}", res.token)) .send() .await .unwrap() @@ -83,14 +89,13 @@ async fn callback( .testausid_login(res.id, res.name, res.platform.id) .await?; - Ok(HttpResponse::PermanentRedirect() - .insert_header(("location", "https://testaustime.fi/oauth_redirect")) - .cookie( - Cookie::build("testaustime_token", token) + Ok(( + jar.add( + Cookie::build(("testaustime_token", token)) .domain("testaustime.fi") .path("/") - .secure(true) - .finish(), - ) - .finish()) + .secure(true), + ), + Redirect::permanent("https://testaustime.fi/oauth_redirect"), + )) } diff --git a/src/api/search.rs b/src/api/search.rs index 6ebd7f8..322c834 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -1,7 +1,4 @@ -use actix_web::{ - web::{Json, Query}, - Responder, -}; +use axum::{extract::Query, response::IntoResponse, Json}; use serde_derive::Deserialize; use crate::{database::DatabaseWrapper, error::TimeError}; @@ -12,10 +9,9 @@ pub struct UserSearch { } //TODO: Maybe return small coding summary? -#[get("/search/users")] pub async fn search_public_users( db: DatabaseWrapper, search: Query, -) -> Result { +) -> Result { Ok(Json(db.search_public_users(search.keyword.clone()).await?)) } diff --git a/src/api/stats.rs b/src/api/stats.rs index 5f81b5c..5e1d4c3 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -1,4 +1,4 @@ -use actix_web::{web, Responder}; +use axum::response::IntoResponse; use serde_derive::Serialize; use crate::{database::DatabaseWrapper, error::TimeError}; @@ -9,12 +9,11 @@ struct Stats { pub coding_time: u64, } -#[get("/stats")] -async fn stats(db: DatabaseWrapper) -> Result { +pub async fn stats(db: DatabaseWrapper) -> Result { let user_count = db.get_total_user_count().await?; let coding_time = db.get_total_coding_time().await?; - Ok(web::Json(Stats { + Ok(axum::Json(Stats { user_count, coding_time, })) diff --git a/src/api/users.rs b/src/api/users.rs index 5ee5e03..145dc6a 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -1,32 +1,49 @@ -use actix_web::{ - error::*, - web::{self, Data, Path, Query}, - HttpResponse, Responder, +use std::sync::Arc; + +use axum::{ + extract::{Path, Query, State}, + response::IntoResponse, + Json, }; -use chrono::{Duration, Local}; +use chrono::{serde::ts_seconds_option, DateTime, Duration, Local, Utc}; +use http::StatusCode; +use serde::Serialize; use serde_derive::Deserialize; use crate::{ api::{activity::HeartBeatMemoryStore, auth::UserIdentityOptional}, database::DatabaseWrapper, error::TimeError, - models::{CurrentActivity, PrivateLeaderboardMember, UserId, UserIdentity}, - requests::DataRequest, + models::{CodingActivity, CurrentActivity, PrivateLeaderboardMember, UserId, UserIdentity}, utils::group_by_language, }; +#[derive(Deserialize, Debug)] +pub struct DataRequest { + #[serde(default)] + #[serde(with = "ts_seconds_option")] + pub from: Option>, + #[serde(default)] + #[serde(with = "ts_seconds_option")] + pub to: Option>, + pub min_duration: Option, + pub editor_name: Option, + pub language: Option, + pub hostname: Option, + pub project_name: Option, +} + #[derive(Deserialize)] pub struct UserAuthentication { pub username: String, pub password: String, } -#[get("/users/@me")] -pub async fn my_profile(user: UserIdentity) -> Result { - Ok(web::Json(user)) +pub async fn my_profile(user: UserIdentity) -> Result { + Ok(Json(user)) } -#[derive(serde::Serialize)] +#[derive(Serialize)] pub struct ListLeaderboard { pub name: String, pub member_count: i32, @@ -35,25 +52,23 @@ pub struct ListLeaderboard { pub me: PrivateLeaderboardMember, } -#[derive(serde::Serialize)] +#[derive(Serialize)] pub struct MinimalLeaderboard { pub name: String, pub member_count: i32, } -#[get("/users/@me/leaderboards")] pub async fn my_leaderboards( user: UserId, db: DatabaseWrapper, -) -> Result { - Ok(web::Json(db.get_user_leaderboards(user.id).await?)) +) -> Result { + Ok(Json(db.get_user_leaderboards(user.id).await?)) } -#[delete("/users/@me/delete")] pub async fn delete_user( db: DatabaseWrapper, - user: web::Json, -) -> Result { + user: Json, +) -> Result { if let Some(user) = db .verify_user_password(&user.username, &user.password) .await? @@ -61,25 +76,23 @@ pub async fn delete_user( db.delete_user(user.id).await?; } - Ok(HttpResponse::Ok().finish()) + Ok(StatusCode::OK) } -#[get("/users/{username}/activity/current")] pub async fn get_current_activity( - path: Path<(String,)>, + Path(name): Path, opt_user: UserIdentityOptional, db: DatabaseWrapper, - heartbeats: Data, -) -> Result { - let mut is_self: bool = false; - let target_user = if let Some(user) = opt_user.identity { - if path.0 == "@me" { - is_self = true; + State(heartbeats): State>, +) -> Result { + let mut is_self = false; + let target_user = if let Some(user) = opt_user.identity { + if name == "@me" { user.id } else { let target_user = db - .get_user_by_name(&path.0) + .get_user_by_name(&name) .await .map_err(|_| TimeError::UserNotFound)?; @@ -95,7 +108,7 @@ pub async fn get_current_activity( } } else { let target_user = db - .get_user_by_name(&path.0) + .get_user_by_name(&name) .await .map_err(|_| TimeError::UserNotFound)?; @@ -113,8 +126,7 @@ pub async fn get_current_activity( let curtime = Local::now().naive_local(); if curtime.signed_duration_since(start + duration) > Duration::seconds(900) { db.add_activity(target_user, inner_heartbeat, start, duration) - .await - .map_err(ErrorInternalServerError)?; + .await?; heartbeats.remove(&target_user); Err(TimeError::NotActive) @@ -129,42 +141,39 @@ pub async fn get_current_activity( current_heartbeat.heartbeat.project_name = Some(String::from("hidden")); } - Ok(web::Json(Some(current_heartbeat))) + Ok(Json(Some(current_heartbeat))) } } None => Err(TimeError::NotActive), } } -#[get("/users/{username}/activity/data")] pub async fn get_activities( + db: DatabaseWrapper, Query(data): Query, - path: Path<(String,)>, + Path(name): Path, opt_user: UserIdentityOptional, - db: DatabaseWrapper, -) -> Result { +) -> Result { let Some(user) = opt_user.identity else { let target_user = db - .get_user_by_name(&path.0) + .get_user_by_name(&name) .await .map_err(|_| TimeError::UserNotFound)?; if target_user.is_public { - return Ok(web::Json( - db.get_activity(data, target_user.id, false).await?, - )); + return Ok(Json(db.get_activity(data, target_user.id, false).await?)); } else { return Err(TimeError::UserNotFound); }; }; - let data = if path.0 == "@me" { + let data: Vec = if name == "@me" { db.get_activity(data, user.id, true).await? } else { //FIXME: This is technically not required when the username equals the username of the //authenticated user let target_user = db - .get_user_by_name(&path.0) + .get_user_by_name(&name) .await .map_err(|_| TimeError::UserNotFound)?; @@ -179,21 +188,20 @@ pub async fn get_activities( } }; - Ok(web::Json(data)) + Ok(Json(data)) } -#[get("/users/{username}/activity/summary")] pub async fn get_activity_summary( - path: Path<(String,)>, + Path(path): Path, opt_user: UserIdentityOptional, db: DatabaseWrapper, -) -> Result { +) -> Result { let data = if let Some(user) = opt_user.identity { - if path.0 == "@me" { + if path == "@me" { db.get_all_activity(user.id).await? } else { let target_user = db - .get_user_by_name(&path.0) + .get_user_by_name(&path) .await .map_err(|_| TimeError::UserNotFound)?; @@ -208,7 +216,7 @@ pub async fn get_activity_summary( } } else { let target_user = db - .get_user_by_name(&path.0) + .get_user_by_name(&path) .await .map_err(|_| TimeError::UserNotFound)?; @@ -248,5 +256,5 @@ pub async fn get_activity_summary( }, }); - Ok(web::Json(langs)) + Ok(Json(langs)) } diff --git a/src/auth/mod.rs b/src/auth/mod.rs index f216208..5ec88d2 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -1,107 +1,107 @@ pub mod secured_access; -use std::rc::Rc; - -use actix_web::{ - dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}, - error::{ErrorInternalServerError, ErrorUnauthorized}, - web::Data, - Error, FromRequest, HttpMessage, +use std::{ + mem, + sync::Arc, + task::{Context, Poll}, }; -use futures::future::LocalBoxFuture; -use self::secured_access::SecuredAccessTokenStorage; -use crate::{database::DatabaseWrapper, models::UserIdentity}; +use axum::extract::Request; +use futures_util::future::BoxFuture; +use tower::{Layer, Service}; + +use crate::{database::DatabaseWrapper, models::UserIdentity, TestaustimeState}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Authentication { NoAuth, AuthToken(UserIdentity), - SecuredAuthToken(UserIdentity), + SecuredAccessToken(UserIdentity), } -pub struct AuthMiddleware; +#[derive(Clone)] +pub struct AuthMiddleware { + pub state: TestaustimeState, +} -pub struct AuthMiddlewareTransform { - service: Rc, +#[derive(Clone)] +pub struct AuthMiddlewareService { + inner: S, + state: TestaustimeState, } -impl Transform for AuthMiddleware -where - S: Service, Error = Error> + 'static, - S::Future: 'static, - B: 'static, -{ - type Response = ServiceResponse; - type Error = Error; - type InitError = (); - type Transform = AuthMiddlewareTransform; - type Future = LocalBoxFuture<'static, Result>; +impl Authentication { + pub fn user(&self) -> Option<&UserIdentity> { + match self { + Authentication::NoAuth => None, + Authentication::AuthToken(user_identity) => Some(user_identity), + Authentication::SecuredAccessToken(user_identity) => Some(user_identity), + } + } +} - fn new_transform(&self, service: S) -> Self::Future { - Box::pin(async move { - Ok(AuthMiddlewareTransform { - service: Rc::new(service), - }) - }) +impl Layer for AuthMiddleware { + type Service = AuthMiddlewareService; + + fn layer(&self, inner: S) -> Self::Service { + AuthMiddlewareService { + inner, + state: self.state.clone(), + } } } -impl Service for AuthMiddlewareTransform +impl Service> for AuthMiddlewareService where - S: Service, Error = Error> + 'static, - S::Future: 'static, - B: 'static, + S: Service> + Clone + 'static, + S::Future: Send + 'static, + S: Send + 'static, + B: Send + 'static, { - type Response = ServiceResponse; + type Response = S::Response; type Error = S::Error; - type Future = LocalBoxFuture<'static, Result>; + type Future = BoxFuture<'static, Result>; - forward_ready!(service); + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.inner.poll_ready(cx) + } - fn call(&self, req: ServiceRequest) -> Self::Future { - let db = DatabaseWrapper::extract(req.request()); - let secured_access_storage = req - .app_data::>() - .expect("Secured token access storage not initialized") - .clone(); + fn call(&mut self, mut req: Request) -> Self::Future { + let db = DatabaseWrapper::from(&self.state.database); + let secured_access_storage = Arc::clone(&self.state.secured_access_storage); let auth = req.headers().get("Authorization").cloned(); - let service = Rc::clone(&self.service); + + let clone = self.inner.clone(); + let mut inner = mem::replace(&mut self.inner, clone); Box::pin(async move { - if let Some(auth) = auth { - if let Some(token) = auth.to_str().unwrap().trim().strip_prefix("Bearer ") { - let db = db.await.map_err(ErrorInternalServerError)?; - - if let Ok(secured_access_instance) = secured_access_storage.get(token).clone() { - let user = db - .get_user_by_id(secured_access_instance.user_id) - .await - .map_err(ErrorUnauthorized)?; - - req.extensions_mut() - .insert(Authentication::SecuredAuthToken(user)); - } else { - let user = db - .get_user_by_token(token.to_string()) - .await - .map_err(ErrorUnauthorized); - - if let Ok(user_identity) = user { - req.extensions_mut() - .insert(Authentication::AuthToken(user_identity)); - } else { - req.extensions_mut().insert(Authentication::NoAuth); - } - } + let auth = 'auth: { + let Some(auth) = auth else { + break 'auth Authentication::NoAuth; + }; + + let Some(token) = auth.to_str().unwrap().trim().strip_prefix("Bearer ") else { + break 'auth Authentication::NoAuth; + }; + + if let Ok(secured_access_instance) = secured_access_storage.get(token).clone() { + let user = db + .get_user_by_id(secured_access_instance.user_id) + .await + .unwrap(); + + Authentication::SecuredAccessToken(user) + } else if let Ok(user_identity) = db.get_user_by_token(token.to_string()).await { + Authentication::AuthToken(user_identity) } else { - req.extensions_mut().insert(Authentication::NoAuth); + Authentication::NoAuth } - } else { - req.extensions_mut().insert(Authentication::NoAuth); - } + }; + + req.extensions_mut().insert(auth); + + let resp = inner.call(req).await?; - let resp = service.call(req).await?; Ok(resp) }) } diff --git a/src/auth/secured_access.rs b/src/auth/secured_access.rs index 33c6891..63884c4 100644 --- a/src/auth/secured_access.rs +++ b/src/auth/secured_access.rs @@ -16,6 +16,7 @@ pub struct SecuredAccessTokenInstance { pub expires: Instant, } +#[derive(Default)] pub struct SecuredAccessTokenStorage { inner: DashMap, } diff --git a/src/database/activity.rs b/src/database/activity.rs index 51c5b65..b1d60ca 100644 --- a/src/database/activity.rs +++ b/src/database/activity.rs @@ -2,11 +2,7 @@ use chrono::{prelude::*, Duration}; use diesel::prelude::*; use diesel_async::RunQueryDsl; -use crate::{ - error::TimeError, - models::*, - requests::{DataRequest, HeartBeat}, -}; +use crate::{api::users::DataRequest, error::TimeError, models::*}; impl super::DatabaseWrapper { pub async fn add_activity( diff --git a/src/database/auth.rs b/src/database/auth.rs index 8a4d185..d54ca40 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -28,7 +28,7 @@ impl super::DatabaseWrapper { pub async fn get_user_by_name(&self, target_username: &str) -> Result { let mut conn = self.db.get().await?; use crate::schema::user_identities::dsl::*; - sql_function!(fn lower(x: diesel::sql_types::Text) -> Text); + define_sql_function!(fn lower(x: diesel::sql_types::Text) -> Text); Ok(user_identities .filter(lower(username).eq(target_username.to_lowercase())) @@ -63,11 +63,12 @@ impl super::DatabaseWrapper { password: &str, ) -> Result, TimeError> { let mut conn = self.db.get().await?; + define_sql_function!(fn lower(x: diesel::sql_types::Text) -> Text); use user_identities::dsl::username; let (user, tuser) = user_identities::table - .filter(username.eq(arg_username)) + .filter(lower(username).eq(arg_username.to_lowercase())) .inner_join(testaustime_users::table) .first::<(UserIdentity, TestaustimeUser)>(&mut conn) .await?; @@ -104,9 +105,10 @@ impl super::DatabaseWrapper { &self, username: &str, password: &str, + email: Option<&str>, ) -> Result { if self.user_exists(username.to_string()).await? { - return Err(TimeError::UserExists); + return Err(TimeError::UsernameTaken); } let salt = SaltString::generate(&mut OsRng); let argon2 = Argon2::default(); @@ -118,6 +120,7 @@ impl super::DatabaseWrapper { registration_time: chrono::Local::now().naive_local(), username: username.to_string(), friend_code: generate_friend_code(), + email: email.map(String::from), }; let new_user_clone = new_user.clone(); @@ -134,7 +137,7 @@ impl super::DatabaseWrapper { .returning(user_identities::id) .get_results::(&mut conn) .await - .map_err(|_| TimeError::UserExists)?; + .map_err(|_| TimeError::UsernameTaken)?; let testaustime_user = NewTestaustimeUser { password: hash.as_bytes().to_vec(), @@ -158,32 +161,29 @@ impl super::DatabaseWrapper { pub async fn change_username(&self, user: i32, new_username: &str) -> Result<(), TimeError> { let mut conn = self.db.get().await?; - conn.build_transaction() - .read_write() - .run(|mut conn| { - Box::pin(async move { - use crate::schema::user_identities::dsl::*; - - if (user_identities - .filter(username.eq(new_username)) - .first::(&mut conn) - .await) - .is_ok() - { - return Err(TimeError::UserExists); - }; + use crate::schema::user_identities::dsl::*; + diesel::update(crate::schema::user_identities::table) + .filter(id.eq(user)) + .set(username.eq(new_username)) + .execute(&mut conn) + .await + .map_err(|_| TimeError::UsernameTaken)?; - diesel::update(crate::schema::user_identities::table) - .filter(id.eq(user)) - .set(username.eq(new_username)) - .execute(&mut conn) - .await - .map_err(|_| TimeError::UserExists)?; + Ok(()) + } - Ok::<(), TimeError>(()) - }) - }) + pub async fn change_email(&self, user: i32, new_email: String) -> Result<(), TimeError> { + let mut conn = self.db.get().await?; + + use crate::schema::user_identities::dsl::*; + diesel::update(crate::schema::user_identities::table) + .filter(id.eq(user)) + .set(email.eq(new_email)) + .execute(&mut conn) .await + .map_err(|_| TimeError::EmailTaken)?; + + Ok(()) } pub async fn change_password(&self, user: i32, new_password: &str) -> Result<(), TimeError> { @@ -223,6 +223,24 @@ impl super::DatabaseWrapper { Ok(user) } + pub async fn get_user_by_email( + &self, + searched_email: &str, + ) -> Result, TimeError> { + let mut conn = self.db.get().await?; + let user = { + use crate::schema::user_identities::dsl::*; + + user_identities + .filter(email.eq(searched_email)) + .first::(&mut conn) + .await + .optional()? + }; + + Ok(user) + } + pub async fn get_testaustime_user_by_id(&self, uid: i32) -> Result { use crate::schema::testaustime_users::dsl::*; let mut conn = self.db.get().await?; @@ -269,13 +287,14 @@ impl super::DatabaseWrapper { registration_time: chrono::Local::now().naive_local(), username, friend_code: generate_friend_code(), + email: None, }; let new_user_id = diesel::insert_into(crate::schema::user_identities::table) .values(&new_user) .returning(id) .get_results::(&mut conn) .await - .map_err(|_| TimeError::UserExists)?; + .map_err(|_| TimeError::UsernameTaken)?; let testausid_user = NewTestausIdUser { user_id: user_id_arg, diff --git a/src/database/leaderboards.rs b/src/database/leaderboards.rs index 5501686..7b9830d 100644 --- a/src/database/leaderboards.rs +++ b/src/database/leaderboards.rs @@ -89,7 +89,7 @@ impl super::DatabaseWrapper { } pub async fn get_leaderboard_id_by_name(&self, lname: &str) -> Result { - sql_function!(fn lower(x: diesel::sql_types::Text) -> Text); + define_sql_function!(fn lower(x: diesel::sql_types::Text) -> Text); use crate::schema::leaderboards::dsl::*; let mut conn = self.db.get().await?; @@ -102,7 +102,7 @@ impl super::DatabaseWrapper { } pub async fn get_leaderboard(&self, lname: &str) -> Result { - sql_function!(fn lower(x: diesel::sql_types::Text) -> Text); + define_sql_function!(fn lower(x: diesel::sql_types::Text) -> Text); let mut conn = self.db.get().await?; let board = { diff --git a/src/database/mod.rs b/src/database/mod.rs index 3fa976b..f3a0d9f 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -1,6 +1,6 @@ -use std::{future::Future, pin::Pin, sync::Arc}; +use std::sync::Arc; -use actix_web::{dev::Payload, web::Data, FromRequest, HttpRequest}; +use axum::extract::{FromRef, FromRequestParts}; use diesel_async::{ pooled_connection::{ deadpool::{Object, Pool}, @@ -8,8 +8,9 @@ use diesel_async::{ }, AsyncPgConnection, }; +use http::request::Parts; -use crate::error::TimeError; +use crate::{error::TimeError, TestaustimeState}; pub mod activity; pub mod auth; @@ -27,20 +28,27 @@ pub struct DatabaseWrapper { db: Arc, } -impl FromRequest for DatabaseWrapper { - type Error = TimeError; - type Future = Pin>>>; +impl From<&Arc> for DatabaseWrapper { + fn from(value: &Arc) -> Self { + Self { + db: Arc::clone(value), + } + } +} + +impl FromRequestParts for DatabaseWrapper +where + TestaustimeState: FromRef, +{ + type Rejection = TimeError; - fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future { + async fn from_request_parts(_parts: &mut Parts, state: &S) -> Result { + let state = TestaustimeState::from_ref(state); let wrapper = DatabaseWrapper { - db: req - .app_data::>() - .unwrap() - .clone() - .into_inner(), + db: Arc::clone(&state.database), }; - Box::pin(async move { Ok(wrapper) }) + Ok(wrapper) } } diff --git a/src/error.rs b/src/error.rs index 812e0b3..847fabb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,8 +1,8 @@ -use actix_web::{ - error::{BlockingError, ResponseError}, - http::{header::ContentType, StatusCode}, - HttpResponse, +use axum::{ + response::{IntoResponse, Response}, + Json, }; +use http::StatusCode; use thiserror::Error; #[derive(Debug, Error)] @@ -14,9 +14,9 @@ pub enum TimeError { #[error("Internal server error")] DieselConnectionError(#[from] diesel::result::ConnectionError), #[error(transparent)] - ActixError(#[from] actix_web::error::Error), + AxumError(#[from] axum::Error), #[error("User exists")] - UserExists, + UsernameTaken, #[error("User not found")] UserNotFound, #[error("You cannot add yourself")] @@ -31,8 +31,6 @@ pub enum TimeError { UnauthroizedSecuredAccess, #[error("Invalid username or password")] InvalidCredentials, - #[error(transparent)] - BlockingError(#[from] BlockingError), #[error("{0}")] InvalidLength(String), #[error("Username has to contain characters from [a-zA-Z0-9_] and has to be between 2 and 32 characters")] @@ -57,14 +55,22 @@ pub enum TimeError { TooManyRegisters, #[error("The user has no active session")] NotActive, + #[error("Cannot connect to mail server")] + Error(#[from] lettre::transport::smtp::Error), + #[error("Invalid password reset token")] + InvalidPasswordResetToken, + #[error("Invalid email")] + InvalidEmail, + #[error("Expired password reset token")] + ExpiredPasswordResetToken, + #[error("Account with this email exist")] + EmailTaken, } -unsafe impl Send for TimeError {} - -impl ResponseError for TimeError { - fn status_code(&self) -> StatusCode { +impl IntoResponse for TimeError { + fn into_response(self) -> Response { error!("{}", self); - match self { + let status_code = match self { TimeError::UserNotFound | TimeError::LeaderboardNotFound | TimeError::NotActive => { StatusCode::NOT_FOUND } @@ -78,18 +84,25 @@ impl ResponseError for TimeError { TimeError::AlreadyFriends | TimeError::LeaderboardExists | TimeError::AlreadyMember - | TimeError::UserExists => StatusCode::CONFLICT, + | TimeError::UsernameTaken + | TimeError::EmailTaken => StatusCode::CONFLICT, TimeError::Unauthorized | TimeError::InvalidCredentials - | TimeError::UnauthroizedSecuredAccess => StatusCode::UNAUTHORIZED, + | TimeError::UnauthroizedSecuredAccess + | TimeError::InvalidPasswordResetToken + | TimeError::ExpiredPasswordResetToken => StatusCode::UNAUTHORIZED, TimeError::TooManyRegisters => StatusCode::TOO_MANY_REQUESTS, _ => StatusCode::INTERNAL_SERVER_ERROR, - } + }; + + let body = Json(json!({"error": self.to_string()})); + + (status_code, body).into_response() } +} - fn error_response(&self) -> HttpResponse { - HttpResponse::build(self.status_code()) - .insert_header(ContentType::json()) - .body(json!({ "error": self.to_string() }).to_string()) +impl TimeError { + pub fn is_unique_violation(&self) -> bool { + matches!(self, TimeError::DieselError(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::UniqueViolation,.. ))) } } diff --git a/src/main.rs b/src/main.rs index 69643d4..95291dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,41 +4,36 @@ mod database; mod error; mod models; mod ratelimiter; -mod requests; mod schema; +mod state; mod utils; #[cfg(test)] mod tests; -use std::{num::NonZeroU32, sync::Arc}; +use std::{net::SocketAddr, num::NonZeroU32, sync::Arc}; -use actix_cors::Cors; -use actix_web::{ - dev::{ServiceRequest, ServiceResponse}, - error::{ErrorBadRequest, QueryPayloadError}, - web, - web::{Data, QueryConfig}, - App, HttpMessage, HttpServer, -}; -#[cfg(feature = "testausid")] -use api::oauth::ClientInfo; +use api::activity::HeartBeatMemoryStore; use auth::{secured_access::SecuredAccessTokenStorage, AuthMiddleware, Authentication}; -use awc::Client; +use axum::{ + body::Body, + routing::{delete, get, post}, + Router, +}; use chrono::NaiveDateTime; use dashmap::DashMap; use database::Database; use governor::{Quota, RateLimiter}; +use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor}; +use models::UserIdentity; use ratelimiter::TestaustimeRateLimiter; use serde_derive::Deserialize; -use tracing::Span; -use tracing_actix_web::{root_span, RootSpanBuilder, TracingLogger}; +use tower::ServiceBuilder; +use tower_http::trace::TraceLayer; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[macro_use] -extern crate actix_web; - -#[macro_use] -extern crate log; +extern crate tracing; #[macro_use] extern crate diesel; @@ -47,32 +42,16 @@ extern crate diesel; extern crate serde_json; #[derive(Debug, Deserialize)] -pub struct TimeConfig { +pub struct TestaustimeConfig { pub bypass_token: String, pub ratelimit_by_peer_ip: bool, pub max_requests_per_min: usize, pub address: String, pub database_url: String, pub allowed_origin: String, - #[cfg(feature = "testausid")] - #[serde(flatten)] - pub oauth_client_info: ClientInfo, -} - -pub struct TestaustimeRootSpanBuilder; - -impl RootSpanBuilder for TestaustimeRootSpanBuilder { - fn on_request_start(request: &ServiceRequest) -> Span { - if let Authentication::AuthToken(user) = - request.extensions().get::().unwrap() - { - root_span!(request, user.id, user.username) - } else { - root_span!(request) - } - } - - fn on_request_end(_span: Span, _outcome: &Result, actix_web::Error>) {} + pub mail_server: String, + pub mail_user: String, + pub mail_password: String, } pub struct RegisterLimiter { @@ -80,22 +59,67 @@ pub struct RegisterLimiter { pub storage: DashMap, } -#[actix_web::main] -async fn main() -> std::io::Result<()> { - dotenv::dotenv().ok(); - env_logger::init(); +pub struct PasswordReset { + pub user: UserIdentity, + pub expires: NaiveDateTime, +} - let config: TimeConfig = - toml::from_str(&std::fs::read_to_string("settings.toml").expect("Missing settings.toml")) - .expect("Invalid Toml in settings.toml"); +pub struct PasswordResetState { + pub storage: DashMap, +} + +#[derive(Clone)] +pub struct TestaustimeState { + smtp: AsyncSmtpTransport, + database: Arc, + heartbeat_store: Arc, + secured_access_storage: Arc, + register_limiter: Arc, + password_reset_state: Arc, +} - let database = Data::new(Database::new(config.database_url)); +fn create_router(config: &TestaustimeConfig) -> Router { + let database = Arc::new(Database::new(config.database_url.clone())); - let register_limiter = Data::new(RegisterLimiter { + let register_limiter = Arc::new(RegisterLimiter { limit_by_peer_ip: config.ratelimit_by_peer_ip, storage: DashMap::new(), }); + let heartbeat_store = Arc::new(HeartBeatMemoryStore::new()); + + let secured_access_storage = Arc::new(SecuredAccessTokenStorage::new()); + + let password_reset_state = Arc::new(PasswordResetState { + storage: DashMap::default(), + }); + + let creds = Credentials::new(config.mail_user.to_owned(), config.mail_password.to_owned()); + + let smtp: AsyncSmtpTransport = + AsyncSmtpTransport::::starttls_relay(&config.mail_server) + .unwrap_or_else(|_| panic!("failed to connect to {}", &config.mail_server)) + .credentials(creds) + .build(); + + debug!( + "Conntected to mail server on {} as {}", + config.mail_server, config.mail_user + ); + + let state = TestaustimeState { + smtp, + secured_access_storage, + heartbeat_store, + database, + register_limiter, + password_reset_state, + }; + + let auth = AuthMiddleware { + state: state.clone(), + }; + let ratelimiter = Arc::new( RateLimiter::keyed(Quota::per_minute( NonZeroU32::new(config.max_requests_per_min as u32).unwrap(), @@ -103,100 +127,155 @@ async fn main() -> std::io::Result<()> { .with_middleware(), ); - let heartbeat_store = Data::new(api::activity::HeartBeatMemoryStore::new()); - - let secured_access_token_storage = Data::new(SecuredAccessTokenStorage::new()); - - HttpServer::new(move || { - #[cfg(feature = "testausid")] - let tracing = TracingLogger::::new(); - let client = Client::new(); - let cors = Cors::default() - .allow_any_origin() - .allowed_methods(vec!["GET", "POST", "DELETE"]) - .allowed_headers(vec![ - http::header::AUTHORIZATION, - http::header::ACCEPT, - http::header::CONTENT_TYPE, - ]) - .max_age(3600); - let query_config = QueryConfig::default().error_handler(|err, _| match err { - QueryPayloadError::Deserialize(e) => ErrorBadRequest(json!({ "error": e.to_string() })), - _ => unreachable!(), - }); - let app = App::new() - .app_data(Data::clone(®ister_limiter)) - .app_data(query_config) - .app_data(Data::clone(&secured_access_token_storage)) - .wrap(cors) - .service(api::health) - .service(api::auth::register) - .service({ - let scope = web::scope("") - .wrap(tracing) - .wrap(AuthMiddleware) - .wrap(TestaustimeRateLimiter { - limiter: Arc::clone(&ratelimiter), - use_peer_addr: config.ratelimit_by_peer_ip, - bypass_token: config.bypass_token.clone(), - }) - .service({ - web::scope("/activity") - .service(api::activity::update) - .service(api::activity::delete) - .service(api::activity::flush) - .service(api::activity::rename_project) - .service(api::activity::hide_project) - }) - .service(api::auth::login) - .service(api::auth::regenerate) - .service(api::auth::changeusername) - .service(api::auth::changepassword) - .service(api::auth::get_secured_access_token) - .service(api::account::change_settings) - .service(api::friends::add_friend) - .service(api::friends::get_friends) - .service(api::friends::regenerate_friend_code) - .service(api::friends::remove) - .service(api::users::my_profile) - .service(api::users::get_activities) - .service(api::users::get_current_activity) - .service(api::users::delete_user) - .service(api::users::my_leaderboards) - .service(api::users::get_activity_summary) - .service(api::leaderboards::create_leaderboard) - .service(api::leaderboards::get_leaderboard) - .service(api::leaderboards::join_leaderboard) - .service(api::leaderboards::leave_leaderboard) - .service(api::leaderboards::delete_leaderboard) - .service(api::leaderboards::promote_member) - .service(api::leaderboards::demote_member) - .service(api::leaderboards::kick_member) - .service(api::leaderboards::regenerate_invite) - .service(api::search::search_public_users) - .service(api::stats::stats); - #[cfg(feature = "testausid")] - { - scope.service(api::oauth::callback) - } - #[cfg(not(feature = "testausid"))] - { - scope - } - }) - .app_data(Data::clone(&database)) - .app_data(Data::clone(&heartbeat_store)); - #[cfg(feature = "testausid")] - { - app.app_data(Data::new(client)) - .app_data(Data::new(config.oauth_client_info.clone())) - } - #[cfg(not(feature = "testausid"))] - { - app - } - }) - .bind(config.address)? - .run() + Router::new() + .route("/health", get(api::health)) + .route("/auth/register", post(api::auth::register)) + .merge({ + let router = Router::new() + .nest("/activity", { + Router::new() + .route("/update", post(api::activity::update)) + .route("/delete", delete(api::activity::delete)) + .route("/flush", post(api::activity::flush)) + .route("/rename", post(api::activity::rename_project)) + .route("/hide", post(api::activity::hide_project)) + }) + .route("/auth/login", post(api::auth::login)) + .route("/auth/regenerate", post(api::auth::regenerate)) + .route("/auth/change_username", post(api::auth::change_username)) + .route("/auth/change_email", post(api::auth::change_email)) + .route("/auth/change_password", post(api::auth::change_password)) + .route( + "/auth/securedaccess", + post(api::auth::get_secured_access_token), + ) + .route( + "/auth/reset_password", + post(api::auth::request_password_reset), + ) + .route( + "/auth/complete_password_reset", + post(api::auth::reset_password), + ) + .route("/friends/add", post(api::friends::add_friend)) + .route("/account/settings", post(api::account::change_settings)) + .route("/friends/list", get(api::friends::get_friends)) + .route( + "/friends/regenerate", + get(api::friends::regenerate_friend_code), + ) + .route("/friends/remove", delete(api::friends::remove)) + .route("/users/@me", get(api::users::my_profile)) + .route("/users/@me/delete", delete(api::users::delete_user)) + .route("/users/@me/leaderboards", get(api::users::my_leaderboards)) + .route( + "/users/{username}/activity/data", + get(api::users::get_activities), + ) + .route( + "/users/{username}/activity/current", + get(api::users::get_current_activity), + ) + .route( + "/users/{username}/activity/summary", + get(api::users::get_activity_summary), + ) + .route( + "/leaderboards/create", + post(api::leaderboards::create_leaderboard), + ) + .route( + "/leaderboards/{name}", + get(api::leaderboards::get_leaderboard), + ) + .route( + "/leaderboards/join", + post(api::leaderboards::join_leaderboard), + ) + .route( + "/leaderboards/{name}/leave", + post(api::leaderboards::leave_leaderboard), + ) + .route( + "/leaderboards/{name}", + delete(api::leaderboards::delete_leaderboard), + ) + .route( + "/leaderboards/{name}/promote", + post(api::leaderboards::promote_member), + ) + .route( + "/leaderboards/{name}/demote", + post(api::leaderboards::demote_member), + ) + .route( + "/leaderboards/{name}/kick", + post(api::leaderboards::kick_member), + ) + .route( + "/leaderboards/{name}/regenerate", + post(api::leaderboards::regenerate_invite), + ) + .route("/search/users", get(api::search::search_public_users)) + .route("/stats", get(api::stats::stats)); + + #[cfg(feature = "testausid")] + let router = router.route("/auth/callback", get(api::oauth::callback)); + + router + .layer( + ServiceBuilder::new() + .layer(TestaustimeRateLimiter { + limiter: ratelimiter, + use_peer_addr: config.ratelimit_by_peer_ip, + bypass_token: config.bypass_token.clone(), + }) + .layer(auth), + ) + .layer(TraceLayer::new_for_http().make_span_with( + |request: &http::Request| { + tracing::debug_span!( + "request", + method = %request.method(), + uri = request.uri().path(), + user = request + .extensions() + .get::() + .and_then(|auth| auth.user().map(|u| &u.username))) + }, + )) + }) + .with_state(state) +} + +#[tokio::main] +async fn main() { + dotenv::dotenv().ok(); + tracing_subscriber::registry() + .with( + tracing_subscriber::EnvFilter::try_from_env("TESTAUSTIME_LOG").unwrap_or_else(|_| { + "testaustime=debug,tower_http=debug,axum::rejection=trace".into() + }), + ) + .with(tracing_subscriber::fmt::layer()) + .init(); + + let config: TestaustimeConfig = + toml::from_str(&std::fs::read_to_string("settings.toml").expect("Missing settings.toml")) + .expect("Invalid Toml in settings.toml"); + + let router = create_router(&config); + + let listener = tokio::net::TcpListener::bind(&config.address) + .await + .unwrap(); + + info!("Staring server on {}", config.address); + + axum::serve( + listener, + router.into_make_service_with_connect_info::(), + ) .await + .unwrap(); } diff --git a/src/models.rs b/src/models.rs index 89062b1..d91c5d5 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,4 +1,5 @@ #![allow(clippy::extra_unused_lifetimes)] +use serde::Deserializer; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash)] @@ -16,6 +17,7 @@ pub struct UserIdentity { pub username: String, pub registration_time: chrono::NaiveDateTime, pub is_public: bool, + pub email: Option, } #[derive(Clone, Debug, Serialize)] @@ -47,7 +49,7 @@ pub struct TestaustimeUser { pub identity: i32, } -use crate::{requests::HeartBeat, schema::testaustime_users}; +use crate::schema::testaustime_users; #[derive(Insertable, Serialize, Clone)] #[diesel(table_name = testaustime_users)] @@ -114,6 +116,7 @@ pub struct NewUserIdentity { pub username: String, pub friend_code: String, pub registration_time: chrono::NaiveDateTime, + pub email: Option, } // NOTE: It is impossible to use diesel::assocations here @@ -251,3 +254,28 @@ pub struct FriendWithTimeAndStatus { pub struct SecuredAccessTokenResponse { pub token: String, } + +#[derive(Deserialize, Serialize, Debug, Hash, Eq, PartialEq, Clone)] +pub struct HeartBeat { + #[serde(deserialize_with = "project_deserialize")] + pub project_name: Option, + pub language: Option, + pub editor_name: Option, + pub hostname: Option, + pub hidden: Option, +} + +// Wtf is this +fn project_deserialize<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let project = Option::::deserialize(deserializer)?; + Ok(project.map(|p| { + if p.starts_with("tmp.") { + String::from("tmp") + } else { + p + } + })) +} diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index 2ffe1f5..a97c9e7 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -1,72 +1,77 @@ -use std::{net::IpAddr, rc::Rc, sync::Arc}; +use std::{ + net::{IpAddr, SocketAddr}, + sync::Arc, + task::{Context, Poll}, +}; -use actix_web::{ - body::EitherBody, - dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}, - Error, HttpResponse, +use axum::{ + body::Body, + extract::{ConnectInfo, Request}, + response::Response, }; -use futures_util::future::LocalBoxFuture; +use futures_util::future::BoxFuture; use governor::{ clock::DefaultClock, middleware::StateInformationMiddleware, state::keyed::DefaultKeyedStateStore, RateLimiter, }; -use http::{header::HeaderName, HeaderValue}; +use http::{ + header::{HeaderName, FORWARDED}, + HeaderValue, StatusCode, +}; +use tower::{Layer, Service}; type SharedRateLimiter = Arc, DefaultClock, M>>; +#[derive(Clone)] pub struct TestaustimeRateLimiter { pub limiter: SharedRateLimiter, pub use_peer_addr: bool, pub bypass_token: String, } -impl Transform for TestaustimeRateLimiter -where - S: Service, Error = Error> + 'static, - S::Future: 'static, - B: 'static, -{ - type Response = ServiceResponse>; - type Error = Error; - type InitError = (); - type Transform = TestaustimeRateLimiterTransform; - type Future = LocalBoxFuture<'static, Result>; - - fn new_transform(&self, service: S) -> Self::Future { - let transform = Ok(Self::Transform { - service: Rc::new(service), +impl Layer for TestaustimeRateLimiter { + type Service = TestaustimeRateLimiterService; + + fn layer(&self, inner: S) -> Self::Service { + Self::Service { + inner, limiter: Arc::clone(&self.limiter), use_peer_addr: self.use_peer_addr, bypass_token: self.bypass_token.clone(), - }); - - Box::pin(async move { transform }) + } } } -pub struct TestaustimeRateLimiterTransform { - service: Rc, +#[derive(Clone)] +pub struct TestaustimeRateLimiterService { + inner: S, limiter: SharedRateLimiter, use_peer_addr: bool, bypass_token: String, } -impl Service for TestaustimeRateLimiterTransform +impl Service for TestaustimeRateLimiterService where - S: Service, Error = Error> + 'static, - S::Future: 'static, - B: 'static, + S: Service, + S::Future: Send + 'static, { - type Response = ServiceResponse>; + type Response = S::Response; type Error = S::Error; - type Future = LocalBoxFuture<'static, Result>; + type Future = BoxFuture<'static, Result>; - forward_ready!(service); + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.inner.poll_ready(cx) + } - fn call(&self, req: ServiceRequest) -> Self::Future { - let conn_info = req.connection_info().clone(); + fn call(&mut self, req: Request) -> Self::Future { if let Some(ip) = { + let conn_info = req + .extensions() + .get::>() + .unwrap() + .ip(); + let bypass = req .headers() .get("bypass-token") @@ -75,18 +80,27 @@ where let addr = if bypass { req.headers() .get("client-ip") - .and_then(|ip| ip.to_str().ok()) + .and_then(|ip| ip.to_str().ok().and_then(|ip| ip.parse::().ok())) } else if self.use_peer_addr { - conn_info.peer_addr() + Some(conn_info) } else { - conn_info.realip_remote_addr() + let header = req + .headers() + .get("x-forwarded-for") + .or_else(|| req.headers().get(FORWARDED)); + + Some( + header + .and_then(|ip| ip.to_str().ok().and_then(|ip| ip.parse::().ok())) + .unwrap_or(conn_info), + ) }; - addr.and_then(|addr| addr.parse::().ok()) + addr } { match self.limiter.check_key(&ip) { Ok(state) => { - let res = self.service.call(req); + let res = self.inner.call(req); Box::pin(async move { let mut res = res.await?; @@ -97,42 +111,45 @@ where headers.insert( HeaderName::from_static("ratelimit-limit"), - HeaderValue::from_str("a.burst_size().to_string())?, + HeaderValue::from_str("a.burst_size().to_string()).unwrap(), ); headers.insert( HeaderName::from_static("ratelimit-remaining"), - HeaderValue::from_str(&state.remaining_burst_capacity().to_string())?, + HeaderValue::from_str(&state.remaining_burst_capacity().to_string()) + .unwrap(), ); headers.insert( HeaderName::from_static("ratelimit-reset"), HeaderValue::from_str( "a.replenish_interval().as_secs().to_string(), - )?, + ) + .unwrap(), ); - Ok(res.map_into_left_body()) + Ok(res) }) } Err(denied) => Box::pin(async move { - let response = HttpResponse::TooManyRequests() - .insert_header(("ratelimit-limit", denied.quota().burst_size().to_string())) - .insert_header(("ratelimit-remaining", "0")) - .insert_header(( + Ok(Response::builder() + .status(StatusCode::TOO_MANY_REQUESTS) + .header("ratelimit-limit", denied.quota().burst_size().to_string()) + .header("ratelimit-remaining", "0") + .header( "ratelimit-reset", denied.quota().replenish_interval().as_secs().to_string(), - )) - .finish(); - - Ok(req.into_response(response.map_into_right_body())) + ) + .body(Body::empty()) + .unwrap()) }), } } else { Box::pin(async move { - Err(actix_web::error::ErrorInternalServerError( - "Failed to get request ip (?)", - )) + Ok(Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(Body::empty()) + .unwrap()) }) } } diff --git a/src/requests.rs b/src/requests.rs deleted file mode 100644 index 161d41f..0000000 --- a/src/requests.rs +++ /dev/null @@ -1,58 +0,0 @@ -use chrono::{serde::ts_seconds_option, DateTime, Utc}; -use serde::{Deserialize, Deserializer, Serialize}; - -#[derive(Deserialize, Serialize, Debug, Hash, Eq, PartialEq, Clone)] -pub struct HeartBeat { - #[serde(deserialize_with = "project_deserialize")] - pub project_name: Option, - pub language: Option, - pub editor_name: Option, - pub hostname: Option, - pub hidden: Option, -} - -fn project_deserialize<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - let project = Option::::deserialize(deserializer)?; - Ok(project.map(|p| { - if p.starts_with("tmp.") { - String::from("tmp") - } else { - p - } - })) -} - -#[derive(Deserialize, Debug)] -pub struct DataRequest { - #[serde(default)] - #[serde(with = "ts_seconds_option")] - pub from: Option>, - #[serde(default)] - #[serde(with = "ts_seconds_option")] - pub to: Option>, - pub min_duration: Option, - pub editor_name: Option, - pub language: Option, - pub hostname: Option, - pub project_name: Option, -} - -#[derive(Deserialize, Debug)] -pub struct RegisterRequest { - pub username: String, - pub password: String, -} - -#[derive(Deserialize)] -pub struct UsernameChangeRequest { - pub new: String, -} - -#[derive(Deserialize)] -pub struct PasswordChangeRequest { - pub old: String, - pub new: String, -} diff --git a/src/schema.rs b/src/schema.rs index b3bc6a2..c99e108 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -75,6 +75,7 @@ diesel::table! { username -> Varchar, registration_time -> Timestamp, is_public -> Bool, + email -> Nullable, } } diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..7ed3cab --- /dev/null +++ b/src/state.rs @@ -0,0 +1,39 @@ +use std::sync::Arc; + +use axum::extract::FromRef; +use lettre::{AsyncSmtpTransport, Tokio1Executor}; + +use crate::{ + api::activity::HeartBeatMemoryStore, auth::secured_access::SecuredAccessTokenStorage, + PasswordResetState, RegisterLimiter, TestaustimeState, +}; + +impl FromRef for Arc { + fn from_ref(input: &TestaustimeState) -> Self { + Arc::clone(&input.heartbeat_store) + } +} + +impl FromRef for Arc { + fn from_ref(input: &TestaustimeState) -> Self { + Arc::clone(&input.secured_access_storage) + } +} + +impl FromRef for Arc { + fn from_ref(input: &TestaustimeState) -> Self { + Arc::clone(&input.register_limiter) + } +} + +impl FromRef for Arc { + fn from_ref(input: &TestaustimeState) -> Self { + Arc::clone(&input.password_reset_state) + } +} + +impl FromRef for AsyncSmtpTransport { + fn from_ref(input: &TestaustimeState) -> Self { + input.smtp.clone() + } +} diff --git a/src/tests/account.rs b/src/tests/account.rs index e8d90ea..ef4898a 100644 --- a/src/tests/account.rs +++ b/src/tests/account.rs @@ -1,66 +1,62 @@ -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - -use actix_web::test::{self, TestRequest}; use serde_json::json; use super::{macros::*, *}; use crate::models::{NewUserIdentity, SecuredAccessTokenResponse}; -#[actix_web::test] +#[tokio::test] async fn public_accounts() { - let app = test::init_service(App::new().configure(init_test_services)).await; + let mut app = create_test_router().into_service(); let body = json!({"username": "celebrity", "password": "password"}); - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); - let resp = request!(app, addr, post, "/auth/register", body); + let resp = request!(app, POST, "/auth/register", body); assert!(resp.status().is_success(), "Creating user failed"); - let user: NewUserIdentity = test::read_body_json(resp).await; - let resp = request_auth!(app, addr, get, "/users/@me", user.auth_token); + let user: NewUserIdentity = body_to_json(resp).await; + let resp = request_auth!(app, GET, "/users/@me", user.auth_token); assert!(resp.status().is_success(), "Getting profile failed"); - let profile: serde_json::Value = test::read_body_json(resp).await; + let profile: serde_json::Value = body_to_json(resp).await; assert!( !profile["is_public"].as_bool().unwrap(), "New account should be private" ); - let resp = request!(app, addr, get, "/users/celebrity/activity/data"); + let resp = request!(app, GET, "/users/celebrity/activity/data"); assert!( resp.status().is_client_error(), "Data should be private for private accounts" ); - let resp = request!(app, addr, post, "/auth/securedaccess", body); + let resp = request!(app, POST, "/auth/securedaccess", body); assert!( resp.status().is_success(), "Getting secured access token failed" ); - let sat: SecuredAccessTokenResponse = test::read_body_json(resp).await; + let sat: SecuredAccessTokenResponse = body_to_json(resp).await; let change = json!({"public_profile": true}); - let resp = request_auth!(app, addr, post, "/account/settings", sat.token, change); + let resp = request_auth!(app, POST, "/account/settings", sat.token, change); assert!(resp.status().is_success(), "Changing settings failed"); - let resp = request_auth!(app, addr, get, "/users/@me", user.auth_token); + let resp = request_auth!(app, GET, "/users/@me", user.auth_token); assert!(resp.status().is_success(), "Getting profile failed"); - let profile: serde_json::Value = test::read_body_json(resp).await; + let profile: serde_json::Value = body_to_json(resp).await; assert!( profile["is_public"].as_bool().unwrap(), "Setting account public failed" ); - let resp = request!(app, addr, get, "/users/celebrity/activity/data"); + let resp = request!(app, GET, "/users/celebrity/activity/data"); assert!( resp.status().is_success(), "Data should be public for public accounts" ); - let resp = request!(app, addr, delete, "/users/@me/delete", body); + let resp = request!(app, DELETE, "/users/@me/delete", body); assert!(resp.status().is_success(), "Failed to delete user"); } diff --git a/src/tests/activity.rs b/src/tests/activity.rs index 57f16ad..59d916f 100644 --- a/src/tests/activity.rs +++ b/src/tests/activity.rs @@ -1,22 +1,17 @@ -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use std::time::Duration; -use actix_web::test::{self, TestRequest}; use serde_json::json; use super::{macros::*, *}; -use crate::{ - models::{CurrentActivity, NewUserIdentity, SecuredAccessTokenResponse}, - requests::HeartBeat, -}; +use crate::models::{CurrentActivity, HeartBeat, NewUserIdentity}; -#[actix_web::test] +#[tokio::test] async fn updating_activity_works() { - let app = test::init_service(App::new().configure(init_test_services)).await; - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); + let mut app = create_test_router().into_service(); let body = json!({"username": "activeuser", "password": "password"}); - let resp = request!(app, addr, post, "/auth/register", body); - let user: NewUserIdentity = test::read_body_json(resp).await; + let resp = request!(app, POST, "/auth/register", body); + let user: NewUserIdentity = body_to_json(resp).await; let heartbeat = HeartBeat { hostname: Some(String::from("hostname")), @@ -26,32 +21,19 @@ async fn updating_activity_works() { hidden: Some(false), }; - let resp = request_auth!( - app, - addr, - post, - "/activity/update", - user.auth_token, - heartbeat - ); + let resp = request_auth!(app, POST, "/activity/update", user.auth_token, heartbeat); assert!( resp.status().is_success(), "Sending heartbeat should succeed" ); - let resp = request_auth!( - app, - addr, - get, - "/users/@me/activity/current", - user.auth_token - ); + let resp = request_auth!(app, GET, "/users/@me/activity/current", user.auth_token); assert!( resp.status().is_success(), "Getting current activity should work" ); - let current: CurrentActivity = test::read_body_json(resp).await; + let current: CurrentActivity = body_to_json(resp).await; assert_eq!( heartbeat, current.heartbeat, @@ -59,26 +41,13 @@ async fn updating_activity_works() { ); // NOTE: adding duration to the session - actix_web::rt::time::sleep(std::time::Duration::from_secs(1)).await; + tokio::time::sleep(Duration::from_secs(1)).await; - let resp = request_auth!( - app, - addr, - post, - "/activity/update", - user.auth_token, - heartbeat - ); + let resp = request_auth!(app, POST, "/activity/update", user.auth_token, heartbeat); assert!(resp.status().is_success(), "Extending session should work"); - let resp = request_auth!( - app, - addr, - get, - "/users/@me/activity/current", - user.auth_token - ); - let current: CurrentActivity = test::read_body_json(resp).await; + let resp = request_auth!(app, GET, "/users/@me/activity/current", user.auth_token); + let current: CurrentActivity = body_to_json(resp).await; assert!( current.duration >= 1, "Duration should be at least 1 second" @@ -93,8 +62,7 @@ async fn updating_activity_works() { }; let resp = request_auth!( app, - addr, - post, + POST, "/activity/update", user.auth_token, new_heartbeat @@ -104,36 +72,29 @@ async fn updating_activity_works() { "Sending heartbeat should succeed" ); - let resp = request_auth!( - app, - addr, - get, - "/users/@me/activity/current", - user.auth_token - ); - let current: CurrentActivity = test::read_body_json(resp).await; + let resp = request_auth!(app, GET, "/users/@me/activity/current", user.auth_token); + let current: CurrentActivity = body_to_json(resp).await; assert!( current.heartbeat == new_heartbeat, "Mismatch should start new session" ); - let resp = request_auth!(app, addr, get, "/users/@me/activity/data", user.auth_token); - let data: Vec = test::read_body_json(resp).await; + let resp = request_auth!(app, GET, "/users/@me/activity/data", user.auth_token); + let data: Vec = body_to_json(resp).await; assert!(!data.is_empty(), "Old session is stored in the database"); - let resp = request!(app, addr, delete, "/users/@me/delete", body); + let resp = request!(app, DELETE, "/users/@me/delete", body); assert!(resp.status().is_success(), "Failed to delete user"); } -#[actix_web::test] +#[tokio::test] async fn flushing_works() { - let app = test::init_service(App::new().configure(init_test_services)).await; - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); + let mut app = create_test_router().into_service(); let body = json!({"username": "activeuser2", "password": "password"}); - let resp = request!(app, addr, post, "/auth/register", body); - let user: NewUserIdentity = test::read_body_json(resp).await; + let resp = request!(app, POST, "/auth/register", body); + let user: NewUserIdentity = body_to_json(resp).await; let heartbeat = HeartBeat { hostname: Some(String::from("hostname")), @@ -143,33 +104,26 @@ async fn flushing_works() { hidden: Some(false), }; - let resp = request_auth!( - app, - addr, - post, - "/activity/update", - user.auth_token, - heartbeat - ); + let resp = request_auth!(app, POST, "/activity/update", user.auth_token, heartbeat); assert!( resp.status().is_success(), "Sending heartbeat should succeed" ); - let resp = request_auth!(app, addr, get, "/users/@me/activity/data", user.auth_token); - let data: Vec = test::read_body_json(resp).await; + let resp = request_auth!(app, GET, "/users/@me/activity/data", user.auth_token); + let data: Vec = body_to_json(resp).await; assert!(data.is_empty(), "No session should exist"); - let resp = request_auth!(app, addr, post, "/activity/flush", user.auth_token); + let resp = request_auth!(app, POST, "/activity/flush", user.auth_token); assert!(resp.status().is_success(), "Flushing should work"); - let resp = request_auth!(app, addr, get, "/users/@me/activity/data", user.auth_token); - let data: Vec = test::read_body_json(resp).await; + let resp = request_auth!(app, GET, "/users/@me/activity/data", user.auth_token); + let data: Vec = body_to_json(resp).await; assert!(!data.is_empty(), "Session should be saved after a flush"); - let resp = request!(app, addr, delete, "/users/@me/delete", body); + let resp = request!(app, DELETE, "/users/@me/delete", body); assert!(resp.status().is_success(), "Failed to delete user"); } diff --git a/src/tests/auth.rs b/src/tests/auth.rs index bdf7a20..ce061d6 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -1,64 +1,61 @@ -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - -use actix_web::test::{self, TestRequest}; use serde_json::json; use super::{macros::*, *}; use crate::models::{NewUserIdentity, SecuredAccessTokenResponse, SelfUser}; -#[actix_web::test] +#[tokio::test] async fn register_and_delete() { - let app = test::init_service(App::new().configure(init_test_services)).await; - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); + let mut app = create_test_router().into_service(); + let body = json!({"username": "testuser", "password": "password"}); - let resp = request!(app, addr, post, "/auth/register", body); + let resp = request!(app, POST, "/auth/register", body); assert!(resp.status().is_success(), "Failed to create user"); - let user: NewUserIdentity = test::read_body_json(resp).await; + let user: NewUserIdentity = body_to_json(resp).await; - let resp = request!(app, addr, post, "/auth/register", body); + let resp = request!(app, POST, "/auth/register", body); assert!(resp.status().is_client_error(), "Usernames must be unique"); - let resp = request_auth!(app, addr, get, "/users/@me", user.auth_token); + let resp = request_auth!(app, GET, "/users/@me", user.auth_token); assert!( resp.status().is_success(), "Authentication token should work" ); - let resp = request!(app, addr, delete, "/users/@me/delete", body); + let resp = request!(app, DELETE, "/users/@me/delete", body); assert!(resp.status().is_success(), "Failed to delete user"); - let resp = request!(app, addr, post, "/auth/login", body); + let resp = request!(app, POST, "/auth/login", body); assert!(resp.status().is_client_error(), "User should be deleted") } -#[actix_web::test] +#[tokio::test] async fn login_change_username_and_password() { - let app = test::init_service(App::new().configure(init_test_services)).await; + let mut app = create_test_router().into_service(); let body = json!({"username": "testuser2", "password": "password"}); - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); - let resp = request!(app, addr, post, "/auth/register", body); + let resp = request!(app, POST, "/auth/register", body); + println!("{:?}", resp); assert!(resp.status().is_success(), "Failed to create user"); - let user: NewUserIdentity = test::read_body_json(resp).await; + let user: NewUserIdentity = body_to_json(resp).await; - let resp = request!(app, addr, post, "/auth/login", body); + let resp = request!(app, POST, "/auth/login", body); assert!(resp.status().is_success(), "Login failed"); - let login_user: SelfUser = test::read_body_json(resp).await; + let login_user: SelfUser = body_to_json(resp).await; assert_eq!( user.auth_token, login_user.auth_token, "Auth tokens should be equal" ); - let resp = request!(app, addr, post, "/auth/securedaccess", body); + let resp = request!(app, POST, "/auth/securedaccess", body); assert!( resp.status().is_success(), "Getting secured access token failed" ); - let sat: SecuredAccessTokenResponse = test::read_body_json(resp).await; + let sat: SecuredAccessTokenResponse = body_to_json(resp).await; let change_request = json!({ "new": "testuser3" @@ -66,8 +63,7 @@ async fn login_change_username_and_password() { let resp = request_auth!( app, - addr, - post, + POST, "/auth/changeusername", user.auth_token, change_request @@ -77,18 +73,11 @@ async fn login_change_username_and_password() { "Auth token is not secured access token" ); - let resp = request_auth!( - app, - addr, - post, - "/auth/changeusername", - sat.token, - change_request - ); + let resp = request_auth!(app, POST, "/auth/changeusername", sat.token, change_request); assert!(resp.status().is_success(), "Username change failed"); - let resp = request_auth!(app, addr, get, "/users/@me", user.auth_token); - let renamed_user: serde_json::Value = test::read_body_json(resp).await; + let resp = request_auth!(app, GET, "/users/@me", user.auth_token); + let renamed_user: serde_json::Value = body_to_json(resp).await; assert_eq!( renamed_user["username"], change_request["new"], "Username not changed" @@ -101,8 +90,7 @@ async fn login_change_username_and_password() { let resp = request_auth!( app, - addr, - post, + POST, "/auth/changepassword", user.auth_token, pw_request @@ -111,26 +99,25 @@ async fn login_change_username_and_password() { let new_body = json!({"username": "testuser3", "password": "password1"}); - let resp = request!(app, addr, post, "/auth/login", new_body); + let resp = request!(app, POST, "/auth/login", new_body); assert!(resp.status().is_success(), "Password not changed"); - let resp = request!(app, addr, delete, "/users/@me/delete", new_body); + let resp = request!(app, DELETE, "/users/@me/delete", new_body); assert!(resp.status().is_success(), "Failed to delete user"); } -#[actix_web::test] +#[tokio::test] async fn invalid_usernames_and_passwords_are_rejected() { - let app = test::init_service(App::new().configure(init_test_services)).await; - - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); + let mut app = create_test_router().into_service(); let body = json!({"username": "invalid[$$]", "password": "password"}); - let resp = request!(app, addr, post, "/auth/register", body); + let resp = request!(app, POST, "/auth/register", body); + assert!( resp.status().is_client_error(), "Invalid username should fail" ); - let resp_body: serde_json::Value = test::read_body_json(resp).await; + let resp_body: serde_json::Value = body_to_json(resp).await; assert!(resp_body["error"] .as_str() @@ -139,12 +126,12 @@ async fn invalid_usernames_and_passwords_are_rejected() { .contains("username")); let body = json!({"username": "validusername", "password": "short"}); - let resp = request!(app, addr, post, "/auth/register", body); + let resp = request!(app, POST, "/auth/register", body); assert!( resp.status().is_client_error(), "Too short password should fail" ); - let resp_body: serde_json::Value = test::read_body_json(resp).await; + let resp_body: serde_json::Value = body_to_json(resp).await; assert!(resp_body["error"] .as_str() diff --git a/src/tests/friends.rs b/src/tests/friends.rs index db83f5f..c83ab16 100644 --- a/src/tests/friends.rs +++ b/src/tests/friends.rs @@ -1,62 +1,40 @@ -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - -use actix_web::test::{self, TestRequest}; use serde_json::json; use super::{macros::*, *}; use crate::models::NewUserIdentity; -#[actix_web::test] +#[tokio::test] async fn adding_friends_works() { - let app = test::init_service(App::new().configure(init_test_services)).await; + let mut app = create_test_router().into_service(); let f1_body = json!({"username": "friend1", "password": "password"}); let f2_body = json!({"username": "friend2", "password": "password"}); - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); - let other_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 2)), 80u16); - let resp = request!(app, addr, post, "/auth/register", f1_body); + let resp = request!(app, POST, "/auth/register", f1_body); assert!(resp.status().is_success(), "Failed to create user"); - let f1: NewUserIdentity = test::read_body_json(resp).await; + let f1: NewUserIdentity = body_to_json(resp).await; - let resp = request!(app, other_addr, post, "/auth/register", f2_body); + let resp = request!(app, POST, "/auth/register", f2_body); assert!(resp.status().is_success(), "Failed to create user"); - let f2: NewUserIdentity = test::read_body_json(resp).await; + let f2: NewUserIdentity = body_to_json(resp).await; - let resp = TestRequest::post() - .peer_addr(addr) - .uri("/friends/add") - .insert_header(("authorization", "Bearer ".to_owned() + &f1.auth_token)) - .set_payload(f2.friend_code.clone()) - .send_request(&app) - .await; + let friend_body = json!({"code": f2.friend_code.clone()}); + let resp = request!(app, POST, "/friends/add", friend_body); assert!(resp.status().is_success(), "Adding friend works"); - let resp = TestRequest::post() - .peer_addr(addr) - .uri("/friends/add") - .insert_header(("authorization", "Bearer ".to_owned() + &f1.auth_token)) - .set_payload(f2.friend_code.clone()) - .send_request(&app) - .await; + let resp = request!(app, POST, "/friends/add", friend_body); assert!(resp.status().is_client_error(), "Re-adding friend fails"); - let resp = TestRequest::post() - .peer_addr(addr) - .uri("/friends/add") - .insert_header(("authorization", "Bearer ".to_owned() + &f1.auth_token)) - .set_payload(f1.friend_code.clone()) - .send_request(&app) - .await; + let self_body = json!({"code": f1.friend_code.clone()}); + let resp = request!(app, POST, "/friends/add", self_body); assert!(resp.status().is_client_error(), "Adding self fails"); let resp = request_auth!( app, - addr, - get, + GET, &format!("/users/{}/activity/data", &f1.username), f2.auth_token ); @@ -65,16 +43,16 @@ async fn adding_friends_works() { "Friends can see eachothers data" ); - let resp = request_auth!(app, addr, get, "/friends/list", f2.auth_token); + let resp = request_auth!(app, GET, "/friends/list", f2.auth_token); assert!(resp.status().is_success(), "Getting friends-list works"); - let friends: Vec = test::read_body_json(resp).await; + let friends: Vec = body_to_json(resp).await; assert_eq!(friends.len(), 1, "Friend appears in friends-list"); - let resp = request!(app, addr, delete, "/users/@me/delete", f1_body); + let resp = request!(app, DELETE, "/users/@me/delete", f1_body); assert!(resp.status().is_success(), "Failed to delete user"); - let resp = request!(app, addr, delete, "/users/@me/delete", f2_body); + let resp = request!(app, DELETE, "/users/@me/delete", f2_body); assert!(resp.status().is_success(), "Failed to delete user"); } diff --git a/src/tests/leaderboards.rs b/src/tests/leaderboards.rs index 099c7dd..b15aa14 100644 --- a/src/tests/leaderboards.rs +++ b/src/tests/leaderboards.rs @@ -1,6 +1,3 @@ -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - -use actix_web::test::{self, TestRequest}; use serde_json::json; use super::{macros::*, *}; @@ -9,50 +6,34 @@ use crate::{ models::{NewUserIdentity, PrivateLeaderboard, SecuredAccessTokenResponse}, }; -#[actix_web::test] +#[tokio::test] async fn creation_joining_and_deletion() { - let app = test::init_service(App::new().configure(init_test_services)).await; + let mut app = create_test_router().into_service(); let owner_body = json!({"username": "leaderboardowner", "password": "password"}); let member_body = json!({"username": "leaderboardmember", "password": "password"}); - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); - let addr2 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 2)), 80u16); - let resp = request!(app, addr, post, "/auth/register", owner_body); + let resp = request!(app, POST, "/auth/register", owner_body); assert!(resp.status().is_success(), "Creating user failed"); - let owner: NewUserIdentity = test::read_body_json(resp).await; + let owner: NewUserIdentity = body_to_json(resp).await; - let resp = request!(app, addr2, post, "/auth/register", member_body); + let resp = request!(app, POST, "/auth/register", member_body); assert!(resp.status().is_success(), "Creating user failed"); - let member: NewUserIdentity = test::read_body_json(resp).await; + let member: NewUserIdentity = body_to_json(resp).await; let create = LeaderboardName { name: "board".to_string(), }; - let resp = request_auth!( - app, - addr, - post, - "/leaderboards/create", - owner.auth_token, - create - ); + let resp = request_auth!(app, POST, "/leaderboards/create", owner.auth_token, create); assert!(resp.status().is_success(), "Leaderboard creation failed"); - let created: serde_json::Value = test::read_body_json(resp).await; + let created: serde_json::Value = body_to_json(resp).await; - let resp = request_auth!( - app, - addr, - post, - "/leaderboards/create", - owner.auth_token, - create - ); + let resp = request_auth!(app, POST, "/leaderboards/create", owner.auth_token, create); assert!( resp.status().is_client_error(), @@ -63,63 +44,49 @@ async fn creation_joining_and_deletion() { invite: created["invite_code"].as_str().unwrap().to_string(), }; - let resp = request_auth!( - app, - addr, - post, - "/leaderboards/join", - member.auth_token, - invite - ); + let resp = request_auth!(app, POST, "/leaderboards/join", member.auth_token, invite); assert!(resp.status().is_success(), "Joining leaderboard failed"); - let resp = request_auth!( - app, - addr, - post, - "/leaderboards/join", - owner.auth_token, - invite - ); + let resp = request_auth!(app, POST, "/leaderboards/join", owner.auth_token, invite); assert!( resp.status().is_client_error(), "Trying to re-join a leaderboard should fail" ); - let resp = request_auth!(app, addr, get, "/leaderboards/board", member.auth_token); + let resp = request_auth!(app, GET, "/leaderboards/board", member.auth_token); assert!(resp.status().is_success(), "Getting leaderboard failed"); - let board: PrivateLeaderboard = test::read_body_json(resp).await; + let board: PrivateLeaderboard = body_to_json(resp).await; assert_eq!( board.members.len(), 2, "Leaderboard member count should be 2" ); - let resp = request!(app, addr, post, "/auth/securedaccess", owner_body); + let resp = request!(app, POST, "/auth/securedaccess", owner_body); assert!( resp.status().is_success(), "Getting secured access token failed" ); - let sat: SecuredAccessTokenResponse = test::read_body_json(resp).await; + let sat: SecuredAccessTokenResponse = body_to_json(resp).await; - let resp = request_auth!(app, addr, delete, "/leaderboards/board", sat.token); + let resp = request_auth!(app, DELETE, "/leaderboards/board", sat.token); assert!(resp.status().is_success(), "Leaderboards deletion failed"); - let resp = request_auth!(app, addr, get, "/leaderboards/board", member.auth_token); + let resp = request_auth!(app, GET, "/leaderboards/board", member.auth_token); assert!( resp.status().is_client_error(), "Leaderboard should be deleted" ); - let resp = request!(app, addr, delete, "/users/@me/delete", owner_body); + let resp = request!(app, DELETE, "/users/@me/delete", owner_body); assert!(resp.status().is_success(), "Failed to delete user"); - let resp = request!(app, addr, delete, "/users/@me/delete", member_body); + let resp = request!(app, DELETE, "/users/@me/delete", member_body); assert!(resp.status().is_success(), "Failed to delete user"); } diff --git a/src/tests/macros.rs b/src/tests/macros.rs index 5ec0209..6302b42 100644 --- a/src/tests/macros.rs +++ b/src/tests/macros.rs @@ -1,38 +1,116 @@ macro_rules! request { - ($app:expr, $addr:expr, $method:tt, $uri:expr) => { - TestRequest::$method() - .peer_addr($addr) - .uri($uri) - .send_request(&$app) + ($app:ident, $method:tt, $uri:expr) => { + tower::Service::call( + ServiceExt::>::ready(&mut $app).await.unwrap(), + Request::builder() + .uri($uri) + .method(http::Method::$method) + .body(Body::empty()) + .unwrap(), + ) + .await + .unwrap() + }; + ($app:ident, $method:tt, $uri:expr, $body:expr) => { + tower::Service::call( + ServiceExt::>::ready(&mut $app).await.unwrap(), + Request::builder() + .uri($uri) + .method(http::Method::$method) + .header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) + .body(Body::from(serde_json::to_vec(&$body).unwrap())) + .unwrap(), + ) + .await + .unwrap() + }; +} + +macro_rules! request_auth { + ($app:expr, $method:tt, $uri:expr, $token:expr) => { + tower::Service::call( + ServiceExt::>::ready(&mut $app).await.unwrap(), + Request::builder() + .uri($uri) + .method(http::Method::$method) + .header("authorization", "Bearer ".to_owned() + &$token) + .body(Body::empty()) + .unwrap(), + ) + .await + .unwrap() + }; + ($app:expr, $method:tt, $uri:expr, $token:expr, $body:expr) => { + tower::Service::call( + ServiceExt::>::ready(&mut $app).await.unwrap(), + Request::builder() + .uri($uri) + .method(http::Method::$method) + .header(http::header::CONTENT_TYPE, "application/json") + .header("authorization", "Bearer ".to_owned() + &$token) + .body(Body::from(serde_json::to_vec(&$body).unwrap())) + .unwrap(), + ) + .await + .unwrap() + }; +} + +macro_rules! oneshot_request { + ($method:tt, $uri:expr) => { + create_test_router() + .oneshot( + Request::builder() + .uri($uri) + .method(Method::$method) + .body(Body::empty()) + .unwrap(), + ) .await + .unwrap() }; - ($app:expr, $addr:expr, $method:tt, $uri:expr, $body:expr) => { - TestRequest::$method() - .peer_addr($addr) - .uri($uri) - .set_json(&$body) - .send_request(&$app) + ($method:tt, $uri:expr, $body:expr) => { + create_test_router() + .oneshot( + Request::builder() + .uri($uri) + .method(http::Method::$method) + .body(Body::from(serde_json::to_vec(&$body).unwrap())) + .unwrap(), + ) .await + .unwrap() }; } -macro_rules! request_auth { - ($app:expr, $addr:expr, $method:tt, $uri:expr, $token:expr) => { - TestRequest::$method() - .peer_addr($addr) - .uri($uri) - .insert_header(("authorization", "Bearer ".to_owned() + &$token)) - .send_request(&$app) +macro_rules! oneshot_request_auth { + ($app:expr, $method:tt, $uri:expr, $token:expr) => { + create_test_router() + .oneshot( + Request::builder() + .uri($uri) + .method(http::Method::$method) + .header(http::header::CONTENT_TYPE, "application/json") + .header("authorization", "Bearer ".to_owned() + &$token) + .body(Body::empty()) + .unwrap(), + ) .await + .unwrap() }; - ($app:expr, $addr:expr, $method:tt, $uri:expr, $token:expr, $body:expr) => { - TestRequest::$method() - .peer_addr($addr) - .uri($uri) - .set_json(&$body) - .insert_header(("authorization", "Bearer ".to_owned() + &$token)) - .send_request(&$app) + ($app:expr, $method:tt, $uri:expr, $token:expr, $body:expr) => { + create_test_router() + .oneshot( + Request::builder() + .uri($uri) + .method(http::Method::$method) + .header(http::header::CONTENT_TYPE, "application/json") + .header("authorization", "Bearer ".to_owned() + &$token) + .body(Body::from(serde_json::to_vec(&$body).unwrap())) + .unwrap(), + ) .await + .unwrap() }; } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 48a8da9..302d1d4 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,4 +1,7 @@ +use std::net::SocketAddr; + // TODO add tests for oauth and improve test coverage +use http_body_util::BodyExt; mod account; mod activity; mod auth; @@ -6,125 +9,49 @@ mod friends; mod leaderboards; mod macros; -use std::{num::NonZeroU32, sync::Arc}; - -use actix_web::{ - http::StatusCode, - test, web, - web::{Data, ServiceConfig}, - App, -}; -use governor::{Quota, RateLimiter}; +use axum::{body::Body, extract::connect_info::MockConnectInfo, response::Response, Router}; +use http::{Request, StatusCode}; +use serde::de::DeserializeOwned; +use tower::ServiceExt; // NOTE: We would like to use diesels Connection::begin_test_transaction // But cannot use them because our database uses transactions to implement // some of the routes and there cannot exists transactions within transactions :'( -use crate::database::Database; - -// FIXME: There is quite a lot of duplicate code from main -// in this function, perhaps these functions could be unified somehow. -fn init_test_services(cfg: &mut ServiceConfig) { - let db_url = - std::env::var("TEST_DATABASE").expect("TEST_DATABASE not set, refusing to run tests"); - - let ratelimiter = Arc::new( - RateLimiter::keyed(Quota::per_minute(NonZeroU32::new(500_u32).unwrap())).with_middleware(), - ); +use crate::create_router; - let heartbeat_store = Data::new(crate::api::activity::HeartBeatMemoryStore::new()); +async fn body_to_json(response: Response) -> T { + let body = response.into_body().collect().await.unwrap().to_bytes(); - let secured_access_token_storage = Data::new(crate::SecuredAccessTokenStorage::new()); - - #[cfg(feature = "testausid")] - let client = crate::Client::new(); - - let cors = crate::Cors::default() - .allow_any_origin() - .allowed_methods(vec!["GET", "POST", "DELETE"]) - .allowed_headers(vec![ - http::header::AUTHORIZATION, - http::header::ACCEPT, - http::header::CONTENT_TYPE, - ]) - .max_age(3600); - let query_config = crate::QueryConfig::default().error_handler(|err, _| match err { - crate::QueryPayloadError::Deserialize(e) => { - crate::ErrorBadRequest(json!({ "error": e.to_string() })) - } - _ => unreachable!(), - }); + serde_json::from_slice(&body).unwrap() +} - cfg.service( - web::scope("") - .app_data(Data::new(crate::RegisterLimiter { - limit_by_peer_ip: false, - storage: crate::DashMap::new(), - })) - .app_data(Data::new(Database::new(db_url))) - .app_data(query_config) - .app_data(Data::clone(&secured_access_token_storage)) - .wrap(cors) - .service(crate::api::health) - .service(crate::api::auth::register) - .service({ - let scope = web::scope("") - .wrap(crate::AuthMiddleware) - .wrap(crate::TestaustimeRateLimiter { - limiter: Arc::clone(&ratelimiter), - use_peer_addr: false, - bypass_token: String::from("balls"), - }) - .service({ - web::scope("/activity") - .service(crate::api::activity::update) - .service(crate::api::activity::delete) - .service(crate::api::activity::flush) - .service(crate::api::activity::rename_project) - }) - .service(crate::api::auth::login) - .service(crate::api::auth::regenerate) - .service(crate::api::auth::changeusername) - .service(crate::api::auth::changepassword) - .service(crate::api::auth::get_secured_access_token) - .service(crate::api::account::change_settings) - .service(crate::api::friends::add_friend) - .service(crate::api::friends::get_friends) - .service(crate::api::friends::regenerate_friend_code) - .service(crate::api::friends::remove) - .service(crate::api::users::my_profile) - .service(crate::api::users::get_activities) - .service(crate::api::users::get_current_activity) - .service(crate::api::users::delete_user) - .service(crate::api::users::my_leaderboards) - .service(crate::api::users::get_activity_summary) - .service(crate::api::leaderboards::create_leaderboard) - .service(crate::api::leaderboards::get_leaderboard) - .service(crate::api::leaderboards::join_leaderboard) - .service(crate::api::leaderboards::leave_leaderboard) - .service(crate::api::leaderboards::delete_leaderboard) - .service(crate::api::leaderboards::promote_member) - .service(crate::api::leaderboards::demote_member) - .service(crate::api::leaderboards::kick_member) - .service(crate::api::leaderboards::regenerate_invite) - .service(crate::api::search::search_public_users) - .service(crate::api::stats::stats); - #[cfg(feature = "testausid")] - { - scope.service(crate::api::oauth::callback) - } - }), - ) - .app_data(Data::clone(&heartbeat_store)); - #[cfg(feature = "testausid")] - { - cfg.app_data(Data::new(client)); - } +fn create_test_router() -> Router { + let config = crate::TestaustimeConfig { + bypass_token: "0000".to_string(), + ratelimit_by_peer_ip: true, + max_requests_per_min: 30, + address: "localhost:8080".to_string(), + database_url: std::env::var("TEST_DATABASE").expect("TEST_DATABASE not defined"), + allowed_origin: "".to_string(), + mail_server: "".to_string(), + mail_user: "".to_string(), + mail_password: "".to_string(), + }; + + create_router(&config).layer(MockConnectInfo(SocketAddr::from(([127, 0, 0, 1], 3000)))) } -#[actix_web::test] +#[tokio::test] async fn health() { - let app = test::init_service(App::new().configure(init_test_services)).await; - let req = test::TestRequest::with_uri("/health").to_request(); - let resp = test::call_service(&app, req).await; - assert_eq!(resp.status(), StatusCode::OK) + let res = create_test_router() + .oneshot( + Request::builder() + .uri("/health") + .body(Body::empty()) + .unwrap(), + ) + .await + .unwrap(); + + assert_eq!(res.status(), StatusCode::OK) } diff --git a/src/utils.rs b/src/utils.rs index f2b5cdb..c4d863a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,12 +1,13 @@ use std::collections::HashMap; use itertools::Itertools; -use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use lettre::Address; +use rand::{distr::Alphanumeric, rng, Rng}; use crate::models::CodingActivity; pub fn generate_token() -> String { - thread_rng() + rng() .sample_iter(&Alphanumeric) .take(32) .map(char::from) @@ -14,13 +15,21 @@ pub fn generate_token() -> String { } pub fn generate_friend_code() -> String { - thread_rng() + rng() .sample_iter(&Alphanumeric) .take(24) .map(char::from) .collect() } +pub fn generate_password_reset_token() -> String { + rng() + .sample_iter(&Alphanumeric) + .take(48) + .map(char::from) + .collect() +} + pub fn group_by_language(iter: impl Iterator) -> HashMap { iter.map(|d| { ( @@ -31,3 +40,7 @@ pub fn group_by_language(iter: impl Iterator) -> HashMap< .into_grouping_map() .sum() } + +pub fn validate_email(email: &str) -> bool { + email.parse::
().is_ok() +} From 80d14063db3107a0f015c73720089b5676915ec0 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Thu, 15 May 2025 08:34:03 +0300 Subject: [PATCH 02/36] fix tests --- src/tests/activity.rs | 41 +++++++++++----------------- src/tests/auth.rs | 7 +++-- src/tests/friends.rs | 7 ++--- src/tests/macros.rs | 62 +++---------------------------------------- src/tests/mod.rs | 7 +++-- 5 files changed, 32 insertions(+), 92 deletions(-) diff --git a/src/tests/activity.rs b/src/tests/activity.rs index 59d916f..a86b461 100644 --- a/src/tests/activity.rs +++ b/src/tests/activity.rs @@ -3,7 +3,7 @@ use std::time::Duration; use serde_json::json; use super::{macros::*, *}; -use crate::models::{CurrentActivity, HeartBeat, NewUserIdentity}; +use crate::models::{CurrentActivity, HeartBeat, NewUserIdentity, SecuredAccessTokenResponse}; #[tokio::test] async fn updating_activity_works() { @@ -127,14 +127,13 @@ async fn flushing_works() { assert!(resp.status().is_success(), "Failed to delete user"); } -#[actix_web::test] -async fn hidden_works() { - let app = test::init_service(App::new().configure(init_test_services)).await; - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80u16); +#[tokio::test] +async fn hidden_project() { + let mut app = create_test_router().into_service(); let body = json!({"username": "activeuser3", "password": "password"}); - let resp = request!(app, addr, post, "/auth/register", body); - let user: NewUserIdentity = test::read_body_json(resp).await; + let resp = request!(app, POST, "/auth/register", body); + let user: NewUserIdentity = body_to_json(resp).await; let heartbeat = HeartBeat { hostname: Some(String::from("nsa-supercomputer")), @@ -144,47 +143,39 @@ async fn hidden_works() { hidden: Some(true), }; - let resp = request_auth!( - app, - addr, - post, - "/activity/update", - user.auth_token, - heartbeat - ); + let resp = request_auth!(app, POST, "/activity/update", user.auth_token, heartbeat); assert!( resp.status().is_success(), "Sending heartbeat should succeed" ); - let resp = request_auth!(app, addr, get, "/users/@me/activity/data", user.auth_token); - let data: Vec = test::read_body_json(resp).await; + let resp = request_auth!(app, GET, "/users/@me/activity/data", user.auth_token); + let data: Vec = body_to_json(resp).await; assert!(data.is_empty(), "No session should exist"); - let resp = request_auth!(app, addr, post, "/activity/flush", user.auth_token); + let resp = request_auth!(app, POST, "/activity/flush", user.auth_token); assert!(resp.status().is_success(), "Flushing should work"); - let resp = request!(app, addr, post, "/auth/securedaccess", body); + let resp = request!(app, POST, "/auth/securedaccess", body); assert!( resp.status().is_success(), "Getting secured access token failed" ); - let sat: SecuredAccessTokenResponse = test::read_body_json(resp).await; + let sat: SecuredAccessTokenResponse = body_to_json(resp).await; let change = json!({"public_profile": true}); - let resp = request_auth!(app, addr, post, "/account/settings", sat.token, change); + let resp = request_auth!(app, POST, "/account/settings", sat.token, change); assert!(resp.status().is_success(), "Making profile public failed"); let resp = request!( app, - addr, - get, + GET, "/users/activeuser3/activity/data", user.auth_token ); - let data: Vec = test::read_body_json(resp).await; + let data: Vec = body_to_json(resp).await; assert!(!data.is_empty(), "Session should be saved after a flush"); // Print the actual value of the project name to see what it is @@ -193,7 +184,7 @@ async fn hidden_works() { "Activity project name should be empty string" ); - let resp = request!(app, addr, delete, "/users/@me/delete", body); + let resp = request!(app, DELETE, "/users/@me/delete", body); assert!(resp.status().is_success(), "Failed to delete user"); } diff --git a/src/tests/auth.rs b/src/tests/auth.rs index ce061d6..bd15795 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -36,7 +36,6 @@ async fn login_change_username_and_password() { let body = json!({"username": "testuser2", "password": "password"}); let resp = request!(app, POST, "/auth/register", body); - println!("{:?}", resp); assert!(resp.status().is_success(), "Failed to create user"); let user: NewUserIdentity = body_to_json(resp).await; @@ -64,7 +63,7 @@ async fn login_change_username_and_password() { let resp = request_auth!( app, POST, - "/auth/changeusername", + "/auth/change_username", user.auth_token, change_request ); @@ -73,7 +72,7 @@ async fn login_change_username_and_password() { "Auth token is not secured access token" ); - let resp = request_auth!(app, POST, "/auth/changeusername", sat.token, change_request); + let resp = request_auth!(app, POST, "/auth/change_username", sat.token, change_request); assert!(resp.status().is_success(), "Username change failed"); let resp = request_auth!(app, GET, "/users/@me", user.auth_token); @@ -91,7 +90,7 @@ async fn login_change_username_and_password() { let resp = request_auth!( app, POST, - "/auth/changepassword", + "/auth/change_password", user.auth_token, pw_request ); diff --git a/src/tests/friends.rs b/src/tests/friends.rs index c83ab16..49d5525 100644 --- a/src/tests/friends.rs +++ b/src/tests/friends.rs @@ -19,16 +19,17 @@ async fn adding_friends_works() { let f2: NewUserIdentity = body_to_json(resp).await; let friend_body = json!({"code": f2.friend_code.clone()}); - let resp = request!(app, POST, "/friends/add", friend_body); + let resp = request_auth!(app, POST, "/friends/add", f1.auth_token, friend_body); + println!("{:?}", resp); assert!(resp.status().is_success(), "Adding friend works"); - let resp = request!(app, POST, "/friends/add", friend_body); + let resp = request_auth!(app, POST, "/friends/add", f1.auth_token, friend_body); assert!(resp.status().is_client_error(), "Re-adding friend fails"); let self_body = json!({"code": f1.friend_code.clone()}); - let resp = request!(app, POST, "/friends/add", self_body); + let resp = request_auth!(app, POST, "/friends/add", f1.auth_token, self_body); assert!(resp.status().is_client_error(), "Adding self fails"); diff --git a/src/tests/macros.rs b/src/tests/macros.rs index 6302b42..d1d1ebf 100644 --- a/src/tests/macros.rs +++ b/src/tests/macros.rs @@ -5,6 +5,7 @@ macro_rules! request { Request::builder() .uri($uri) .method(http::Method::$method) + .extension(axum::extract::ConnectInfo(TEST_ADDR)) .body(Body::empty()) .unwrap(), ) @@ -18,6 +19,7 @@ macro_rules! request { .uri($uri) .method(http::Method::$method) .header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) + .extension(axum::extract::ConnectInfo(TEST_ADDR)) .body(Body::from(serde_json::to_vec(&$body).unwrap())) .unwrap(), ) @@ -34,6 +36,7 @@ macro_rules! request_auth { .uri($uri) .method(http::Method::$method) .header("authorization", "Bearer ".to_owned() + &$token) + .extension(axum::extract::ConnectInfo(TEST_ADDR)) .body(Body::empty()) .unwrap(), ) @@ -48,6 +51,7 @@ macro_rules! request_auth { .method(http::Method::$method) .header(http::header::CONTENT_TYPE, "application/json") .header("authorization", "Bearer ".to_owned() + &$token) + .extension(axum::extract::ConnectInfo(TEST_ADDR)) .body(Body::from(serde_json::to_vec(&$body).unwrap())) .unwrap(), ) @@ -56,63 +60,5 @@ macro_rules! request_auth { }; } -macro_rules! oneshot_request { - ($method:tt, $uri:expr) => { - create_test_router() - .oneshot( - Request::builder() - .uri($uri) - .method(Method::$method) - .body(Body::empty()) - .unwrap(), - ) - .await - .unwrap() - }; - ($method:tt, $uri:expr, $body:expr) => { - create_test_router() - .oneshot( - Request::builder() - .uri($uri) - .method(http::Method::$method) - .body(Body::from(serde_json::to_vec(&$body).unwrap())) - .unwrap(), - ) - .await - .unwrap() - }; -} - -macro_rules! oneshot_request_auth { - ($app:expr, $method:tt, $uri:expr, $token:expr) => { - create_test_router() - .oneshot( - Request::builder() - .uri($uri) - .method(http::Method::$method) - .header(http::header::CONTENT_TYPE, "application/json") - .header("authorization", "Bearer ".to_owned() + &$token) - .body(Body::empty()) - .unwrap(), - ) - .await - .unwrap() - }; - ($app:expr, $method:tt, $uri:expr, $token:expr, $body:expr) => { - create_test_router() - .oneshot( - Request::builder() - .uri($uri) - .method(http::Method::$method) - .header(http::header::CONTENT_TYPE, "application/json") - .header("authorization", "Bearer ".to_owned() + &$token) - .body(Body::from(serde_json::to_vec(&$body).unwrap())) - .unwrap(), - ) - .await - .unwrap() - }; -} - pub(crate) use request; pub(crate) use request_auth; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 302d1d4..1fe5099 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,4 +1,4 @@ -use std::net::SocketAddr; +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; // TODO add tests for oauth and improve test coverage use http_body_util::BodyExt; @@ -19,6 +19,8 @@ use tower::ServiceExt; // some of the routes and there cannot exists transactions within transactions :'( use crate::create_router; +const TEST_ADDR: SocketAddr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 3000)); + async fn body_to_json(response: Response) -> T { let body = response.into_body().collect().await.unwrap().to_bytes(); @@ -30,7 +32,8 @@ fn create_test_router() -> Router { bypass_token: "0000".to_string(), ratelimit_by_peer_ip: true, max_requests_per_min: 30, - address: "localhost:8080".to_string(), + max_registers_per_hour: 5, + address: "localhost:3000".to_string(), database_url: std::env::var("TEST_DATABASE").expect("TEST_DATABASE not defined"), allowed_origin: "".to_string(), mail_server: "".to_string(), From 40a15f91030ff7c049b3dc3c3c0c28680d6ec634 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Thu, 15 May 2025 08:48:22 +0300 Subject: [PATCH 03/36] use hyphens in endpoints --- src/main.rs | 10 +++++----- src/tests/auth.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 95291dd..f98e45f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,19 +142,19 @@ fn create_router(config: &TestaustimeConfig) -> Router { }) .route("/auth/login", post(api::auth::login)) .route("/auth/regenerate", post(api::auth::regenerate)) - .route("/auth/change_username", post(api::auth::change_username)) - .route("/auth/change_email", post(api::auth::change_email)) - .route("/auth/change_password", post(api::auth::change_password)) + .route("/auth/change-username", post(api::auth::change_username)) + .route("/auth/change-email", post(api::auth::change_email)) + .route("/auth/change-password", post(api::auth::change_password)) .route( "/auth/securedaccess", post(api::auth::get_secured_access_token), ) .route( - "/auth/reset_password", + "/auth/reset-password", post(api::auth::request_password_reset), ) .route( - "/auth/complete_password_reset", + "/auth/complete-password-reset", post(api::auth::reset_password), ) .route("/friends/add", post(api::friends::add_friend)) diff --git a/src/tests/auth.rs b/src/tests/auth.rs index bd15795..2c23061 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -63,7 +63,7 @@ async fn login_change_username_and_password() { let resp = request_auth!( app, POST, - "/auth/change_username", + "/auth/change-username", user.auth_token, change_request ); @@ -72,7 +72,7 @@ async fn login_change_username_and_password() { "Auth token is not secured access token" ); - let resp = request_auth!(app, POST, "/auth/change_username", sat.token, change_request); + let resp = request_auth!(app, POST, "/auth/change-username", sat.token, change_request); assert!(resp.status().is_success(), "Username change failed"); let resp = request_auth!(app, GET, "/users/@me", user.auth_token); @@ -90,7 +90,7 @@ async fn login_change_username_and_password() { let resp = request_auth!( app, POST, - "/auth/change_password", + "/auth/change-password", user.auth_token, pw_request ); From 66278f098cfd3ffcefa38486a5c77a8fbb49dcd3 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Tue, 20 May 2025 10:36:03 +0300 Subject: [PATCH 04/36] use register middleware for register also implement max_registers_per_hour --- settings.toml.example | 1 + src/api/auth.rs | 39 ++++----------------------------------- src/main.rs | 22 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/settings.toml.example b/settings.toml.example index 0f29a80..3aa52c9 100644 --- a/settings.toml.example +++ b/settings.toml.example @@ -6,3 +6,4 @@ max_requests_per_min=30 max_heartbeats_per_min=8 max_registers_per_day=3 bypass_token="5woKC8Z3pqLqhDTX/zY1j1JxMozglIukNsr3YMMLBOk=" +max_registers_per_hour=5 diff --git a/src/api/auth.rs b/src/api/auth.rs index 9afc335..6267cb2 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -1,15 +1,12 @@ -use std::{ - net::{IpAddr, SocketAddr}, - sync::Arc, -}; +use std::sync::Arc; use axum::{ - extract::{ConnectInfo, FromRequestParts, State}, + extract::{FromRequestParts, State}, response::IntoResponse, Json, }; use chrono::{Duration, Local}; -use http::{header::FORWARDED, request::Parts, HeaderMap, StatusCode}; +use http::{request::Parts, StatusCode}; use lettre::{ message::header::ContentType, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, }; @@ -21,7 +18,7 @@ use crate::{ error::TimeError, models::{SecuredAccessTokenResponse, SelfUser, UserId, UserIdentity}, utils::{generate_password_reset_token, validate_email}, - PasswordReset, PasswordResetState, RegisterLimiter, + PasswordReset, PasswordResetState, }; #[derive(Deserialize)] @@ -177,9 +174,6 @@ pub async fn regenerate( } pub async fn register( - State(rls): State>, - ConnectInfo(conn_info): ConnectInfo, - headers: HeaderMap, db: DatabaseWrapper, Json(data): Json, ) -> Result { @@ -201,35 +195,10 @@ pub async fn register( return Err(TimeError::UsernameTaken); } - let ip = if rls.limit_by_peer_ip { - conn_info.ip() - } else { - let header = headers - .get("x-forwarded-for") - .or_else(|| headers.get(FORWARDED)); - - header - .and_then(|ip| ip.to_str().ok().and_then(|ip| ip.parse::().ok())) - .unwrap_or(conn_info.ip()) - }; - - if let Some(res) = rls.storage.get(&ip.to_string()) { - if chrono::Local::now() - .naive_local() - .signed_duration_since(*res) - < chrono::Duration::days(1) - { - return Err(TimeError::TooManyRegisters); - } - } - let res = db .new_testaustime_user(&data.username, &data.password, data.email.as_deref()) .await?; - rls.storage - .insert(ip.to_string(), chrono::Local::now().naive_local()); - Ok(Json(res)) } diff --git a/src/main.rs b/src/main.rs index f98e45f..0f7dbdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,7 +45,8 @@ extern crate serde_json; pub struct TestaustimeConfig { pub bypass_token: String, pub ratelimit_by_peer_ip: bool, - pub max_requests_per_min: usize, + pub max_requests_per_min: u32, + pub max_registers_per_hour: u32, pub address: String, pub database_url: String, pub allowed_origin: String, @@ -122,14 +123,29 @@ fn create_router(config: &TestaustimeConfig) -> Router { let ratelimiter = Arc::new( RateLimiter::keyed(Quota::per_minute( - NonZeroU32::new(config.max_requests_per_min as u32).unwrap(), + NonZeroU32::new(config.max_requests_per_min).unwrap(), + )) + .with_middleware(), + ); + + let register_ratelimiter = Arc::new( + RateLimiter::keyed(Quota::per_hour( + NonZeroU32::new(config.max_registers_per_hour).unwrap(), )) .with_middleware(), ); Router::new() .route("/health", get(api::health)) - .route("/auth/register", post(api::auth::register)) + .merge( + Router::new() + .route("/auth/register", post(api::auth::register)) + .layer(TestaustimeRateLimiter { + limiter: register_ratelimiter, + use_peer_addr: config.ratelimit_by_peer_ip, + bypass_token: config.bypass_token.clone(), + }), + ) .merge({ let router = Router::new() .nest("/activity", { From 4d1a12fab954f19007656f428e572f1141a2f71e Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Tue, 20 May 2025 10:38:19 +0300 Subject: [PATCH 05/36] cleanup and errors --- Cargo.toml | 2 +- src/api/leaderboards.rs | 4 +--- src/api/mod.rs | 5 ++--- src/auth/secured_access.rs | 4 ++-- src/database/auth.rs | 21 +++++++++++---------- src/database/leaderboards.rs | 4 ++-- src/error.rs | 26 +++++++++++++++++++++----- src/tests/auth.rs | 8 +++++++- src/utils.rs | 2 +- 9 files changed, 48 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f7d36df..b853686 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ futures = "0.3" futures-util = "0.3" chrono = { version = "0.4", features = ["serde"] } dashmap = "6.1" -argon2 = "0.4" +argon2 = { version = "0.4", features = ["std"]} rand = "0.9" dotenv = "0.15" url = "2.2" diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 2918749..0290cb7 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -102,9 +102,7 @@ pub async fn join_leaderboard( DatabaseErrorKind::UniqueViolation, .., )) => TimeError::AlreadyMember, - TimeError::DieselError(DieselError::NotFound) => { - TimeError::LeaderboardNotFound - } + TimeError::DieselError(DieselError::NotFound) => TimeError::LeaderboardNotFound, _ => e, }) } diff --git a/src/api/mod.rs b/src/api/mod.rs index e940465..20303c1 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -15,9 +15,8 @@ pub mod search; pub mod stats; pub mod users; -pub static VALID_NAME_REGEX: LazyLock = LazyLock::new(|| { - Regex::new("^[[:word:]]{2,32}$").unwrap() -}); +pub static VALID_NAME_REGEX: LazyLock = + LazyLock::new(|| Regex::new("^[[:word:]]{2,32}$").unwrap()); pub async fn health() -> impl IntoResponse { StatusCode::OK diff --git a/src/auth/secured_access.rs b/src/auth/secured_access.rs index 63884c4..a9d3fb4 100644 --- a/src/auth/secured_access.rs +++ b/src/auth/secured_access.rs @@ -2,7 +2,7 @@ use std::time::{Duration, Instant}; use dashmap::DashMap; -use crate::utils::generate_token; +use crate::utils::generate_auth_token; #[derive(Clone, Copy, Debug)] pub enum SecuredAccessError { @@ -44,7 +44,7 @@ impl SecuredAccessTokenStorage { } pub fn create_token(&self, user_id: i32) -> String { - let token = generate_token(); + let token = generate_auth_token(); self.inner.insert( token.clone(), diff --git a/src/database/auth.rs b/src/database/auth.rs index d54ca40..8f205cc 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -56,7 +56,6 @@ impl super::DatabaseWrapper { .await?) } - // TODO: get rid of unwraps pub async fn verify_user_password( &self, arg_username: &str, @@ -74,12 +73,14 @@ impl super::DatabaseWrapper { .await?; let argon2 = Argon2::default(); - let Ok(salt) = SaltString::new(std::str::from_utf8(&tuser.salt).expect("bug: impossible")) - else { - return Ok(None); // The user has no password - }; - let password_hash = argon2.hash_password(password.as_bytes(), &salt).unwrap(); - if password_hash.hash.expect("bug: impossible").as_bytes() == tuser.password { + let salt = SaltString::new(std::str::from_utf8(&tuser.salt).expect("Infallible"))?; + + let password_hash = argon2.hash_password(password.as_bytes(), &salt)?; + + if password_hash + .hash + .is_some_and(|p| p.as_bytes() == tuser.password) + { Ok(Some(user)) } else { Ok(None) @@ -89,7 +90,7 @@ impl super::DatabaseWrapper { pub async fn regenerate_token(&self, userid: i32) -> Result { let mut conn = self.db.get().await?; - let token = crate::utils::generate_token(); + let token = crate::utils::generate_auth_token(); use crate::schema::user_identities::dsl::*; @@ -113,7 +114,7 @@ impl super::DatabaseWrapper { let salt = SaltString::generate(&mut OsRng); let argon2 = Argon2::default(); let password_hash = argon2.hash_password(password.as_bytes(), &salt).unwrap(); - let token = generate_token(); + let token = generate_auth_token(); let hash = password_hash.hash.unwrap(); let new_user = NewUserIdentity { auth_token: token, @@ -283,7 +284,7 @@ impl super::DatabaseWrapper { Ok(token) } else { let new_user = NewUserIdentity { - auth_token: generate_token(), + auth_token: generate_auth_token(), registration_time: chrono::Local::now().naive_local(), username, friend_code: generate_friend_code(), diff --git a/src/database/leaderboards.rs b/src/database/leaderboards.rs index 7b9830d..4ef192f 100644 --- a/src/database/leaderboards.rs +++ b/src/database/leaderboards.rs @@ -22,7 +22,7 @@ impl super::DatabaseWrapper { creator_id: i32, name: &str, ) -> Result { - let code = crate::utils::generate_token(); + let code = crate::utils::generate_auth_token(); let board = NewLeaderboard { name: name.to_string(), @@ -64,7 +64,7 @@ impl super::DatabaseWrapper { } pub async fn regenerate_leaderboard_invite(&self, lid: i32) -> Result { - let newinvite = crate::utils::generate_token(); + let newinvite = crate::utils::generate_auth_token(); let mut conn = self.db.get().await?; diff --git a/src/error.rs b/src/error.rs index 847fabb..8433a3d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -56,15 +56,17 @@ pub enum TimeError { #[error("The user has no active session")] NotActive, #[error("Cannot connect to mail server")] - Error(#[from] lettre::transport::smtp::Error), + SmtpError(#[from] lettre::transport::smtp::Error), #[error("Invalid password reset token")] InvalidPasswordResetToken, #[error("Invalid email")] InvalidEmail, #[error("Expired password reset token")] ExpiredPasswordResetToken, - #[error("Account with this email exist")] + #[error("Account with this email exists")] EmailTaken, + #[error("Password hashing failed")] + HashError(#[from] argon2::password_hash::Error), } impl IntoResponse for TimeError { @@ -77,7 +79,9 @@ impl IntoResponse for TimeError { TimeError::BadUsername | TimeError::InvalidLength(_) | TimeError::BadId - | TimeError::BadLeaderboardName => StatusCode::BAD_REQUEST, + | TimeError::BadLeaderboardName + | TimeError::InvalidEmail + | TimeError::BadCode => StatusCode::BAD_REQUEST, TimeError::CurrentUser | TimeError::NotMember | TimeError::LastAdmin => { StatusCode::FORBIDDEN } @@ -92,7 +96,13 @@ impl IntoResponse for TimeError { | TimeError::InvalidPasswordResetToken | TimeError::ExpiredPasswordResetToken => StatusCode::UNAUTHORIZED, TimeError::TooManyRegisters => StatusCode::TOO_MANY_REQUESTS, - _ => StatusCode::INTERNAL_SERVER_ERROR, + TimeError::DieselError(_) + | TimeError::DieselConnectionError(_) + | TimeError::DeadpoolError(_) + | Self::AxumError(_) + | TimeError::UnknownError + | TimeError::SmtpError(_) + | TimeError::HashError(_) => StatusCode::INTERNAL_SERVER_ERROR, }; let body = Json(json!({"error": self.to_string()})); @@ -103,6 +113,12 @@ impl IntoResponse for TimeError { impl TimeError { pub fn is_unique_violation(&self) -> bool { - matches!(self, TimeError::DieselError(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::UniqueViolation,.. ))) + matches!( + self, + TimeError::DieselError(diesel::result::Error::DatabaseError( + diesel::result::DatabaseErrorKind::UniqueViolation, + .. + )) + ) } } diff --git a/src/tests/auth.rs b/src/tests/auth.rs index 2c23061..c7d27db 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -72,7 +72,13 @@ async fn login_change_username_and_password() { "Auth token is not secured access token" ); - let resp = request_auth!(app, POST, "/auth/change-username", sat.token, change_request); + let resp = request_auth!( + app, + POST, + "/auth/change-username", + sat.token, + change_request + ); assert!(resp.status().is_success(), "Username change failed"); let resp = request_auth!(app, GET, "/users/@me", user.auth_token); diff --git a/src/utils.rs b/src/utils.rs index c4d863a..43b23f7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,7 +6,7 @@ use rand::{distr::Alphanumeric, rng, Rng}; use crate::models::CodingActivity; -pub fn generate_token() -> String { +pub fn generate_auth_token() -> String { rng() .sample_iter(&Alphanumeric) .take(32) From 8cb1b892d7cb1e60bf58f20cecdaa9c67106c524 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Wed, 21 May 2025 09:22:57 +0300 Subject: [PATCH 06/36] make activity endpoints use json --- src/api/activity.rs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/api/activity.rs b/src/api/activity.rs index 2d6f8ad..b072f81 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -4,7 +4,7 @@ use axum::{extract::State, response::IntoResponse, Json}; use chrono::{Duration, Local}; use dashmap::DashMap; use http::StatusCode; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use crate::{ api::auth::SecuredUserIdentity, @@ -26,6 +26,11 @@ pub struct HideRequest { target_project: String, hidden: bool, } + +#[derive(Serialize)] +pub struct UpdateResponse { + duration: i64, +} pub async fn update( user: UserId, db: DatabaseWrapper, @@ -77,14 +82,18 @@ pub async fn update( user.id, (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(0i32.to_string()) + Ok(Json(UpdateResponse { + duration: 0, + })) } else { // Extend current coding session if heartbeat matches and it has been under the maximum duration of a break heartbeats.insert( user.id, (heartbeat, start, curtime.signed_duration_since(start)), ); - Ok(curtime.signed_duration_since(start).to_string()) + Ok(Json(UpdateResponse { + duration: curtime.signed_duration_since(start).num_seconds() + })) } } else { // Flush current session and start new session if heartbeat changes @@ -100,7 +109,9 @@ pub async fn update( (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(0i32.to_string()) + Ok(Json(UpdateResponse { + duration: 0 + })) } } None => { @@ -109,7 +120,9 @@ pub async fn update( user.id, (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(0.to_string()) + Ok(Json(UpdateResponse { + duration: 0, + })) } } } @@ -129,15 +142,20 @@ pub async fn flush( Ok(StatusCode::OK) } +#[derive(Deserialize)] +pub struct ActivityDeleteRequest { + id: i32, +} + pub async fn delete( user: SecuredUserIdentity, db: DatabaseWrapper, - body: String, + Json(body): Json, ) -> Result { let deleted = db .delete_activity( user.identity.id, - body.parse::().map_err(|_| TimeError::BadId)?, + body.id, ) .await?; if deleted { From 964df2388eb72b5a1ed6c220631145c908b2f15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Fri, 23 May 2025 17:15:10 +0200 Subject: [PATCH 07/36] feat: add nix flake --- .envrc | 10 ++ .gitignore | 3 + Cargo.lock | 282 +++++++++++++++-------------------------------- Cargo.toml | 4 +- flake.lock | 317 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 87 +++++++++++++++ 6 files changed, 509 insertions(+), 194 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..dc25ec7 --- /dev/null +++ b/.envrc @@ -0,0 +1,10 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" +fi + +watch_file flake.nix +watch_file flake.lock +if ! use flake . --no-pure-eval +then + echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 +fi diff --git a/.gitignore b/.gitignore index 3264e87..f386328 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ target */target .env settings.toml +result +.direnv +.devenv diff --git a/Cargo.lock b/Cargo.lock index 5c4d9de..127caec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -301,6 +301,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.40" @@ -607,16 +613,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" -[[package]] -name = "errno" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" -dependencies = [ - "libc", - "windows-sys 0.59.0", -] - [[package]] name = "fallible-iterator" version = "0.2.0" @@ -641,21 +637,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -777,8 +758,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -836,9 +819,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75249d144030531f8dee69fe9cea04d3edf809a017ae445e2abdff6629e86633" +checksum = "a9421a676d1b147b16b82c9225157dc629087ef8ec4d5e2960f9437a90dac0a5" dependencies = [ "atomic-waker", "bytes", @@ -988,22 +971,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -1269,15 +1237,16 @@ dependencies = [ "httpdate", "idna", "mime", - "native-tls", "nom", "percent-encoding", "quoted_printable", + "rustls", "socket2", "tokio", - "tokio-native-tls", + "tokio-rustls", "tracing", "url", + "webpki-roots", ] [[package]] @@ -1286,12 +1255,6 @@ version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" -[[package]] -name = "linux-raw-sys" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" - [[package]] name = "litemap" version = "0.7.5" @@ -1371,23 +1334,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "native-tls" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nom" version = "8.0.0" @@ -1459,50 +1405,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "openssl" -version = "0.10.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" - -[[package]] -name = "openssl-sys" -version = "0.9.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8288979acd84749c744a9014b4382d42b8f7b2592847b5afb2ed29e5d16ede07" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "overload" version = "0.1.1" @@ -1599,12 +1501,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" - [[package]] name = "polyval" version = "0.6.2" @@ -1700,6 +1596,60 @@ dependencies = [ "winapi", ] +[[package]] +name = "quinn" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3bd15a6f2967aef83887dcb9fec0014580467e33720d073560cf015a5683012" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcbafbbdbb0f638fe3f35f3c56739f77a8a1d070cb25603226c83339b391472b" +dependencies = [ + "bytes", + "getrandom 0.3.2", + "rand 0.9.0", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4e529991f949c5e25755532370b8af5d114acae52326361d68d47af64aa842" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.40" @@ -1860,30 +1810,32 @@ dependencies = [ "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1908,17 +1860,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "1.0.5" +name = "rustc-hash" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.59.0", -] +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustls" @@ -1926,7 +1871,9 @@ version = "0.23.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df51b5869f3a441595eac5e8ff14d486ff285f7b8c0df8770e49c3b56351f0f0" dependencies = [ + "log", "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1947,6 +1894,9 @@ name = "rustls-pki-types" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +dependencies = [ + "web-time", +] [[package]] name = "rustls-webpki" @@ -1971,15 +1921,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" -[[package]] -name = "schannel" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scoped-futures" version = "0.1.4" @@ -1995,29 +1936,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.219" @@ -2241,19 +2159,6 @@ dependencies = [ "libc", ] -[[package]] -name = "tempfile" -version = "3.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf" -dependencies = [ - "fastrand", - "getrandom 0.3.2", - "once_cell", - "rustix", - "windows-sys 0.59.0", -] - [[package]] name = "testaustime" version = "0.3.1" @@ -2404,16 +2309,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-postgres" version = "0.7.13" @@ -2697,12 +2592,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -2830,6 +2719,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37493cadf42a2a939ed404698ded7fb378bf301b5011f973361779a3a74f8c93" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "whoami" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index b853686..8f2e652 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ lto = true axum = { version = "0.8", features = ["macros", "tokio"] } axum-extra = { version = "0.10", features = ["cookie", "cookie-private"] } tokio = { version = "1.35", features = ["macros", "rt-multi-thread"]} -reqwest = { version = "0.12", optional = true, features = ["json"] } +reqwest = { version = "0.12", optional = true, default-features = false, features = ["json", "rustls-tls", "charset", "http2", "macos-system-configuration"] } http = "1.0" http-body-util = "0.1" regex = "1.5" @@ -48,5 +48,5 @@ itertools = "0.14" governor = "0.10.0" diesel = { version = "2.1.0", features = ["chrono", "serde_json"] } diesel-async = { version = "0.5.1", features = ["postgres", "deadpool"] } -lettre = { version = "0.11.14", features = ["tokio1-native-tls", "tracing", "pool"]} +lettre = { version = "0.11.14", default-features = false, features = ["tokio1-rustls-tls", "tracing", "pool", "smtp-transport", "hostname", "builder"]} mime = "0.3.17" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ae65130 --- /dev/null +++ b/flake.lock @@ -0,0 +1,317 @@ +{ + "nodes": { + "cachix": { + "inputs": { + "devenv": [ + "devenv" + ], + "flake-compat": [ + "devenv" + ], + "git-hooks": [ + "devenv" + ], + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1742042642, + "narHash": "sha256-D0gP8srrX0qj+wNYNPdtVJsQuFzIng3q43thnHXQ/es=", + "owner": "cachix", + "repo": "cachix", + "rev": "a624d3eaf4b1d225f918de8543ed739f2f574203", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "cachix", + "type": "github" + } + }, + "crane": { + "locked": { + "lastModified": 1746291859, + "narHash": "sha256-DdWJLA+D5tcmrRSg5Y7tp/qWaD05ATI4Z7h22gd1h7Q=", + "owner": "ipetkov", + "repo": "crane", + "rev": "dfd9a8dfd09db9aad544c4d3b6c47b12562544a5", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat", + "git-hooks": "git-hooks", + "nix": "nix", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1746707904, + "narHash": "sha256-j1BAUl+NYtWWWVkuDLfSE0wlF7FlkwhrcJxDISXAVvE=", + "owner": "cachix", + "repo": "devenv", + "rev": "fada79d97f2066c444766d039b0a62affd3e3cab", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1746772806, + "narHash": "sha256-5/Nq62wjkZrOhUULTFjgi4Dsc7T8kIluUPkoLsyAeUA=", + "owner": "nix-community", + "repo": "fenix", + "rev": "505bf684711e964c8f84d4c804e38f62b24accec", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "devenv", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1742649964, + "narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "libgit2": { + "flake": false, + "locked": { + "lastModified": 1697646580, + "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", + "owner": "libgit2", + "repo": "libgit2", + "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", + "type": "github" + }, + "original": { + "owner": "libgit2", + "repo": "libgit2", + "type": "github" + } + }, + "nix": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "flake-parts": "flake-parts", + "libgit2": "libgit2", + "nixpkgs": "nixpkgs_2", + "nixpkgs-23-11": [ + "devenv" + ], + "nixpkgs-regression": [ + "devenv" + ], + "pre-commit-hooks": [ + "devenv" + ] + }, + "locked": { + "lastModified": 1745930071, + "narHash": "sha256-bYyjarS3qSNqxfgc89IoVz8cAFDkF9yPE63EJr+h50s=", + "owner": "domenkozar", + "repo": "nix", + "rev": "b455edf3505f1bf0172b39a735caef94687d0d9c", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.24", + "repo": "nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1733212471, + "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "55d15ad12a74eb7d4646254e13638ad0c4128776", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1717432640, + "narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "88269ab3044128b7c2f4c7d68448b2fb50456870", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1746663147, + "narHash": "sha256-Ua0drDHawlzNqJnclTJGf87dBmaO/tn7iZ+TCkTRpRc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "dda3dcd3fe03e991015e9a74b22d35950f264a54", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "devenv": "devenv", + "fenix": "fenix", + "nixpkgs": "nixpkgs_3", + "systems": "systems" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1746722075, + "narHash": "sha256-t4ZntWiW4C3lE621lV3XyK3KltC5/SW1V9G+CSz70rQ=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "8b624868e4ce2cb5b39559175f0978bee86bdeea", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..88b99b5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,87 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default"; + devenv.url = "github:cachix/devenv"; + devenv.inputs.nixpkgs.follows = "nixpkgs"; + + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + crane.url = "github:ipetkov/crane"; + }; + + outputs = + { + self, + nixpkgs, + devenv, + systems, + fenix, + crane, + ... + }@inputs: + let + forEachSystem = nixpkgs.lib.genAttrs (import systems); + in + { + packages = forEachSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + toolchain = fenix.packages.${system}.minimal.toolchain; + + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + in + rec { + devenv-up = self.devShells.${system}.default.config.procfileScript; + devenv-test = self.devShells.${system}.default.config.test; + + testaustime-backend = craneLib.buildPackage { + src = ./.; + # The tests don't work currently + doCheck = false; + }; + + default = testaustime-backend; + + docker = pkgs.dockerTools.buildLayeredImage { + name = "ghcr.io/testaustime/testaustime-backend"; + tag = "nix"; + config.Cmd = + let + entrypoint = pkgs.writeShellScriptBin "entrypoint.sh" '' + while [ 1 ]; + do + ${pkgs.diesel-cli}/bin/diesel database setup --migration-dir ${./migrations} && break; + done + ${testaustime-backend}/bin/testaustime + ''; + in + [ "./${entrypoint}/bin/entrypoint.sh" ]; + }; + } + ); + + devShells = forEachSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + default = devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + { + languages.rust.enable = true; + + packages = [ self.outputs.packages.${system}.testaustime-backend ]; + } + ]; + }; + } + ); + }; +} From f38b3966da2dca71e332e301058af1b44fb84447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Fri, 24 Oct 2025 09:31:48 +0200 Subject: [PATCH 08/36] chore(ci): improve nix build and use it in docker build --- .github/workflows/docker.yml | 114 +++++++++++++++++++++++++++-------- flake.nix | 49 +++++++++++++-- 2 files changed, 133 insertions(+), 30 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4982eea..d4d7d17 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,5 +1,4 @@ name: Docker - on: push: branches: @@ -7,36 +6,102 @@ on: tags: - "*" workflow_dispatch: - env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} - jobs: - build-and-push-image: - name: Build and publish - runs-on: ubuntu-latest + build-image: + name: Build Docker image + strategy: + matrix: + runner: + - ubuntu-24.04 + - ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - + + - name: Install Nix + uses: cachix/install-nix-action@v24 + with: + nix_path: nixpkgs=channel:nixos-unstable + + - name: Set up Magic Nix Cache + uses: DeterminateSystems/magic-nix-cache-action@v2 + + - name: Build Docker image with Nix + run: | + nix build .#docker + IMAGE_PATH=$(readlink -f result) + echo "IMAGE_PATH=$IMAGE_PATH" >> $GITHUB_ENV + + - name: Load Docker image + run: | + docker load < ${{ env.IMAGE_PATH }} + - name: Log in to the Container registry uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - + + - name: Determine architecture + id: arch + run: | + if [ "${{ matrix.runner }}" = "ubuntu-24.04" ]; then + echo "arch=amd64" >> $GITHUB_OUTPUT + echo "platform=linux/amd64" >> $GITHUB_OUTPUT + else + echo "arch=arm64" >> $GITHUB_OUTPUT + echo "platform=linux/arm64" >> $GITHUB_OUTPUT + fi + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value={{branch}}-${{ steps.arch.outputs.arch }} + type=raw,value=latest-${{ steps.arch.outputs.arch }},enable=${{ startsWith(github.ref, 'refs/tags/') }} + type=raw,value={{tag}}-${{ steps.arch.outputs.arch }},enable=${{ startsWith(github.ref, 'refs/tags/') }} + flavor: | + latest=false + + - name: Get image name from Nix build + id: image + run: | + IMAGE_NAME=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1) + echo "name=$IMAGE_NAME" >> $GITHUB_OUTPUT + + - name: Tag and push Docker image + run: | + for tag in ${{ steps.meta.outputs.tags }}; do + docker tag ${{ steps.image.outputs.name }} $tag + docker push $tag + done + + create-manifest: + name: Create multi-arch manifest + needs: build-image + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + steps: + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for manifest id: meta uses: docker/metadata-action@v4 with: @@ -48,14 +113,13 @@ jobs: type=match,pattern=\d+,group=0,enable=${{ startsWith(github.ref, 'refs/tags/') }} flavor: | latest=false - - - name: Build and push Docker image - uses: docker/build-push-action@v3 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + + - name: Create and push manifest + run: | + TAGS="${{ steps.meta.outputs.tags }}" + for tag in $TAGS; do + docker manifest create $tag \ + ${tag}-amd64 \ + ${tag}-arm64 + docker manifest push $tag + done diff --git a/flake.nix b/flake.nix index 88b99b5..fd3a839 100644 --- a/flake.nix +++ b/flake.nix @@ -34,16 +34,55 @@ toolchain = fenix.packages.${system}.minimal.toolchain; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + + commonArgs = { + src = craneLib.cleanCargoSource ./.; + }; + + cargoArtifacts = craneLib.buildDepsOnly ( + commonArgs + // { + doCheck = false; + } + ); in rec { devenv-up = self.devShells.${system}.default.config.procfileScript; devenv-test = self.devShells.${system}.default.config.test; - testaustime-backend = craneLib.buildPackage { - src = ./.; - # The tests don't work currently - doCheck = false; - }; + testaustime-backend = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; + + nativeBuildInputs = [ + pkgs.postgresql + pkgs.diesel-cli + ]; + + checkInputs = [ + pkgs.postgresql + pkgs.diesel-cli + ]; + + preCheck = '' + # Set up a temporary PostgreSQL database + export PGDATA=$(mktemp -d) + export PGHOST=$PGDATA + + initdb -U postgres + pg_ctl start -o "-k $PGDATA -h \"\"" + + # Create your test database + createdb -U postgres test_db + + # Set environment variables your tests expect + export TEST_DATABASE="postgresql://postgres@localhost/test_db?host=$PGDATA" + + diesel database setup --database-url "$TEST_DATABASE" --migration-dir ${./migrations} + ''; + } + ); default = testaustime-backend; From ba8d79d8e32de923d164887b2b6cc27eff8136f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Fri, 24 Oct 2025 09:38:48 +0200 Subject: [PATCH 09/36] chore: fmt --- src/api/activity.rs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/api/activity.rs b/src/api/activity.rs index b072f81..dcc224f 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -82,9 +82,7 @@ pub async fn update( user.id, (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(Json(UpdateResponse { - duration: 0, - })) + Ok(Json(UpdateResponse { duration: 0 })) } else { // Extend current coding session if heartbeat matches and it has been under the maximum duration of a break heartbeats.insert( @@ -92,7 +90,7 @@ pub async fn update( (heartbeat, start, curtime.signed_duration_since(start)), ); Ok(Json(UpdateResponse { - duration: curtime.signed_duration_since(start).num_seconds() + duration: curtime.signed_duration_since(start).num_seconds(), })) } } else { @@ -109,9 +107,7 @@ pub async fn update( (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(Json(UpdateResponse { - duration: 0 - })) + Ok(Json(UpdateResponse { duration: 0 })) } } None => { @@ -120,9 +116,7 @@ pub async fn update( user.id, (heartbeat, Local::now().naive_local(), Duration::seconds(0)), ); - Ok(Json(UpdateResponse { - duration: 0, - })) + Ok(Json(UpdateResponse { duration: 0 })) } } } @@ -152,12 +146,7 @@ pub async fn delete( db: DatabaseWrapper, Json(body): Json, ) -> Result { - let deleted = db - .delete_activity( - user.identity.id, - body.id, - ) - .await?; + let deleted = db.delete_activity(user.identity.id, body.id).await?; if deleted { Ok(StatusCode::OK) } else { From 2de393da93ec71d7d1c909a014ecfeb3983c8081 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Wed, 29 Oct 2025 08:36:11 +0200 Subject: [PATCH 10/36] unimplement secured access --- src/api/account.rs | 6 ++-- src/api/activity.rs | 7 ++-- src/api/auth.rs | 66 ++++---------------------------------- src/api/friends.rs | 12 +++---- src/api/leaderboards.rs | 28 ++++++++-------- src/auth/mod.rs | 15 +-------- src/auth/secured_access.rs | 63 ------------------------------------ src/database/auth.rs | 25 --------------- src/main.rs | 11 +------ src/state.rs | 8 +---- 10 files changed, 35 insertions(+), 206 deletions(-) delete mode 100644 src/auth/secured_access.rs diff --git a/src/api/account.rs b/src/api/account.rs index cb7bff9..f4f90e6 100644 --- a/src/api/account.rs +++ b/src/api/account.rs @@ -2,7 +2,7 @@ use axum::{response::IntoResponse, Json}; use http::StatusCode; use serde_derive::Deserialize; -use crate::{api::auth::SecuredUserIdentity, database::DatabaseWrapper, error::TimeError}; +use crate::{database::DatabaseWrapper, error::TimeError, models::UserIdentity}; #[derive(Deserialize)] pub struct Settings { @@ -10,12 +10,12 @@ pub struct Settings { } pub async fn change_settings( - userid: SecuredUserIdentity, + user: UserIdentity, db: DatabaseWrapper, settings: Json, ) -> Result { if let Some(public_profile) = settings.public_profile { - db.change_visibility(userid.identity.id, public_profile) + db.change_visibility(user.id, public_profile) .await?; }; diff --git a/src/api/activity.rs b/src/api/activity.rs index dcc224f..6e3f53e 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -7,10 +7,9 @@ use http::StatusCode; use serde::{Deserialize, Serialize}; use crate::{ - api::auth::SecuredUserIdentity, database::DatabaseWrapper, error::TimeError, - models::{HeartBeat, UserId}, + models::{HeartBeat, UserId, UserIdentity}, }; pub type HeartBeatMemoryStore = DashMap; @@ -142,11 +141,11 @@ pub struct ActivityDeleteRequest { } pub async fn delete( - user: SecuredUserIdentity, + user: UserIdentity, db: DatabaseWrapper, Json(body): Json, ) -> Result { - let deleted = db.delete_activity(user.identity.id, body.id).await?; + let deleted = db.delete_activity(user.id, body.id).await?; if deleted { Ok(StatusCode::OK) } else { diff --git a/src/api/auth.rs b/src/api/auth.rs index 6267cb2..36cd9ee 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -13,10 +13,10 @@ use lettre::{ use serde::{Deserialize, Serialize}; use crate::{ - auth::{secured_access::SecuredAccessTokenStorage, Authentication}, + auth::Authentication, database::DatabaseWrapper, error::TimeError, - models::{SecuredAccessTokenResponse, SelfUser, UserId, UserIdentity}, + models::{SelfUser, UserId, UserIdentity}, utils::{generate_password_reset_token, validate_email}, PasswordReset, PasswordResetState, }; @@ -78,24 +78,6 @@ impl FromRequestParts for UserIdentity { } } -pub struct SecuredUserIdentity { - pub identity: UserIdentity, -} - -impl FromRequestParts for SecuredUserIdentity { - type Rejection = TimeError; - - async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result { - let auth = parts.extensions.get::().cloned().unwrap(); - - if let Authentication::SecuredAccessToken(user) = auth { - Ok(SecuredUserIdentity { identity: user }) - } else { - Err(TimeError::UnauthroizedSecuredAccess) - } - } -} - pub struct UserIdentityOptional { pub identity: Option, } @@ -137,42 +119,6 @@ pub async fn login( } } -pub async fn get_secured_access_token( - State(secured_access_storage): State>, - db: DatabaseWrapper, - data: Json, -) -> Result { - if data.password.len() > 128 { - return Err(TimeError::InvalidLength( - "Password cannot be longer than 128 characters".to_string(), - )); - } - - if let Ok(Some(user)) = db - .verify_user_password(&data.username, &data.password) - .await - { - Ok(Json(SecuredAccessTokenResponse { - token: secured_access_storage.create_token(user.id), - })) - } else { - Err(TimeError::InvalidCredentials) - } -} - -pub async fn regenerate( - user: SecuredUserIdentity, - db: DatabaseWrapper, -) -> Result { - db.regenerate_token(user.identity.id) - .await - .inspect_err(|e| error!("{}", e)) - .map(|token| { - let token = json!({ "token": token }); - Json(token) - }) -} - pub async fn register( db: DatabaseWrapper, Json(data): Json, @@ -203,7 +149,7 @@ pub async fn register( } pub async fn change_username( - user: SecuredUserIdentity, + user: UserIdentity, db: DatabaseWrapper, Json(data): Json, ) -> Result { @@ -217,7 +163,7 @@ pub async fn change_username( return Err(TimeError::BadUsername); } - let result = db.change_username(user.identity.id, &data.new).await; + let result = db.change_username(user.id, &data.new).await; if result.as_ref().is_err_and(|e| e.is_unique_violation()) { return Err(TimeError::UsernameTaken); @@ -227,7 +173,7 @@ pub async fn change_username( } pub async fn change_email( - user: SecuredUserIdentity, + user: UserIdentity, db: DatabaseWrapper, Json(data): Json, ) -> Result { @@ -235,7 +181,7 @@ pub async fn change_email( return Err(TimeError::InvalidEmail); } - let result = db.change_email(user.identity.id, data.new).await; + let result = db.change_email(user.id, data.new).await; if result.as_ref().is_err_and(|e| e.is_unique_violation()) { return Err(TimeError::EmailTaken); diff --git a/src/api/friends.rs b/src/api/friends.rs index 45101ae..41fe410 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -6,10 +6,10 @@ use http::StatusCode; use serde::Deserialize; use crate::{ - api::{activity::HeartBeatMemoryStore, auth::SecuredUserIdentity}, + api::activity::HeartBeatMemoryStore, database::DatabaseWrapper, error::TimeError, - models::{CurrentActivity, FriendWithTimeAndStatus, UserId}, + models::{CurrentActivity, FriendWithTimeAndStatus, UserId, UserIdentity}, }; #[derive(Deserialize, Debug)] @@ -93,10 +93,10 @@ pub async fn get_friends( } pub async fn regenerate_friend_code( - user: SecuredUserIdentity, + user: UserIdentity, db: DatabaseWrapper, ) -> Result { - db.regenerate_friend_code(user.identity.id) + db.regenerate_friend_code(user.id) .await .inspect_err(|e| error!("{}", e)) .map(|code| Json(json!({ "friend_code": code }))) @@ -108,12 +108,12 @@ pub struct RemoveFriendRequest { } pub async fn remove( - user: SecuredUserIdentity, + user: UserIdentity, db: DatabaseWrapper, Json(body): Json, ) -> Result { let friend = db.get_user_by_name(&body.name).await?; - let deleted = db.remove_friend(user.identity.id, friend.id).await?; + let deleted = db.remove_friend(user.id, friend.id).await?; if deleted { Ok(StatusCode::OK) diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 0290cb7..912c52f 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -4,7 +4,7 @@ use http::StatusCode; use serde::{Deserialize, Serialize}; use crate::{ - api::auth::SecuredUserIdentity, database::DatabaseWrapper, error::TimeError, models::UserId, + database::DatabaseWrapper, error::TimeError, models::{UserId, UserIdentity}, }; #[derive(Deserialize, Serialize)] @@ -69,7 +69,7 @@ pub async fn get_leaderboard( } pub async fn delete_leaderboard( - user: SecuredUserIdentity, + user: UserIdentity, Path(name): Path, db: DatabaseWrapper, ) -> Result { @@ -78,7 +78,7 @@ pub async fn delete_leaderboard( .await .map_err(|_| TimeError::LeaderboardNotFound)?; - if db.is_leaderboard_admin(user.identity.id, lid).await? { + if db.is_leaderboard_admin(user.id, lid).await? { db.delete_leaderboard(&name).await?; Ok(StatusCode::OK) } else { @@ -111,7 +111,7 @@ pub async fn join_leaderboard( } pub async fn leave_leaderboard( - user: SecuredUserIdentity, + user: UserIdentity, Path(name): Path, db: DatabaseWrapper, ) -> Result { @@ -120,14 +120,14 @@ pub async fn leave_leaderboard( .await .map_err(|_| TimeError::LeaderboardNotFound)?; - if db.is_leaderboard_admin(user.identity.id, lid).await? + if db.is_leaderboard_admin(user.id, lid).await? && db.get_leaderboard_admin_count(lid).await? == 1 { return Err(TimeError::LastAdmin); } if db - .remove_user_from_leaderboard(lid, user.identity.id) + .remove_user_from_leaderboard(lid, user.id) .await? { Ok(StatusCode::OK) @@ -137,7 +137,7 @@ pub async fn leave_leaderboard( } pub async fn promote_member( - user: SecuredUserIdentity, + user: UserIdentity, Path(name): Path, db: DatabaseWrapper, promotion: Json, @@ -147,7 +147,7 @@ pub async fn promote_member( .await .map_err(|_| TimeError::LeaderboardNotFound)?; - if db.is_leaderboard_admin(user.identity.id, lid).await? { + if db.is_leaderboard_admin(user.id, lid).await? { let newadmin = db .get_user_by_name(&promotion.user) .await @@ -168,7 +168,7 @@ pub async fn promote_member( } pub async fn demote_member( - user: SecuredUserIdentity, + user: UserIdentity, Path(name): Path, db: DatabaseWrapper, demotion: Json, @@ -178,7 +178,7 @@ pub async fn demote_member( .await .map_err(|_| TimeError::LeaderboardNotFound)?; - if db.is_leaderboard_admin(user.identity.id, lid).await? { + if db.is_leaderboard_admin(user.id, lid).await? { let oldadmin = db .get_user_by_name(&demotion.user) .await @@ -199,7 +199,7 @@ pub async fn demote_member( } pub async fn kick_member( - user: SecuredUserIdentity, + user: UserIdentity, Path(name): Path, db: DatabaseWrapper, kick: Json, @@ -209,7 +209,7 @@ pub async fn kick_member( .await .map_err(|_| TimeError::LeaderboardNotFound)?; - if db.is_leaderboard_admin(user.identity.id, lid).await? { + if db.is_leaderboard_admin(user.id, lid).await? { let kmember = db .get_user_by_name(&kick.user) .await @@ -225,7 +225,7 @@ pub async fn kick_member( } pub async fn regenerate_invite( - user: SecuredUserIdentity, + user: UserIdentity, Path(name): Path, db: DatabaseWrapper, ) -> Result { @@ -234,7 +234,7 @@ pub async fn regenerate_invite( .await .map_err(|_| TimeError::LeaderboardNotFound)?; - if db.is_leaderboard_admin(user.identity.id, lid).await? { + if db.is_leaderboard_admin(user.id, lid).await? { let code = db.regenerate_leaderboard_invite(lid).await?; Ok(Json(json!({ "invite_code": code }))) } else { diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 5ec88d2..1309422 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -1,8 +1,5 @@ -pub mod secured_access; - use std::{ mem, - sync::Arc, task::{Context, Poll}, }; @@ -16,7 +13,6 @@ use crate::{database::DatabaseWrapper, models::UserIdentity, TestaustimeState}; pub enum Authentication { NoAuth, AuthToken(UserIdentity), - SecuredAccessToken(UserIdentity), } #[derive(Clone)] @@ -35,7 +31,6 @@ impl Authentication { match self { Authentication::NoAuth => None, Authentication::AuthToken(user_identity) => Some(user_identity), - Authentication::SecuredAccessToken(user_identity) => Some(user_identity), } } } @@ -68,7 +63,6 @@ where fn call(&mut self, mut req: Request) -> Self::Future { let db = DatabaseWrapper::from(&self.state.database); - let secured_access_storage = Arc::clone(&self.state.secured_access_storage); let auth = req.headers().get("Authorization").cloned(); let clone = self.inner.clone(); @@ -84,14 +78,7 @@ where break 'auth Authentication::NoAuth; }; - if let Ok(secured_access_instance) = secured_access_storage.get(token).clone() { - let user = db - .get_user_by_id(secured_access_instance.user_id) - .await - .unwrap(); - - Authentication::SecuredAccessToken(user) - } else if let Ok(user_identity) = db.get_user_by_token(token.to_string()).await { + if let Ok(user_identity) = db.get_user_by_token(token.to_string()).await { Authentication::AuthToken(user_identity) } else { Authentication::NoAuth diff --git a/src/auth/secured_access.rs b/src/auth/secured_access.rs deleted file mode 100644 index a9d3fb4..0000000 --- a/src/auth/secured_access.rs +++ /dev/null @@ -1,63 +0,0 @@ -use std::time::{Duration, Instant}; - -use dashmap::DashMap; - -use crate::utils::generate_auth_token; - -#[derive(Clone, Copy, Debug)] -pub enum SecuredAccessError { - InvalidToken, - ExpiredToken, -} - -#[derive(Clone)] -pub struct SecuredAccessTokenInstance { - pub user_id: i32, - pub expires: Instant, -} - -#[derive(Default)] -pub struct SecuredAccessTokenStorage { - inner: DashMap, -} - -impl SecuredAccessTokenStorage { - pub fn new() -> Self { - Self { - inner: DashMap::new(), - } - } - - pub fn get(&self, token: &str) -> Result { - let instance = self - .inner - .get(token) - .ok_or(SecuredAccessError::InvalidToken)? - .clone(); - - if instance.expires < Instant::now() { - self.inner.remove(token); - Err(SecuredAccessError::ExpiredToken) - } else { - Ok(instance) - } - } - - pub fn create_token(&self, user_id: i32) -> String { - let token = generate_auth_token(); - - self.inner.insert( - token.clone(), - SecuredAccessTokenInstance { - user_id, - expires: Instant::now() + Duration::from_secs(60 * 60), - }, - ); - - let now = Instant::now(); - - self.inner.retain(|_, v| v.expires > now); - - token - } -} diff --git a/src/database/auth.rs b/src/database/auth.rs index 8f205cc..d4133f4 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -46,16 +46,6 @@ impl super::DatabaseWrapper { > 0) } - pub async fn get_user_by_id(&self, userid: i32) -> Result { - let mut conn = self.db.get().await?; - use crate::schema::user_identities::dsl::*; - - Ok(user_identities - .find(userid) - .first::(&mut conn) - .await?) - } - pub async fn verify_user_password( &self, arg_username: &str, @@ -87,21 +77,6 @@ impl super::DatabaseWrapper { } } - pub async fn regenerate_token(&self, userid: i32) -> Result { - let mut conn = self.db.get().await?; - - let token = crate::utils::generate_auth_token(); - - use crate::schema::user_identities::dsl::*; - - diesel::update(user_identities.find(userid)) - .set(auth_token.eq(&token)) - .execute(&mut conn) - .await?; - - Ok(token) - } - pub async fn new_testaustime_user( &self, username: &str, diff --git a/src/main.rs b/src/main.rs index 0f7dbdb..687fd46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ mod tests; use std::{net::SocketAddr, num::NonZeroU32, sync::Arc}; use api::activity::HeartBeatMemoryStore; -use auth::{secured_access::SecuredAccessTokenStorage, AuthMiddleware, Authentication}; +use auth::{AuthMiddleware, Authentication}; use axum::{ body::Body, routing::{delete, get, post}, @@ -74,7 +74,6 @@ pub struct TestaustimeState { smtp: AsyncSmtpTransport, database: Arc, heartbeat_store: Arc, - secured_access_storage: Arc, register_limiter: Arc, password_reset_state: Arc, } @@ -89,8 +88,6 @@ fn create_router(config: &TestaustimeConfig) -> Router { let heartbeat_store = Arc::new(HeartBeatMemoryStore::new()); - let secured_access_storage = Arc::new(SecuredAccessTokenStorage::new()); - let password_reset_state = Arc::new(PasswordResetState { storage: DashMap::default(), }); @@ -110,7 +107,6 @@ fn create_router(config: &TestaustimeConfig) -> Router { let state = TestaustimeState { smtp, - secured_access_storage, heartbeat_store, database, register_limiter, @@ -157,14 +153,9 @@ fn create_router(config: &TestaustimeConfig) -> Router { .route("/hide", post(api::activity::hide_project)) }) .route("/auth/login", post(api::auth::login)) - .route("/auth/regenerate", post(api::auth::regenerate)) .route("/auth/change-username", post(api::auth::change_username)) .route("/auth/change-email", post(api::auth::change_email)) .route("/auth/change-password", post(api::auth::change_password)) - .route( - "/auth/securedaccess", - post(api::auth::get_secured_access_token), - ) .route( "/auth/reset-password", post(api::auth::request_password_reset), diff --git a/src/state.rs b/src/state.rs index 7ed3cab..2872b85 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,7 +4,7 @@ use axum::extract::FromRef; use lettre::{AsyncSmtpTransport, Tokio1Executor}; use crate::{ - api::activity::HeartBeatMemoryStore, auth::secured_access::SecuredAccessTokenStorage, + api::activity::HeartBeatMemoryStore, PasswordResetState, RegisterLimiter, TestaustimeState, }; @@ -14,12 +14,6 @@ impl FromRef for Arc { } } -impl FromRef for Arc { - fn from_ref(input: &TestaustimeState) -> Self { - Arc::clone(&input.secured_access_storage) - } -} - impl FromRef for Arc { fn from_ref(input: &TestaustimeState) -> Self { Arc::clone(&input.register_limiter) From bd914db05634254902b4a1fc41d4b20144488e6e Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Wed, 29 Oct 2025 08:41:33 +0200 Subject: [PATCH 11/36] fmt, clippy and tests --- src/api/account.rs | 3 +-- src/api/leaderboards.rs | 9 ++++----- src/models.rs | 5 ----- src/state.rs | 3 +-- src/tests/account.rs | 11 ++--------- src/tests/activity.rs | 11 ++--------- src/tests/auth.rs | 12 ++---------- src/tests/leaderboards.rs | 11 ++--------- 8 files changed, 14 insertions(+), 51 deletions(-) diff --git a/src/api/account.rs b/src/api/account.rs index f4f90e6..f953a8d 100644 --- a/src/api/account.rs +++ b/src/api/account.rs @@ -15,8 +15,7 @@ pub async fn change_settings( settings: Json, ) -> Result { if let Some(public_profile) = settings.public_profile { - db.change_visibility(user.id, public_profile) - .await?; + db.change_visibility(user.id, public_profile).await?; }; Ok(StatusCode::OK) diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 912c52f..4ca0eb4 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -4,7 +4,9 @@ use http::StatusCode; use serde::{Deserialize, Serialize}; use crate::{ - database::DatabaseWrapper, error::TimeError, models::{UserId, UserIdentity}, + database::DatabaseWrapper, + error::TimeError, + models::{UserId, UserIdentity}, }; #[derive(Deserialize, Serialize)] @@ -126,10 +128,7 @@ pub async fn leave_leaderboard( return Err(TimeError::LastAdmin); } - if db - .remove_user_from_leaderboard(lid, user.id) - .await? - { + if db.remove_user_from_leaderboard(lid, user.id).await? { Ok(StatusCode::OK) } else { Err(TimeError::NotMember) diff --git a/src/models.rs b/src/models.rs index d91c5d5..cb5579d 100644 --- a/src/models.rs +++ b/src/models.rs @@ -250,11 +250,6 @@ pub struct FriendWithTimeAndStatus { pub status: Option, } -#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash)] -pub struct SecuredAccessTokenResponse { - pub token: String, -} - #[derive(Deserialize, Serialize, Debug, Hash, Eq, PartialEq, Clone)] pub struct HeartBeat { #[serde(deserialize_with = "project_deserialize")] diff --git a/src/state.rs b/src/state.rs index 2872b85..121cc2b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,8 +4,7 @@ use axum::extract::FromRef; use lettre::{AsyncSmtpTransport, Tokio1Executor}; use crate::{ - api::activity::HeartBeatMemoryStore, - PasswordResetState, RegisterLimiter, TestaustimeState, + api::activity::HeartBeatMemoryStore, PasswordResetState, RegisterLimiter, TestaustimeState, }; impl FromRef for Arc { diff --git a/src/tests/account.rs b/src/tests/account.rs index ef4898a..de5a2e5 100644 --- a/src/tests/account.rs +++ b/src/tests/account.rs @@ -1,7 +1,7 @@ use serde_json::json; use super::{macros::*, *}; -use crate::models::{NewUserIdentity, SecuredAccessTokenResponse}; +use crate::models::NewUserIdentity; #[tokio::test] async fn public_accounts() { @@ -28,15 +28,8 @@ async fn public_accounts() { "Data should be private for private accounts" ); - let resp = request!(app, POST, "/auth/securedaccess", body); - assert!( - resp.status().is_success(), - "Getting secured access token failed" - ); - let sat: SecuredAccessTokenResponse = body_to_json(resp).await; - let change = json!({"public_profile": true}); - let resp = request_auth!(app, POST, "/account/settings", sat.token, change); + let resp = request_auth!(app, POST, "/account/settings", user.auth_token, change); assert!(resp.status().is_success(), "Changing settings failed"); diff --git a/src/tests/activity.rs b/src/tests/activity.rs index a86b461..6bcdf54 100644 --- a/src/tests/activity.rs +++ b/src/tests/activity.rs @@ -3,7 +3,7 @@ use std::time::Duration; use serde_json::json; use super::{macros::*, *}; -use crate::models::{CurrentActivity, HeartBeat, NewUserIdentity, SecuredAccessTokenResponse}; +use crate::models::{CurrentActivity, HeartBeat, NewUserIdentity}; #[tokio::test] async fn updating_activity_works() { @@ -157,15 +157,8 @@ async fn hidden_project() { let resp = request_auth!(app, POST, "/activity/flush", user.auth_token); assert!(resp.status().is_success(), "Flushing should work"); - let resp = request!(app, POST, "/auth/securedaccess", body); - assert!( - resp.status().is_success(), - "Getting secured access token failed" - ); - let sat: SecuredAccessTokenResponse = body_to_json(resp).await; - let change = json!({"public_profile": true}); - let resp = request_auth!(app, POST, "/account/settings", sat.token, change); + let resp = request_auth!(app, POST, "/account/settings", user.auth_token, change); assert!(resp.status().is_success(), "Making profile public failed"); diff --git a/src/tests/auth.rs b/src/tests/auth.rs index c7d27db..c368700 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -1,7 +1,7 @@ use serde_json::json; use super::{macros::*, *}; -use crate::models::{NewUserIdentity, SecuredAccessTokenResponse, SelfUser}; +use crate::models::{NewUserIdentity, SelfUser}; #[tokio::test] async fn register_and_delete() { @@ -48,14 +48,6 @@ async fn login_change_username_and_password() { "Auth tokens should be equal" ); - let resp = request!(app, POST, "/auth/securedaccess", body); - assert!( - resp.status().is_success(), - "Getting secured access token failed" - ); - - let sat: SecuredAccessTokenResponse = body_to_json(resp).await; - let change_request = json!({ "new": "testuser3" }); @@ -76,7 +68,7 @@ async fn login_change_username_and_password() { app, POST, "/auth/change-username", - sat.token, + user.auth_token, change_request ); assert!(resp.status().is_success(), "Username change failed"); diff --git a/src/tests/leaderboards.rs b/src/tests/leaderboards.rs index b15aa14..ffd1c4b 100644 --- a/src/tests/leaderboards.rs +++ b/src/tests/leaderboards.rs @@ -3,7 +3,7 @@ use serde_json::json; use super::{macros::*, *}; use crate::{ api::leaderboards::{LeaderboardInvite, LeaderboardName}, - models::{NewUserIdentity, PrivateLeaderboard, SecuredAccessTokenResponse}, + models::{NewUserIdentity, PrivateLeaderboard}, }; #[tokio::test] @@ -66,14 +66,7 @@ async fn creation_joining_and_deletion() { "Leaderboard member count should be 2" ); - let resp = request!(app, POST, "/auth/securedaccess", owner_body); - assert!( - resp.status().is_success(), - "Getting secured access token failed" - ); - let sat: SecuredAccessTokenResponse = body_to_json(resp).await; - - let resp = request_auth!(app, DELETE, "/leaderboards/board", sat.token); + let resp = request_auth!(app, DELETE, "/leaderboards/board", owner.auth_token); assert!(resp.status().is_success(), "Leaderboards deletion failed"); let resp = request_auth!(app, GET, "/leaderboards/board", member.auth_token); From 61493a4bd8b831bdf5ac0e8a21c90e1559f4817d Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Wed, 29 Oct 2025 08:54:57 +0200 Subject: [PATCH 12/36] tests --- src/tests/auth.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/tests/auth.rs b/src/tests/auth.rs index c368700..e029d9b 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -52,18 +52,6 @@ async fn login_change_username_and_password() { "new": "testuser3" }); - let resp = request_auth!( - app, - POST, - "/auth/change-username", - user.auth_token, - change_request - ); - assert!( - resp.status().is_client_error(), - "Auth token is not secured access token" - ); - let resp = request_auth!( app, POST, From 216ade6726662b08cc6fbfbe49d9ab527e89c998 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Mon, 17 Nov 2025 09:57:42 +0200 Subject: [PATCH 13/36] openapi via utoipa also remove all instances of impl IntoResponse in endpoint types --- Cargo.lock | 233 +++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 + src/api/account.rs | 17 ++- src/api/activity.rs | 110 +++++++++++++++---- src/api/auth.rs | 138 +++++++++++++++++------- src/api/friends.rs | 64 +++++++++-- src/api/leaderboards.rs | 170 +++++++++++++++++++++++++---- src/api/mod.rs | 11 +- src/api/oauth.rs | 14 ++- src/api/search.rs | 19 +++- src/api/stats.rs | 18 +++- src/api/users.rs | 138 +++++++++++++++++++----- src/main.rs | 169 +++++++++++++---------------- src/models.rs | 23 ++-- 14 files changed, 879 insertions(+), 248 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 127caec..2b415ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,6 +94,15 @@ dependencies = [ "libc", ] +[[package]] +name = "arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "argon2" version = "0.4.1" @@ -382,6 +391,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -483,6 +501,17 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "diesel" version = "2.2.9" @@ -625,6 +654,17 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "flate2" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb" +dependencies = [ + "crc32fast", + "libz-rs-sys", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1171,6 +1211,7 @@ checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", "hashbrown 0.15.2", + "serde", ] [[package]] @@ -1255,6 +1296,15 @@ version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +[[package]] +name = "libz-rs-sys" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "840db8cf39d9ec4dd794376f38acc40d0fc65eec2a8f484f7fd375b84602becd" +dependencies = [ + "zlib-rs", +] + [[package]] name = "litemap" version = "0.7.5" @@ -1314,6 +1364,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "miniz_oxide" version = "0.8.8" @@ -1321,6 +1381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" dependencies = [ "adler2", + "simd-adler32", ] [[package]] @@ -1445,6 +1506,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -1647,7 +1714,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1853,6 +1920,40 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rust-embed" +version = "8.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb44e1917075637ee8c7bcb865cf8830e3a92b5b1189e44e3a0ab5a0d5be314b" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "8.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382499b49db77a7c19abd2a574f85ada7e9dbe125d5d1160fa5cad7c4cf71fc9" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "syn", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "8.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21fcbee55c2458836bcdbfffb6ec9ba74bbc23ca7aa6816015a3dd2c4d8fc185" +dependencies = [ + "sha2", + "walkdir", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1921,6 +2022,15 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scoped-futures" version = "0.1.4" @@ -2025,6 +2135,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + [[package]] name = "siphasher" version = "1.0.1" @@ -2194,6 +2310,9 @@ dependencies = [ "tracing-futures", "tracing-subscriber", "url", + "utoipa", + "utoipa-axum", + "utoipa-swagger-ui", ] [[package]] @@ -2520,6 +2639,12 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + [[package]] name = "unicode-bidi" version = "0.3.18" @@ -2586,6 +2711,61 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utoipa" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fcc29c80c21c31608227e0912b2d7fddba57ad76b606890627ba8ee7964e993" +dependencies = [ + "indexmap", + "serde", + "serde_json", + "utoipa-gen", +] + +[[package]] +name = "utoipa-axum" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c25bae5bccc842449ec0c5ddc5cbb6a3a1eaeac4503895dc105a1138f8234a0" +dependencies = [ + "axum", + "paste", + "tower-layer", + "tower-service", + "utoipa", +] + +[[package]] +name = "utoipa-gen" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d79d08d92ab8af4c5e8a6da20c47ae3f61a0f1dabc1997cdf2d082b757ca08b" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn", +] + +[[package]] +name = "utoipa-swagger-ui" +version = "9.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d047458f1b5b65237c2f6dc6db136945667f40a7668627b3490b9513a3d43a55" +dependencies = [ + "axum", + "base64", + "mime_guess", + "regex", + "rust-embed", + "serde", + "serde_json", + "url", + "utoipa", + "zip", +] + [[package]] name = "valuable" version = "0.1.1" @@ -2598,6 +2778,16 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -2755,6 +2945,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3128,3 +3327,35 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zip" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12598812502ed0105f607f941c386f43d441e00148fce9dec3ca5ffb0bde9308" +dependencies = [ + "arbitrary", + "crc32fast", + "flate2", + "indexmap", + "memchr", + "zopfli", +] + +[[package]] +name = "zlib-rs" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f06ae92f42f5e5c42443fd094f245eb656abf56dd7cce9b8b263236565e00f2" + +[[package]] +name = "zopfli" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfc5ee405f504cd4984ecc6f14d02d55cfda60fa4b689434ef4102aae150cd7" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] diff --git a/Cargo.toml b/Cargo.toml index 8f2e652..4c2b9a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,3 +50,6 @@ diesel = { version = "2.1.0", features = ["chrono", "serde_json"] } diesel-async = { version = "0.5.1", features = ["postgres", "deadpool"] } lettre = { version = "0.11.14", default-features = false, features = ["tokio1-rustls-tls", "tracing", "pool", "smtp-transport", "hostname", "builder"]} mime = "0.3.17" +utoipa = { version = "5.4.0", features = ["axum_extras", "chrono"] } +utoipa-axum = "0.2.0" +utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } diff --git a/src/api/account.rs b/src/api/account.rs index f953a8d..dfb644f 100644 --- a/src/api/account.rs +++ b/src/api/account.rs @@ -1,19 +1,30 @@ -use axum::{response::IntoResponse, Json}; +use axum::Json; use http::StatusCode; use serde_derive::Deserialize; +use utoipa::ToSchema; use crate::{database::DatabaseWrapper, error::TimeError, models::UserIdentity}; -#[derive(Deserialize)] +#[derive(Deserialize, ToSchema)] pub struct Settings { public_profile: Option, } +#[utoipa::path( + post, + path = "/account/settings", + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn change_settings( user: UserIdentity, db: DatabaseWrapper, settings: Json, -) -> Result { +) -> Result { if let Some(public_profile) = settings.public_profile { db.change_visibility(user.id, public_profile).await?; }; diff --git a/src/api/activity.rs b/src/api/activity.rs index 6e3f53e..a14ea98 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -1,10 +1,11 @@ use std::sync::Arc; -use axum::{extract::State, response::IntoResponse, Json}; +use axum::{extract::State, Json}; use chrono::{Duration, Local}; use dashmap::DashMap; use http::StatusCode; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; use crate::{ database::DatabaseWrapper, @@ -14,28 +15,27 @@ use crate::{ pub type HeartBeatMemoryStore = DashMap; -#[derive(Deserialize)] -pub struct ActivityRenameRequest { - from: String, - to: String, -} - -#[derive(Deserialize)] -pub struct HideRequest { - target_project: String, - hidden: bool, -} - -#[derive(Serialize)] +#[derive(Serialize, ToSchema)] pub struct UpdateResponse { duration: i64, } + +#[utoipa::path( + post, + path = "/activity/update", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = UpdateResponse) + ) +)] pub async fn update( user: UserId, db: DatabaseWrapper, heartbeats: State>, Json(heartbeat): Json, -) -> Result { +) -> Result, TimeError> { if let Some(project) = &heartbeat.project_name { if project.len() > 64 { return Err(TimeError::InvalidLength( @@ -120,11 +120,21 @@ pub async fn update( } } +#[utoipa::path( + post, + path = "/activity/flush", + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn flush( user: UserId, db: DatabaseWrapper, heartbeats: State>, -) -> Result { +) -> Result { if let Some(heartbeat) = heartbeats.get(&user.id) { let (inner_heartbeat, start, duration) = heartbeat.to_owned(); drop(heartbeat); @@ -135,16 +145,26 @@ pub async fn flush( Ok(StatusCode::OK) } -#[derive(Deserialize)] +#[derive(Deserialize, ToSchema)] pub struct ActivityDeleteRequest { id: i32, } +#[utoipa::path( + delete, + path = "/activity/delete", + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn delete( user: UserIdentity, db: DatabaseWrapper, Json(body): Json, -) -> Result { +) -> Result { let deleted = db.delete_activity(user.id, body.id).await?; if deleted { Ok(StatusCode::OK) @@ -153,24 +173,70 @@ pub async fn delete( } } +#[derive(Deserialize, ToSchema)] +pub struct ActivityRenameRequest { + from: String, + to: String, +} + +#[derive(Serialize, ToSchema)] +pub struct ActivityRenameResponse { + affected_activities: usize, +} + +#[utoipa::path( + post, + path = "/activity/rename", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = ActivityRenameResponse) + ) +)] pub async fn rename_project( user: UserId, db: DatabaseWrapper, body: Json, -) -> Result { +) -> Result, TimeError> { let renamed = db.rename_project(user.id, &body.from, &body.to).await?; - Ok(Json(json!({ "affected_activities": renamed }))) + Ok(Json(ActivityRenameResponse { + affected_activities: renamed, + })) +} + +#[derive(Deserialize, ToSchema)] +pub struct HideRequest { + target_project: String, + hidden: bool, +} + +#[derive(Serialize, ToSchema)] +pub struct HideResponse { + affected_activities: usize, } +#[utoipa::path( + post, + path = "/activity/hide", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = HideResponse) + ) +)] pub async fn hide_project( user: UserId, db: DatabaseWrapper, body: Json, -) -> Result { +) -> Result, TimeError> { let renamed = db .set_project_hidden(user.id, &body.target_project, body.hidden) .await?; - Ok(Json(json!({ "affected_activities": renamed }))) + Ok(Json(HideResponse { + affected_activities: renamed, + })) } diff --git a/src/api/auth.rs b/src/api/auth.rs index 36cd9ee..0912b49 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use axum::{ extract::{FromRequestParts, State}, - response::IntoResponse, Json, }; use chrono::{Duration, Local}; @@ -11,45 +10,17 @@ use lettre::{ message::header::ContentType, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, }; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; use crate::{ auth::Authentication, database::DatabaseWrapper, error::TimeError, - models::{SelfUser, UserId, UserIdentity}, + models::{NewUserIdentity, SelfUser, UserId, UserIdentity}, utils::{generate_password_reset_token, validate_email}, PasswordReset, PasswordResetState, }; -#[derive(Deserialize)] -pub struct UsernameChangeRequest { - pub new: String, -} - -#[derive(Deserialize)] -pub struct EmailChangeRequest { - pub new: String, -} - -#[derive(Deserialize)] -pub struct PasswordChangeRequest { - pub old: String, - pub new: String, -} - -#[derive(Deserialize, Debug)] -pub struct LoginRequest { - pub username: String, - pub password: String, -} - -#[derive(Deserialize, Debug)] -pub struct RegisterRequest { - pub username: String, - pub email: Option, - pub password: String, -} - impl FromRequestParts for UserId { type Rejection = TimeError; @@ -101,10 +72,23 @@ where } } +#[derive(Deserialize, Debug, ToSchema)] +pub struct LoginRequest { + pub username: String, + pub password: String, +} + +#[utoipa::path( + post, + path = "/auth/login", + responses( + (status = OK, body = SelfUser), + ) +)] pub async fn login( db: DatabaseWrapper, data: Json, -) -> Result { +) -> Result, TimeError> { if data.password.len() > 128 { return Err(TimeError::InvalidLength( "Password cannot be longer than 128 characters".to_string(), @@ -119,10 +103,24 @@ pub async fn login( } } +#[derive(Deserialize, Debug, ToSchema)] +pub struct RegisterRequest { + pub username: String, + pub email: Option, + pub password: String, +} + +#[utoipa::path( + post, + path = "/auth/register", + responses( + (status = OK, body = NewUserIdentity) + ) +)] pub async fn register( db: DatabaseWrapper, Json(data): Json, -) -> Result { +) -> Result, TimeError> { if data.password.len() < 8 || data.password.len() > 128 { return Err(TimeError::InvalidLength( "Password has to be between 8 and 128 characters long".to_string(), @@ -148,11 +146,26 @@ pub async fn register( Ok(Json(res)) } +#[derive(Deserialize, ToSchema)] +pub struct UsernameChangeRequest { + pub new: String, +} + +#[utoipa::path( + post, + path = "/auth/change-username", + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn change_username( user: UserIdentity, db: DatabaseWrapper, Json(data): Json, -) -> Result { +) -> Result { if data.new.len() < 2 || data.new.len() > 32 { return Err(TimeError::InvalidLength( "Username is not between 2 and 32 chars".to_string(), @@ -172,11 +185,26 @@ pub async fn change_username( result.map(|_| StatusCode::OK) } +#[derive(Deserialize, ToSchema)] +pub struct EmailChangeRequest { + pub new: String, +} + +#[utoipa::path( + post, + path = "/auth/change-email", + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn change_email( user: UserIdentity, db: DatabaseWrapper, Json(data): Json, -) -> Result { +) -> Result { if !validate_email(&data.new) { return Err(TimeError::InvalidEmail); } @@ -190,11 +218,27 @@ pub async fn change_email( result.map(|_| StatusCode::OK) } +#[derive(Deserialize, ToSchema)] +pub struct PasswordChangeRequest { + pub old: String, + pub new: String, +} + +#[utoipa::path( + post, + path = "/auth/change-password", + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn change_password( user: UserIdentity, db: DatabaseWrapper, Json(body): Json, -) -> Result { +) -> Result { if body.new.len() < 8 || body.new.len() > 128 { return Err(TimeError::InvalidLength( "Password has to be between 8 and 128 characters long".to_string(), @@ -212,17 +256,24 @@ pub async fn change_password( } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct PasswordResetRequest { pub email: String, } +#[utoipa::path( + post, + path = "/auth/reset-password", + responses( + (status = OK) + ) +)] pub async fn request_password_reset( db: DatabaseWrapper, State(password_resets): State>, State(relay): State>, Json(body): Json, -) -> Result { +) -> Result { let Some(user) = db.get_user_by_email(&body.email).await? else { return Ok(StatusCode::OK); }; @@ -259,17 +310,24 @@ pub async fn request_password_reset( Ok(StatusCode::OK) } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct PasswordResetCompletionRequest { password: String, token: String, } +#[utoipa::path( + post, + path = "/auth/complete-password-reset", + responses( + (status = OK) + ) +)] pub async fn reset_password( db: DatabaseWrapper, State(password_resets): State>, Json(body): Json, -) -> Result { +) -> Result { let Some(reset) = password_resets.storage.get(&body.token) else { return Err(TimeError::InvalidPasswordResetToken); }; diff --git a/src/api/friends.rs b/src/api/friends.rs index 41fe410..27c482b 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -1,9 +1,10 @@ use std::sync::Arc; -use axum::{extract::State, response::IntoResponse, Json}; +use axum::{extract::State, Json}; use diesel::result::DatabaseErrorKind; use http::StatusCode; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; use crate::{ api::activity::HeartBeatMemoryStore, @@ -12,17 +13,27 @@ use crate::{ models::{CurrentActivity, FriendWithTimeAndStatus, UserId, UserIdentity}, }; -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, ToSchema)] pub struct FriendRequest { pub code: String, } +#[utoipa::path( + post, + path = "/friends/add", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = FriendWithTimeAndStatus) + ) +)] pub async fn add_friend( user: UserId, db: DatabaseWrapper, State(heartbeats): State>, Json(body): Json, -) -> Result { +) -> Result, TimeError> { match db .add_friend(user.id, body.code.trim_start_matches("ttfc_").to_string()) .await @@ -61,11 +72,21 @@ pub async fn add_friend( } } +#[utoipa::path( + get, + path = "/friends/list", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = Vec) + ) +)] pub async fn get_friends( user: UserId, db: DatabaseWrapper, State(heartbeats): State>, -) -> Result { +) -> Result>, TimeError> { let friends = db .get_friends_with_time(user.id) .await @@ -92,26 +113,51 @@ pub async fn get_friends( Ok(Json(friends)) } +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +pub struct RegenerateFriendCodeResponse { + friend_code: String, +} + +#[utoipa::path( + post, + path = "/friends/regenerate", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = RegenerateFriendCodeResponse) + ) +)] pub async fn regenerate_friend_code( user: UserIdentity, db: DatabaseWrapper, -) -> Result { +) -> Result, TimeError> { db.regenerate_friend_code(user.id) .await .inspect_err(|e| error!("{}", e)) - .map(|code| Json(json!({ "friend_code": code }))) + .map(|c| Json(RegenerateFriendCodeResponse { friend_code: c })) } -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone, Deserialize, ToSchema)] pub struct RemoveFriendRequest { name: String, } +#[utoipa::path( + delete, + path = "/friends/remove", + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn remove( user: UserIdentity, db: DatabaseWrapper, Json(body): Json, -) -> Result { +) -> Result { let friend = db.get_user_by_name(&body.name).await?; let deleted = db.remove_friend(user.id, friend.id).await?; diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 4ca0eb4..28a4031 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -1,34 +1,47 @@ -use axum::{extract::Path, response::IntoResponse, Json}; +use axum::{extract::Path, Json}; use diesel::result::{DatabaseErrorKind, Error as DieselError}; use http::StatusCode; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; use crate::{ database::DatabaseWrapper, error::TimeError, - models::{UserId, UserIdentity}, + models::{PrivateLeaderboard, UserId, UserIdentity}, }; -#[derive(Deserialize, Serialize)] -pub struct LeaderboardName { - pub name: String, -} +use super::users::MinimalLeaderboard; -#[derive(Deserialize, Serialize)] -pub struct LeaderboardInvite { - pub invite: String, +#[derive(Deserialize, Serialize, ToSchema)] +pub struct LeaderboardCreateRequest { + pub name: String, } -#[derive(Deserialize)] +#[derive(Deserialize, ToSchema)] pub struct LeaderboardUser { pub user: String, } +#[derive(Serialize, ToSchema)] +pub struct LeaderboardCreateResponse { + invite_code: String, +} + +#[utoipa::path( + post, + path = "/leaderboards/create", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = LeaderboardCreateResponse) + ) +)] pub async fn create_leaderboard( creator: UserId, db: DatabaseWrapper, - body: Json, -) -> Result { + body: Json, +) -> Result, TimeError> { if !super::VALID_NAME_REGEX.is_match(&body.name) { return Err(TimeError::BadLeaderboardName); } @@ -38,7 +51,7 @@ pub async fn create_leaderboard( } match db.create_leaderboard(creator.id, &body.name).await { - Ok(code) => Ok(Json(json!({ "invite_code": code }))), + Ok(code) => Ok(Json(LeaderboardCreateResponse { invite_code: code })), Err(e) => { error!("{}", e); Err(match e { @@ -52,11 +65,24 @@ pub async fn create_leaderboard( } } +#[utoipa::path( + get, + path = "/leaderboards/{name}", + params( + ("name", description = "Leaderboard name") + ), + security( + ("api_key" = []) + ), + responses( + (status = OK, body = PrivateLeaderboard) + ) +)] pub async fn get_leaderboard( user: UserId, Path(name): Path, db: DatabaseWrapper, -) -> Result { +) -> Result, TimeError> { let lid = db .get_leaderboard_id_by_name(&name) .await @@ -70,11 +96,24 @@ pub async fn get_leaderboard( } } +#[utoipa::path( + delete, + path = "/leaderboard/{name}", + params( + ("name", description = "Leaderboard name") + ), + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn delete_leaderboard( user: UserIdentity, Path(name): Path, db: DatabaseWrapper, -) -> Result { +) -> Result { let lid = db .get_leaderboard_id_by_name(&name) .await @@ -88,11 +127,26 @@ pub async fn delete_leaderboard( } } +#[derive(Deserialize, Serialize, ToSchema)] +pub struct LeaderboardInvite { + pub invite: String, +} + +#[utoipa::path( + get, + path = "/leaderboards/join", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = MinimalLeaderboard) + ) +)] pub async fn join_leaderboard( user: UserId, db: DatabaseWrapper, body: Json, -) -> Result { +) -> Result, TimeError> { match db .add_user_to_leaderboard(user.id, body.invite.trim().trim_start_matches("ttlic_")) .await @@ -108,15 +162,28 @@ pub async fn join_leaderboard( _ => e, }) } - Ok(leaderboard) => Ok(Json(json!(leaderboard))), + Ok(leaderboard) => Ok(Json(leaderboard)), } } +#[utoipa::path( + post, + path = "/leaderboards/{name}/leave", + params( + ("name", description = "Leaderboard name") + ), + security( + ("api_key" = []), + ), + responses( + (status = OK) + ) +)] pub async fn leave_leaderboard( user: UserIdentity, Path(name): Path, db: DatabaseWrapper, -) -> Result { +) -> Result { let lid = db .get_leaderboard_id_by_name(&name) .await @@ -135,12 +202,25 @@ pub async fn leave_leaderboard( } } +#[utoipa::path( + post, + path = "/leaderboards/{name}/promote", + params( + ("name", description = "Leaderboard name") + ), + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn promote_member( user: UserIdentity, Path(name): Path, db: DatabaseWrapper, promotion: Json, -) -> Result { +) -> Result { let lid = db .get_leaderboard_id_by_name(&name) .await @@ -166,12 +246,25 @@ pub async fn promote_member( } } +#[utoipa::path( + post, + path = "/leaderboards/{name}/demote", + params( + ("name", description = "Leaderboard name") + ), + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn demote_member( user: UserIdentity, Path(name): Path, db: DatabaseWrapper, demotion: Json, -) -> Result { +) -> Result { let lid = db .get_leaderboard_id_by_name(&name) .await @@ -197,12 +290,25 @@ pub async fn demote_member( } } +#[utoipa::path( + post, + path = "/leaderboards/{name}/kick", + params( + ("name", description = "Leaderboard name") + ), + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn kick_member( user: UserIdentity, Path(name): Path, db: DatabaseWrapper, kick: Json, -) -> Result { +) -> Result { let lid = db .get_leaderboard_id_by_name(&name) .await @@ -223,11 +329,29 @@ pub async fn kick_member( } } +#[derive(Debug, Clone, Serialize, ToSchema)] +pub struct InviteCodeRegenerateResponse { + invite_code: String, +} + +#[utoipa::path( + post, + path = "/leaderboards/{name}/regenerate", + params( + ("name", description = "Leaderboard name") + ), + security( + ("api_key" = []) + ), + responses( + (status = OK, body = InviteCodeRegenerateResponse) + ) +)] pub async fn regenerate_invite( user: UserIdentity, Path(name): Path, db: DatabaseWrapper, -) -> Result { +) -> Result, TimeError> { let lid = db .get_leaderboard_id_by_name(&name) .await @@ -235,7 +359,7 @@ pub async fn regenerate_invite( if db.is_leaderboard_admin(user.id, lid).await? { let code = db.regenerate_leaderboard_invite(lid).await?; - Ok(Json(json!({ "invite_code": code }))) + Ok(Json(InviteCodeRegenerateResponse { invite_code: code })) } else { Err(TimeError::Unauthorized) } diff --git a/src/api/mod.rs b/src/api/mod.rs index 20303c1..8c9c3c2 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,6 +1,5 @@ use std::sync::LazyLock; -use axum::response::IntoResponse; use http::StatusCode; use regex::Regex; @@ -18,6 +17,14 @@ pub mod users; pub static VALID_NAME_REGEX: LazyLock = LazyLock::new(|| Regex::new("^[[:word:]]{2,32}$").unwrap()); -pub async fn health() -> impl IntoResponse { +#[utoipa::path( + get, + path = "/health", + responses( + (status = OK) + ), + description = "Is the api healthy" +)] +pub async fn health() -> StatusCode { StatusCode::OK } diff --git a/src/api/oauth.rs b/src/api/oauth.rs index ceb6964..882c592 100644 --- a/src/api/oauth.rs +++ b/src/api/oauth.rs @@ -1,9 +1,6 @@ use std::{collections::HashMap, sync::LazyLock}; -use axum::{ - extract::Query, - response::{IntoResponse, Redirect}, -}; +use axum::{extract::Query, response::Redirect}; use axum_extra::extract::{cookie::Cookie, CookieJar}; use reqwest::Client; use serde_derive::Deserialize; @@ -47,11 +44,18 @@ static CLIENT_INFO: LazyLock = LazyLock::new(|| { .expect("Invalid Toml in settings.toml") }); +#[utoipa::path( + get, + path = "/auth/callback", + responses( + (status = OK) + ) +)] pub async fn callback( db: DatabaseWrapper, jar: CookieJar, request: Query, -) -> Result { +) -> Result<(CookieJar, Redirect), TimeError> { if request.code.chars().any(|c| !c.is_alphanumeric()) { return Err(TimeError::BadCode); } diff --git a/src/api/search.rs b/src/api/search.rs index 322c834..8d55e21 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -1,17 +1,28 @@ -use axum::{extract::Query, response::IntoResponse, Json}; +use axum::{extract::Query, Json}; use serde_derive::Deserialize; +use utoipa::IntoParams; -use crate::{database::DatabaseWrapper, error::TimeError}; +use crate::{database::DatabaseWrapper, error::TimeError, models::PublicUser}; -#[derive(Deserialize)] +#[derive(Deserialize, IntoParams)] pub struct UserSearch { pub keyword: String, } //TODO: Maybe return small coding summary? +#[utoipa::path( + get, + path = "/search/users", + params( + UserSearch + ), + responses( + (status = OK, body = Vec) + ) +)] pub async fn search_public_users( db: DatabaseWrapper, search: Query, -) -> Result { +) -> Result>, TimeError> { Ok(Json(db.search_public_users(search.keyword.clone()).await?)) } diff --git a/src/api/stats.rs b/src/api/stats.rs index 5e1d4c3..a9de6e2 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -1,19 +1,27 @@ -use axum::response::IntoResponse; +use axum::Json; use serde_derive::Serialize; +use utoipa::ToSchema; use crate::{database::DatabaseWrapper, error::TimeError}; -#[derive(Serialize)] -struct Stats { +#[derive(Serialize, ToSchema)] +pub struct Stats { pub user_count: u64, pub coding_time: u64, } -pub async fn stats(db: DatabaseWrapper) -> Result { +#[utoipa::path( + get, + path = "/stats", + responses( + (status = OK, body = Stats) + ) +)] +pub async fn stats(db: DatabaseWrapper) -> Result, TimeError> { let user_count = db.get_total_user_count().await?; let coding_time = db.get_total_coding_time().await?; - Ok(axum::Json(Stats { + Ok(Json(Stats { user_count, coding_time, })) diff --git a/src/api/users.rs b/src/api/users.rs index 145dc6a..d810d4b 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -1,14 +1,14 @@ -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; use axum::{ extract::{Path, Query, State}, - response::IntoResponse, Json, }; use chrono::{serde::ts_seconds_option, DateTime, Duration, Local, Utc}; use http::StatusCode; use serde::Serialize; use serde_derive::Deserialize; +use utoipa::ToSchema; use crate::{ api::{activity::HeartBeatMemoryStore, auth::UserIdentityOptional}, @@ -33,17 +33,21 @@ pub struct DataRequest { pub project_name: Option, } -#[derive(Deserialize)] -pub struct UserAuthentication { - pub username: String, - pub password: String, -} - -pub async fn my_profile(user: UserIdentity) -> Result { +#[utoipa::path( + get, + path = "/users/@me", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = UserIdentity) + ) +)] +pub async fn my_profile(user: UserIdentity) -> Result, TimeError> { Ok(Json(user)) } -#[derive(Serialize)] +#[derive(Serialize, ToSchema)] pub struct ListLeaderboard { pub name: String, pub member_count: i32, @@ -52,23 +56,49 @@ pub struct ListLeaderboard { pub me: PrivateLeaderboardMember, } -#[derive(Serialize)] +#[derive(Serialize, ToSchema)] pub struct MinimalLeaderboard { pub name: String, pub member_count: i32, } +#[utoipa::path( + get, + path = "/users/@me/leaderboards", + security( + ("api_key" = []) + ), + responses( + (status = OK, body = Vec) + ) +)] pub async fn my_leaderboards( user: UserId, db: DatabaseWrapper, -) -> Result { +) -> Result>, TimeError> { Ok(Json(db.get_user_leaderboards(user.id).await?)) } +#[derive(Deserialize, ToSchema)] +pub struct UserAuthentication { + pub username: String, + pub password: String, +} + +#[utoipa::path( + delete, + path = "/users/@me/delete", + security( + ("api_key" = []) + ), + responses( + (status = OK) + ) +)] pub async fn delete_user( db: DatabaseWrapper, user: Json, -) -> Result { +) -> Result { if let Some(user) = db .verify_user_password(&user.username, &user.password) .await? @@ -79,12 +109,25 @@ pub async fn delete_user( Ok(StatusCode::OK) } +#[utoipa::path( + get, + path = "/users/{username}/activity/current", + params( + ("username", description = "User name"), + ), + security( + ("api_key" = []) + ), + responses( + (status = OK, body = Option) + ) +)] pub async fn get_current_activity( Path(name): Path, opt_user: UserIdentityOptional, db: DatabaseWrapper, State(heartbeats): State>, -) -> Result { +) -> Result>, TimeError> { let mut is_self = false; let target_user = if let Some(user) = opt_user.identity { @@ -148,12 +191,25 @@ pub async fn get_current_activity( } } +#[utoipa::path( + get, + path = "/users/{username}/activity/data", + params( + ("username", description = "User name"), + ), + security( + ("api_key" = []) + ), + responses( + (status = OK, body = Vec) + ) +)] pub async fn get_activities( db: DatabaseWrapper, Query(data): Query, Path(name): Path, opt_user: UserIdentityOptional, -) -> Result { +) -> Result>, TimeError> { let Some(user) = opt_user.identity else { let target_user = db .get_user_by_name(&name) @@ -191,11 +247,37 @@ pub async fn get_activities( Ok(Json(data)) } +#[derive(Debug, Clone, Serialize, ToSchema)] +pub struct LanguageSummary { + languages: HashMap, + total: i32, +} + +#[derive(Debug, Clone, Serialize, ToSchema)] +pub struct ActivitySummary { + last_week: LanguageSummary, + last_month: LanguageSummary, + all_time: LanguageSummary, +} + +#[utoipa::path( + get, + path = "/users/{username}/activity/summary", + params( + ("username", description = "User name") + ), + security( + ("api_key" = []) + ), + responses( + (status = OK, body = ActivitySummary) + ) +)] pub async fn get_activity_summary( Path(path): Path, opt_user: UserIdentityOptional, db: DatabaseWrapper, -) -> Result { +) -> Result, TimeError> { let data = if let Some(user) = opt_user.identity { if path == "@me" { db.get_all_activity(user.id).await? @@ -241,20 +323,18 @@ pub async fn get_activity_summary( .filter(|d| now.signed_duration_since(d.start_time) < Duration::days(7)), ); - let langs = serde_json::json!({ - "last_week": { - "languages": last_week, - "total": last_week.values().sum::(), + Ok(Json(ActivitySummary { + last_week: LanguageSummary { + total: last_week.values().sum::(), + languages: last_week, }, - "last_month": { - "languages": last_month, - "total": last_month.values().sum::(), + last_month: LanguageSummary { + total: last_month.values().sum::(), + languages: last_month, }, - "all_time": { - "languages": all_time, - "total": all_time.values().sum::(), + all_time: LanguageSummary { + total: all_time.values().sum::(), + languages: all_time, }, - }); - - Ok(Json(langs)) + })) } diff --git a/src/main.rs b/src/main.rs index 687fd46..8be8d4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,11 +15,7 @@ use std::{net::SocketAddr, num::NonZeroU32, sync::Arc}; use api::activity::HeartBeatMemoryStore; use auth::{AuthMiddleware, Authentication}; -use axum::{ - body::Body, - routing::{delete, get, post}, - Router, -}; +use axum::{body::Body, Router}; use chrono::NaiveDateTime; use dashmap::DashMap; use database::Database; @@ -31,6 +27,12 @@ use serde_derive::Deserialize; use tower::ServiceBuilder; use tower_http::trace::TraceLayer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; +use utoipa::{ + openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, + Modify, OpenApi, +}; +use utoipa_axum::{router::OpenApiRouter, routes}; +use utoipa_swagger_ui::SwaggerUi; #[macro_use] extern crate tracing; @@ -78,7 +80,31 @@ pub struct TestaustimeState { password_reset_state: Arc, } -fn create_router(config: &TestaustimeConfig) -> Router { +#[derive(OpenApi)] +#[openapi( + modifiers(&SecurityAddon), +)] +struct ApiDoc; + +struct SecurityAddon; + +impl Modify for SecurityAddon { + fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) { + if let Some(components) = openapi.components.as_mut() { + components.add_security_scheme( + "api_key", + SecurityScheme::Http( + HttpBuilder::new() + .scheme(HttpAuthScheme::Bearer) + .bearer_format("Bearer") + .build(), + ), + ) + } + } +} + +fn create_router_with_openapi(config: &TestaustimeConfig) -> (Router, utoipa::openapi::OpenApi) { let database = Arc::new(Database::new(config.database_url.clone())); let register_limiter = Arc::new(RegisterLimiter { @@ -131,11 +157,11 @@ fn create_router(config: &TestaustimeConfig) -> Router { .with_middleware(), ); - Router::new() - .route("/health", get(api::health)) + OpenApiRouter::new() + .routes(routes!(api::health)) .merge( - Router::new() - .route("/auth/register", post(api::auth::register)) + OpenApiRouter::new() + .routes(routes!(api::auth::register)) .layer(TestaustimeRateLimiter { limiter: register_ratelimiter, use_peer_addr: config.ratelimit_by_peer_ip, @@ -143,91 +169,43 @@ fn create_router(config: &TestaustimeConfig) -> Router { }), ) .merge({ - let router = Router::new() - .nest("/activity", { - Router::new() - .route("/update", post(api::activity::update)) - .route("/delete", delete(api::activity::delete)) - .route("/flush", post(api::activity::flush)) - .route("/rename", post(api::activity::rename_project)) - .route("/hide", post(api::activity::hide_project)) - }) - .route("/auth/login", post(api::auth::login)) - .route("/auth/change-username", post(api::auth::change_username)) - .route("/auth/change-email", post(api::auth::change_email)) - .route("/auth/change-password", post(api::auth::change_password)) - .route( - "/auth/reset-password", - post(api::auth::request_password_reset), - ) - .route( - "/auth/complete-password-reset", - post(api::auth::reset_password), - ) - .route("/friends/add", post(api::friends::add_friend)) - .route("/account/settings", post(api::account::change_settings)) - .route("/friends/list", get(api::friends::get_friends)) - .route( - "/friends/regenerate", - get(api::friends::regenerate_friend_code), - ) - .route("/friends/remove", delete(api::friends::remove)) - .route("/users/@me", get(api::users::my_profile)) - .route("/users/@me/delete", delete(api::users::delete_user)) - .route("/users/@me/leaderboards", get(api::users::my_leaderboards)) - .route( - "/users/{username}/activity/data", - get(api::users::get_activities), - ) - .route( - "/users/{username}/activity/current", - get(api::users::get_current_activity), - ) - .route( - "/users/{username}/activity/summary", - get(api::users::get_activity_summary), - ) - .route( - "/leaderboards/create", - post(api::leaderboards::create_leaderboard), - ) - .route( - "/leaderboards/{name}", - get(api::leaderboards::get_leaderboard), - ) - .route( - "/leaderboards/join", - post(api::leaderboards::join_leaderboard), - ) - .route( - "/leaderboards/{name}/leave", - post(api::leaderboards::leave_leaderboard), - ) - .route( - "/leaderboards/{name}", - delete(api::leaderboards::delete_leaderboard), - ) - .route( - "/leaderboards/{name}/promote", - post(api::leaderboards::promote_member), - ) - .route( - "/leaderboards/{name}/demote", - post(api::leaderboards::demote_member), - ) - .route( - "/leaderboards/{name}/kick", - post(api::leaderboards::kick_member), - ) - .route( - "/leaderboards/{name}/regenerate", - post(api::leaderboards::regenerate_invite), - ) - .route("/search/users", get(api::search::search_public_users)) - .route("/stats", get(api::stats::stats)); + let router = OpenApiRouter::with_openapi(ApiDoc::openapi()) + .routes(routes!(api::activity::update)) + .routes(routes!(api::activity::delete)) + .routes(routes!(api::activity::flush)) + .routes(routes!(api::activity::rename_project)) + .routes(routes!(api::activity::hide_project)) + .routes(routes!(api::auth::login)) + .routes(routes!(api::auth::change_username)) + .routes(routes!(api::auth::change_email)) + .routes(routes!(api::auth::change_password)) + .routes(routes!(api::auth::request_password_reset)) + .routes(routes!(api::auth::reset_password)) + .routes(routes!(api::account::change_settings)) + .routes(routes!(api::friends::add_friend)) + .routes(routes!(api::friends::get_friends)) + .routes(routes!(api::friends::regenerate_friend_code)) + .routes(routes!(api::friends::remove)) + .routes(routes!(api::users::my_profile)) + .routes(routes!(api::users::delete_user)) + .routes(routes!(api::users::my_leaderboards)) + .routes(routes!(api::users::get_activities)) + .routes(routes!(api::users::get_current_activity)) + .routes(routes!(api::users::get_activity_summary)) + .routes(routes!(api::leaderboards::create_leaderboard)) + .routes(routes!(api::leaderboards::get_leaderboard)) + .routes(routes!(api::leaderboards::join_leaderboard)) + .routes(routes!(api::leaderboards::leave_leaderboard)) + .routes(routes!(api::leaderboards::delete_leaderboard)) + .routes(routes!(api::leaderboards::promote_member)) + .routes(routes!(api::leaderboards::demote_member)) + .routes(routes!(api::leaderboards::kick_member)) + .routes(routes!(api::leaderboards::regenerate_invite)) + .routes(routes!(api::search::search_public_users)) + .routes(routes!(api::stats::stats)); #[cfg(feature = "testausid")] - let router = router.route("/auth/callback", get(api::oauth::callback)); + let router = router.routes(routes!(api::oauth::callback)); router .layer( @@ -253,6 +231,7 @@ fn create_router(config: &TestaustimeConfig) -> Router { )) }) .with_state(state) + .split_for_parts() } #[tokio::main] @@ -271,7 +250,9 @@ async fn main() { toml::from_str(&std::fs::read_to_string("settings.toml").expect("Missing settings.toml")) .expect("Invalid Toml in settings.toml"); - let router = create_router(&config); + let (router, openapi) = create_router_with_openapi(&config); + let router = + router.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", openapi.clone())); let listener = tokio::net::TcpListener::bind(&config.address) .await diff --git a/src/models.rs b/src/models.rs index cb5579d..2958766 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,13 +1,14 @@ #![allow(clippy::extra_unused_lifetimes)] use serde::Deserializer; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; #[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash)] pub struct UserId { pub id: i32, } -#[derive(Identifiable, Queryable, Clone, Debug, Serialize, PartialEq, Eq)] +#[derive(Identifiable, Queryable, Clone, Debug, Serialize, PartialEq, Eq, ToSchema)] #[diesel(table_name = user_identities)] pub struct UserIdentity { pub id: i32, @@ -20,7 +21,7 @@ pub struct UserIdentity { pub email: Option, } -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Debug, Serialize, ToSchema)] pub struct PublicUser { pub id: i32, pub username: String, @@ -61,7 +62,7 @@ pub struct NewTestaustimeUser { pub identity: i32, } -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)] pub struct SelfUser { pub id: i32, pub auth_token: String, @@ -109,7 +110,7 @@ pub struct TestausIdUser { use crate::schema::user_identities; -#[derive(Insertable, Serialize, Clone, Deserialize)] +#[derive(Insertable, Serialize, ToSchema, Clone, Deserialize)] #[diesel(table_name = user_identities)] pub struct NewUserIdentity { pub auth_token: String, @@ -137,7 +138,7 @@ pub struct NewFriendRelation { pub greater_id: i32, } -#[derive(Queryable, Clone, Debug, Serialize, Identifiable, Associations)] +#[derive(Queryable, Clone, Debug, Serialize, Identifiable, Associations, ToSchema)] #[diesel(belongs_to(UserIdentity, foreign_key=user_id))] #[diesel(table_name = coding_activities)] pub struct CodingActivity { @@ -207,7 +208,7 @@ pub struct NewLeaderboardMember { pub admin: bool, } -#[derive(Serialize, Clone, Debug, Deserialize)] +#[derive(Serialize, Clone, Debug, Deserialize, ToSchema)] pub struct PrivateLeaderboardMember { pub id: i32, pub username: String, @@ -215,7 +216,7 @@ pub struct PrivateLeaderboardMember { pub time_coded: i32, } -#[derive(Serialize, Clone, Debug, Deserialize)] +#[derive(Serialize, Clone, Debug, Deserialize, ToSchema)] pub struct PrivateLeaderboard { pub name: String, pub invite: String, @@ -223,14 +224,14 @@ pub struct PrivateLeaderboard { pub members: Vec, } -#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash, ToSchema)] pub struct CodingTimeSteps { pub all_time: i32, pub past_month: i32, pub past_week: i32, } -#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone, ToSchema)] pub struct CurrentActivity { pub started: chrono::NaiveDateTime, pub duration: i64, @@ -243,14 +244,14 @@ pub struct FriendWithTime { pub coding_time: CodingTimeSteps, } -#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash, ToSchema)] pub struct FriendWithTimeAndStatus { pub username: String, pub coding_time: CodingTimeSteps, pub status: Option, } -#[derive(Deserialize, Serialize, Debug, Hash, Eq, PartialEq, Clone)] +#[derive(Deserialize, Serialize, ToSchema, Debug, Hash, Eq, PartialEq, Clone)] pub struct HeartBeat { #[serde(deserialize_with = "project_deserialize")] pub project_name: Option, From 801e38d586715ea469e5a07f27fb9d2ed4ae61c8 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Mon, 17 Nov 2025 10:33:55 +0200 Subject: [PATCH 14/36] I forgot we have tests also thank you utoipa --- src/api/leaderboards.rs | 2 +- src/main.rs | 8 ++++++-- src/tests/leaderboards.rs | 4 ++-- src/tests/mod.rs | 6 ++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 28a4031..8f102ac 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -133,7 +133,7 @@ pub struct LeaderboardInvite { } #[utoipa::path( - get, + post, path = "/leaderboards/join", security( ("api_key" = []) diff --git a/src/main.rs b/src/main.rs index 8be8d4f..73f4fa8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -193,10 +193,14 @@ fn create_router_with_openapi(config: &TestaustimeConfig) -> (Router, utoipa::op .routes(routes!(api::users::get_current_activity)) .routes(routes!(api::users::get_activity_summary)) .routes(routes!(api::leaderboards::create_leaderboard)) - .routes(routes!(api::leaderboards::get_leaderboard)) + .routes(routes!( + // utoipa/axum will not resolve these correctly based on method if registered + // seperately, go figure + api::leaderboards::get_leaderboard, + api::leaderboards::delete_leaderboard + )) .routes(routes!(api::leaderboards::join_leaderboard)) .routes(routes!(api::leaderboards::leave_leaderboard)) - .routes(routes!(api::leaderboards::delete_leaderboard)) .routes(routes!(api::leaderboards::promote_member)) .routes(routes!(api::leaderboards::demote_member)) .routes(routes!(api::leaderboards::kick_member)) diff --git a/src/tests/leaderboards.rs b/src/tests/leaderboards.rs index ffd1c4b..003322c 100644 --- a/src/tests/leaderboards.rs +++ b/src/tests/leaderboards.rs @@ -2,7 +2,7 @@ use serde_json::json; use super::{macros::*, *}; use crate::{ - api::leaderboards::{LeaderboardInvite, LeaderboardName}, + api::leaderboards::{LeaderboardCreateRequest, LeaderboardInvite}, models::{NewUserIdentity, PrivateLeaderboard}, }; @@ -23,7 +23,7 @@ async fn creation_joining_and_deletion() { let member: NewUserIdentity = body_to_json(resp).await; - let create = LeaderboardName { + let create = LeaderboardCreateRequest { name: "board".to_string(), }; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 1fe5099..245df0e 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -17,7 +17,7 @@ use tower::ServiceExt; // NOTE: We would like to use diesels Connection::begin_test_transaction // But cannot use them because our database uses transactions to implement // some of the routes and there cannot exists transactions within transactions :'( -use crate::create_router; +use crate::create_router_with_openapi; const TEST_ADDR: SocketAddr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 3000)); @@ -41,7 +41,9 @@ fn create_test_router() -> Router { mail_password: "".to_string(), }; - create_router(&config).layer(MockConnectInfo(SocketAddr::from(([127, 0, 0, 1], 3000)))) + create_router_with_openapi(&config) + .0 + .layer(MockConnectInfo(SocketAddr::from(([127, 0, 0, 1], 3000)))) } #[tokio::test] From 6411d46d9a8947256a465b911b1555fcb85888f8 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Sat, 13 Dec 2025 15:32:52 +0200 Subject: [PATCH 15/36] add email fields to example --- settings.toml.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/settings.toml.example b/settings.toml.example index 3aa52c9..3982f05 100644 --- a/settings.toml.example +++ b/settings.toml.example @@ -7,3 +7,6 @@ max_heartbeats_per_min=8 max_registers_per_day=3 bypass_token="5woKC8Z3pqLqhDTX/zY1j1JxMozglIukNsr3YMMLBOk=" max_registers_per_hour=5 +mail_server="mail.testaustime.fi" +mail_user="noreply@testaustime.fi" +mail_password="password" From e9ec3512234601f4c470838d0a23b489da83f332 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Sat, 13 Dec 2025 15:33:49 +0200 Subject: [PATCH 16/36] typo --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 73f4fa8..d3fb790 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,7 +127,7 @@ fn create_router_with_openapi(config: &TestaustimeConfig) -> (Router, utoipa::op .build(); debug!( - "Conntected to mail server on {} as {}", + "Connected to mail server on {} as {}", config.mail_server, config.mail_user ); From 2cd3e04bea321f273ce737d8700ecd42dacd9c90 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Sat, 13 Dec 2025 15:49:46 +0200 Subject: [PATCH 17/36] add back token regeneration --- src/api/auth.rs | 30 ++++++++++++++++++++++++++++++ src/database/auth.rs | 15 +++++++++++++++ src/main.rs | 1 + 3 files changed, 46 insertions(+) diff --git a/src/api/auth.rs b/src/api/auth.rs index 0912b49..cbe0c89 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::{ + api::users::UserAuthentication, auth::Authentication, database::DatabaseWrapper, error::TimeError, @@ -146,6 +147,35 @@ pub async fn register( Ok(Json(res)) } +#[derive(Serialize, ToSchema)] +pub struct RegenerateResponse { + pub token: String, +} + +#[utoipa::path( + post, + path = "/auth/regenerate", + responses( + (status = OK, body = RegenerateResponse) + ) +)] +pub async fn regenerate_auth_token( + db: DatabaseWrapper, + Json(credentials): Json, +) -> Result, TimeError> { + if let Some(user) = db + .verify_user_password(&credentials.username, &credentials.password) + .await? + { + db.regenerate_token(user.id) + .await + .inspect_err(|e| error!("{}", e)) + .map(|token| Json(RegenerateResponse { token })) + } else { + Err(TimeError::Unauthorized) + } +} + #[derive(Deserialize, ToSchema)] pub struct UsernameChangeRequest { pub new: String, diff --git a/src/database/auth.rs b/src/database/auth.rs index d4133f4..89a1ea1 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -77,6 +77,21 @@ impl super::DatabaseWrapper { } } + pub async fn regenerate_token(&self, userid: i32) -> Result { + let mut conn = self.db.get().await?; + + let token = crate::utils::generate_auth_token(); + + use crate::schema::user_identities::dsl::*; + + diesel::update(user_identities.find(userid)) + .set(auth_token.eq(&token)) + .execute(&mut conn) + .await?; + + Ok(token) + } + pub async fn new_testaustime_user( &self, username: &str, diff --git a/src/main.rs b/src/main.rs index d3fb790..b55b110 100644 --- a/src/main.rs +++ b/src/main.rs @@ -176,6 +176,7 @@ fn create_router_with_openapi(config: &TestaustimeConfig) -> (Router, utoipa::op .routes(routes!(api::activity::rename_project)) .routes(routes!(api::activity::hide_project)) .routes(routes!(api::auth::login)) + .routes(routes!(api::auth::regenerate_auth_token)) .routes(routes!(api::auth::change_username)) .routes(routes!(api::auth::change_email)) .routes(routes!(api::auth::change_password)) From a981ed42fae0d2d36d15e1d14d5ad19b74ae76f6 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Sat, 13 Dec 2025 15:50:18 +0200 Subject: [PATCH 18/36] small fixes --- src/api/users.rs | 5 +++-- src/error.rs | 3 --- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/api/users.rs b/src/api/users.rs index d810d4b..f0d09e7 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -104,9 +104,10 @@ pub async fn delete_user( .await? { db.delete_user(user.id).await?; + Ok(StatusCode::OK) + } else { + Err(TimeError::Unauthorized) } - - Ok(StatusCode::OK) } #[utoipa::path( diff --git a/src/error.rs b/src/error.rs index 8433a3d..78fe05a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -27,8 +27,6 @@ pub enum TimeError { LeaderboardNotFound, #[error("You are not authorized")] Unauthorized, - #[error("Missing secured access token")] - UnauthroizedSecuredAccess, #[error("Invalid username or password")] InvalidCredentials, #[error("{0}")] @@ -92,7 +90,6 @@ impl IntoResponse for TimeError { | TimeError::EmailTaken => StatusCode::CONFLICT, TimeError::Unauthorized | TimeError::InvalidCredentials - | TimeError::UnauthroizedSecuredAccess | TimeError::InvalidPasswordResetToken | TimeError::ExpiredPasswordResetToken => StatusCode::UNAUTHORIZED, TimeError::TooManyRegisters => StatusCode::TOO_MANY_REQUESTS, From 53ed1c6efb78512e0f55b7025447b63d3165cc4c Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Sat, 13 Dec 2025 15:52:59 +0200 Subject: [PATCH 19/36] removed markdown apispec this was done in favor of the new openapi docs --- docs/APISPEC.md | 1680 ----------------------------------------------- 1 file changed, 1680 deletions(-) delete mode 100644 docs/APISPEC.md diff --git a/docs/APISPEC.md b/docs/APISPEC.md deleted file mode 100644 index 1a15340..0000000 --- a/docs/APISPEC.md +++ /dev/null @@ -1,1680 +0,0 @@ -# Testaustime-rs api documentation - -## General info - -Testaustime API gives 5 different routes: - -- [/auth/](#auth) -- [/users/](#users) -- [/activity/](#activity) -- [/friends/](#friends) -- [/leaderboards/](#leaderboards) - -Basic path: `https://api.testaustime.fi` - -Limits: - -- Usual Ratelimit: 10 req/m. - -## Auth - -Contains various user authorization operations - -### Endpoints - -| Endpoint | Method | Description | -| --------------------------------------- | ------ | -------------------------------------------------------------------------------------- | -| [/auth/register](#register) | POST | Creating a new user and returns the user auth token, friend code and registration time | -| [/auth/login](#login) | POST | Loging user to system and returns the user auth token and friend code | -| [/auth/securedaccess](#securedaccess) | POST | Generating secured access token | -| [/auth/changeusername](#changeusername) | POST | Changing user username | -| [/auth/changepassword](#changepassword) | POST | Changing user password | -| [/auth/regenerate](#regenerate) | POST | Regenerating user auth token | - -#### [1. POST /auth/register](#auth) - -Creating a new user and returns the user auth token, friend code and registration time. Ratelimit: 1 req/24h - -
- Header params - -| Name | Value | -| ------------ | ---------------- | -| Content-Type | application/json | - -
- -
- Body params - -| Param | Type | Required | Description | -| -------- | ------ | -------- | ---------------------------------------------------- | -| username | string | Yes | Usename has to be between 2 and 32 characters long | -| password | string | Yes | Password has to be between 8 and 128 characters long | - -
- -**Sample request** - -```curl -curl --request POST https://api.testaustime.fi/auth/register' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "username": "username", - "password": "password" -} -``` - -**Sample response** - -```JSON -{ - "auth_token": "", - "username": "username", - "friend_code": "friend_code", - "registration_time": "YYYY-MM-DDTHH:MM:SS.sssssssssZ" -} -``` - -
- Response definitions - -| Response Item | Type | Description | -| ----------------- | ------ | ---------------------------------------------------------- | -| auth_token | string | Authentication token for identifying the user | -| username | string | Username | -| friend_code | string | With this code other users can add user to the friend list | -| registration_time | string | Time of registration in ISO 8601 format | - -
- -#### [2. POST /auth/login](#auth) - -Logins to a users account and returning the authentication token - -
- Header params - -| Name | Value | -| ------------ | ---------------- | -| Content-Type | application/json | - -
- -
- Body params - -| Param | Type | Required | Description | -| -------- | ------ | -------- | ---------------------------------------------------- | -| username | string | Yes | Usename has to be between 2 and 32 characters long | -| password | string | Yes | Password has to be between 8 and 128 characters long | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/auth/login' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "username": "username", - "password": "password" -}' - -``` - -**Sample response** - -```JSON -{ - "id": 0, - "auth_token": "", - "friend_code": "friend_code", - "username": "username", - "registration_time": "YYYY-MM-DDTHH:MM:SS.ssssssZ" -} -``` - -
- Response definitions - -| Response Item | Type | Description | -| ----------------- | ------ | ---------------------------------------------------------- | -| id | int | User id | -| auth_token | string | Authentication token for identifying the user | -| username | string | Username | -| friend_code | string | With this code other users can add user to the friend list | -| registration_time | string | Time of registration in ISO 8601 format | - -
- -#### [3. POST /auth/securedaccess](#auth) - -Generates new secured access token, each token is valid for 1 hour. Used for confirming user identity when doing critical changes. - -
- Header params - -| Name | Value | -| ------------ | ---------------- | -| Content-Type | application/json | - -
- -
- Body params - -| Param | Type | Required | Description | -| -------- | ------ | -------- | ---------------------------------------------------- | -| username | string | Yes | Usename has to be between 2 and 32 characters long | -| password | string | Yes | Password has to be between 8 and 128 characters long | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/auth/securedaccess' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "username": "username", - "password": "password" -}' - -``` - -**Sample response** - -```JSON -{ - "token": "" -} -``` - -
- Response definitions - -| Response Item | Type | Description | -| ------------- | ------ | -------------------- | -| token | string | Secured access token | - -
- -#### [4. POST /auth/changeusername](#auth) - -Changes username, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Content-Type | application/json | -| Authorization | Bearer `` | - -
- -
- Body params: - -| Param | Type | Required | Description | -| ----- | ------ | -------- | ---------------------------------------------------------------- | -| new | string | Yes | New username. Usename has to be between 2 and 32 characters long | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/auth/changeusername' \ ---header 'Content-Type: application/json' \ ---header 'Authorization: Bearer '{ - "new": "new_username" -}' -``` - -**Sample response** - -```http -200 OK -``` - -
- Error examples: - -| Error | Error code | Body | -| -------------------------------- | --------------- | ------------------------------------------------------ | -| "new" has <2 or >32 symbols | 400 Bad Request | `{"error" : "Username is not between 2 and 32 chars"}` | -| "new" is using existing username | 403 Forbidden | `"error"» : "User exists"` | - -
- -#### [5. POST /auth/changepassword](#auth) - -Changes users password, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Content-Type | application/json | -| Authorization | Bearer `` | - -
- -
- Body params: - -| Param | Type | Required | Description | -| ----- | ------ | -------- | ------------------------------------------------------------------ | -| old | string | Yes | Current password | -| new | string | Yes | New password. Password has to be between 8 and 128 characters long | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/auth/changepassword' \ ---header 'Content-Type: application/json' \ ---header 'Authorization: Bearer ' \ ---data-raw '{ - "old": "old_password", - "new": "new_password" -}' -``` - -**Sample response** - -```http -200 OK -``` - -
- Error examples: - -| Error | Error code | Body | -| ----------------------------- | --------------- | ------------------------------------------------------ | -| "new" has < 8 or >132 symbols | 400 Bad Request | `{"error": "Password is not between 8 and 132 chars"}` | -| "old" is incorrect | 401 Unathorized | `{"error": "You are not authorized"}` | - -
- -#### [6. POST /auth/regenerate](#auth) - -Regenerates users authentication token, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Authorization | Bearer `` | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/auth/regenerate' \ ---header 'Content-Type: application/json' ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -{ - "token": "" -} -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------ | -------------------------------------------------- | -| token | string | New Authentication token used for identifying user | - -
- -## Users - -Contains various mostly read-operations with user data - -### Endpoints - -| Endpoint | Method | Description | -| ------------------------------------------------------- | ------ | ----------------------------------------------- | -| [/users/@me](#me) | GET | Geting data about authorized user | -| [/users/@me/leaderboards](#my_leaderboards) | GET | Geting list of user leaderboards | -| [/users/{username}/activity/data](#activity_data) | GET | Geting user or user friend coding activity data | -| [/users/{username}/activity/summary](#activity_summary) | GET | Get a summary of a users activity | -| [/users/{username}/activity/current](#activity_cur) | GET | Get a users current coding session | -| [/users/@me/delete](#delete_myself) | DELETE | Deleting user account | - -#### [1. GET /users/@me](#users) - -Gets data about authorized user - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -**Sample request** - -```curl -curl --location --request GET 'https://api.testaustime.fi/users/@me' \ ---header 'Authorization: Bearer ``' -``` - -**Sample response** - -```JSON -{ - "id": 0, - "friend_code": "friend_code", - "username": "username", - "registration_time": "YYYY-MM-DDTHH:MM:SS.ssssssZ" -} -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ----------------- | ------ | ---------------------------------------------------------- | -| id | int | User id | -| friend_code | string | With this code other users can add user to the friend list | -| username | string | Username | -| registration_time | string | Time of registration in ISO 8601 format | - -
- -#### [2. GET /users/@me/leaderboards](#users) - -Gets list of user leaderboards - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -**Sample request** - -```curl -curl --location --request GET 'https://api.testaustime.fi/users/@me/leaderboards' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -[ - { - "name": "Leaderboard name", - "member_count": 2 - } -] -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------ | ------------------------------------------------- | -| name | string | Name of leaderboard in which the user is a member | -| member_count | int | Number of users in the leaderboard | - -
- -Required headers: - -``` -Authorization: Bearer -``` - -#### [3. GET /users/{username}/activity/data](#users) - -Geting user or user friend coding activity data - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ------------------------------------------------------------------ | -| Username | Own or friend username. Also own username can be replaced on `@me` | - -
- -**Sample request** - -```curl -curl --location --request GET 'https://api.testaustime.fi/users/@me/activity/data' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -[ - { - "id": 0, - "start_time": "YYYY-MM-DDTHH:MM:SS.ssssssZ", - "duration": 0, - "project_name": "project_name", - "language": "language", - "editor_name": "editor_name", - "hostname": "hostname", - "hidden": false - } -] -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------- | ------------------------------------------------------------------------------------ | -| id | int | ID of user code session | -| start_time | string | Start time (time of sending first heartbeat) of user code session in ISO 8601 format | -| duration | int | Duration of user code session in seconds | -| project_name | string | Name of the project in which user have a code session. Empty string if hidden. | -| language | string | Code language of the code session | -| editor_name | string | Name of IDE (Visual Studio Code, IntelliJ, Neovim, etc.) in which user is coding | -| hostname | string | User hostname | -| hidden | boolean | Is this project hidden? | - -
- -#### [4. GET /users/{username}/activity/summary](#users) - -Get a summary of a users activity - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | --------------------------------------------------------------------- | -| Username | Own or a friends username. Own username can be substituted with `@me` | - -
- -**Sample request** - -```curl -curl --location --request GET 'https://api.testaustime.fi/users/@me/activity/summary' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -{ - "all_time": { - "languages": { - "c": 1000, - "rust": 2000 - }, - "total": 3000 - }, - "last_month": { - "languages": { - "c": 100, - "rust": 200, - } - "total": 300 - }, - "last_week": { - "languages": { - "c": 10, - "rust": 20 - }, - "total": 30 - } -} -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------ | ------------------------------------------------------------------------------ | -| all_time | Object | All time coding activity summary for the user | -| languages | Object | Contains fields named after languages that have the coding time as their value | -| total | int | The total coding time of the given period | -| last_month | Object | Similar to `all_time` | -| last_week | Object | Similar to `all_time` and `last_month` | - -
- -#### [5. GET /users/{username}/activity/current](#users) - -Gets details of the ongoing coding session if there is one. - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ----------------------------------------------------------------------- | -| Username | Own or a friends username. Own username can also be replaced with `@me` | - -
- -**Sample request** - -```curl -curl --request GET 'https://api.testaustime.fi/users/@me/activity/current' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -{ - "started": "YYYY-MM-DDTHH:MM:SS.ssssssZ", - "duration": "10", - "heartbeat": { - "language": "c", - "hostname": "hostname1", - "editor_name": "Neovim", - "project_name": "cool_project22", - "hidden": false - } -} -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------ | ------------------------------------------------------------------------------------ | -| started | string | Start time (time of sending first heartbeat) of user code session in ISO 8601 format | -| duration | int | Duration of user code session in seconds | -| heartbeat | Object | The HeartBeat object described [here](#activity_up) | - -
- -#### [6. DELETE /users/@me/delete](#users) - -Deletes user account - -
- Header params: - -| Name | Value | -| ------------ | ---------------- | -| Content-Type | application/json | - -
- -
- Body params: - -| Param | Type | Required | Description | -| -------- | ------ | -------- | ------------- | -| username | string | Yes | Username | -| password | string | Yes | User password | - -
- -**Sample request** - -```curl -curl --request DELETE 'https://api.testaustime.fi/users/@me/delete' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "username": "username", - "password": "password" -}' -``` - -**Sample response** - -```http -200 OK -``` - -## Activity - -Contains main operations with activity heartbeats on which this service is based on - -### Endpoints - -| Endpoint | Method | Description | -| ------------------------------------ | ------ | ------------------------------------------------------------ | -| [/activity/update](#activity_up) | POST | Creating code session and logs current activity in that | -| [/activity/flush](#activity_fl) | POST | Flushing any currently active coding session | -| [/activity/rename](#activity_rename) | POST | Rename all activities with matching `project_name` | -| [/activity/delete](#activity_del) | DELETE | Deleting selected code session | -| [/activity/hide](#activity_hide) | POST | Hides or reveals all activities with matching `project_name` | - -#### [1. POST /activity/update](#activity) - -Main endpoint of the service. Creates code session and logs current activity in that. - -> _The desired interval at which to send heartbeats is immediately when editing a file, and after that at max every 30 seconds, and only when the user does something actively in the editor_ - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | -| Content-Type | application/json | - -
- -
- Body params: - -| Param | Type | Description | -| ------------ | ------- | -------------------------------------------------------------------------------- | -| language | string | Code language of the code session | -| hostname | string | User hostname | -| editor_name | string | Name of IDE (Visual Studio Code, IntelliJ, Neovim, etc.) in which user is coding | -| project_name | string | Name of the project in which user have a code session. | -| hidden | boolean | Should this project be hidden? | - -
- -**Sample first request** - -If the user doesn't have any active code session with this set of body params, then first request `POST /activity/update` creates new code session. Any other code session automatically stops/flushes after starting new one, so the user can't have >1 active code sessions in one time - -```curl -curl --request POST 'https://api.testaustime.fi/activity/update' \ ---header 'Authorization: Bearer ' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "language": "Python", - "hostname": "Hostname1", - "editor_name": "IntelliJ", - "project_name": "example_project", - "hidden": false -}' -``` - -**Sample first response** - -```HTTP -200 OK -``` - -**Sample next request** - -```curl -curl --request POST 'https://api.testaustime.fi/activity/update' \ ---header 'Authorization: Bearer ' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "language": "Python", - "hostname": "Hostname1", - "editor_name": "IntelliJ", - "project_name": "example_project", - "hidden": false -}' -``` - -**Sample next response** - -```HTTP -200 OK -Body: PT7.420699439S //duration of the user code session in seconds to nanoseconds -``` - -#### [2. POST /activity/flush](#activity) - -Flushes/stops any currently active coding session - -> _Active coding session can be flushed/stoped automatically without any activity updates for a long time. Also can be flushed automatically in case of starting new code session_ - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/activity/flush' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```HTTP -200 OK -``` - -#### [3. POST /activity/rename](#activity) - -Rename all activities that have a matching `project_name` - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Content-Type | application/json | -| Authorization | Bearer `` | - -
- -
- Body params: -| Param | Type | Required | Description | -| --- | --- | --- | --- | -| from | string | Yes | old name | -| to | string | Yes | new name | -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/activity/rename' \ ---header 'Content-Type: application/json' \ ---header 'Authorization: Bearer ' \ ---data-raw '{ - "from": "old_name", - "to": "new_name" -}' -``` - -**Sample response** - -```JSON -{ - "affected_activities": 20 -} -``` - -
- Response definitions: -| Response Item | Type | Description | -| --- | --- | --- | -| affected_activities | int | Number of activities renamed | -
- -#### [4. POST /activity/delete](#activity) - -Deletes selected code session, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Authorization | Bearer `` | - -
- -
- Body params: - -| Param | Type | Description | -| -------- | ------ | --------------------------------------------------------------------------------- | -| raw text | string | Activity id from response [`GET /users/{username}/activity/data`](#activity_data) | - -
- -**Sample request** - -```curl -curl --request DELETE 'https://api.testaustime.fi/activity/delete' \ ---header 'Authorization: Bearer ' \ ---data-raw 'activity_id' -``` - -**Sample response** - -```HTTP -200 OK -``` - -#### [5. POST /activity/hide](#activity) - -Hide or reveal all activities that have a matching `project_name` - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Content-Type | application/json | -| Authorization | Bearer `` | - -
- -
- Body params: -| Param | Type | Required | Description | -| --- | --- | --- | --- | -| target_project | string | Yes | Project name | -| hidden | boolean | Yes | Should the project be hidden? | -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/activity/hide' \ ---header 'Content-Type: application/json' \ ---header 'Authorization: Bearer ' \ ---data-raw '{ - "project_name": "super_secret_project", - "hidden": true -}' -``` - -**Sample response** - -```JSON -{ - "affected_activities": 100 -} -``` - -
- Response definitions: -| Response Item | Type | Description | -| --- | --- | --- | -| affected_activities | int | Number of activities hidden/revealed | -
- -## Friends - -Containts CRUD-operations with user friends - -### Endpoints - -| Endpoint | Method | Description | -| ------------------------------------- | ------ | -------------------------------------------------------------------- | -| [/friends/add](#add_friend) | POST | Adding the holder of the friend_token as a friend of authorized user | -| [/friends/list](#list_friends) | GET | Geting a list of added user friends | -| [/friends/regenerate](#regenerate_fc) | POST | Regenerateing the authorized user's friend code | -| [/friends/remove](#remove_friend) | DELETE | Removing another user from user friend list | - -#### [1. POST /friends/add](#friends) - -Adds the holder of the friend token as a friend of the authenticating user - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -
- Body params: - -| Param | Type | Description | -| -------- | ------ | ----------------------------------------------- | -| raw text | string | Should contain friend code without any prefixes | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/friends/add' \ ---header 'Authorization: Bearer ' \ ---data-raw 'friend_code' -``` - -**Sample response** - -```JSON -{ - "username": "Username", - "coding_time": { - "all_time": 0, - "past_month": 0, - "past_week": 0 - }, - "status": { - "started": "2023-03-02T12:13:53.121240868", - "duration": 5, - "heartbeat": { - "project_name": "My Project", - "language": "javascript", - "editor_name": "vscode", - "hostname": "mylaptop", - "hidden": false - } - } -} -``` - -
- Error examples: - -| Error | Error code | Body | -| -------------------------------------------------------------- | ------------- | ------------------------------------- | -| Friendcode is already used for adding a friend | 403 Forbidden | { "error": "Already friends"} | -| Friendcode from body request is not found | 404 Not Found | { "error": "User not found"} | -| Friendcode matches with friendcode of authorized user themself | 403 Forbidden | { "error": "You cannot add yourself"} | - -
- -#### [2. GET friends/list](#friends) - -Gets a list of added user friends - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -**Sample request** - -```curl -curl --request GET ''https://api.testaustime.fi/friends/list' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -[ - { - "username": "username", - "coding_time": { - "all_time": 0, - "past_month": 0, - "past_week": 0 - }, - "status": { - "started": "2023-03-02T12:13:53.121240868", - "duration": 5, - "heartbeat": { - "project_name": "My Project", - "language": "javascript", - "editor_name": "vscode", - "hostname": "mylaptop", - "hidden": true - } - } - } -] -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------- | -------------------------------------------------------------------------------- | -| username | string | Friend's username | -| coding_time | Object | Coding friend's time by total, past month and past week | -| all_time | int | Total duration of user code sessions in seconds | -| past_month | int | Total duration of user code sessions in seconds for past month | -| past_week | int | Total duration of user code sessions in seconds for past week | -| status | Object | Information about the user's current activity | -| started | string | Timestamp of when the session start | -| duration | int | Duration of user code session in seconds | -| heartbeat | Object | Information about the latest heartbeat | -| project_name | string | Name of the project in which user have a code session. Empty string if hidden. | -| language | string | Code language of the code session | -| editor_name | string | Name of IDE (Visual Studio Code, IntelliJ, Neovim, etc.) in which user is coding | -| hostname | string | User hostname | -| hidden | boolean | Is the project hidden? | - -
- -#### [3. POST /friends/regenerate](#friends) - -Regenerates the authorized user's friend code, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Authorization | Bearer `` | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/friends/regenerate' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -{ - "friend_code": "friend_code" -} -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------ | ----------------------------------------------------------------------- | -| friend_code | string | New friend code. Using for the all next create friends paire operations | - -
- -#### [4. DELETE /friends/remove](#friends) - -Removes another user from your friend list, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Authorization | Bearer `` | - -
- -
- Body: - -| Param | Type | Description | -| -------- | ------ | -------------------------------------------- | -| raw text | string | Should contain username without any prefixes | - -
- -**Sample request** - -```curl -curl --request DELETE 'https://api.testaustime.fi/friends/remove' \ ---header 'Authorization: Bearer ' \ ---data-raw 'username' -``` - -**Sample response** - -```HTTP -200 OK -``` - -## Leaderboards - -Containts CRUD-operations with leaderboards consisting of other Testaustime users - -### Endpoints - -| Endpoint | Method | Description | -| ------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------ | -| [/leaderboards/create](#create_lb) | POST | Adding new leaderboard | -| [/leaderboard/join](#join_lb) | POST | Joining leaderboard by it's invite code | -| [/leaderboards/{name}](#read_lb) | GET | Getting info about leaderboard if authorized user is a member | -| [/leaderboard/{name}](#delete_lb) | DELETE | Deleting leaderboard if authorized user has admin rights | -| [/leaderboards/{name}/leave](#leave_lb) | POST | Leaving the leaderboard | -| [/leaderboards/{name}/regenerate](#regenerate_lb) | POST | Regenerating invite code of the leaderboard if authorized user has admin rights | -| [/leaderboards/{name}/promote](#promote_lb) | POST | Promoting member of a leaderboard to admin if authorized user has admin rights | -| [/leaderboards/{name}/demote](#demote_lb) | POST | Demoting promoted admin to regular member of the leaderboard if authorized user has admin rights | -| [/leaderboards/{name}/kick](#kick_lb) | POST | Kicking user from leaderboard if authorized user has root admin rights | - -#### [1. POST /leaderboards/create](#leaderboards) - -Adds new leaderboard - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | -| Content-Type | application/json | - -
- -
- Body params: - -| Param | Type | Description | -| ----- | ------ | ---------------------------- | -| name | string | Name of creating leaderboard | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/leaderboards/create' \ ---header 'Authorization: Bearer ' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "name": "" -}' -``` - -**Sample response** - -```JSON -{ - "invite_code": "invite_code" -} -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------ | ----------------------------------- | -| invite_code | string | Invite code for joining leaderboard | - -
- -
- Error examples: - -| Error | Error code | Body | -| ----------------------------------------- | ------------- | -------------------------------- | -| "Name" of the leaderboard is already used | 403 Forbidden | { "error": "Leaderboard exists"} | - -
- -#### [2. POST /leaderboard/join](#leaderboards) - -Joins leaderboard by it's invite code - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | -| Content-Type | application/json | - -
- -
- Body params: - -| Param | Type | Description | -| ------ | ------ | ----------------------------------- | -| invite | string | Invite code for joining leaderboard | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/leaderboards/join' \ ---header 'Authorization: Bearer ' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "invite": "invite_code" -}' -``` - -**Sample response** - -```JSON -{ - "member_count": 0, - "name": "name" -} - -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------ | ----------------------------- | -| member_count | int | Number of leaderboard members | -| name | string | Leaderboard name | - -
- -
- Error examples: - -| Error | Error code | Body | -| -------------------------------------------------- | ------------- | ------------------------------------- | -| Authorized user is already part of the leaderboard | 403 Forbidden | { "error": "You're already a member"} | -| Leaderboard not found by invite code | 404 Not Found | { "error": "Leaderboard not found"} | - -
- -#### [3. GET /leaderboards/{name}](#leaderboards) - -Gets info about leaderboard if authorized user is a member - -
- Header params: - -| Name | Value | -| ------------- | --------------------- | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ---------------- | -| {name} | Leaderboard name | - -
- -**Sample request** - -```curl -curl --request GET 'https://api.testaustime.fi/leaderboards/{name}' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -{ - "name": "name", - "invite": "invite_code", - "creation_time": "YYYY-MM-DDTHH:MM:SS.ssssssZ", - "members": [ - { - "username": "username", - "admin": true, - "time_coded": 0 - } - ] -} -``` - -
- Response definitions: - -| Response Item | Type | Description | -| ------------- | ------------------------ | ---------------------------------------------- | -| name | int | Leaderboard name | -| invite | int | Invite code for joining leaderboard | -| creation_time | string (ISO 8601 format) | Time of leaderboard creation to microsends | -| members | array object | Information about leaderboard members | -| username | string | Member username | -| admin | boolean | Rights of leaderboard member: admin or regular | -| time_coded | int | Total duration of user code sessions in second | - -
- -
- Error examples: - -| Error | Error code | Body | -| ----------------------------------------------- | ---------------- | ------------------------------------ | -| Authorized user is not part of this leaderboard | 401 Unauthorized | { "error": "You are not authorized"} | -| Leaderboard not found by name | 404 Not Found | { "error": "Leaderboard not found"} | - -
- -#### [4. DELETE /leaderboard/{name}](#leaderboards) - -Deletes leaderboard if authorized user has admin rights, requires secured access token - -> _Note: Leaderboard can be deleted either by root administrator or by promoted one_ - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ---------------- | -| {name} | Leaderboard name | - -
- -**Sample request** - -```curl -curl --request DELETE 'https://api.testaustime.fi/leaderboards/{name}' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```HTTP -200 OK -``` - -
- Error examples: - -| Error | Error code | Body | -| ----------------------------------------------- | ---------------- | ------------------------------------ | -| Authorized user is not part of this leaderboard | 401 Unauthorized | { "error": "You are not authorized"} | -| Leaderboard not found by name | 404 Not Found | { "error": "Leaderboard not found"} | - -
- -#### [5. POST /leaderboards/{name}/leave](#leaderboards) - -Leaves the leaderboard, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ---------------- | -| {name} | Leaderboard name | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/leaderboards/{name}/leave' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```HTTP -200 OK -``` - -
- Error examples: - -| Error | Error code | Body | -| ------------------------------------------------ | ------------- | ------------------------------------------------------------- | -| Authorized user is the last admin in leaderboard | 403 Forbidden | { "error": "There are no more admins left, you cannot leave"} | -| User is not the part of the leaderboard | 403 Frobidden | { "error": "You're not a member"} | -| Leaderboard not found by name | 404 Not Found | { "error": "Leaderboard not found"} | - -
- -#### [6. POST /leaderboards/{name}/regenerate](#leaderboards) - -Regenerates invite code of the leaderboard if authorized user has admin rights, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ---------------- | -| {name} | Leaderboard name | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/leaderboards/{name}/regenerate' \ ---header 'Authorization: Bearer ' -``` - -**Sample response** - -```JSON -{ - "invite_code": "" -} -``` - -
- Error examples: - -| Error | Error code | Body | -| ------------------------------------------------------------------------ | ---------------- | ------------------------------------ | -| Authorized user is not part of found leaderboard or user is not an admin | 401 Unauthorized | { "error": "You are not authorized"} | -| Leaderboard not found by name | 404 Not Found | { "error": "Leaderboard not found"} | - -
- -#### [7. POST /leaderboards/{name}/promote](#leaderboards) - -Promotes member of a leaderboard to admin if authorized user has admin rights. Be careful of promoting users, root admin (creator of the leaderboard) can be demoted/kicked by a promoted one. Requires secured access token. - -> \*This request is idempotent, it means that you can: -> -> 1. _Promote user that is already admin and have in response 200 OK_ -> 2. _Promote yourself to admin being already admin and have in response 200 OK_ - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Content-Type | application/json | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ---------------- | -| {name} | Leaderboard name | - -
- -
- Body params: - -| Param | Type | Description | -| ----- | ------ | ---------------------------------------------------- | -| user | string | Username of a leaderboard member you want to promote | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/leaderboards/{name}/promote' \ ---header 'Content-Type: application/json' \ ---header 'Authorization: Bearer ' \ ---data-raw '{ - "user": "" -}' -``` - -**Sample response** - -```HTTP -200 OK - -``` - -
- Error examples: - -| Error | Error code | Body | -| ------------------------------------------------------------------------ | ---------------- | ------------------------------------ | -| Authorized user is not part of found leaderboard or user is not an admin | 401 Unauthorized | { "error": "You are not authorized"} | -| Promoting user is not the leaderboard member | 403 Forbidden | { "error": "You're not a member"} | - -
- -#### [8. POST /leaderboards/{name}/demote](#leaderboards) - -Demotes admin to regular member in the leaderboard if authorized user has admin rights. Be careful of promoting users, root admin (creator of the leaderboard) can be demoted by a promoted one. Requires secured access token. - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Content-Type | application/json | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ---------------- | -| {name} | Leaderboard name | - -
- -
- Body params: - -| Param | Type | Description | -| ----- | ------ | -------------------------------------------------- | -| user | string | Username of a leaderboard admin you want to demote | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/leaderboards/{name}/demote' \ ---header 'Content-Type: application/json' \ ---header 'Authorization: Bearer ' \ ---data-raw '{ - "user": "" -}' -``` - -**Sample response** - -```HTTP -200 OK - -``` - -
- Error examples: - -| Error | Error code | Body | -| ------------------------------------------------------------------------ | ---------------- | ------------------------------------ | -| Authorized user is not part of found leaderboard or user is not an admin | 401 Unauthorized | { "error": "You are not authorized"} | -| Demoting user is not the leaderboard member | 403 Forbidden | { "error": "You're not a member"} | - -
- -#### [9. POST /leaderboards/{name}/kick](#leaderboards) - -Kicks user from leaderboard if authorized user has admin rights, requires secured access token - -
- Header params: - -| Name | Value | -| ------------- | -------------------- | -| Content-Type | application/json | -| Authorization | Bearer `` | - -
- -
- Path params: - -| Path param | Description | -| ---------- | ---------------- | -| {name} | Leaderboard name | - -
- -
- Body params: - -| Param | Type | Description | -| ----- | ------ | ------------------------------------------------- | -| user | string | Username of a leaderboard member you want to kick | - -
- -**Sample request** - -```curl -curl --request POST 'https://api.testaustime.fi/leaderboards/{name}/kick' \ ---header 'Content-Type: application/json' \ ---header 'Authorization: Bearer ' \ ---data-raw '{ - "user": "" -}' -``` - -**Sample response** - -```HTTP -200 OK - -``` - -
- Error examples: - -| Error | Error code | Body | -| ------------------------------------------------------------------------ | ---------------- | ------------------------------------ | -| Authorized user is not part of found leaderboard or user is not an admin | 401 Unauthorized | { "error": "You are not authorized"} | -| Kicking user is not the leaderboard member | 403 Forbidden | { "error": "You're not a member"} | - -
From a1ad0b01308ccfe042b0ef85cee6e41ab10dbc8d Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Sat, 13 Dec 2025 21:36:09 +0200 Subject: [PATCH 20/36] typo #2 --- src/api/leaderboards.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 8f102ac..31ad4ba 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -98,7 +98,7 @@ pub async fn get_leaderboard( #[utoipa::path( delete, - path = "/leaderboard/{name}", + path = "/leaderboards/{name}", params( ("name", description = "Leaderboard name") ), From 1dc67c116aba583a3e38735f45dded213212591a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Mon, 15 Dec 2025 14:18:45 +0200 Subject: [PATCH 21/36] chore: use nix in the entire CI, formatting and clippy fixes --- .github/workflows/build.yml | 30 --- .github/workflows/{docker.yml => ci.yml} | 55 ++++- .github/workflows/rust.yml | 88 -------- Cargo.lock | 7 + Cargo.toml | 33 ++- flake.lock | 244 +++-------------------- flake.nix | 88 ++++++-- src/api/activity.rs | 2 +- src/api/auth.rs | 10 +- src/api/friends.rs | 2 +- src/api/leaderboards.rs | 2 +- src/api/oauth.rs | 2 +- src/api/search.rs | 2 +- src/api/users.rs | 4 +- src/auth/mod.rs | 2 +- src/database/activity.rs | 2 +- src/database/auth.rs | 2 +- src/database/mod.rs | 6 +- src/error.rs | 10 +- src/main.rs | 6 +- src/ratelimiter.rs | 6 +- src/state.rs | 2 +- src/tests/auth.rs | 24 ++- src/tests/friends.rs | 2 +- src/tests/mod.rs | 2 +- src/utils.rs | 2 +- 26 files changed, 219 insertions(+), 416 deletions(-) delete mode 100644 .github/workflows/build.yml rename .github/workflows/{docker.yml => ci.yml} (72%) delete mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 818a375..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Build - -on: - push: - branches: [ main ] - paths: - - '**.rs' - - '**.yml' - - '**.toml' - - '**.lock' - -jobs: - build: - name: Build - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - uses: actions-rs/cargo@v1 - with: - command: build - args: --release - - uses: actions/upload-artifact@v2 - with: - name: build - path: target/release/testaustime-rs diff --git a/.github/workflows/docker.yml b/.github/workflows/ci.yml similarity index 72% rename from .github/workflows/docker.yml rename to .github/workflows/ci.yml index d4d7d17..9bc35e2 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/ci.yml @@ -1,17 +1,50 @@ -name: Docker +name: CI/CD + on: push: - branches: - - "main" - tags: - - "*" - workflow_dispatch: + branches: [ main ] + tags: [ '*' ] + pull_request: + env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + jobs: + check: + name: Nix CI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v24 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: DeterminateSystems/magic-nix-cache-action@v2 + - run: nix flake check -L + - run: nix build -L + + build: + name: Build Binary + needs: check + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v24 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: DeterminateSystems/magic-nix-cache-action@v2 + - run: nix build -L + - run: mkdir -p target/release && cp result/bin/testaustime target/release/testaustime-rs + - uses: actions/upload-artifact@v4 + with: + name: build + path: target/release/testaustime-rs + build-image: name: Build Docker image + needs: check + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) strategy: matrix: runner: @@ -23,7 +56,7 @@ jobs: packages: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Nix uses: cachix/install-nix-action@v24 @@ -35,7 +68,7 @@ jobs: - name: Build Docker image with Nix run: | - nix build .#docker + nix build -L .#docker IMAGE_PATH=$(readlink -f result) echo "IMAGE_PATH=$IMAGE_PATH" >> $GITHUB_ENV @@ -81,7 +114,8 @@ jobs: - name: Tag and push Docker image run: | - for tag in ${{ steps.meta.outputs.tags }}; do + for tag in ${{ steps.meta.outputs.tags }}; + do docker tag ${{ steps.image.outputs.name }} $tag docker push $tag done @@ -117,7 +151,8 @@ jobs: - name: Create and push manifest run: | TAGS="${{ steps.meta.outputs.tags }}" - for tag in $TAGS; do + for tag in $TAGS; + do docker manifest create $tag \ ${tag}-amd64 \ ${tag}-arm64 diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 08d72cd..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,88 +0,0 @@ -on: [push, pull_request] - -name: Continuous integration - -jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - uses: actions-rs/cargo@v1 - with: - command: check - - test: - name: Test Suite - runs-on: ubuntu-latest - - services: - postgres: - image: postgres - env: - POSTGRES_DB: testaustime - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - ports: - - 5432:5432 - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - name: Install Diesel - run: cargo install diesel_cli --features=postgres - - name: Create Test DB - env: - DATABASE_URL: postgres://postgres:postgres@localhost/testaustime - run: diesel migration run - - - name: Run tests - env: - TEST_DATABASE: postgres://postgres:postgres@localhost/testaustime - run: cargo test - - fmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - run: rustup component add clippy - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index 2b415ff..48288b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2763,9 +2763,16 @@ dependencies = [ "serde_json", "url", "utoipa", + "utoipa-swagger-ui-vendored", "zip", ] +[[package]] +name = "utoipa-swagger-ui-vendored" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2eebbbfe4093922c2b6734d7c679ebfebd704a0d7e56dfcb0d05818ce28977d" + [[package]] name = "valuable" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 4c2b9a6..582cb4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,10 @@ name = "testaustime" version = "0.3.1" edition = "2021" -authors = ["Ville Järvinen ", "Luukas Pörtfors "] +authors = [ + "Ville Järvinen ", + "Luukas Pörtfors ", +] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] @@ -15,8 +18,14 @@ lto = true [dependencies] axum = { version = "0.8", features = ["macros", "tokio"] } axum-extra = { version = "0.10", features = ["cookie", "cookie-private"] } -tokio = { version = "1.35", features = ["macros", "rt-multi-thread"]} -reqwest = { version = "0.12", optional = true, default-features = false, features = ["json", "rustls-tls", "charset", "http2", "macos-system-configuration"] } +tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] } +reqwest = { version = "0.12", optional = true, default-features = false, features = [ + "json", + "rustls-tls", + "charset", + "http2", + "macos-system-configuration", +] } http = "1.0" http-body-util = "0.1" regex = "1.5" @@ -25,7 +34,10 @@ tower = "0.5" tower-http = { version = "0.6", features = ["trace"] } tracing = "0.1.40" -tracing-subscriber = { version = "0.3", features = ["env-filter", "tracing-log"] } +tracing-subscriber = { version = "0.3", features = [ + "env-filter", + "tracing-log", +] } tracing-futures = "0.2" thiserror = "2.0" @@ -39,7 +51,7 @@ futures = "0.3" futures-util = "0.3" chrono = { version = "0.4", features = ["serde"] } dashmap = "6.1" -argon2 = { version = "0.4", features = ["std"]} +argon2 = { version = "0.4", features = ["std"] } rand = "0.9" dotenv = "0.15" url = "2.2" @@ -48,8 +60,15 @@ itertools = "0.14" governor = "0.10.0" diesel = { version = "2.1.0", features = ["chrono", "serde_json"] } diesel-async = { version = "0.5.1", features = ["postgres", "deadpool"] } -lettre = { version = "0.11.14", default-features = false, features = ["tokio1-rustls-tls", "tracing", "pool", "smtp-transport", "hostname", "builder"]} +lettre = { version = "0.11.14", default-features = false, features = [ + "tokio1-rustls-tls", + "tracing", + "pool", + "smtp-transport", + "hostname", + "builder", +] } mime = "0.3.17" utoipa = { version = "5.4.0", features = ["axum_extras", "chrono"] } utoipa-axum = "0.2.0" -utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } +utoipa-swagger-ui = { version = "9.0.2", features = ["axum", "vendored"] } diff --git a/flake.lock b/flake.lock index ae65130..bbe5ac6 100644 --- a/flake.lock +++ b/flake.lock @@ -1,33 +1,5 @@ { "nodes": { - "cachix": { - "inputs": { - "devenv": [ - "devenv" - ], - "flake-compat": [ - "devenv" - ], - "git-hooks": [ - "devenv" - ], - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1742042642, - "narHash": "sha256-D0gP8srrX0qj+wNYNPdtVJsQuFzIng3q43thnHXQ/es=", - "owner": "cachix", - "repo": "cachix", - "rev": "a624d3eaf4b1d225f918de8543ed739f2f574203", - "type": "github" - }, - "original": { - "owner": "cachix", - "ref": "latest", - "repo": "cachix", - "type": "github" - } - }, "crane": { "locked": { "lastModified": 1746291859, @@ -43,30 +15,6 @@ "type": "github" } }, - "devenv": { - "inputs": { - "cachix": "cachix", - "flake-compat": "flake-compat", - "git-hooks": "git-hooks", - "nix": "nix", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1746707904, - "narHash": "sha256-j1BAUl+NYtWWWVkuDLfSE0wlF7FlkwhrcJxDISXAVvE=", - "owner": "cachix", - "repo": "devenv", - "rev": "fada79d97f2066c444766d039b0a62affd3e3cab", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "devenv", - "type": "github" - } - }, "fenix": { "inputs": { "nixpkgs": [ @@ -88,173 +36,7 @@ "type": "github" } }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1733328505, - "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "devenv", - "nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1712014858, - "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "git-hooks": { - "inputs": { - "flake-compat": [ - "devenv" - ], - "gitignore": "gitignore", - "nixpkgs": [ - "devenv", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1742649964, - "narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=", - "owner": "cachix", - "repo": "git-hooks.nix", - "rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "git-hooks.nix", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "devenv", - "git-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709087332, - "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "libgit2": { - "flake": false, - "locked": { - "lastModified": 1697646580, - "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", - "owner": "libgit2", - "repo": "libgit2", - "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", - "type": "github" - }, - "original": { - "owner": "libgit2", - "repo": "libgit2", - "type": "github" - } - }, - "nix": { - "inputs": { - "flake-compat": [ - "devenv" - ], - "flake-parts": "flake-parts", - "libgit2": "libgit2", - "nixpkgs": "nixpkgs_2", - "nixpkgs-23-11": [ - "devenv" - ], - "nixpkgs-regression": [ - "devenv" - ], - "pre-commit-hooks": [ - "devenv" - ] - }, - "locked": { - "lastModified": 1745930071, - "narHash": "sha256-bYyjarS3qSNqxfgc89IoVz8cAFDkF9yPE63EJr+h50s=", - "owner": "domenkozar", - "repo": "nix", - "rev": "b455edf3505f1bf0172b39a735caef94687d0d9c", - "type": "github" - }, - "original": { - "owner": "domenkozar", - "ref": "devenv-2.24", - "repo": "nix", - "type": "github" - } - }, "nixpkgs": { - "locked": { - "lastModified": 1733212471, - "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "55d15ad12a74eb7d4646254e13638ad0c4128776", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1717432640, - "narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "88269ab3044128b7c2f4c7d68448b2fb50456870", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "release-24.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { "locked": { "lastModified": 1746663147, "narHash": "sha256-Ua0drDHawlzNqJnclTJGf87dBmaO/tn7iZ+TCkTRpRc=", @@ -273,10 +55,10 @@ "root": { "inputs": { "crane": "crane", - "devenv": "devenv", "fenix": "fenix", - "nixpkgs": "nixpkgs_3", - "systems": "systems" + "nixpkgs": "nixpkgs", + "systems": "systems", + "treefmt-nix": "treefmt-nix" } }, "rust-analyzer-src": { @@ -310,6 +92,26 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1762938485, + "narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index fd3a839..451fc54 100644 --- a/flake.nix +++ b/flake.nix @@ -2,36 +2,36 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; systems.url = "github:nix-systems/default"; - devenv.url = "github:cachix/devenv"; - devenv.inputs.nixpkgs.follows = "nixpkgs"; fenix = { url = "github:nix-community/fenix"; inputs.nixpkgs.follows = "nixpkgs"; }; crane.url = "github:ipetkov/crane"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, - devenv, systems, fenix, crane, + treefmt-nix, ... }@inputs: let forEachSystem = nixpkgs.lib.genAttrs (import systems); - in - { - packages = forEachSystem ( + + perSystem = system: let pkgs = nixpkgs.legacyPackages.${system}; - toolchain = fenix.packages.${system}.minimal.toolchain; + # Use default toolchain to include clippy and rustfmt + toolchain = fenix.packages.${system}.default.toolchain; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; @@ -45,11 +45,39 @@ doCheck = false; } ); + + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs.nixfmt.enable = true; + programs.nixfmt.package = pkgs.nixfmt-rfc-style; + programs.taplo.enable = true; + programs.rustfmt.enable = true; + programs.rustfmt.package = toolchain; + }; + in + { + inherit + pkgs + toolchain + craneLib + commonArgs + cargoArtifacts + treefmtEval + ; + }; + in + { + packages = forEachSystem ( + system: + let + inherit (perSystem system) + pkgs + craneLib + commonArgs + cargoArtifacts + ; in rec { - devenv-up = self.devShells.${system}.default.config.procfileScript; - devenv-test = self.devShells.${system}.default.config.test; - testaustime-backend = craneLib.buildPackage ( commonArgs // { @@ -104,20 +132,42 @@ } ); + checks = forEachSystem ( + system: + let + inherit (perSystem system) + craneLib + commonArgs + cargoArtifacts + treefmtEval + ; + in + { + testaustime-backend-clippy = craneLib.cargoClippy ( + commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + formatting = treefmtEval.config.build.check self; + } + ); + + formatter = forEachSystem (system: (perSystem system).treefmtEval.config.build.wrapper); + devShells = forEachSystem ( system: let - pkgs = nixpkgs.legacyPackages.${system}; + inherit (perSystem system) pkgs toolchain treefmtEval; in { - default = devenv.lib.mkShell { - inherit inputs pkgs; - modules = [ - { - languages.rust.enable = true; - - packages = [ self.outputs.packages.${system}.testaustime-backend ]; - } + default = pkgs.mkShell { + packages = [ + toolchain + pkgs.diesel-cli + treefmtEval.config.build.wrapper ]; }; } diff --git a/src/api/activity.rs b/src/api/activity.rs index a14ea98..4726d02 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{extract::State, Json}; +use axum::{Json, extract::State}; use chrono::{Duration, Local}; use dashmap::DashMap; use http::StatusCode; diff --git a/src/api/auth.rs b/src/api/auth.rs index cbe0c89..31e07a8 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -1,25 +1,25 @@ use std::sync::Arc; use axum::{ - extract::{FromRequestParts, State}, Json, + extract::{FromRequestParts, State}, }; use chrono::{Duration, Local}; -use http::{request::Parts, StatusCode}; +use http::{StatusCode, request::Parts}; use lettre::{ - message::header::ContentType, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, + AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, message::header::ContentType, }; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::{ + PasswordReset, PasswordResetState, api::users::UserAuthentication, auth::Authentication, database::DatabaseWrapper, error::TimeError, models::{NewUserIdentity, SelfUser, UserId, UserIdentity}, utils::{generate_password_reset_token, validate_email}, - PasswordReset, PasswordResetState, }; impl FromRequestParts for UserId { @@ -319,7 +319,7 @@ pub async fn request_password_reset( .to(format!("{} <{}>", user.username, email).parse().map_err(|_| TimeError::InvalidEmail)?) .subject("Testaustime password reset") .header(ContentType::TEXT_PLAIN) - .body(format!("Here is your testaustime password reset link: https://testaustime.fi/reset_password?token={}", token)).unwrap(); + .body(format!("Here is your testaustime password reset link: https://testaustime.fi/reset_password?token={token}")).unwrap(); tokio::spawn(async move { if let Err(err) = relay.send(message).await { diff --git a/src/api/friends.rs b/src/api/friends.rs index 27c482b..eb7eae4 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{extract::State, Json}; +use axum::{Json, extract::State}; use diesel::result::DatabaseErrorKind; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 31ad4ba..cdd3064 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -1,4 +1,4 @@ -use axum::{extract::Path, Json}; +use axum::{Json, extract::Path}; use diesel::result::{DatabaseErrorKind, Error as DieselError}; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/oauth.rs b/src/api/oauth.rs index 882c592..394b83d 100644 --- a/src/api/oauth.rs +++ b/src/api/oauth.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, sync::LazyLock}; use axum::{extract::Query, response::Redirect}; -use axum_extra::extract::{cookie::Cookie, CookieJar}; +use axum_extra::extract::{CookieJar, cookie::Cookie}; use reqwest::Client; use serde_derive::Deserialize; diff --git a/src/api/search.rs b/src/api/search.rs index 8d55e21..4547a71 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -1,4 +1,4 @@ -use axum::{extract::Query, Json}; +use axum::{Json, extract::Query}; use serde_derive::Deserialize; use utoipa::IntoParams; diff --git a/src/api/users.rs b/src/api/users.rs index f0d09e7..a114747 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -1,10 +1,10 @@ use std::{collections::HashMap, sync::Arc}; use axum::{ - extract::{Path, Query, State}, Json, + extract::{Path, Query, State}, }; -use chrono::{serde::ts_seconds_option, DateTime, Duration, Local, Utc}; +use chrono::{DateTime, Duration, Local, Utc, serde::ts_seconds_option}; use http::StatusCode; use serde::Serialize; use serde_derive::Deserialize; diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 1309422..9a8a0d5 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -7,7 +7,7 @@ use axum::extract::Request; use futures_util::future::BoxFuture; use tower::{Layer, Service}; -use crate::{database::DatabaseWrapper, models::UserIdentity, TestaustimeState}; +use crate::{TestaustimeState, database::DatabaseWrapper, models::UserIdentity}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Authentication { diff --git a/src/database/activity.rs b/src/database/activity.rs index b1d60ca..970d401 100644 --- a/src/database/activity.rs +++ b/src/database/activity.rs @@ -1,4 +1,4 @@ -use chrono::{prelude::*, Duration}; +use chrono::{Duration, prelude::*}; use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/src/database/auth.rs b/src/database/auth.rs index 89a1ea1..292d1a8 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -1,6 +1,6 @@ use argon2::{ - password_hash::{rand_core::OsRng, PasswordHasher, SaltString}, Argon2, + password_hash::{PasswordHasher, SaltString, rand_core::OsRng}, }; use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/src/database/mod.rs b/src/database/mod.rs index f3a0d9f..67dff37 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -2,15 +2,15 @@ use std::sync::Arc; use axum::extract::{FromRef, FromRequestParts}; use diesel_async::{ + AsyncPgConnection, pooled_connection::{ - deadpool::{Object, Pool}, AsyncDieselConnectionManager, + deadpool::{Object, Pool}, }, - AsyncPgConnection, }; use http::request::Parts; -use crate::{error::TimeError, TestaustimeState}; +use crate::{TestaustimeState, error::TimeError}; pub mod activity; pub mod auth; diff --git a/src/error.rs b/src/error.rs index 78fe05a..87057d2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use axum::{ - response::{IntoResponse, Response}, Json, + response::{IntoResponse, Response}, }; use http::StatusCode; use thiserror::Error; @@ -31,9 +31,13 @@ pub enum TimeError { InvalidCredentials, #[error("{0}")] InvalidLength(String), - #[error("Username has to contain characters from [a-zA-Z0-9_] and has to be between 2 and 32 characters")] + #[error( + "Username has to contain characters from [a-zA-Z0-9_] and has to be between 2 and 32 characters" + )] BadUsername, - #[error("Leaderboard name has to contain characters from [a-zA-Z0-9_] and has to be between 2 and 32 characters")] + #[error( + "Leaderboard name has to contain characters from [a-zA-Z0-9_] and has to be between 2 and 32 characters" + )] BadLeaderboardName, #[error("Bad id")] BadId, diff --git a/src/main.rs b/src/main.rs index b55b110..3ec4de4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,12 +15,12 @@ use std::{net::SocketAddr, num::NonZeroU32, sync::Arc}; use api::activity::HeartBeatMemoryStore; use auth::{AuthMiddleware, Authentication}; -use axum::{body::Body, Router}; +use axum::{Router, body::Body}; use chrono::NaiveDateTime; use dashmap::DashMap; use database::Database; use governor::{Quota, RateLimiter}; -use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor}; +use lettre::{AsyncSmtpTransport, Tokio1Executor, transport::smtp::authentication::Credentials}; use models::UserIdentity; use ratelimiter::TestaustimeRateLimiter; use serde_derive::Deserialize; @@ -28,8 +28,8 @@ use tower::ServiceBuilder; use tower_http::trace::TraceLayer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use utoipa::{ - openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, Modify, OpenApi, + openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, }; use utoipa_axum::{router::OpenApiRouter, routes}; use utoipa_swagger_ui::SwaggerUi; diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index a97c9e7..43b155a 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -11,12 +11,12 @@ use axum::{ }; use futures_util::future::BoxFuture; use governor::{ - clock::DefaultClock, middleware::StateInformationMiddleware, - state::keyed::DefaultKeyedStateStore, RateLimiter, + RateLimiter, clock::DefaultClock, middleware::StateInformationMiddleware, + state::keyed::DefaultKeyedStateStore, }; use http::{ - header::{HeaderName, FORWARDED}, HeaderValue, StatusCode, + header::{FORWARDED, HeaderName}, }; use tower::{Layer, Service}; diff --git a/src/state.rs b/src/state.rs index 121cc2b..f0dbe9b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,7 +4,7 @@ use axum::extract::FromRef; use lettre::{AsyncSmtpTransport, Tokio1Executor}; use crate::{ - api::activity::HeartBeatMemoryStore, PasswordResetState, RegisterLimiter, TestaustimeState, + PasswordResetState, RegisterLimiter, TestaustimeState, api::activity::HeartBeatMemoryStore, }; impl FromRef for Arc { diff --git a/src/tests/auth.rs b/src/tests/auth.rs index e029d9b..80693d5 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -104,11 +104,13 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!(resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("username")); + assert!( + resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("username") + ); let body = json!({"username": "validusername", "password": "short"}); let resp = request!(app, POST, "/auth/register", body); @@ -118,11 +120,13 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!(resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("password")); + assert!( + resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("password") + ); } // TODO: test ratelimits diff --git a/src/tests/friends.rs b/src/tests/friends.rs index 49d5525..64842f6 100644 --- a/src/tests/friends.rs +++ b/src/tests/friends.rs @@ -20,7 +20,7 @@ async fn adding_friends_works() { let friend_body = json!({"code": f2.friend_code.clone()}); let resp = request_auth!(app, POST, "/friends/add", f1.auth_token, friend_body); - println!("{:?}", resp); + println!("{resp:?}"); assert!(resp.status().is_success(), "Adding friend works"); diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 245df0e..8670eb6 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -9,7 +9,7 @@ mod friends; mod leaderboards; mod macros; -use axum::{body::Body, extract::connect_info::MockConnectInfo, response::Response, Router}; +use axum::{Router, body::Body, extract::connect_info::MockConnectInfo, response::Response}; use http::{Request, StatusCode}; use serde::de::DeserializeOwned; use tower::ServiceExt; diff --git a/src/utils.rs b/src/utils.rs index 43b23f7..8f9fe41 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use itertools::Itertools; use lettre::Address; -use rand::{distr::Alphanumeric, rng, Rng}; +use rand::{Rng, distr::Alphanumeric, rng}; use crate::models::CodingActivity; From c9bf86904e51cc861bfa7c8e09569ba92be0c1d0 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Thu, 8 Jan 2026 09:57:38 +0200 Subject: [PATCH 22/36] do not store 0s activities --- src/api/activity.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/api/activity.rs b/src/api/activity.rs index 4726d02..d2da5f7 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -74,8 +74,10 @@ pub async fn update( if curtime.signed_duration_since(start + duration) > Duration::seconds(900) { // If the user sends a heartbeat but maximum activity duration has been exceeded, // end session and start new - db.add_activity(user.id, current_heartbeat, start, duration) - .await?; + if duration > Duration::zero() { + db.add_activity(user.id, current_heartbeat, start, duration) + .await?; + } heartbeats.insert( user.id, @@ -98,8 +100,10 @@ pub async fn update( duration = curtime.signed_duration_since(start); } - db.add_activity(user.id, current_heartbeat, start, duration) - .await?; + if duration > Duration::zero() { + db.add_activity(user.id, current_heartbeat, start, duration) + .await?; + } heartbeats.insert( user.id, @@ -139,8 +143,10 @@ pub async fn flush( let (inner_heartbeat, start, duration) = heartbeat.to_owned(); drop(heartbeat); heartbeats.remove(&user.id); - db.add_activity(user.id, inner_heartbeat, start, duration) - .await?; + if duration > Duration::zero() { + db.add_activity(user.id, inner_heartbeat, start, duration) + .await?; + } } Ok(StatusCode::OK) } From c526d98cab90cfe1b90896fdbbca3a08ad87281b Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Tue, 13 Jan 2026 12:21:01 +0200 Subject: [PATCH 23/36] increase all heartbeat limits to 64 chars --- .../down.sql | 5 +++++ .../up.sql | 5 +++++ src/api/activity.rs | 12 ++++++------ src/schema.rs | 6 +++--- 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 migrations/2026-01-13-101356-0000_increase_heartbeat_limits/down.sql create mode 100644 migrations/2026-01-13-101356-0000_increase_heartbeat_limits/up.sql diff --git a/migrations/2026-01-13-101356-0000_increase_heartbeat_limits/down.sql b/migrations/2026-01-13-101356-0000_increase_heartbeat_limits/down.sql new file mode 100644 index 0000000..3e96a2d --- /dev/null +++ b/migrations/2026-01-13-101356-0000_increase_heartbeat_limits/down.sql @@ -0,0 +1,5 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE coding_activities + ALTER COLUMN language TYPE VARCHAR(32), + ALTER COLUMN editor_name TYPE VARCHAR(32), + ALTER COLUMN hostname TYPE VARCHAR(32); diff --git a/migrations/2026-01-13-101356-0000_increase_heartbeat_limits/up.sql b/migrations/2026-01-13-101356-0000_increase_heartbeat_limits/up.sql new file mode 100644 index 0000000..0fc8773 --- /dev/null +++ b/migrations/2026-01-13-101356-0000_increase_heartbeat_limits/up.sql @@ -0,0 +1,5 @@ +-- Your SQL goes here +ALTER TABLE coding_activities + ALTER COLUMN language TYPE VARCHAR(64), + ALTER COLUMN editor_name TYPE VARCHAR(64), + ALTER COLUMN hostname TYPE VARCHAR(64); diff --git a/src/api/activity.rs b/src/api/activity.rs index d2da5f7..c7a4257 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -44,23 +44,23 @@ pub async fn update( } } if let Some(language) = &heartbeat.language { - if language.len() > 32 { + if language.len() > 64 { return Err(TimeError::InvalidLength( - "Language is over 32 chars".to_string(), + "Language is over 64 chars".to_string(), )); } } if let Some(editor) = &heartbeat.editor_name { - if editor.len() > 32 { + if editor.len() > 64 { return Err(TimeError::InvalidLength( - "Editor name is over 32 chars".to_string(), + "Editor name is over 64 chars".to_string(), )); } } if let Some(hostname) = &heartbeat.hostname { - if hostname.len() > 32 { + if hostname.len() > 64 { return Err(TimeError::InvalidLength( - "Hostname is over 32 chars".to_string(), + "Hostname is over 64 chars".to_string(), )); } } diff --git a/src/schema.rs b/src/schema.rs index c99e108..2a73baf 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -8,11 +8,11 @@ diesel::table! { duration -> Int4, #[max_length = 64] project_name -> Nullable, - #[max_length = 32] + #[max_length = 64] language -> Nullable, - #[max_length = 32] + #[max_length = 64] editor_name -> Nullable, - #[max_length = 32] + #[max_length = 64] hostname -> Nullable, hidden -> Bool, } From fd12e8d85e3d901f410e1ea30114b60078f09766 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Tue, 13 Jan 2026 12:56:24 +0200 Subject: [PATCH 24/36] fix tests --- src/tests/activity.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tests/activity.rs b/src/tests/activity.rs index 6bcdf54..413a8a4 100644 --- a/src/tests/activity.rs +++ b/src/tests/activity.rs @@ -41,7 +41,7 @@ async fn updating_activity_works() { ); // NOTE: adding duration to the session - tokio::time::sleep(Duration::from_secs(1)).await; + tokio::time::sleep(Duration::from_secs(2)).await; let resp = request_auth!(app, POST, "/activity/update", user.auth_token, heartbeat); assert!(resp.status().is_success(), "Extending session should work"); @@ -121,7 +121,7 @@ async fn flushing_works() { let resp = request_auth!(app, GET, "/users/@me/activity/data", user.auth_token); let data: Vec = body_to_json(resp).await; - assert!(!data.is_empty(), "Session should be saved after a flush"); + assert!(data.is_empty(), "0 duration session should not be saved"); let resp = request!(app, DELETE, "/users/@me/delete", body); assert!(resp.status().is_success(), "Failed to delete user"); @@ -149,6 +149,14 @@ async fn hidden_project() { "Sending heartbeat should succeed" ); + tokio::time::sleep(Duration::from_secs(2)).await; + + let resp = request_auth!(app, POST, "/activity/update", user.auth_token, heartbeat); + assert!( + resp.status().is_success(), + "Sending heartbeat should succeed" + ); + let resp = request_auth!(app, GET, "/users/@me/activity/data", user.auth_token); let data: Vec = body_to_json(resp).await; @@ -170,7 +178,7 @@ async fn hidden_project() { ); let data: Vec = body_to_json(resp).await; - assert!(!data.is_empty(), "Session should be saved after a flush"); + assert!(!data.is_empty(), "Session with non-zero duration should be saved"); // Print the actual value of the project name to see what it is assert!( data[0].get("project_name").unwrap_or(&json!("not_hidden")) == &json!("hidden"), From 647652157ac36e63b93ba9fcc732551fbc304c70 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Wed, 14 Jan 2026 08:26:07 +0200 Subject: [PATCH 25/36] bump deps and update code most notably argon2 --- Cargo.lock | 1465 +++++++++++++++++++++++------------------- Cargo.toml | 14 +- src/database/auth.rs | 37 +- 3 files changed, 856 insertions(+), 660 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48288b3..1cbaf9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,20 +2,11 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "addr2line" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" -dependencies = [ - "gimli", -] - [[package]] name = "adler2" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "aead" @@ -54,21 +45,21 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" dependencies = [ "cfg-if", "once_cell", "version_check", - "zerocopy 0.7.35", + "zerocopy", ] [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] @@ -79,12 +70,6 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - [[package]] name = "android_system_properties" version = "0.1.5" @@ -94,6 +79,15 @@ dependencies = [ "libc", ] +[[package]] +name = "ar_archive_writer" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c269894b6fe5e9d7ada0cf69b5bf847ff35bc25fc271f08e1d080fce80339a" +dependencies = [ + "object", +] + [[package]] name = "arbitrary" version = "1.4.2" @@ -105,20 +99,21 @@ dependencies = [ [[package]] name = "argon2" -version = "0.4.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4ce4441f99dbd377ca8a8f57b698c44d0d6e712d8329b5040da5a64aa1ce73" +checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" dependencies = [ "base64ct", "blake2", + "cpufeatures", "password-hash", ] [[package]] name = "async-trait" -version = "0.1.88" +version = "0.1.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", @@ -133,15 +128,37 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.4.0" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "aws-lc-rs" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88aab2464f1f25453baa7a07c84c5b7684e274054ba06817f382357f77a288" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "b45afffdee1e7c9126814751f88dddc747f41d91da16c9551a0f1e8a11e788a1" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", +] [[package]] name = "axum" -version = "0.8.3" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de45108900e1f9b9242f7f2e254aa3e2c029c921c258fe9e6b4217eeebd54288" +checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" dependencies = [ "axum-core", "axum-macros", @@ -159,8 +176,7 @@ dependencies = [ "mime", "percent-encoding", "pin-project-lite", - "rustversion", - "serde", + "serde_core", "serde_json", "serde_path_to_error", "serde_urlencoded", @@ -174,9 +190,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.5.2" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" dependencies = [ "bytes", "futures-core", @@ -185,7 +201,6 @@ dependencies = [ "http-body-util", "mime", "pin-project-lite", - "rustversion", "sync_wrapper", "tower-layer", "tower-service", @@ -194,25 +209,24 @@ dependencies = [ [[package]] name = "axum-extra" -version = "0.10.1" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45bf463831f5131b7d3c756525b305d40f1185b688565648a92e1392ca35713d" +checksum = "fef252edff26ddba56bbcdf2ee3307b8129acb86f5749b68990c168a6fcc9c76" dependencies = [ "axum", "axum-core", "bytes", "cookie", + "futures-core", "futures-util", "http", "http-body", "http-body-util", "mime", "pin-project-lite", - "rustversion", - "serde", - "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -226,21 +240,6 @@ dependencies = [ "syn", ] -[[package]] -name = "backtrace" -version = "0.3.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", - "windows-targets 0.52.6", -] - [[package]] name = "base64" version = "0.22.1" @@ -249,15 +248,15 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" -version = "1.7.3" +version = "1.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" [[package]] name = "bitflags" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "blake2" @@ -279,9 +278,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.17.0" +version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" [[package]] name = "byteorder" @@ -291,24 +290,33 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" [[package]] name = "cc" -version = "1.2.19" +version = "1.2.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" +checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3" dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", "shlex", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cfg_aliases" @@ -318,11 +326,10 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.40" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" dependencies = [ - "android-tzdata", "iana-time-zone", "js-sys", "num-traits", @@ -351,6 +358,25 @@ dependencies = [ "inout", ] +[[package]] +name = "cmake" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d" +dependencies = [ + "cc", +] + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "cookie" version = "0.18.1" @@ -368,9 +394,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.9.4" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" dependencies = [ "core-foundation-sys", "libc", @@ -408,9 +434,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", "rand_core 0.6.4", @@ -428,9 +454,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.11" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" dependencies = [ "darling_core", "darling_macro", @@ -438,9 +464,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.11" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4" dependencies = [ "fnv", "ident_case", @@ -452,9 +478,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.11" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" dependencies = [ "darling_core", "quote", @@ -477,11 +503,12 @@ dependencies = [ [[package]] name = "deadpool" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ed5957ff93768adf7a65ab167a17835c3d2c3c50d084fe305174c112f468e2f" +checksum = "0be2b1d1d6ec8d846f05e137292d0b89133caf95ef33695424c09568bdd39b1b" dependencies = [ "deadpool-runtime", + "lazy_static", "num_cpus", "tokio", ] @@ -494,9 +521,9 @@ checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" [[package]] name = "deranged" -version = "0.4.0" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" dependencies = [ "powerfmt", ] @@ -514,27 +541,28 @@ dependencies = [ [[package]] name = "diesel" -version = "2.2.9" +version = "2.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34d3950690ba3a6910126162b47e775e203006d4242a15de912bec6c0a695153" +checksum = "e130c806dccc85428c564f2dc5a96e05b6615a27c9a28776bd7761a9af4bb552" dependencies = [ "bitflags", "byteorder", "chrono", "diesel_derives", + "downcast-rs", "itoa", "serde_json", ] [[package]] name = "diesel-async" -version = "0.5.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51a307ac00f7c23f526a04a77761a0519b9f0eb2838ebf5b905a58580095bdcb" +checksum = "13096fb8dae53f2d411c4b523bec85f45552ed3044a2ab4d85fb2092d9cb4f34" dependencies = [ - "async-trait", "deadpool", "diesel", + "futures-core", "futures-util", "scoped-futures", "tokio", @@ -543,9 +571,9 @@ dependencies = [ [[package]] name = "diesel_derives" -version = "2.2.4" +version = "2.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a93958254b70bea63b4187ff73d10180599d9d8d177071b7f91e6da4e0c0ad55" +checksum = "c30b2969f923fa1f73744b92bb7df60b858df8832742d9a3aceb79236c0be1d2" dependencies = [ "diesel_table_macro_syntax", "dsl_auto_type", @@ -556,9 +584,9 @@ dependencies = [ [[package]] name = "diesel_table_macro_syntax" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" +checksum = "fe2444076b48641147115697648dc743c2c00b61adade0f01ce67133c7babe8c" dependencies = [ "syn", ] @@ -591,11 +619,17 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +[[package]] +name = "downcast-rs" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117240f60069e65410b3ae1bb213295bd828f707b5bec6596a1afc8793ce0cbc" + [[package]] name = "dsl_auto_type" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139ae9aca7527f85f26dd76483eb38533fd84bd571065da1739656ef71c5ff5b" +checksum = "dd122633e4bef06db27737f21d3738fb89c8f6d5360d6d9d7635dda142a7757e" dependencies = [ "darling", "either", @@ -605,6 +639,12 @@ dependencies = [ "syn", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "either" version = "1.15.0" @@ -654,15 +694,21 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "find-msvc-tools" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41" + [[package]] name = "flate2" -version = "1.1.5" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb" +checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" dependencies = [ "crc32fast", - "libz-rs-sys", "miniz_oxide", + "zlib-rs", ] [[package]] @@ -673,19 +719,25 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foldhash" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "form_urlencoded" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures" version = "0.3.31" @@ -793,28 +845,28 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] [[package]] name = "getrandom" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "js-sys", "libc", "r-efi", - "wasi 0.14.2+wasi-0.2.4", + "wasip2", "wasm-bindgen", ] @@ -828,30 +880,24 @@ dependencies = [ "polyval", ] -[[package]] -name = "gimli" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" - [[package]] name = "governor" -version = "0.10.0" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbe789d04bf14543f03c4b60cd494148aa79438c8440ae7d81a7778147745c3" +checksum = "9efcab3c1958580ff1f25a2a41be1668f7603d849bb63af523b208a3cc1223b8" dependencies = [ "cfg-if", "dashmap", "futures-sink", "futures-timer", "futures-util", - "getrandom 0.3.2", - "hashbrown 0.15.2", + "getrandom 0.3.4", + "hashbrown 0.16.1", "nonzero_ext", "parking_lot", "portable-atomic", "quanta", - "rand 0.9.0", + "rand 0.9.2", "smallvec", "spinning_top", "web-time", @@ -859,9 +905,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.10" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9421a676d1b147b16b82c9225157dc629087ef8ec4d5e2960f9437a90dac0a5" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" dependencies = [ "atomic-waker", "bytes", @@ -888,9 +934,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.2" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "allocator-api2", "equivalent", @@ -905,9 +951,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.3.9" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" [[package]] name = "hmac" @@ -920,9 +966,9 @@ dependencies = [ [[package]] name = "hostname" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56f203cd1c76362b69e3863fd987520ac36cf70a8c92627449b2f64a8cf7d65" +checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd" dependencies = [ "cfg-if", "libc", @@ -931,12 +977,11 @@ dependencies = [ [[package]] name = "http" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" dependencies = [ "bytes", - "fnv", "itoa", ] @@ -977,13 +1022,14 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "1.6.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" dependencies = [ + "atomic-waker", "bytes", "futures-channel", - "futures-util", + "futures-core", "h2", "http", "http-body", @@ -991,6 +1037,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", + "pin-utils", "smallvec", "tokio", "want", @@ -998,11 +1045,10 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.5" +version = "0.27.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" dependencies = [ - "futures-util", "http", "hyper", "hyper-util", @@ -1011,22 +1057,25 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots", ] [[package]] name = "hyper-util" -version = "0.1.11" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" +checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" dependencies = [ + "base64", "bytes", "futures-channel", + "futures-core", "futures-util", "http", "http-body", "hyper", + "ipnet", "libc", + "percent-encoding", "pin-project-lite", "socket2", "tokio", @@ -1036,9 +1085,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.63" +version = "0.1.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1060,21 +1109,22 @@ dependencies = [ [[package]] name = "icu_collections" -version = "1.5.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" dependencies = [ "displaydoc", + "potential_utf", "yoke", "zerofrom", "zerovec", ] [[package]] -name = "icu_locid" -version = "1.5.0" +name = "icu_locale_core" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" dependencies = [ "displaydoc", "litemap", @@ -1083,99 +1133,61 @@ dependencies = [ "zerovec", ] -[[package]] -name = "icu_locid_transform" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_locid_transform_data", - "icu_provider", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_locid_transform_data" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" - [[package]] name = "icu_normalizer" -version = "1.5.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" dependencies = [ - "displaydoc", "icu_collections", "icu_normalizer_data", "icu_properties", "icu_provider", "smallvec", - "utf16_iter", - "utf8_iter", - "write16", "zerovec", ] [[package]] name = "icu_normalizer_data" -version = "1.5.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" [[package]] name = "icu_properties" -version = "1.5.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" dependencies = [ - "displaydoc", "icu_collections", - "icu_locid_transform", + "icu_locale_core", "icu_properties_data", "icu_provider", - "tinystr", + "zerotrie", "zerovec", ] [[package]] name = "icu_properties_data" -version = "1.5.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" [[package]] name = "icu_provider" -version = "1.5.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" dependencies = [ "displaydoc", - "icu_locid", - "icu_provider_macros", - "stable_deref_trait", - "tinystr", + "icu_locale_core", "writeable", "yoke", "zerofrom", + "zerotrie", "zerovec", ] -[[package]] -name = "icu_provider_macros" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "ident_case" version = "1.0.1" @@ -1184,9 +1196,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" dependencies = [ "idna_adapter", "smallvec", @@ -1195,9 +1207,9 @@ dependencies = [ [[package]] name = "idna_adapter" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" dependencies = [ "icu_normalizer", "icu_properties", @@ -1205,13 +1217,14 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.9.0" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown 0.15.2", + "hashbrown 0.16.1", "serde", + "serde_core", ] [[package]] @@ -1229,6 +1242,16 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "itertools" version = "0.14.0" @@ -1240,15 +1263,47 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.15" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" dependencies = [ "once_cell", "wasm-bindgen", @@ -1262,9 +1317,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lettre" -version = "0.11.15" +version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759bc2b8eabb6a30b235d6f716f7f36479f4b38cbe65b8747aefee51f89e8437" +checksum = "9e13e10e8818f8b2a60f52cb127041d388b89f3a96a62be9ceaffa22262fef7f" dependencies = [ "async-trait", "base64", @@ -1292,48 +1347,55 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.172" +version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] -name = "libz-rs-sys" -version = "0.5.2" +name = "libredox" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "840db8cf39d9ec4dd794376f38acc40d0fc65eec2a8f484f7fd375b84602becd" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" dependencies = [ - "zlib-rs", + "bitflags", + "libc", + "redox_syscall 0.7.0", ] [[package]] name = "litemap" -version = "0.7.5" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" [[package]] name = "lock_api" -version = "0.4.12" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" dependencies = [ - "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.27" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" [[package]] name = "matchers" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" dependencies = [ - "regex-automata 0.1.10", + "regex-automata", ] [[package]] @@ -1354,9 +1416,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "mime" @@ -1376,9 +1438,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" dependencies = [ "adler2", "simd-adler32", @@ -1386,13 +1448,13 @@ dependencies = [ [[package]] name = "mio" -version = "1.0.3" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" dependencies = [ "libc", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.52.0", + "wasi", + "windows-sys 0.61.2", ] [[package]] @@ -1412,12 +1474,11 @@ checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" [[package]] name = "nu-ansi-term" -version = "0.46.0" +version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "overload", - "winapi", + "windows-sys 0.61.2", ] [[package]] @@ -1437,9 +1498,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" dependencies = [ "hermit-abi", "libc", @@ -1447,9 +1508,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.7" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -1467,16 +1528,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] -name = "overload" -version = "0.1.1" +name = "openssl-probe" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +checksum = "9f50d9b3dabb09ecd771ad0aa242ca6894994c130308ca3d7684634df8037391" [[package]] name = "parking_lot" -version = "0.12.3" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" dependencies = [ "lock_api", "parking_lot_core", @@ -1484,22 +1545,22 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.10" +version = "0.9.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.18", "smallvec", - "windows-targets 0.52.6", + "windows-link", ] [[package]] name = "password-hash" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" dependencies = [ "base64ct", "rand_core 0.6.4", @@ -1514,24 +1575,25 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "percent-encoding" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "phf" -version = "0.11.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" +checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" dependencies = [ "phf_shared", + "serde", ] [[package]] name = "phf_shared" -version = "0.11.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" dependencies = [ "siphasher", ] @@ -1582,15 +1644,15 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.11.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" +checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" [[package]] name = "postgres-protocol" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ff0abab4a9b844b93ef7b81f1efc0a366062aaef2cd702c76256b5dc075c54" +checksum = "fbef655056b916eb868048276cfd5d6a7dea4f81560dfd047f97c8c6fe3fcfd4" dependencies = [ "base64", "byteorder", @@ -1599,22 +1661,31 @@ dependencies = [ "hmac", "md-5", "memchr", - "rand 0.9.0", + "rand 0.9.2", "sha2", "stringprep", ] [[package]] name = "postgres-types" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613283563cd90e1dfc3518d548caee47e0e725455ed619881f5cf21f36de4b48" +checksum = "ef4605b7c057056dd35baeb6ac0c0338e4975b1f2bef0f65da953285eb007095" dependencies = [ "bytes", "fallible-iterator", "postgres-protocol", ] +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -1627,47 +1698,48 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ - "zerocopy 0.8.24", + "zerocopy", ] [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" dependencies = [ "unicode-ident", ] [[package]] name = "psm" -version = "0.1.25" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f58e5423e24c18cc840e1c98370b3993c6649cd1678b4d24318bcf0a083cbe88" +checksum = "d11f2fedc3b7dafdc2851bc52f277377c5473d378859be234bc7ebb593144d01" dependencies = [ + "ar_archive_writer", "cc", ] [[package]] name = "quanta" -version = "0.12.5" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bd1fe6824cea6538803de3ff1bc0cf3949024db3d43c9643024bfb33a807c0e" +checksum = "f3ab5a9d756f0d97bdc89019bd2e4ea098cf9cde50ee7564dde6b81ccc8f06c7" dependencies = [ "crossbeam-utils", "libc", "once_cell", "raw-cpuid", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "web-sys", "winapi", ] [[package]] name = "quinn" -version = "0.11.7" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3bd15a6f2967aef83887dcb9fec0014580467e33720d073560cf015a5683012" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" dependencies = [ "bytes", "cfg_aliases", @@ -1677,7 +1749,7 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror", + "thiserror 2.0.17", "tokio", "tracing", "web-time", @@ -1685,19 +1757,21 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.11" +version = "0.11.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcbafbbdbb0f638fe3f35f3c56739f77a8a1d070cb25603226c83339b391472b" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" dependencies = [ + "aws-lc-rs", "bytes", - "getrandom 0.3.2", - "rand 0.9.0", + "getrandom 0.3.4", + "lru-slab", + "rand 0.9.2", "ring", "rustc-hash", "rustls", "rustls-pki-types", "slab", - "thiserror", + "thiserror 2.0.17", "tinyvec", "tracing", "web-time", @@ -1705,23 +1779,23 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.12" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee4e529991f949c5e25755532370b8af5d114acae52326361d68d47af64aa842" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" dependencies = [ "cfg_aliases", "libc", "once_cell", "socket2", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "quote" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" dependencies = [ "proc-macro2", ] @@ -1734,9 +1808,9 @@ checksum = "640c9bd8497b02465aeef5375144c26062e0dcd5939dfcbb0f5db76cb8c17c73" [[package]] name = "r-efi" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" @@ -1751,13 +1825,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha 0.9.0", - "rand_core 0.9.3", - "zerocopy 0.8.24", + "rand_core 0.9.5", ] [[package]] @@ -1777,7 +1850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core 0.9.3", + "rand_core 0.9.5", ] [[package]] @@ -1786,91 +1859,84 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.17", ] [[package]] name = "rand_core" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.4", ] [[package]] name = "raw-cpuid" -version = "11.5.0" +version = "11.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6df7ab838ed27997ba19a4664507e6f82b41fe6e20be42929332156e5e85146" +checksum = "498cd0dc59d73224351ee52a95fee0f1a617a2eae0e7d9d720cc622c73a54186" dependencies = [ "bitflags", ] [[package]] name = "redox_syscall" -version = "0.5.11" +version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ "bitflags", ] [[package]] -name = "regex" -version = "1.11.1" +name = "redox_syscall" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" dependencies = [ - "aho-corasick", - "memchr", - "regex-automata 0.4.9", - "regex-syntax 0.8.5", + "bitflags", ] [[package]] -name = "regex-automata" -version = "0.1.10" +name = "regex" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ - "regex-syntax 0.6.29", + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", ] [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.5", + "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - -[[package]] -name = "regex-syntax" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "reqwest" -version = "0.12.15" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d19c46a6fdd48bc4dab94b6103fccc55d34c67cc0ad04653aad4ea2a07cd7bbb" +checksum = "04e9018c9d814e5f30cc16a0f03271aeab3571e609612d9fe78c1aa8d11c2f62" dependencies = [ "base64", "bytes", "encoding_rs", "futures-core", - "futures-util", "h2", "http", "http-body", @@ -1878,32 +1944,28 @@ dependencies = [ "hyper", "hyper-rustls", "hyper-util", - "ipnet", "js-sys", "log", "mime", - "once_cell", "percent-encoding", "pin-project-lite", "quinn", "rustls", - "rustls-pemfile", "rustls-pki-types", + "rustls-platform-verifier", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", "tokio-rustls", "tower", + "tower-http", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", - "windows-registry", ] [[package]] @@ -1914,7 +1976,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.15", + "getrandom 0.2.17", "libc", "untrusted", "windows-sys 0.52.0", @@ -1922,9 +1984,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "8.8.0" +version = "8.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb44e1917075637ee8c7bcb865cf8830e3a92b5b1189e44e3a0ab5a0d5be314b" +checksum = "947d7f3fad52b283d261c4c99a084937e2fe492248cb9a68a8435a861b8798ca" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -1933,9 +1995,9 @@ dependencies = [ [[package]] name = "rust-embed-impl" -version = "8.8.0" +version = "8.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "382499b49db77a7c19abd2a574f85ada7e9dbe125d5d1160fa5cad7c4cf71fc9" +checksum = "5fa2c8c9e8711e10f9c4fd2d64317ef13feaab820a4c51541f1a8c8e2e851ab2" dependencies = [ "proc-macro2", "quote", @@ -1946,20 +2008,14 @@ dependencies = [ [[package]] name = "rust-embed-utils" -version = "8.8.0" +version = "8.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21fcbee55c2458836bcdbfffb6ec9ba74bbc23ca7aa6816015a3dd2c4d8fc185" +checksum = "60b161f275cb337fe0a44d924a5f4df0ed69c2c39519858f931ce61c779d3475" dependencies = [ "sha2", "walkdir", ] -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - [[package]] name = "rustc-hash" version = "2.1.1" @@ -1968,10 +2024,11 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustls" -version = "0.23.26" +version = "0.23.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df51b5869f3a441595eac5e8ff14d486ff285f7b8c0df8770e49c3b56351f0f0" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" dependencies = [ + "aws-lc-rs", "log", "once_cell", "ring", @@ -1982,29 +2039,61 @@ dependencies = [ ] [[package]] -name = "rustls-pemfile" -version = "2.2.0" +name = "rustls-native-certs" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" dependencies = [ + "openssl-probe", "rustls-pki-types", + "schannel", + "security-framework", ] [[package]] name = "rustls-pki-types" -version = "1.11.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282" dependencies = [ "web-time", + "zeroize", ] +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + [[package]] name = "rustls-webpki" -version = "0.103.1" +version = "0.103.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03" +checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" dependencies = [ + "aws-lc-rs", "ring", "rustls-pki-types", "untrusted", @@ -2012,15 +2101,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" [[package]] name = "same-file" @@ -2031,6 +2120,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "scoped-futures" version = "0.1.4" @@ -2046,20 +2144,53 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -2068,33 +2199,35 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", - "ryu", "serde", + "serde_core", + "zmij", ] [[package]] name = "serde_path_to_error" -version = "0.1.17" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" dependencies = [ "itoa", "serde", + "serde_core", ] [[package]] name = "serde_spanned" -version = "0.6.8" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" dependencies = [ - "serde", + "serde_core", ] [[package]] @@ -2111,9 +2244,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures", @@ -2137,9 +2270,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "simd-adler32" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" [[package]] name = "siphasher" @@ -2149,27 +2282,24 @@ checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slab" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" [[package]] name = "smallvec" -version = "1.15.0" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "socket2" -version = "0.5.9" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" +checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -2183,15 +2313,15 @@ dependencies = [ [[package]] name = "stable_deref_trait" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "stacker" -version = "0.1.20" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601f9201feb9b09c00266478bf459952b9ef9a6b94edb2f21eba14ab681a60a9" +checksum = "e1f8b29fb42aafcea4edeeb6b2f2d7ecd0d969c48b4cf0d2e64aafc471dd6e59" dependencies = [ "cc", "cfg-if", @@ -2225,9 +2355,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.100" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -2245,36 +2375,15 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "testaustime" version = "0.3.1" @@ -2295,13 +2404,13 @@ dependencies = [ "itertools", "lettre", "mime", - "rand 0.9.0", + "rand 0.9.2", "regex", "reqwest", "serde", "serde_derive", "serde_json", - "thiserror", + "thiserror 2.0.17", "tokio", "toml", "tower", @@ -2317,18 +2426,38 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.12" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl 2.0.17", ] [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", @@ -2337,40 +2466,39 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" dependencies = [ "cfg-if", - "once_cell", ] [[package]] name = "time" -version = "0.3.41" +version = "0.3.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +checksum = "f9e442fc33d7fdb45aa9bfeb312c095964abdf596f7567261062b2a7107aaabd" dependencies = [ "deranged", "itoa", "num-conv", "powerfmt", - "serde", + "serde_core", "time-core", "time-macros", ] [[package]] name = "time-core" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" +checksum = "8b36ee98fd31ec7426d599183e8fe26932a8dc1fb76ddb6214d05493377d34ca" [[package]] name = "time-macros" -version = "0.2.22" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +checksum = "71e552d1249bf61ac2a52db88179fd0673def1e1ad8243a00d9ec9ed71fee3dd" dependencies = [ "num-conv", "time-core", @@ -2378,9 +2506,9 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.7.6" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" dependencies = [ "displaydoc", "zerovec", @@ -2388,9 +2516,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" dependencies = [ "tinyvec_macros", ] @@ -2403,25 +2531,24 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.44.2" +version = "1.49.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" dependencies = [ - "backtrace", "bytes", "libc", "mio", "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] name = "tokio-macros" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" dependencies = [ "proc-macro2", "quote", @@ -2430,9 +2557,9 @@ dependencies = [ [[package]] name = "tokio-postgres" -version = "0.7.13" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c95d533c83082bb6490e0189acaa0bbeef9084e60471b696ca6988cd0541fb0" +checksum = "2b40d66d9b2cfe04b628173409368e58247e8eddbbd3b0e6c6ba1d09f20f6c9e" dependencies = [ "async-trait", "byteorder", @@ -2447,7 +2574,7 @@ dependencies = [ "pin-project-lite", "postgres-protocol", "postgres-types", - "rand 0.9.0", + "rand 0.9.2", "socket2", "tokio", "tokio-util", @@ -2456,9 +2583,9 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.26.2" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" dependencies = [ "rustls", "tokio", @@ -2466,9 +2593,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.14" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" dependencies = [ "bytes", "futures-core", @@ -2479,43 +2606,48 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.20" +version = "0.9.11+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" +checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46" dependencies = [ - "serde", + "indexmap", + "serde_core", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_parser", + "toml_writer", + "winnow", ] [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.7.5+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" dependencies = [ - "serde", + "serde_core", ] [[package]] -name = "toml_edit" -version = "0.22.24" +name = "toml_parser" +version = "1.0.6+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" +checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44" dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", "winnow", ] +[[package]] +name = "toml_writer" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" + [[package]] name = "tower" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" dependencies = [ "futures-core", "futures-util", @@ -2529,15 +2661,18 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.2" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" dependencies = [ "bitflags", "bytes", + "futures-util", "http", "http-body", + "iri-string", "pin-project-lite", + "tower", "tower-layer", "tower-service", "tracing", @@ -2557,9 +2692,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.41" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "log", "pin-project-lite", @@ -2569,9 +2704,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.28" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", @@ -2580,9 +2715,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.33" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" dependencies = [ "once_cell", "valuable", @@ -2611,14 +2746,14 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" dependencies = [ "matchers", "nu-ansi-term", "once_cell", - "regex", + "regex-automata", "sharded-slab", "smallvec", "thread_local", @@ -2635,15 +2770,15 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" [[package]] name = "unicase" -version = "2.8.1" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" [[package]] name = "unicode-bidi" @@ -2653,24 +2788,24 @@ checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "unicode-normalization" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" dependencies = [ "tinyvec", ] [[package]] name = "unicode-properties" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" [[package]] name = "universal-hash" @@ -2690,21 +2825,16 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.4" +version = "2.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] -[[package]] -name = "utf16_iter" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" - [[package]] name = "utf8_iter" version = "1.0.4" @@ -2806,17 +2936,17 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] -name = "wasi" -version = "0.14.2+wasi-0.2.4" +name = "wasip2" +version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ - "wit-bindgen-rt", + "wit-bindgen", ] [[package]] @@ -2827,35 +2957,22 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.50" +version = "0.4.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c" dependencies = [ "cfg-if", "js-sys", @@ -2866,9 +2983,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2876,31 +2993,31 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" dependencies = [ + "bumpalo", "proc-macro2", "quote", "syn", - "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" dependencies = [ "unicode-ident", ] [[package]] name = "web-sys" -version = "0.3.77" +version = "0.3.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac" dependencies = [ "js-sys", "wasm-bindgen", @@ -2916,22 +3033,31 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-root-certs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36a29fc0408b113f68cf32637857ab740edfafdf460c326cd2afaa2d84cc05dc" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "webpki-roots" -version = "0.26.10" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37493cadf42a2a939ed404698ded7fb378bf301b5011f973361779a3a74f8c93" +checksum = "12bed680863276c63889429bfd6cab3b99943659923822de1c8a39c49e4d722c" dependencies = [ "rustls-pki-types", ] [[package]] name = "whoami" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6994d13118ab492c3c80c1f81928718159254c53c472bf9ce36f8dae4add02a7" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" dependencies = [ - "redox_syscall", + "libredox", "wasite", "web-sys", ] @@ -2958,7 +3084,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -2969,22 +3095,22 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-core" -version = "0.61.0" +version = "0.62.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" dependencies = [ "windows-implement", "windows-interface", "windows-link", "windows-result", - "windows-strings 0.4.0", + "windows-strings", ] [[package]] name = "windows-implement" -version = "0.60.0" +version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", @@ -2993,9 +3119,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.59.1" +version = "0.59.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", @@ -3004,46 +3130,35 @@ dependencies = [ [[package]] name = "windows-link" -version = "0.1.1" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" - -[[package]] -name = "windows-registry" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" -dependencies = [ - "windows-result", - "windows-strings 0.3.1", - "windows-targets 0.53.0", -] +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-result" -version = "0.3.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" dependencies = [ "windows-link", ] [[package]] name = "windows-strings" -version = "0.3.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" dependencies = [ "windows-link", ] [[package]] -name = "windows-strings" -version = "0.4.0" +name = "windows-sys" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-link", + "windows-targets 0.42.2", ] [[package]] @@ -3064,6 +3179,39 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -3082,20 +3230,27 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.53.0" +version = "0.53.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ - "windows_aarch64_gnullvm 0.53.0", - "windows_aarch64_msvc 0.53.0", - "windows_i686_gnu 0.53.0", - "windows_i686_gnullvm 0.53.0", - "windows_i686_msvc 0.53.0", - "windows_x86_64_gnu 0.53.0", - "windows_x86_64_gnullvm 0.53.0", - "windows_x86_64_msvc 0.53.0", + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" @@ -3104,9 +3259,15 @@ checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_gnullvm" -version = "0.53.0" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_aarch64_msvc" @@ -3116,9 +3277,15 @@ checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_aarch64_msvc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_gnu" @@ -3128,9 +3295,9 @@ checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnu" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" [[package]] name = "windows_i686_gnullvm" @@ -3140,9 +3307,15 @@ checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_gnullvm" -version = "0.53.0" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_i686_msvc" @@ -3152,9 +3325,15 @@ checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_i686_msvc" -version = "0.53.0" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnu" @@ -3164,9 +3343,15 @@ checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnu" -version = "0.53.0" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_gnullvm" @@ -3176,59 +3361,52 @@ checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_gnullvm" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" [[package]] name = "windows_x86_64_msvc" -version = "0.52.6" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" -version = "0.53.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] -name = "winnow" -version = "0.7.6" +name = "windows_x86_64_msvc" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63d3fcd9bba44b03821e7d699eeee959f3126dcc4aa8e4ae18ec617c2a5cea10" -dependencies = [ - "memchr", -] +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] -name = "wit-bindgen-rt" -version = "0.39.0" +name = "winnow" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" -dependencies = [ - "bitflags", -] +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" [[package]] -name = "write16" -version = "1.0.0" +name = "wit-bindgen" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" [[package]] name = "writeable" -version = "0.5.5" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" [[package]] name = "yoke" -version = "0.7.5" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" dependencies = [ - "serde", "stable_deref_trait", "yoke-derive", "zerofrom", @@ -3236,9 +3414,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.5" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" dependencies = [ "proc-macro2", "quote", @@ -3248,38 +3426,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.35" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" dependencies = [ - "zerocopy-derive 0.7.35", -] - -[[package]] -name = "zerocopy" -version = "0.8.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" -dependencies = [ - "zerocopy-derive 0.8.24", + "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.35" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" dependencies = [ "proc-macro2", "quote", @@ -3309,15 +3467,26 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.8.1" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] [[package]] name = "zerovec" -version = "0.10.4" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" dependencies = [ "yoke", "zerofrom", @@ -3326,9 +3495,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.10.3" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" dependencies = [ "proc-macro2", "quote", @@ -3351,15 +3520,21 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.5.2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" + +[[package]] +name = "zmij" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f06ae92f42f5e5c42443fd094f245eb656abf56dd7cce9b8b263236565e00f2" +checksum = "bd8f3f50b848df28f887acb68e41201b5aea6bc8a8dacc00fb40635ff9a72fea" [[package]] name = "zopfli" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfc5ee405f504cd4984ecc6f14d02d55cfda60fa4b689434ef4102aae150cd7" +checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" dependencies = [ "bumpalo", "crc32fast", diff --git a/Cargo.toml b/Cargo.toml index 582cb4f..fa483e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,14 +17,14 @@ lto = true [dependencies] axum = { version = "0.8", features = ["macros", "tokio"] } -axum-extra = { version = "0.10", features = ["cookie", "cookie-private"] } +axum-extra = { version = "0.12", features = ["cookie", "cookie-private"] } tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] } -reqwest = { version = "0.12", optional = true, default-features = false, features = [ +reqwest = { version = "0.13", optional = true, default-features = false, features = [ "json", - "rustls-tls", + "rustls", "charset", "http2", - "macos-system-configuration", + "form" ] } http = "1.0" http-body-util = "0.1" @@ -46,12 +46,12 @@ serde = { version = "1.0.164", features = ["derive"] } serde_json = "1.0" serde_derive = "1.0" -toml = "0.8" +toml = "0.9" futures = "0.3" futures-util = "0.3" chrono = { version = "0.4", features = ["serde"] } dashmap = "6.1" -argon2 = { version = "0.4", features = ["std"] } +argon2 = { version = "0.5", features = ["std"] } rand = "0.9" dotenv = "0.15" url = "2.2" @@ -59,7 +59,7 @@ url = "2.2" itertools = "0.14" governor = "0.10.0" diesel = { version = "2.1.0", features = ["chrono", "serde_json"] } -diesel-async = { version = "0.5.1", features = ["postgres", "deadpool"] } +diesel-async = { version = "0.7", features = ["postgres", "deadpool"] } lettre = { version = "0.11.14", default-features = false, features = [ "tokio1-rustls-tls", "tracing", diff --git a/src/database/auth.rs b/src/database/auth.rs index 292d1a8..316821d 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -1,6 +1,5 @@ use argon2::{ - Argon2, - password_hash::{PasswordHasher, SaltString, rand_core::OsRng}, + Algorithm, Argon2, Params, Version, password_hash::{PasswordHasher, SaltString, rand_core::OsRng} }; use diesel::prelude::*; use diesel_async::RunQueryDsl; @@ -62,8 +61,15 @@ impl super::DatabaseWrapper { .first::<(UserIdentity, TestaustimeUser)>(&mut conn) .await?; - let argon2 = Argon2::default(); - let salt = SaltString::new(std::str::from_utf8(&tuser.salt).expect("Infallible"))?; + let argon2 = Argon2::new( + Algorithm::Argon2id, Version::V0x13, Params::new( + 4096, + 3, + 1, + None, + ).unwrap() + ); + let salt = SaltString::from_b64(std::str::from_utf8(&tuser.salt).expect("Infallible"))?; let password_hash = argon2.hash_password(password.as_bytes(), &salt)?; @@ -102,7 +108,14 @@ impl super::DatabaseWrapper { return Err(TimeError::UsernameTaken); } let salt = SaltString::generate(&mut OsRng); - let argon2 = Argon2::default(); + let argon2 = Argon2::new( + Algorithm::Argon2id, Version::V0x13, Params::new( + 4096, + 3, + 1, + None, + ).unwrap() + ); let password_hash = argon2.hash_password(password.as_bytes(), &salt).unwrap(); let token = generate_auth_token(); let hash = password_hash.hash.unwrap(); @@ -132,7 +145,7 @@ impl super::DatabaseWrapper { let testaustime_user = NewTestaustimeUser { password: hash.as_bytes().to_vec(), - salt: salt.as_bytes().to_vec(), + salt: salt.as_str().as_bytes().to_vec(), identity: id[0], }; @@ -179,7 +192,15 @@ impl super::DatabaseWrapper { pub async fn change_password(&self, user: i32, new_password: &str) -> Result<(), TimeError> { let new_salt = SaltString::generate(&mut OsRng); - let argon2 = Argon2::default(); + let argon2 = Argon2::new( + Algorithm::Argon2id, Version::V0x13, Params::new( + 4096, + 3, + 1, + None, + ).unwrap() + ); + let password_hash = argon2 .hash_password(new_password.as_bytes(), &new_salt) .unwrap(); @@ -192,7 +213,7 @@ impl super::DatabaseWrapper { .filter(identity.eq(user)) .set(( password.eq(&new_hash.as_bytes()), - salt.eq(new_salt.as_bytes()), + salt.eq(new_salt.as_str().as_bytes()), )) .execute(&mut conn) .await?; From 910b1d179e9c922eb4761287c957e336ee58b78d Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Wed, 14 Jan 2026 08:33:49 +0200 Subject: [PATCH 26/36] fmt --- src/api/activity.rs | 2 +- src/api/auth.rs | 8 ++++---- src/api/friends.rs | 2 +- src/api/leaderboards.rs | 2 +- src/api/oauth.rs | 2 +- src/api/search.rs | 2 +- src/api/users.rs | 4 ++-- src/auth/mod.rs | 2 +- src/database/activity.rs | 2 +- src/database/auth.rs | 30 +++++++++++------------------- src/database/mod.rs | 6 +++--- src/error.rs | 2 +- src/main.rs | 6 +++--- src/ratelimiter.rs | 6 +++--- src/state.rs | 2 +- src/tests/activity.rs | 5 ++++- src/tests/auth.rs | 24 ++++++++++-------------- src/tests/mod.rs | 2 +- src/utils.rs | 2 +- 19 files changed, 51 insertions(+), 60 deletions(-) diff --git a/src/api/activity.rs b/src/api/activity.rs index c7a4257..8ef8f99 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{Json, extract::State}; +use axum::{extract::State, Json}; use chrono::{Duration, Local}; use dashmap::DashMap; use http::StatusCode; diff --git a/src/api/auth.rs b/src/api/auth.rs index 31e07a8..566ede9 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -1,25 +1,25 @@ use std::sync::Arc; use axum::{ - Json, extract::{FromRequestParts, State}, + Json, }; use chrono::{Duration, Local}; -use http::{StatusCode, request::Parts}; +use http::{request::Parts, StatusCode}; use lettre::{ - AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, message::header::ContentType, + message::header::ContentType, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, }; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::{ - PasswordReset, PasswordResetState, api::users::UserAuthentication, auth::Authentication, database::DatabaseWrapper, error::TimeError, models::{NewUserIdentity, SelfUser, UserId, UserIdentity}, utils::{generate_password_reset_token, validate_email}, + PasswordReset, PasswordResetState, }; impl FromRequestParts for UserId { diff --git a/src/api/friends.rs b/src/api/friends.rs index eb7eae4..27c482b 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{Json, extract::State}; +use axum::{extract::State, Json}; use diesel::result::DatabaseErrorKind; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index cdd3064..31ad4ba 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -1,4 +1,4 @@ -use axum::{Json, extract::Path}; +use axum::{extract::Path, Json}; use diesel::result::{DatabaseErrorKind, Error as DieselError}; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/oauth.rs b/src/api/oauth.rs index 394b83d..882c592 100644 --- a/src/api/oauth.rs +++ b/src/api/oauth.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, sync::LazyLock}; use axum::{extract::Query, response::Redirect}; -use axum_extra::extract::{CookieJar, cookie::Cookie}; +use axum_extra::extract::{cookie::Cookie, CookieJar}; use reqwest::Client; use serde_derive::Deserialize; diff --git a/src/api/search.rs b/src/api/search.rs index 4547a71..8d55e21 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -1,4 +1,4 @@ -use axum::{Json, extract::Query}; +use axum::{extract::Query, Json}; use serde_derive::Deserialize; use utoipa::IntoParams; diff --git a/src/api/users.rs b/src/api/users.rs index a114747..f0d09e7 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -1,10 +1,10 @@ use std::{collections::HashMap, sync::Arc}; use axum::{ - Json, extract::{Path, Query, State}, + Json, }; -use chrono::{DateTime, Duration, Local, Utc, serde::ts_seconds_option}; +use chrono::{serde::ts_seconds_option, DateTime, Duration, Local, Utc}; use http::StatusCode; use serde::Serialize; use serde_derive::Deserialize; diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 9a8a0d5..1309422 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -7,7 +7,7 @@ use axum::extract::Request; use futures_util::future::BoxFuture; use tower::{Layer, Service}; -use crate::{TestaustimeState, database::DatabaseWrapper, models::UserIdentity}; +use crate::{database::DatabaseWrapper, models::UserIdentity, TestaustimeState}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Authentication { diff --git a/src/database/activity.rs b/src/database/activity.rs index 970d401..b1d60ca 100644 --- a/src/database/activity.rs +++ b/src/database/activity.rs @@ -1,4 +1,4 @@ -use chrono::{Duration, prelude::*}; +use chrono::{prelude::*, Duration}; use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/src/database/auth.rs b/src/database/auth.rs index 316821d..33673e6 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -1,5 +1,6 @@ use argon2::{ - Algorithm, Argon2, Params, Version, password_hash::{PasswordHasher, SaltString, rand_core::OsRng} + password_hash::{rand_core::OsRng, PasswordHasher, SaltString}, + Algorithm, Argon2, Params, Version, }; use diesel::prelude::*; use diesel_async::RunQueryDsl; @@ -62,12 +63,9 @@ impl super::DatabaseWrapper { .await?; let argon2 = Argon2::new( - Algorithm::Argon2id, Version::V0x13, Params::new( - 4096, - 3, - 1, - None, - ).unwrap() + Algorithm::Argon2id, + Version::V0x13, + Params::new(4096, 3, 1, None).unwrap(), ); let salt = SaltString::from_b64(std::str::from_utf8(&tuser.salt).expect("Infallible"))?; @@ -109,12 +107,9 @@ impl super::DatabaseWrapper { } let salt = SaltString::generate(&mut OsRng); let argon2 = Argon2::new( - Algorithm::Argon2id, Version::V0x13, Params::new( - 4096, - 3, - 1, - None, - ).unwrap() + Algorithm::Argon2id, + Version::V0x13, + Params::new(4096, 3, 1, None).unwrap(), ); let password_hash = argon2.hash_password(password.as_bytes(), &salt).unwrap(); let token = generate_auth_token(); @@ -193,12 +188,9 @@ impl super::DatabaseWrapper { pub async fn change_password(&self, user: i32, new_password: &str) -> Result<(), TimeError> { let new_salt = SaltString::generate(&mut OsRng); let argon2 = Argon2::new( - Algorithm::Argon2id, Version::V0x13, Params::new( - 4096, - 3, - 1, - None, - ).unwrap() + Algorithm::Argon2id, + Version::V0x13, + Params::new(4096, 3, 1, None).unwrap(), ); let password_hash = argon2 diff --git a/src/database/mod.rs b/src/database/mod.rs index 67dff37..f3a0d9f 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -2,15 +2,15 @@ use std::sync::Arc; use axum::extract::{FromRef, FromRequestParts}; use diesel_async::{ - AsyncPgConnection, pooled_connection::{ - AsyncDieselConnectionManager, deadpool::{Object, Pool}, + AsyncDieselConnectionManager, }, + AsyncPgConnection, }; use http::request::Parts; -use crate::{TestaustimeState, error::TimeError}; +use crate::{error::TimeError, TestaustimeState}; pub mod activity; pub mod auth; diff --git a/src/error.rs b/src/error.rs index 87057d2..1bb22c8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use axum::{ - Json, response::{IntoResponse, Response}, + Json, }; use http::StatusCode; use thiserror::Error; diff --git a/src/main.rs b/src/main.rs index 3ec4de4..b55b110 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,12 +15,12 @@ use std::{net::SocketAddr, num::NonZeroU32, sync::Arc}; use api::activity::HeartBeatMemoryStore; use auth::{AuthMiddleware, Authentication}; -use axum::{Router, body::Body}; +use axum::{body::Body, Router}; use chrono::NaiveDateTime; use dashmap::DashMap; use database::Database; use governor::{Quota, RateLimiter}; -use lettre::{AsyncSmtpTransport, Tokio1Executor, transport::smtp::authentication::Credentials}; +use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor}; use models::UserIdentity; use ratelimiter::TestaustimeRateLimiter; use serde_derive::Deserialize; @@ -28,8 +28,8 @@ use tower::ServiceBuilder; use tower_http::trace::TraceLayer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use utoipa::{ - Modify, OpenApi, openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, + Modify, OpenApi, }; use utoipa_axum::{router::OpenApiRouter, routes}; use utoipa_swagger_ui::SwaggerUi; diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index 43b155a..a97c9e7 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -11,12 +11,12 @@ use axum::{ }; use futures_util::future::BoxFuture; use governor::{ - RateLimiter, clock::DefaultClock, middleware::StateInformationMiddleware, - state::keyed::DefaultKeyedStateStore, + clock::DefaultClock, middleware::StateInformationMiddleware, + state::keyed::DefaultKeyedStateStore, RateLimiter, }; use http::{ + header::{HeaderName, FORWARDED}, HeaderValue, StatusCode, - header::{FORWARDED, HeaderName}, }; use tower::{Layer, Service}; diff --git a/src/state.rs b/src/state.rs index f0dbe9b..121cc2b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,7 +4,7 @@ use axum::extract::FromRef; use lettre::{AsyncSmtpTransport, Tokio1Executor}; use crate::{ - PasswordResetState, RegisterLimiter, TestaustimeState, api::activity::HeartBeatMemoryStore, + api::activity::HeartBeatMemoryStore, PasswordResetState, RegisterLimiter, TestaustimeState, }; impl FromRef for Arc { diff --git a/src/tests/activity.rs b/src/tests/activity.rs index 413a8a4..3a09e71 100644 --- a/src/tests/activity.rs +++ b/src/tests/activity.rs @@ -178,7 +178,10 @@ async fn hidden_project() { ); let data: Vec = body_to_json(resp).await; - assert!(!data.is_empty(), "Session with non-zero duration should be saved"); + assert!( + !data.is_empty(), + "Session with non-zero duration should be saved" + ); // Print the actual value of the project name to see what it is assert!( data[0].get("project_name").unwrap_or(&json!("not_hidden")) == &json!("hidden"), diff --git a/src/tests/auth.rs b/src/tests/auth.rs index 80693d5..e029d9b 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -104,13 +104,11 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!( - resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("username") - ); + assert!(resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("username")); let body = json!({"username": "validusername", "password": "short"}); let resp = request!(app, POST, "/auth/register", body); @@ -120,13 +118,11 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!( - resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("password") - ); + assert!(resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("password")); } // TODO: test ratelimits diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 8670eb6..245df0e 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -9,7 +9,7 @@ mod friends; mod leaderboards; mod macros; -use axum::{Router, body::Body, extract::connect_info::MockConnectInfo, response::Response}; +use axum::{body::Body, extract::connect_info::MockConnectInfo, response::Response, Router}; use http::{Request, StatusCode}; use serde::de::DeserializeOwned; use tower::ServiceExt; diff --git a/src/utils.rs b/src/utils.rs index 8f9fe41..43b23f7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use itertools::Itertools; use lettre::Address; -use rand::{Rng, distr::Alphanumeric, rng}; +use rand::{distr::Alphanumeric, rng, Rng}; use crate::models::CodingActivity; From 0a8e34acc05f21cab3287fc5acc7833d9763ff70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Sat, 31 Jan 2026 21:52:34 +0100 Subject: [PATCH 27/36] fix: fmt --- Cargo.toml | 2 +- src/api/activity.rs | 2 +- src/api/auth.rs | 8 ++++---- src/api/friends.rs | 2 +- src/api/leaderboards.rs | 2 +- src/api/oauth.rs | 2 +- src/api/search.rs | 2 +- src/api/users.rs | 4 ++-- src/auth/mod.rs | 2 +- src/database/activity.rs | 2 +- src/database/auth.rs | 2 +- src/database/mod.rs | 6 +++--- src/error.rs | 2 +- src/main.rs | 6 +++--- src/ratelimiter.rs | 6 +++--- src/state.rs | 2 +- src/tests/auth.rs | 24 ++++++++++++++---------- src/tests/mod.rs | 2 +- src/utils.rs | 2 +- 19 files changed, 42 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa483e7..b733bc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ reqwest = { version = "0.13", optional = true, default-features = false, feature "rustls", "charset", "http2", - "form" + "form", ] } http = "1.0" http-body-util = "0.1" diff --git a/src/api/activity.rs b/src/api/activity.rs index 8ef8f99..c7a4257 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{extract::State, Json}; +use axum::{Json, extract::State}; use chrono::{Duration, Local}; use dashmap::DashMap; use http::StatusCode; diff --git a/src/api/auth.rs b/src/api/auth.rs index 566ede9..31e07a8 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -1,25 +1,25 @@ use std::sync::Arc; use axum::{ - extract::{FromRequestParts, State}, Json, + extract::{FromRequestParts, State}, }; use chrono::{Duration, Local}; -use http::{request::Parts, StatusCode}; +use http::{StatusCode, request::Parts}; use lettre::{ - message::header::ContentType, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, + AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, message::header::ContentType, }; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::{ + PasswordReset, PasswordResetState, api::users::UserAuthentication, auth::Authentication, database::DatabaseWrapper, error::TimeError, models::{NewUserIdentity, SelfUser, UserId, UserIdentity}, utils::{generate_password_reset_token, validate_email}, - PasswordReset, PasswordResetState, }; impl FromRequestParts for UserId { diff --git a/src/api/friends.rs b/src/api/friends.rs index 27c482b..eb7eae4 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{extract::State, Json}; +use axum::{Json, extract::State}; use diesel::result::DatabaseErrorKind; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index 31ad4ba..cdd3064 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -1,4 +1,4 @@ -use axum::{extract::Path, Json}; +use axum::{Json, extract::Path}; use diesel::result::{DatabaseErrorKind, Error as DieselError}; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/oauth.rs b/src/api/oauth.rs index 882c592..394b83d 100644 --- a/src/api/oauth.rs +++ b/src/api/oauth.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, sync::LazyLock}; use axum::{extract::Query, response::Redirect}; -use axum_extra::extract::{cookie::Cookie, CookieJar}; +use axum_extra::extract::{CookieJar, cookie::Cookie}; use reqwest::Client; use serde_derive::Deserialize; diff --git a/src/api/search.rs b/src/api/search.rs index 8d55e21..4547a71 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -1,4 +1,4 @@ -use axum::{extract::Query, Json}; +use axum::{Json, extract::Query}; use serde_derive::Deserialize; use utoipa::IntoParams; diff --git a/src/api/users.rs b/src/api/users.rs index f0d09e7..a114747 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -1,10 +1,10 @@ use std::{collections::HashMap, sync::Arc}; use axum::{ - extract::{Path, Query, State}, Json, + extract::{Path, Query, State}, }; -use chrono::{serde::ts_seconds_option, DateTime, Duration, Local, Utc}; +use chrono::{DateTime, Duration, Local, Utc, serde::ts_seconds_option}; use http::StatusCode; use serde::Serialize; use serde_derive::Deserialize; diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 1309422..9a8a0d5 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -7,7 +7,7 @@ use axum::extract::Request; use futures_util::future::BoxFuture; use tower::{Layer, Service}; -use crate::{database::DatabaseWrapper, models::UserIdentity, TestaustimeState}; +use crate::{TestaustimeState, database::DatabaseWrapper, models::UserIdentity}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Authentication { diff --git a/src/database/activity.rs b/src/database/activity.rs index b1d60ca..970d401 100644 --- a/src/database/activity.rs +++ b/src/database/activity.rs @@ -1,4 +1,4 @@ -use chrono::{prelude::*, Duration}; +use chrono::{Duration, prelude::*}; use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/src/database/auth.rs b/src/database/auth.rs index 33673e6..5b61218 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -1,6 +1,6 @@ use argon2::{ - password_hash::{rand_core::OsRng, PasswordHasher, SaltString}, Algorithm, Argon2, Params, Version, + password_hash::{PasswordHasher, SaltString, rand_core::OsRng}, }; use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/src/database/mod.rs b/src/database/mod.rs index f3a0d9f..67dff37 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -2,15 +2,15 @@ use std::sync::Arc; use axum::extract::{FromRef, FromRequestParts}; use diesel_async::{ + AsyncPgConnection, pooled_connection::{ - deadpool::{Object, Pool}, AsyncDieselConnectionManager, + deadpool::{Object, Pool}, }, - AsyncPgConnection, }; use http::request::Parts; -use crate::{error::TimeError, TestaustimeState}; +use crate::{TestaustimeState, error::TimeError}; pub mod activity; pub mod auth; diff --git a/src/error.rs b/src/error.rs index 1bb22c8..87057d2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use axum::{ - response::{IntoResponse, Response}, Json, + response::{IntoResponse, Response}, }; use http::StatusCode; use thiserror::Error; diff --git a/src/main.rs b/src/main.rs index b55b110..3ec4de4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,12 +15,12 @@ use std::{net::SocketAddr, num::NonZeroU32, sync::Arc}; use api::activity::HeartBeatMemoryStore; use auth::{AuthMiddleware, Authentication}; -use axum::{body::Body, Router}; +use axum::{Router, body::Body}; use chrono::NaiveDateTime; use dashmap::DashMap; use database::Database; use governor::{Quota, RateLimiter}; -use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor}; +use lettre::{AsyncSmtpTransport, Tokio1Executor, transport::smtp::authentication::Credentials}; use models::UserIdentity; use ratelimiter::TestaustimeRateLimiter; use serde_derive::Deserialize; @@ -28,8 +28,8 @@ use tower::ServiceBuilder; use tower_http::trace::TraceLayer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use utoipa::{ - openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, Modify, OpenApi, + openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, }; use utoipa_axum::{router::OpenApiRouter, routes}; use utoipa_swagger_ui::SwaggerUi; diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index a97c9e7..43b155a 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -11,12 +11,12 @@ use axum::{ }; use futures_util::future::BoxFuture; use governor::{ - clock::DefaultClock, middleware::StateInformationMiddleware, - state::keyed::DefaultKeyedStateStore, RateLimiter, + RateLimiter, clock::DefaultClock, middleware::StateInformationMiddleware, + state::keyed::DefaultKeyedStateStore, }; use http::{ - header::{HeaderName, FORWARDED}, HeaderValue, StatusCode, + header::{FORWARDED, HeaderName}, }; use tower::{Layer, Service}; diff --git a/src/state.rs b/src/state.rs index 121cc2b..f0dbe9b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,7 +4,7 @@ use axum::extract::FromRef; use lettre::{AsyncSmtpTransport, Tokio1Executor}; use crate::{ - api::activity::HeartBeatMemoryStore, PasswordResetState, RegisterLimiter, TestaustimeState, + PasswordResetState, RegisterLimiter, TestaustimeState, api::activity::HeartBeatMemoryStore, }; impl FromRef for Arc { diff --git a/src/tests/auth.rs b/src/tests/auth.rs index e029d9b..80693d5 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -104,11 +104,13 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!(resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("username")); + assert!( + resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("username") + ); let body = json!({"username": "validusername", "password": "short"}); let resp = request!(app, POST, "/auth/register", body); @@ -118,11 +120,13 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!(resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("password")); + assert!( + resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("password") + ); } // TODO: test ratelimits diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 245df0e..8670eb6 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -9,7 +9,7 @@ mod friends; mod leaderboards; mod macros; -use axum::{body::Body, extract::connect_info::MockConnectInfo, response::Response, Router}; +use axum::{Router, body::Body, extract::connect_info::MockConnectInfo, response::Response}; use http::{Request, StatusCode}; use serde::de::DeserializeOwned; use tower::ServiceExt; diff --git a/src/utils.rs b/src/utils.rs index 43b23f7..8f9fe41 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use itertools::Itertools; use lettre::Address; -use rand::{distr::Alphanumeric, rng, Rng}; +use rand::{Rng, distr::Alphanumeric, rng}; use crate::models::CodingActivity; From 0d782e9fefbd30b8f71d89510e867d29d88e53dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Sat, 31 Jan 2026 22:51:06 +0100 Subject: [PATCH 28/36] docs: vastly improve api documentation --- src/api/account.rs | 9 ++++- src/api/activity.rs | 51 ++++++++++++++++++++++--- src/api/auth.rs | 82 +++++++++++++++++++++++++++++++++++++---- src/api/friends.rs | 35 ++++++++++++++++-- src/api/leaderboards.rs | 81 +++++++++++++++++++++++++++++++++++----- src/api/mod.rs | 8 ++-- src/api/oauth.rs | 7 +++- src/api/search.rs | 6 ++- src/api/stats.rs | 8 +++- src/api/users.rs | 68 +++++++++++++++++++++++++++++----- src/main.rs | 3 ++ src/models.rs | 61 ++++++++++++++++++++++++++++++ 12 files changed, 376 insertions(+), 43 deletions(-) diff --git a/src/api/account.rs b/src/api/account.rs index dfb644f..a4c9b88 100644 --- a/src/api/account.rs +++ b/src/api/account.rs @@ -5,19 +5,26 @@ use utoipa::ToSchema; use crate::{database::DatabaseWrapper, error::TimeError, models::UserIdentity}; +/// Request body for updating account settings. #[derive(Deserialize, ToSchema)] pub struct Settings { + /// Whether the user's profile should be publicly visible. public_profile: Option, } +/// Update account settings. +/// +/// Currently supports toggling public profile visibility. #[utoipa::path( post, path = "/account/settings", + request_body = Settings, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Settings updated"), + (status = 401, description = "Unauthorized"), ) )] pub async fn change_settings( diff --git a/src/api/activity.rs b/src/api/activity.rs index c7a4257..72343e4 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -15,19 +15,28 @@ use crate::{ pub type HeartBeatMemoryStore = DashMap; +/// Response from heartbeat update. #[derive(Serialize, ToSchema)] pub struct UpdateResponse { + /// Duration of the current coding session in seconds. duration: i64, } +/// Send a heartbeat to track coding activity. +/// +/// Editor extensions send heartbeats periodically to track coding sessions. +/// Returns the duration of the current session. #[utoipa::path( post, path = "/activity/update", + request_body = HeartBeat, security( ("api_key" = []) ), responses( - (status = OK, body = UpdateResponse) + (status = OK, description = "Heartbeat recorded", body = UpdateResponse), + (status = 400, description = "Field exceeds maximum length"), + (status = 401, description = "Unauthorized"), ) )] pub async fn update( @@ -124,6 +133,9 @@ pub async fn update( } } +/// Flush current activity session to database. +/// +/// Forces the current in-memory activity session to be saved to the database. #[utoipa::path( post, path = "/activity/flush", @@ -131,7 +143,8 @@ pub async fn update( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Activity flushed to database"), + (status = 401, description = "Unauthorized"), ) )] pub async fn flush( @@ -151,19 +164,27 @@ pub async fn flush( Ok(StatusCode::OK) } +/// Request body for deleting a coding activity. #[derive(Deserialize, ToSchema)] pub struct ActivityDeleteRequest { + /// The ID of the activity to delete. id: i32, } +/// Delete a specific coding activity. +/// +/// Permanently removes an activity entry by its ID. #[utoipa::path( delete, path = "/activity/delete", + request_body = ActivityDeleteRequest, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Activity deleted"), + (status = 400, description = "Invalid activity ID"), + (status = 401, description = "Unauthorized"), ) )] pub async fn delete( @@ -179,25 +200,35 @@ pub async fn delete( } } +/// Request body for renaming a project. #[derive(Deserialize, ToSchema)] pub struct ActivityRenameRequest { + /// The current project name to rename. from: String, + /// The new project name. to: String, } +/// Response from project rename operation. #[derive(Serialize, ToSchema)] pub struct ActivityRenameResponse { + /// Number of activities that were updated. affected_activities: usize, } +/// Rename a project across all activities. +/// +/// Updates all activities with the source project name to use the new name. #[utoipa::path( post, path = "/activity/rename", + request_body = ActivityRenameRequest, security( ("api_key" = []) ), responses( - (status = OK, body = ActivityRenameResponse) + (status = OK, description = "Project renamed", body = ActivityRenameResponse), + (status = 401, description = "Unauthorized"), ) )] pub async fn rename_project( @@ -212,25 +243,35 @@ pub async fn rename_project( })) } +/// Request body for setting project visibility. #[derive(Deserialize, ToSchema)] pub struct HideRequest { + /// The project name to modify. target_project: String, + /// Whether the project should be hidden from friends and public view. hidden: bool, } +/// Response from project visibility change. #[derive(Serialize, ToSchema)] pub struct HideResponse { + /// Number of activities that were updated. affected_activities: usize, } +/// Set project visibility in activities. +/// +/// Marks all activities for a project as hidden or visible to friends and public profiles. #[utoipa::path( post, path = "/activity/hide", + request_body = HideRequest, security( ("api_key" = []) ), responses( - (status = OK, body = HideResponse) + (status = OK, description = "Project visibility updated", body = HideResponse), + (status = 401, description = "Unauthorized"), ) )] pub async fn hide_project( diff --git a/src/api/auth.rs b/src/api/auth.rs index 31e07a8..72ae368 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -73,17 +73,26 @@ where } } +/// Request body for user login. #[derive(Deserialize, Debug, ToSchema)] pub struct LoginRequest { + /// The user's username. pub username: String, + /// The user's password. pub password: String, } +/// Authenticate user with username and password. +/// +/// Returns the user's profile including their authentication token on successful login. #[utoipa::path( post, path = "/auth/login", + request_body = LoginRequest, responses( - (status = OK, body = SelfUser), + (status = OK, description = "Successfully authenticated", body = SelfUser), + (status = 400, description = "Password too long"), + (status = 401, description = "Invalid credentials"), ) )] pub async fn login( @@ -104,18 +113,28 @@ pub async fn login( } } +/// Request body for user registration. #[derive(Deserialize, Debug, ToSchema)] pub struct RegisterRequest { + /// Desired username (2-32 alphanumeric characters). pub username: String, + /// Optional email address for account recovery. pub email: Option, + /// Password (8-128 characters). pub password: String, } +/// Create a new Testaustime account. +/// +/// Username must be 2-32 alphanumeric characters. Password must be 8-128 characters. #[utoipa::path( post, path = "/auth/register", + request_body = RegisterRequest, responses( - (status = OK, body = NewUserIdentity) + (status = OK, description = "Account created successfully", body = NewUserIdentity), + (status = 400, description = "Invalid username or password length"), + (status = 409, description = "Username already taken"), ) )] pub async fn register( @@ -147,16 +166,23 @@ pub async fn register( Ok(Json(res)) } +/// Response containing the newly generated authentication token. #[derive(Serialize, ToSchema)] pub struct RegenerateResponse { + /// The new authentication token. pub token: String, } +/// Generate a new authentication token. +/// +/// Requires username and password verification. Invalidates the previous token. #[utoipa::path( post, path = "/auth/regenerate", + request_body = UserAuthentication, responses( - (status = OK, body = RegenerateResponse) + (status = OK, description = "New token generated", body = RegenerateResponse), + (status = 401, description = "Invalid credentials"), ) )] pub async fn regenerate_auth_token( @@ -176,19 +202,28 @@ pub async fn regenerate_auth_token( } } +/// Request body for changing username. #[derive(Deserialize, ToSchema)] pub struct UsernameChangeRequest { + /// The new username (2-32 alphanumeric characters). pub new: String, } +/// Update the authenticated user's username. +/// +/// New username must be 2-32 alphanumeric characters and not already taken. #[utoipa::path( post, path = "/auth/change-username", + request_body = UsernameChangeRequest, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Username changed successfully"), + (status = 400, description = "Invalid username format or length"), + (status = 401, description = "Unauthorized"), + (status = 409, description = "Username already taken"), ) )] pub async fn change_username( @@ -215,19 +250,26 @@ pub async fn change_username( result.map(|_| StatusCode::OK) } +/// Request body for changing email address. #[derive(Deserialize, ToSchema)] pub struct EmailChangeRequest { + /// The new email address. pub new: String, } +/// Update the authenticated user's email address. #[utoipa::path( post, path = "/auth/change-email", + request_body = EmailChangeRequest, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Email changed successfully"), + (status = 400, description = "Invalid email format"), + (status = 401, description = "Unauthorized"), + (status = 409, description = "Email already taken"), ) )] pub async fn change_email( @@ -248,20 +290,29 @@ pub async fn change_email( result.map(|_| StatusCode::OK) } +/// Request body for changing password. #[derive(Deserialize, ToSchema)] pub struct PasswordChangeRequest { + /// The current password for verification. pub old: String, + /// The new password (8-128 characters). pub new: String, } +/// Update the authenticated user's password. +/// +/// Requires the current password for verification. New password must be 8-128 characters. #[utoipa::path( post, path = "/auth/change-password", + request_body = PasswordChangeRequest, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Password changed successfully"), + (status = 400, description = "Invalid password length"), + (status = 401, description = "Unauthorized or incorrect current password"), ) )] pub async fn change_password( @@ -286,16 +337,23 @@ pub async fn change_password( } } +/// Request body for initiating password reset. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct PasswordResetRequest { + /// The email address associated with the account. pub email: String, } +/// Request a password reset email. +/// +/// Sends a password reset link to the user's email if the account exists. +/// Always returns OK to prevent email enumeration. #[utoipa::path( post, path = "/auth/reset-password", + request_body = PasswordResetRequest, responses( - (status = OK) + (status = OK, description = "Password reset email sent if account exists"), ) )] pub async fn request_password_reset( @@ -340,17 +398,25 @@ pub async fn request_password_reset( Ok(StatusCode::OK) } +/// Request body for completing password reset. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct PasswordResetCompletionRequest { + /// The new password to set. password: String, + /// The reset token received via email. token: String, } +/// Complete password reset with token. +/// +/// Completes the password reset process using the token from the reset email. #[utoipa::path( post, path = "/auth/complete-password-reset", + request_body = PasswordResetCompletionRequest, responses( - (status = OK) + (status = OK, description = "Password reset successfully"), + (status = 400, description = "Invalid or expired token"), ) )] pub async fn reset_password( diff --git a/src/api/friends.rs b/src/api/friends.rs index eb7eae4..3ff5934 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -13,19 +13,28 @@ use crate::{ models::{CurrentActivity, FriendWithTimeAndStatus, UserId, UserIdentity}, }; +/// Request body for adding a friend. #[derive(Deserialize, Debug, ToSchema)] pub struct FriendRequest { + /// The friend code (starts with ttfc_). pub code: String, } +/// Add a friend using their friend code. +/// +/// Friend codes start with `ttfc_`. Returns the friend's profile with coding stats. #[utoipa::path( post, path = "/friends/add", + request_body = FriendRequest, security( ("api_key" = []) ), responses( - (status = OK, body = FriendWithTimeAndStatus) + (status = OK, description = "Friend added successfully", body = FriendWithTimeAndStatus), + (status = 400, description = "Invalid friend code"), + (status = 401, description = "Unauthorized"), + (status = 409, description = "Already friends"), ) )] pub async fn add_friend( @@ -72,6 +81,9 @@ pub async fn add_friend( } } +/// Get list of friends with coding stats. +/// +/// Returns all friends with their coding time and current activity status. #[utoipa::path( get, path = "/friends/list", @@ -79,7 +91,8 @@ pub async fn add_friend( ("api_key" = []) ), responses( - (status = OK, body = Vec) + (status = OK, description = "Friends list retrieved", body = Vec), + (status = 401, description = "Unauthorized"), ) )] pub async fn get_friends( @@ -113,11 +126,16 @@ pub async fn get_friends( Ok(Json(friends)) } +/// Response containing the newly generated friend code. #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct RegenerateFriendCodeResponse { + /// The new friend code (starts with ttfc_). friend_code: String, } +/// Generate a new friend code. +/// +/// Invalidates the previous friend code. Others must use the new code to add you as a friend. #[utoipa::path( post, path = "/friends/regenerate", @@ -125,7 +143,8 @@ pub struct RegenerateFriendCodeResponse { ("api_key" = []) ), responses( - (status = OK, body = RegenerateFriendCodeResponse) + (status = OK, description = "New friend code generated", body = RegenerateFriendCodeResponse), + (status = 401, description = "Unauthorized"), ) )] pub async fn regenerate_friend_code( @@ -138,19 +157,27 @@ pub async fn regenerate_friend_code( .map(|c| Json(RegenerateFriendCodeResponse { friend_code: c })) } +/// Request body for removing a friend. #[derive(Debug, Clone, Deserialize, ToSchema)] pub struct RemoveFriendRequest { + /// Username of the friend to remove. name: String, } +/// Remove a friend. +/// +/// Removes the friendship in both directions. #[utoipa::path( delete, path = "/friends/remove", + request_body = RemoveFriendRequest, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Friend removed"), + (status = 400, description = "Friend not found"), + (status = 401, description = "Unauthorized"), ) )] pub async fn remove( diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index cdd3064..a7b9a6d 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -12,29 +12,42 @@ use crate::{ use super::users::MinimalLeaderboard; +/// Request body for creating a leaderboard. #[derive(Deserialize, Serialize, ToSchema)] pub struct LeaderboardCreateRequest { + /// Name of the leaderboard (2-32 alphanumeric characters). pub name: String, } +/// Request body specifying a leaderboard member. #[derive(Deserialize, ToSchema)] pub struct LeaderboardUser { + /// Username of the target member. pub user: String, } +/// Response from leaderboard creation. #[derive(Serialize, ToSchema)] pub struct LeaderboardCreateResponse { + /// The invite code for others to join (starts with ttlic_). invite_code: String, } +/// Create a new leaderboard. +/// +/// Creates a leaderboard with the authenticated user as admin. Returns an invite code for others to join. #[utoipa::path( post, path = "/leaderboards/create", + request_body = LeaderboardCreateRequest, security( ("api_key" = []) ), responses( - (status = OK, body = LeaderboardCreateResponse) + (status = OK, description = "Leaderboard created", body = LeaderboardCreateResponse), + (status = 400, description = "Invalid leaderboard name"), + (status = 401, description = "Unauthorized"), + (status = 409, description = "Leaderboard name already exists"), ) )] pub async fn create_leaderboard( @@ -65,6 +78,9 @@ pub async fn create_leaderboard( } } +/// Get leaderboard details and members. +/// +/// Returns the leaderboard with all members and their coding times. Only accessible to members. #[utoipa::path( get, path = "/leaderboards/{name}", @@ -75,7 +91,9 @@ pub async fn create_leaderboard( ("api_key" = []) ), responses( - (status = OK, body = PrivateLeaderboard) + (status = OK, description = "Leaderboard retrieved", body = PrivateLeaderboard), + (status = 401, description = "Unauthorized or not a member"), + (status = 404, description = "Leaderboard not found"), ) )] pub async fn get_leaderboard( @@ -96,6 +114,9 @@ pub async fn get_leaderboard( } } +/// Delete a leaderboard. +/// +/// Permanently deletes the leaderboard. Only accessible to admins. #[utoipa::path( delete, path = "/leaderboards/{name}", @@ -106,7 +127,9 @@ pub async fn get_leaderboard( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Leaderboard deleted"), + (status = 401, description = "Unauthorized or not an admin"), + (status = 404, description = "Leaderboard not found"), ) )] pub async fn delete_leaderboard( @@ -127,19 +150,28 @@ pub async fn delete_leaderboard( } } +/// Request body for joining a leaderboard. #[derive(Deserialize, Serialize, ToSchema)] pub struct LeaderboardInvite { + /// The invite code (starts with ttlic_). pub invite: String, } +/// Join a leaderboard with invite code. +/// +/// Invite codes start with `ttlic_`. Returns basic leaderboard info on success. #[utoipa::path( post, path = "/leaderboards/join", + request_body = LeaderboardInvite, security( ("api_key" = []) ), responses( - (status = OK, body = MinimalLeaderboard) + (status = OK, description = "Joined leaderboard", body = MinimalLeaderboard), + (status = 401, description = "Unauthorized"), + (status = 404, description = "Invalid invite code"), + (status = 409, description = "Already a member"), ) )] pub async fn join_leaderboard( @@ -166,6 +198,9 @@ pub async fn join_leaderboard( } } +/// Leave a leaderboard. +/// +/// Removes the user from the leaderboard. Admins cannot leave if they are the last admin. #[utoipa::path( post, path = "/leaderboards/{name}/leave", @@ -176,7 +211,10 @@ pub async fn join_leaderboard( ("api_key" = []), ), responses( - (status = OK) + (status = OK, description = "Left leaderboard"), + (status = 400, description = "Cannot leave as last admin"), + (status = 401, description = "Unauthorized"), + (status = 404, description = "Leaderboard not found or not a member"), ) )] pub async fn leave_leaderboard( @@ -202,17 +240,23 @@ pub async fn leave_leaderboard( } } +/// Promote a member to admin. +/// +/// Only accessible to existing admins. The promoted user gains admin privileges. #[utoipa::path( post, path = "/leaderboards/{name}/promote", params( ("name", description = "Leaderboard name") ), + request_body = LeaderboardUser, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Member promoted to admin"), + (status = 401, description = "Unauthorized or not an admin"), + (status = 404, description = "Leaderboard or user not found"), ) )] pub async fn promote_member( @@ -246,17 +290,23 @@ pub async fn promote_member( } } +/// Demote an admin to member. +/// +/// Only accessible to existing admins. The demoted user loses admin privileges. #[utoipa::path( post, path = "/leaderboards/{name}/demote", params( ("name", description = "Leaderboard name") ), + request_body = LeaderboardUser, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Admin demoted to member"), + (status = 401, description = "Unauthorized or not an admin"), + (status = 404, description = "Leaderboard or user not found"), ) )] pub async fn demote_member( @@ -290,17 +340,23 @@ pub async fn demote_member( } } +/// Remove a member from leaderboard. +/// +/// Only accessible to admins. Removes the specified user from the leaderboard. #[utoipa::path( post, path = "/leaderboards/{name}/kick", params( ("name", description = "Leaderboard name") ), + request_body = LeaderboardUser, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Member removed from leaderboard"), + (status = 401, description = "Unauthorized or not an admin"), + (status = 404, description = "Leaderboard or user not found"), ) )] pub async fn kick_member( @@ -329,11 +385,16 @@ pub async fn kick_member( } } +/// Response containing the newly generated invite code. #[derive(Debug, Clone, Serialize, ToSchema)] pub struct InviteCodeRegenerateResponse { + /// The new invite code (starts with ttlic_). invite_code: String, } +/// Generate new leaderboard invite code. +/// +/// Only accessible to admins. Invalidates the previous invite code. #[utoipa::path( post, path = "/leaderboards/{name}/regenerate", @@ -344,7 +405,9 @@ pub struct InviteCodeRegenerateResponse { ("api_key" = []) ), responses( - (status = OK, body = InviteCodeRegenerateResponse) + (status = OK, description = "New invite code generated", body = InviteCodeRegenerateResponse), + (status = 401, description = "Unauthorized or not an admin"), + (status = 404, description = "Leaderboard not found"), ) )] pub async fn regenerate_invite( diff --git a/src/api/mod.rs b/src/api/mod.rs index 8c9c3c2..72e0902 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -17,13 +17,15 @@ pub mod users; pub static VALID_NAME_REGEX: LazyLock = LazyLock::new(|| Regex::new("^[[:word:]]{2,32}$").unwrap()); +/// Check API health status. +/// +/// Returns OK if the API is running and healthy. #[utoipa::path( get, path = "/health", responses( - (status = OK) - ), - description = "Is the api healthy" + (status = OK, description = "API is healthy") + ) )] pub async fn health() -> StatusCode { StatusCode::OK diff --git a/src/api/oauth.rs b/src/api/oauth.rs index 394b83d..cb477ff 100644 --- a/src/api/oauth.rs +++ b/src/api/oauth.rs @@ -44,11 +44,16 @@ static CLIENT_INFO: LazyLock = LazyLock::new(|| { .expect("Invalid Toml in settings.toml") }); +/// Handle TestausID OAuth callback. +/// +/// Exchanges the OAuth authorization code for a token and authenticates the user. +/// Sets a cookie with the authentication token and redirects to the frontend. #[utoipa::path( get, path = "/auth/callback", responses( - (status = OK) + (status = 308, description = "Redirects to frontend with auth cookie"), + (status = 400, description = "Invalid authorization code"), ) )] pub async fn callback( diff --git a/src/api/search.rs b/src/api/search.rs index 4547a71..a994085 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -9,7 +9,9 @@ pub struct UserSearch { pub keyword: String, } -//TODO: Maybe return small coding summary? +/// Search for users with public profiles. +/// +/// Searches usernames matching the keyword. Only returns users with public profiles. #[utoipa::path( get, path = "/search/users", @@ -17,7 +19,7 @@ pub struct UserSearch { UserSearch ), responses( - (status = OK, body = Vec) + (status = OK, description = "Search results", body = Vec), ) )] pub async fn search_public_users( diff --git a/src/api/stats.rs b/src/api/stats.rs index a9de6e2..16ae701 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -4,17 +4,23 @@ use utoipa::ToSchema; use crate::{database::DatabaseWrapper, error::TimeError}; +/// Global Testaustime statistics. #[derive(Serialize, ToSchema)] pub struct Stats { + /// Total number of registered users. pub user_count: u64, + /// Total coding time tracked in seconds. pub coding_time: u64, } +/// Get global Testaustime statistics. +/// +/// Returns the total number of registered users and total coding time tracked. #[utoipa::path( get, path = "/stats", responses( - (status = OK, body = Stats) + (status = OK, description = "Global statistics", body = Stats), ) )] pub async fn stats(db: DatabaseWrapper) -> Result, TimeError> { diff --git a/src/api/users.rs b/src/api/users.rs index a114747..b6d6b24 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -33,6 +33,9 @@ pub struct DataRequest { pub project_name: Option, } +/// Get the authenticated user's profile. +/// +/// Returns the user's identity including username, friend code, and registration time. #[utoipa::path( get, path = "/users/@me", @@ -40,28 +43,41 @@ pub struct DataRequest { ("api_key" = []) ), responses( - (status = OK, body = UserIdentity) + (status = OK, description = "User profile retrieved", body = UserIdentity), + (status = 401, description = "Unauthorized"), ) )] pub async fn my_profile(user: UserIdentity) -> Result, TimeError> { Ok(Json(user)) } +/// Leaderboard summary for the user's leaderboard list. #[derive(Serialize, ToSchema)] pub struct ListLeaderboard { + /// Name of the leaderboard. pub name: String, + /// Total number of members in the leaderboard. pub member_count: i32, + /// The member with the most coding time. pub top_member: PrivateLeaderboardMember, + /// The authenticated user's position (1-indexed). pub my_position: i32, + /// The authenticated user's member info. pub me: PrivateLeaderboardMember, } +/// Basic leaderboard information. #[derive(Serialize, ToSchema)] pub struct MinimalLeaderboard { + /// Name of the leaderboard. pub name: String, + /// Total number of members in the leaderboard. pub member_count: i32, } +/// Get leaderboards the user is a member of. +/// +/// Returns a list of leaderboards with member count, top member, and user's position. #[utoipa::path( get, path = "/users/@me/leaderboards", @@ -69,7 +85,8 @@ pub struct MinimalLeaderboard { ("api_key" = []) ), responses( - (status = OK, body = Vec) + (status = OK, description = "Leaderboards retrieved", body = Vec), + (status = 401, description = "Unauthorized"), ) )] pub async fn my_leaderboards( @@ -79,20 +96,28 @@ pub async fn my_leaderboards( Ok(Json(db.get_user_leaderboards(user.id).await?)) } +/// Credentials for user authentication. #[derive(Deserialize, ToSchema)] pub struct UserAuthentication { + /// The user's username. pub username: String, + /// The user's password. pub password: String, } +/// Delete a user account. +/// +/// Requires username and password verification. This action is irreversible. #[utoipa::path( delete, path = "/users/@me/delete", + request_body = UserAuthentication, security( ("api_key" = []) ), responses( - (status = OK) + (status = OK, description = "Account deleted successfully"), + (status = 401, description = "Invalid credentials"), ) )] pub async fn delete_user( @@ -110,17 +135,23 @@ pub async fn delete_user( } } +/// Get a user's current coding activity. +/// +/// Returns the user's current coding session if active. Use `@me` for the authenticated user. +/// Accessible for public profiles, friends, or the authenticated user. #[utoipa::path( get, path = "/users/{username}/activity/current", params( - ("username", description = "User name"), + ("username", description = "Username or @me for self"), ), security( ("api_key" = []) ), responses( - (status = OK, body = Option) + (status = OK, description = "Current activity retrieved", body = Option), + (status = 401, description = "Unauthorized"), + (status = 404, description = "User not found or not currently active"), ) )] pub async fn get_current_activity( @@ -192,17 +223,23 @@ pub async fn get_current_activity( } } +/// Get a user's coding activity history. +/// +/// Returns all coding activities with optional filtering by date range, duration, editor, language, hostname, or project. +/// Use `@me` for the authenticated user. Accessible for public profiles, friends, or the authenticated user. #[utoipa::path( get, path = "/users/{username}/activity/data", params( - ("username", description = "User name"), + ("username", description = "Username or @me for self"), ), security( ("api_key" = []) ), responses( - (status = OK, body = Vec) + (status = OK, description = "Activity history retrieved", body = Vec), + (status = 401, description = "Unauthorized"), + (status = 404, description = "User not found"), ) )] pub async fn get_activities( @@ -248,30 +285,43 @@ pub async fn get_activities( Ok(Json(data)) } +/// Coding time breakdown by programming language. #[derive(Debug, Clone, Serialize, ToSchema)] pub struct LanguageSummary { + /// Map of language name to coding time in seconds. languages: HashMap, + /// Total coding time in seconds. total: i32, } +/// Summary of coding activity over different time periods. #[derive(Debug, Clone, Serialize, ToSchema)] pub struct ActivitySummary { + /// Coding time breakdown for the last 7 days. last_week: LanguageSummary, + /// Coding time breakdown for the last 30 days. last_month: LanguageSummary, + /// Coding time breakdown for all time. all_time: LanguageSummary, } +/// Get a summary of a user's coding activity. +/// +/// Returns aggregated coding time by language for last week, last month, and all time. +/// Use `@me` for the authenticated user. Accessible for public profiles, friends, or the authenticated user. #[utoipa::path( get, path = "/users/{username}/activity/summary", params( - ("username", description = "User name") + ("username", description = "Username or @me for self") ), security( ("api_key" = []) ), responses( - (status = OK, body = ActivitySummary) + (status = OK, description = "Activity summary retrieved", body = ActivitySummary), + (status = 401, description = "Unauthorized"), + (status = 404, description = "User not found"), ) )] pub async fn get_activity_summary( diff --git a/src/main.rs b/src/main.rs index 3ec4de4..dd86e22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,6 +97,9 @@ impl Modify for SecurityAddon { HttpBuilder::new() .scheme(HttpAuthScheme::Bearer) .bearer_format("Bearer") + .description(Some( + "Authentication token obtained from /auth/login or /auth/register", + )) .build(), ), ) diff --git a/src/models.rs b/src/models.rs index 2958766..3ff49ae 100644 --- a/src/models.rs +++ b/src/models.rs @@ -8,23 +8,34 @@ pub struct UserId { pub id: i32, } +/// A user's identity and profile information. #[derive(Identifiable, Queryable, Clone, Debug, Serialize, PartialEq, Eq, ToSchema)] #[diesel(table_name = user_identities)] pub struct UserIdentity { + /// Unique user identifier. pub id: i32, #[serde(skip_serializing)] pub auth_token: String, + /// Code for others to add this user as a friend (starts with ttfc_). pub friend_code: String, + /// The user's display name. pub username: String, + /// When the user registered. pub registration_time: chrono::NaiveDateTime, + /// Whether the user's profile is publicly visible. pub is_public: bool, + /// The user's email address (optional). pub email: Option, } +/// Public user information visible to anyone. #[derive(Clone, Debug, Serialize, ToSchema)] pub struct PublicUser { + /// Unique user identifier. pub id: i32, + /// The user's display name. pub username: String, + /// When the user registered. pub registration_time: chrono::NaiveDateTime, } @@ -62,13 +73,20 @@ pub struct NewTestaustimeUser { pub identity: i32, } +/// Full user profile returned to the authenticated user. #[derive(Clone, Debug, Serialize, Deserialize, ToSchema)] pub struct SelfUser { + /// Unique user identifier. pub id: i32, + /// Authentication token for API requests. pub auth_token: String, + /// Code for others to add this user as a friend (starts with ttfc_). pub friend_code: String, + /// The user's display name. pub username: String, + /// When the user registered. pub registration_time: chrono::NaiveDateTime, + /// Whether the user's profile is publicly visible. pub is_public: bool, } @@ -110,13 +128,19 @@ pub struct TestausIdUser { use crate::schema::user_identities; +/// A newly created user identity. #[derive(Insertable, Serialize, ToSchema, Clone, Deserialize)] #[diesel(table_name = user_identities)] pub struct NewUserIdentity { + /// Authentication token for API requests. pub auth_token: String, + /// The user's display name. pub username: String, + /// Code for others to add this user as a friend (starts with ttfc_). pub friend_code: String, + /// When the user registered. pub registration_time: chrono::NaiveDateTime, + /// The user's email address (optional). pub email: Option, } @@ -138,19 +162,28 @@ pub struct NewFriendRelation { pub greater_id: i32, } +/// A recorded coding activity session. #[derive(Queryable, Clone, Debug, Serialize, Identifiable, Associations, ToSchema)] #[diesel(belongs_to(UserIdentity, foreign_key=user_id))] #[diesel(table_name = coding_activities)] pub struct CodingActivity { + /// Unique activity identifier. pub id: i32, #[serde(skip_serializing)] pub user_id: i32, + /// When the coding session started. pub start_time: chrono::NaiveDateTime, + /// Duration of the session in seconds. pub duration: i32, + /// Name of the project being worked on. pub project_name: Option, + /// Programming language used. pub language: Option, + /// Name of the editor/IDE. pub editor_name: Option, + /// Hostname of the machine. pub hostname: Option, + /// Whether this activity is hidden from friends and public view. pub hidden: bool, } @@ -208,33 +241,51 @@ pub struct NewLeaderboardMember { pub admin: bool, } +/// A member of a leaderboard with their stats. #[derive(Serialize, Clone, Debug, Deserialize, ToSchema)] pub struct PrivateLeaderboardMember { + /// Unique user identifier. pub id: i32, + /// The member's display name. pub username: String, + /// Whether the member is an admin of this leaderboard. pub admin: bool, + /// Total coding time in seconds (last 7 days). pub time_coded: i32, } +/// Full leaderboard details including all members. #[derive(Serialize, Clone, Debug, Deserialize, ToSchema)] pub struct PrivateLeaderboard { + /// Name of the leaderboard. pub name: String, + /// Invite code for others to join (starts with ttlic_). pub invite: String, + /// When the leaderboard was created. pub creation_time: chrono::NaiveDateTime, + /// List of all members with their stats. pub members: Vec, } +/// Coding time statistics over different time periods. #[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash, ToSchema)] pub struct CodingTimeSteps { + /// Total coding time in seconds (all time). pub all_time: i32, + /// Coding time in seconds (last 30 days). pub past_month: i32, + /// Coding time in seconds (last 7 days). pub past_week: i32, } +/// A user's current coding activity (if active). #[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone, ToSchema)] pub struct CurrentActivity { + /// When the current session started. pub started: chrono::NaiveDateTime, + /// Duration of the current session in seconds. pub duration: i64, + /// Details of what the user is working on. pub heartbeat: HeartBeat, } @@ -244,20 +295,30 @@ pub struct FriendWithTime { pub coding_time: CodingTimeSteps, } +/// Friend information with coding stats and current status. #[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Hash, ToSchema)] pub struct FriendWithTimeAndStatus { + /// The friend's display name. pub username: String, + /// The friend's coding time statistics. pub coding_time: CodingTimeSteps, + /// The friend's current activity (if currently coding). pub status: Option, } +/// A heartbeat sent by editor extensions to track coding activity. #[derive(Deserialize, Serialize, ToSchema, Debug, Hash, Eq, PartialEq, Clone)] pub struct HeartBeat { + /// Name of the project being worked on. #[serde(deserialize_with = "project_deserialize")] pub project_name: Option, + /// Programming language of the current file. pub language: Option, + /// Name of the editor/IDE. pub editor_name: Option, + /// Hostname of the machine. pub hostname: Option, + /// Whether this activity should be hidden from friends and public view. pub hidden: Option, } From 7580bad2e747db172a8911eaa9e86cffad836c75 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Thu, 5 Feb 2026 06:24:58 +0200 Subject: [PATCH 29/36] remove unwraps and implement phc strings --- src/api/activity.rs | 2 +- src/api/auth.rs | 34 ++++++++++++++++--------- src/api/friends.rs | 2 +- src/api/leaderboards.rs | 2 +- src/api/mod.rs | 5 ++-- src/api/oauth.rs | 3 ++- src/api/search.rs | 2 +- src/api/users.rs | 4 +-- src/auth/mod.rs | 8 ++++-- src/database/activity.rs | 2 +- src/database/auth.rs | 48 ++++++++++++------------------------ src/database/leaderboards.rs | 6 +++-- src/database/mod.rs | 6 ++--- src/error.rs | 7 ++++-- src/main.rs | 14 +++++------ src/models.rs | 12 +++------ src/ratelimiter.rs | 19 +++++++------- src/schema.rs | 3 +-- src/state.rs | 2 +- src/tests/auth.rs | 24 ++++++++---------- src/tests/mod.rs | 2 +- src/utils.rs | 2 +- 22 files changed, 104 insertions(+), 105 deletions(-) diff --git a/src/api/activity.rs b/src/api/activity.rs index 72343e4..09e6fa8 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{Json, extract::State}; +use axum::{extract::State, Json}; use chrono::{Duration, Local}; use dashmap::DashMap; use http::StatusCode; diff --git a/src/api/auth.rs b/src/api/auth.rs index 72ae368..190df27 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -1,32 +1,36 @@ use std::sync::Arc; use axum::{ - Json, extract::{FromRequestParts, State}, + Json, }; use chrono::{Duration, Local}; -use http::{StatusCode, request::Parts}; +use http::{request::Parts, StatusCode}; use lettre::{ - AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, message::header::ContentType, + message::header::ContentType, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, }; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::{ - PasswordReset, PasswordResetState, api::users::UserAuthentication, auth::Authentication, database::DatabaseWrapper, error::TimeError, models::{NewUserIdentity, SelfUser, UserId, UserIdentity}, utils::{generate_password_reset_token, validate_email}, + PasswordReset, PasswordResetState, }; impl FromRequestParts for UserId { type Rejection = TimeError; async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { - let auth = parts.extensions.get::().cloned().unwrap(); + let auth = parts + .extensions + .get::() + .cloned() + .expect("BUG: Every request should contain authentication, middleware issue"); if let Authentication::AuthToken(user) = auth { Ok(UserId { id: user.id }) @@ -40,7 +44,11 @@ impl FromRequestParts for UserIdentity { type Rejection = TimeError; async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result { - let auth = parts.extensions.get::().cloned().unwrap(); + let auth = parts + .extensions + .get::() + .cloned() + .expect("BUG: Every request should contain authentication, middleware issue"); if let Authentication::AuthToken(user) = auth { Ok(user) @@ -61,7 +69,11 @@ where type Rejection = TimeError; async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { - let auth = parts.extensions.get::().cloned().unwrap(); + let auth = parts + .extensions + .get::() + .cloned() + .expect("BUG: Every request should contain authentication, middleware issue"); if let Authentication::AuthToken(user) = auth { Ok(UserIdentityOptional { @@ -326,10 +338,9 @@ pub async fn change_password( )); } - let testaustime_user = db.get_testaustime_user_by_id(user.id).await?; let k = db.verify_user_password(&user.username, &body.old).await?; - if k.is_some() || testaustime_user.password.iter().all(|n| *n == 0) { + if k.is_some() { db.change_password(user.id, &body.new).await?; Ok(StatusCode::OK) } else { @@ -373,11 +384,12 @@ pub async fn request_password_reset( let token = generate_password_reset_token(); let message = Message::builder() - .from("Testaustime ".parse().unwrap()) + .from("Testaustime ".parse().expect("BUG: Infallible, email is hardcoded")) .to(format!("{} <{}>", user.username, email).parse().map_err(|_| TimeError::InvalidEmail)?) .subject("Testaustime password reset") .header(ContentType::TEXT_PLAIN) - .body(format!("Here is your testaustime password reset link: https://testaustime.fi/reset_password?token={token}")).unwrap(); + .body(format!("Here is your testaustime password reset link: https://testaustime.fi/reset_password?token={token}")) + .expect("BUG: Infallible, everything is hardcoded and tested"); tokio::spawn(async move { if let Err(err) = relay.send(message).await { diff --git a/src/api/friends.rs b/src/api/friends.rs index 3ff5934..6eed4ce 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{Json, extract::State}; +use axum::{extract::State, Json}; use diesel::result::DatabaseErrorKind; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index a7b9a6d..a9bfa0e 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -1,4 +1,4 @@ -use axum::{Json, extract::Path}; +use axum::{extract::Path, Json}; use diesel::result::{DatabaseErrorKind, Error as DieselError}; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/mod.rs b/src/api/mod.rs index 72e0902..a881152 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -14,8 +14,9 @@ pub mod search; pub mod stats; pub mod users; -pub static VALID_NAME_REGEX: LazyLock = - LazyLock::new(|| Regex::new("^[[:word:]]{2,32}$").unwrap()); +pub static VALID_NAME_REGEX: LazyLock = LazyLock::new(|| { + Regex::new("^[[:word:]]{2,32}$").expect("BUG: Infallible, hardcoded and tested") +}); /// Check API health status. /// diff --git a/src/api/oauth.rs b/src/api/oauth.rs index cb477ff..63a42f1 100644 --- a/src/api/oauth.rs +++ b/src/api/oauth.rs @@ -1,7 +1,8 @@ +// FIXME: Care about this feature use std::{collections::HashMap, sync::LazyLock}; use axum::{extract::Query, response::Redirect}; -use axum_extra::extract::{CookieJar, cookie::Cookie}; +use axum_extra::extract::{cookie::Cookie, CookieJar}; use reqwest::Client; use serde_derive::Deserialize; diff --git a/src/api/search.rs b/src/api/search.rs index a994085..396b599 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -1,4 +1,4 @@ -use axum::{Json, extract::Query}; +use axum::{extract::Query, Json}; use serde_derive::Deserialize; use utoipa::IntoParams; diff --git a/src/api/users.rs b/src/api/users.rs index b6d6b24..5e42a3d 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -1,10 +1,10 @@ use std::{collections::HashMap, sync::Arc}; use axum::{ - Json, extract::{Path, Query, State}, + Json, }; -use chrono::{DateTime, Duration, Local, Utc, serde::ts_seconds_option}; +use chrono::{serde::ts_seconds_option, DateTime, Duration, Local, Utc}; use http::StatusCode; use serde::Serialize; use serde_derive::Deserialize; diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 9a8a0d5..54b58b8 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -7,7 +7,7 @@ use axum::extract::Request; use futures_util::future::BoxFuture; use tower::{Layer, Service}; -use crate::{TestaustimeState, database::DatabaseWrapper, models::UserIdentity}; +use crate::{database::DatabaseWrapper, models::UserIdentity, TestaustimeState}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Authentication { @@ -74,7 +74,11 @@ where break 'auth Authentication::NoAuth; }; - let Some(token) = auth.to_str().unwrap().trim().strip_prefix("Bearer ") else { + let Some(token) = auth + .to_str() + .ok() + .and_then(|a| a.trim().strip_prefix("Bearer ")) + else { break 'auth Authentication::NoAuth; }; diff --git a/src/database/activity.rs b/src/database/activity.rs index 970d401..b1d60ca 100644 --- a/src/database/activity.rs +++ b/src/database/activity.rs @@ -1,4 +1,4 @@ -use chrono::{Duration, prelude::*}; +use chrono::{prelude::*, Duration}; use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/src/database/auth.rs b/src/database/auth.rs index 5b61218..492156c 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -1,6 +1,6 @@ use argon2::{ - Algorithm, Argon2, Params, Version, - password_hash::{PasswordHasher, SaltString, rand_core::OsRng}, + password_hash::{rand_core::OsRng, PasswordHasher, SaltString}, + Algorithm, Argon2, Params, PasswordHash, PasswordVerifier, Version, }; use diesel::prelude::*; use diesel_async::RunQueryDsl; @@ -65,16 +65,13 @@ impl super::DatabaseWrapper { let argon2 = Argon2::new( Algorithm::Argon2id, Version::V0x13, - Params::new(4096, 3, 1, None).unwrap(), + Params::new(4096, 3, 1, None).expect("BUG: Hardcoded params, wont change"), ); - let salt = SaltString::from_b64(std::str::from_utf8(&tuser.salt).expect("Infallible"))?; - let password_hash = argon2.hash_password(password.as_bytes(), &salt)?; + let hash = PasswordHash::new(&tuser.password) + .expect("BUG: This is valid if it was succesfully inserted into database"); - if password_hash - .hash - .is_some_and(|p| p.as_bytes() == tuser.password) - { + if argon2.verify_password(password.as_bytes(), &hash).is_ok() { Ok(Some(user)) } else { Ok(None) @@ -109,11 +106,13 @@ impl super::DatabaseWrapper { let argon2 = Argon2::new( Algorithm::Argon2id, Version::V0x13, - Params::new(4096, 3, 1, None).unwrap(), + Params::new(4096, 3, 1, None).expect("BUG: Hardcoded params, wont change"), ); - let password_hash = argon2.hash_password(password.as_bytes(), &salt).unwrap(); + + let hash = argon2 + .hash_password(password.as_bytes(), &salt) + .expect("BUG: Hashing failed on sanitized output"); let token = generate_auth_token(); - let hash = password_hash.hash.unwrap(); let new_user = NewUserIdentity { auth_token: token, registration_time: chrono::Local::now().naive_local(), @@ -139,8 +138,7 @@ impl super::DatabaseWrapper { .map_err(|_| TimeError::UsernameTaken)?; let testaustime_user = NewTestaustimeUser { - password: hash.as_bytes().to_vec(), - salt: salt.as_str().as_bytes().to_vec(), + password: hash.to_string(), identity: id[0], }; @@ -190,23 +188,19 @@ impl super::DatabaseWrapper { let argon2 = Argon2::new( Algorithm::Argon2id, Version::V0x13, - Params::new(4096, 3, 1, None).unwrap(), + Params::new(4096, 3, 1, None).expect("BUG: Hardcoded params, wont change"), ); - let password_hash = argon2 + let hash = argon2 .hash_password(new_password.as_bytes(), &new_salt) - .unwrap(); - let new_hash = password_hash.hash.unwrap(); + .expect("BUG: Hashing failed on sanitized output"); let mut conn = self.db.get().await?; use crate::schema::testaustime_users::dsl::*; diesel::update(crate::schema::testaustime_users::table) .filter(identity.eq(user)) - .set(( - password.eq(&new_hash.as_bytes()), - salt.eq(new_salt.as_str().as_bytes()), - )) + .set((password.eq(&hash.to_string()),)) .execute(&mut conn) .await?; @@ -245,16 +239,6 @@ impl super::DatabaseWrapper { Ok(user) } - pub async fn get_testaustime_user_by_id(&self, uid: i32) -> Result { - use crate::schema::testaustime_users::dsl::*; - let mut conn = self.db.get().await?; - - Ok(testaustime_users - .filter(identity.eq(uid)) - .first::(&mut conn) - .await?) - } - // FIXME: Use transactions #[cfg(feature = "testausid")] pub async fn testausid_login( diff --git a/src/database/leaderboards.rs b/src/database/leaderboards.rs index 4ef192f..120e7ab 100644 --- a/src/database/leaderboards.rs +++ b/src/database/leaderboards.rs @@ -126,7 +126,8 @@ impl super::DatabaseWrapper { let aweekago = NaiveDateTime::new( Local::now().date_naive() - chrono::Duration::weeks(1), - chrono::NaiveTime::from_num_seconds_from_midnight_opt(0, 0).unwrap(), + chrono::NaiveTime::from_num_seconds_from_midnight_opt(0, 0) + .expect("BUG: Always a valid time"), ); let members = @@ -305,7 +306,8 @@ impl super::DatabaseWrapper { let aweekago = NaiveDateTime::new( Local::now().date_naive() - chrono::Duration::weeks(1), - chrono::NaiveTime::from_num_seconds_from_midnight_opt(0, 0).unwrap(), + chrono::NaiveTime::from_num_seconds_from_midnight_opt(0, 0) + .expect("BUG: Always a valid time"), ); // FIXME: We could maybe use limit here because we only need the diff --git a/src/database/mod.rs b/src/database/mod.rs index 67dff37..f3a0d9f 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -2,15 +2,15 @@ use std::sync::Arc; use axum::extract::{FromRef, FromRequestParts}; use diesel_async::{ - AsyncPgConnection, pooled_connection::{ - AsyncDieselConnectionManager, deadpool::{Object, Pool}, + AsyncDieselConnectionManager, }, + AsyncPgConnection, }; use http::request::Parts; -use crate::{TestaustimeState, error::TimeError}; +use crate::{error::TimeError, TestaustimeState}; pub mod activity; pub mod auth; diff --git a/src/error.rs b/src/error.rs index 87057d2..b970bea 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use axum::{ - Json, response::{IntoResponse, Response}, + Json, }; use http::StatusCode; use thiserror::Error; @@ -69,6 +69,8 @@ pub enum TimeError { EmailTaken, #[error("Password hashing failed")] HashError(#[from] argon2::password_hash::Error), + #[error(transparent)] + HeaderError(#[from] http::header::ToStrError), } impl IntoResponse for TimeError { @@ -83,7 +85,8 @@ impl IntoResponse for TimeError { | TimeError::BadId | TimeError::BadLeaderboardName | TimeError::InvalidEmail - | TimeError::BadCode => StatusCode::BAD_REQUEST, + | TimeError::BadCode + | TimeError::HeaderError(_) => StatusCode::BAD_REQUEST, TimeError::CurrentUser | TimeError::NotMember | TimeError::LastAdmin => { StatusCode::FORBIDDEN } diff --git a/src/main.rs b/src/main.rs index dd86e22..b6f09d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,12 +15,12 @@ use std::{net::SocketAddr, num::NonZeroU32, sync::Arc}; use api::activity::HeartBeatMemoryStore; use auth::{AuthMiddleware, Authentication}; -use axum::{Router, body::Body}; +use axum::{body::Body, Router}; use chrono::NaiveDateTime; use dashmap::DashMap; use database::Database; use governor::{Quota, RateLimiter}; -use lettre::{AsyncSmtpTransport, Tokio1Executor, transport::smtp::authentication::Credentials}; +use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor}; use models::UserIdentity; use ratelimiter::TestaustimeRateLimiter; use serde_derive::Deserialize; @@ -28,8 +28,8 @@ use tower::ServiceBuilder; use tower_http::trace::TraceLayer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use utoipa::{ - Modify, OpenApi, openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, + Modify, OpenApi, }; use utoipa_axum::{router::OpenApiRouter, routes}; use utoipa_swagger_ui::SwaggerUi; @@ -148,14 +148,14 @@ fn create_router_with_openapi(config: &TestaustimeConfig) -> (Router, utoipa::op let ratelimiter = Arc::new( RateLimiter::keyed(Quota::per_minute( - NonZeroU32::new(config.max_requests_per_min).unwrap(), + NonZeroU32::new(config.max_requests_per_min).expect("Ratelimit set to 0"), )) .with_middleware(), ); let register_ratelimiter = Arc::new( RateLimiter::keyed(Quota::per_hour( - NonZeroU32::new(config.max_registers_per_hour).unwrap(), + NonZeroU32::new(config.max_registers_per_hour).expect("Ratelimit set to 0"), )) .with_middleware(), ); @@ -264,7 +264,7 @@ async fn main() { let listener = tokio::net::TcpListener::bind(&config.address) .await - .unwrap(); + .unwrap_or_else(|_| panic!("Could not bind to address {}", &config.address)); info!("Staring server on {}", config.address); @@ -273,5 +273,5 @@ async fn main() { router.into_make_service_with_connect_info::(), ) .await - .unwrap(); + .expect("BUG: Could not start server"); } diff --git a/src/models.rs b/src/models.rs index 3ff49ae..70d8307 100644 --- a/src/models.rs +++ b/src/models.rs @@ -54,11 +54,9 @@ impl From for PublicUser { #[diesel(table_name = testaustime_users)] pub struct TestaustimeUser { pub id: i32, - #[serde(skip_serializing)] - pub password: Vec, - #[serde(skip_serializing)] - pub salt: Vec, pub identity: i32, + #[serde(skip_serializing)] + pub password: String, } use crate::schema::testaustime_users; @@ -66,11 +64,9 @@ use crate::schema::testaustime_users; #[derive(Insertable, Serialize, Clone)] #[diesel(table_name = testaustime_users)] pub struct NewTestaustimeUser { - #[serde(skip_serializing)] - pub password: Vec, - #[serde(skip_serializing)] - pub salt: Vec, pub identity: i32, + #[serde(skip_serializing)] + pub password: String, } /// Full user profile returned to the authenticated user. diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index 43b155a..2188e6d 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -11,12 +11,12 @@ use axum::{ }; use futures_util::future::BoxFuture; use governor::{ - RateLimiter, clock::DefaultClock, middleware::StateInformationMiddleware, - state::keyed::DefaultKeyedStateStore, + clock::DefaultClock, middleware::StateInformationMiddleware, + state::keyed::DefaultKeyedStateStore, RateLimiter, }; use http::{ + header::{HeaderName, FORWARDED}, HeaderValue, StatusCode, - header::{FORWARDED, HeaderName}, }; use tower::{Layer, Service}; @@ -69,7 +69,7 @@ where let conn_info = req .extensions() .get::>() - .unwrap() + .expect("BUG: Tokio always provides connection info") .ip(); let bypass = req @@ -111,13 +111,14 @@ where headers.insert( HeaderName::from_static("ratelimit-limit"), - HeaderValue::from_str("a.burst_size().to_string()).unwrap(), + HeaderValue::from_str("a.burst_size().to_string()) + .expect("BUG: Integer to String is always a valid HeaderValue"), ); headers.insert( HeaderName::from_static("ratelimit-remaining"), HeaderValue::from_str(&state.remaining_burst_capacity().to_string()) - .unwrap(), + .expect("BUG: Integer to String is always a valid HeaderValue"), ); headers.insert( @@ -125,7 +126,7 @@ where HeaderValue::from_str( "a.replenish_interval().as_secs().to_string(), ) - .unwrap(), + .expect("BUG: Integer to String is always a valid HeaderValue"), ); Ok(res) @@ -141,7 +142,7 @@ where denied.quota().replenish_interval().as_secs().to_string(), ) .body(Body::empty()) - .unwrap()) + .expect("BUG: Integer to String is always a valid HeaderValue")) }), } } else { @@ -149,7 +150,7 @@ where Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::empty()) - .unwrap()) + .expect("BUG: Always valid")) }) } } diff --git a/src/schema.rs b/src/schema.rs index 2a73baf..0f24ff0 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -58,9 +58,8 @@ diesel::table! { diesel::table! { testaustime_users (id) { id -> Int4, - password -> Bytea, - salt -> Bytea, identity -> Int4, + password -> Text, } } diff --git a/src/state.rs b/src/state.rs index f0dbe9b..121cc2b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,7 +4,7 @@ use axum::extract::FromRef; use lettre::{AsyncSmtpTransport, Tokio1Executor}; use crate::{ - PasswordResetState, RegisterLimiter, TestaustimeState, api::activity::HeartBeatMemoryStore, + api::activity::HeartBeatMemoryStore, PasswordResetState, RegisterLimiter, TestaustimeState, }; impl FromRef for Arc { diff --git a/src/tests/auth.rs b/src/tests/auth.rs index 80693d5..e029d9b 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -104,13 +104,11 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!( - resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("username") - ); + assert!(resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("username")); let body = json!({"username": "validusername", "password": "short"}); let resp = request!(app, POST, "/auth/register", body); @@ -120,13 +118,11 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!( - resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("password") - ); + assert!(resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("password")); } // TODO: test ratelimits diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 8670eb6..245df0e 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -9,7 +9,7 @@ mod friends; mod leaderboards; mod macros; -use axum::{Router, body::Body, extract::connect_info::MockConnectInfo, response::Response}; +use axum::{body::Body, extract::connect_info::MockConnectInfo, response::Response, Router}; use http::{Request, StatusCode}; use serde::de::DeserializeOwned; use tower::ServiceExt; diff --git a/src/utils.rs b/src/utils.rs index 8f9fe41..43b23f7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use itertools::Itertools; use lettre::Address; -use rand::{Rng, distr::Alphanumeric, rng}; +use rand::{distr::Alphanumeric, rng, Rng}; use crate::models::CodingActivity; From ebf06d48be01d50b185c0842b01ebc6f95f826b6 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Thu, 5 Feb 2026 06:30:01 +0200 Subject: [PATCH 30/36] forgot to commit migrations --- .../down.sql | 14 ++++++++++++++ .../2026-02-05-023415-0000_phc-strings/up.sql | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 migrations/2026-02-05-023415-0000_phc-strings/down.sql create mode 100644 migrations/2026-02-05-023415-0000_phc-strings/up.sql diff --git a/migrations/2026-02-05-023415-0000_phc-strings/down.sql b/migrations/2026-02-05-023415-0000_phc-strings/down.sql new file mode 100644 index 0000000..9ab338a --- /dev/null +++ b/migrations/2026-02-05-023415-0000_phc-strings/down.sql @@ -0,0 +1,14 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE testaustime_users +ADD raw_password bytea, +ADD salt bytea; + +UPDATE testaustime_users +SET salt = decode(SPLIT_PART(password, '$', 5), 'escape'), +raw_password = decode(RPAD(SPLIT_PART(password, '$', 6), 44, '='), 'base64'); + +ALTER TABLE testaustime_users +DROP COLUMN password; + +ALTER TABLE testaustime_users +RENAME COLUMN raw_password to password; diff --git a/migrations/2026-02-05-023415-0000_phc-strings/up.sql b/migrations/2026-02-05-023415-0000_phc-strings/up.sql new file mode 100644 index 0000000..f7eebed --- /dev/null +++ b/migrations/2026-02-05-023415-0000_phc-strings/up.sql @@ -0,0 +1,19 @@ +ALTER TABLE testaustime_users +RENAME COLUMN password TO raw_password; +ALTER TABLE testaustime_users +ADD password TEXT; + +UPDATE testaustime_users AS t +SET password = CONCAT( + '$argon2id$v=19$m=4096,t=3,p=1$', + convert_from(t.salt, 'UTF-8'), + '$', + TRIM(TRAILING '=' FROM encode(t.raw_password, 'base64')) +); + +ALTER TABLE testaustime_users +ALTER COLUMN password SET NOT NULL; + +ALTER TABLE testaustime_users +DROP COLUMN raw_password, +DROP COLUMN salt; From 6bd84ec8b6a1dfa73392a4dfd454a7384124c609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Sat, 28 Mar 2026 13:50:55 +0200 Subject: [PATCH 31/36] chore: add rust-toolchain.toml with latest stable --- flake.nix | 7 +++++-- rust-toolchain.toml | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/flake.nix b/flake.nix index 451fc54..a55ca0d 100644 --- a/flake.nix +++ b/flake.nix @@ -30,8 +30,11 @@ let pkgs = nixpkgs.legacyPackages.${system}; - # Use default toolchain to include clippy and rustfmt - toolchain = fenix.packages.${system}.default.toolchain; + # Use toolchain specified in rust-toolchain.toml + toolchain = fenix.packages.${system}.fromToolchainFile { + file = ./rust-toolchain.toml; + sha256 = "sha256-zC8E38iDVJ1oPIzCqTk/Ujo9+9kx9dXq7wAwPMpkpg0="; + }; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..d1cc2c1 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.94.1" +components = ["clippy", "rustfmt"] From 911b5efa17ce051130382efbfd94e65e4a4c6676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Sat, 28 Mar 2026 14:14:55 +0200 Subject: [PATCH 32/36] chore(nix): use crane devShell over pkgs.mkShell --- flake.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index a55ca0d..c222499 100644 --- a/flake.nix +++ b/flake.nix @@ -163,12 +163,13 @@ devShells = forEachSystem ( system: let - inherit (perSystem system) pkgs toolchain treefmtEval; + inherit (perSystem system) pkgs craneLib treefmtEval; in { - default = pkgs.mkShell { + default = craneLib.devShell { + checks = self.checks.${system}; + packages = [ - toolchain pkgs.diesel-cli treefmtEval.config.build.wrapper ]; From 062328a37ea6c544da19352cdbe983f6084329b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Sat, 28 Mar 2026 14:38:38 +0200 Subject: [PATCH 33/36] chore: remove Dockerfile, embed migrations to binary --- Cargo.lock | 57 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 ++- Dockerfile | 69 --------------------------------------------------- entrypoint.sh | 7 ------ flake.nix | 12 +-------- src/main.rs | 31 +++++++++++++++++++++++ 6 files changed, 91 insertions(+), 88 deletions(-) delete mode 100644 Dockerfile delete mode 100755 entrypoint.sh diff --git a/Cargo.lock b/Cargo.lock index 1cbaf9b..18a2934 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -551,6 +551,7 @@ dependencies = [ "diesel_derives", "downcast-rs", "itoa", + "pq-sys", "serde_json", ] @@ -582,6 +583,17 @@ dependencies = [ "syn", ] +[[package]] +name = "diesel_migrations" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "745fd255645f0f1135f9ec55c7b00e0882192af9683ab4731e4bba3da82b8f9c" +dependencies = [ + "diesel", + "migrations_internals", + "migrations_macros", +] + [[package]] name = "diesel_table_macro_syntax" version = "0.3.0" @@ -1420,6 +1432,27 @@ version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "migrations_internals" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c791ecdf977c99f45f23280405d7723727470f6689a5e6dbf513ac547ae10d" +dependencies = [ + "serde", + "toml", +] + +[[package]] +name = "migrations_macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36fc5ac76be324cfd2d3f2cf0fdf5d5d3c4f14ed8aaebadb09e304ba42282703" +dependencies = [ + "migrations_internals", + "proc-macro2", + "quote", +] + [[package]] name = "mime" version = "0.3.17" @@ -1630,6 +1663,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "polyval" version = "0.6.2" @@ -1701,6 +1740,17 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "pq-sys" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "574ddd6a267294433f140b02a726b0640c43cf7c6f717084684aaa3b285aba61" +dependencies = [ + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "proc-macro2" version = "1.0.105" @@ -2395,6 +2445,7 @@ dependencies = [ "dashmap", "diesel", "diesel-async", + "diesel_migrations", "dotenv", "futures", "futures-util", @@ -2909,6 +2960,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" diff --git a/Cargo.toml b/Cargo.toml index b733bc9..41e408e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,8 +58,9 @@ url = "2.2" itertools = "0.14" governor = "0.10.0" -diesel = { version = "2.1.0", features = ["chrono", "serde_json"] } +diesel = { version = "2.1.0", features = ["chrono", "serde_json", "postgres"] } diesel-async = { version = "0.7", features = ["postgres", "deadpool"] } +diesel_migrations = "2.2" lettre = { version = "0.11.14", default-features = false, features = [ "tokio1-rustls-tls", "tracing", diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index d8cc8ba..0000000 --- a/Dockerfile +++ /dev/null @@ -1,69 +0,0 @@ -FROM --platform=$BUILDPLATFORM rustlang/rust:nightly-bullseye-slim AS build - -ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="aarch64-linux-gnu-gcc" - -RUN apt update \ - && apt upgrade -y \ - && apt install -y git libpq-dev pkg-config libssl-dev perl make - -ARG TARGETPLATFORM -RUN case "$TARGETPLATFORM" in \ - "linux/amd64") echo "x86_64-unknown-linux-gnu" > /target.txt ;; \ - "linux/arm64") echo "aarch64-unknown-linux-gnu" > /target.txt ;; \ - *) exit 1 ;; \ -esac - -RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ - dpkg --add-architecture arm64 \ - && apt update \ - && apt install gcc-aarch64-linux-gnu libc6-dev-arm64-cross -y \ - && apt install libpq-dev:arm64 -y; \ -fi - -RUN rustup target add $(cat /target.txt) - -RUN cargo install --target $(cat /target.txt) diesel_cli --no-default-features --features "postgres" \ - && mkdir /out \ - && cp /usr/local/cargo/bin/diesel /out - -RUN cargo new --bin testaustime-rs - -WORKDIR /testaustime-rs - -COPY Cargo.toml Cargo.lock ./ - -RUN cargo build --target $(cat /target.txt) --release && rm -rf .git src/ target/$(cat /target.txt)/release/deps/testaustime* - -COPY src/ src/ - -RUN cargo build --target $(cat /target.txt) --release && mv target/$(cat /target.txt)/release/testaustime-rs /out - - - -FROM --platform=$TARGETPLATFORM debian:bullseye-slim AS runner - -RUN apt update \ - && apt upgrade -y \ - && apt install --no-install-recommends postgresql-client ca-certificates -y \ - && rm -rf /var/lib/apt/lists/* - -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/none" \ - --shell "/sbin/nologin" \ - --no-create-home \ - testaustime - -WORKDIR /app - -COPY --from=build /out/diesel ./ -COPY --from=build /out/testaustime-rs ./ -COPY migrations /app/migrations -COPY entrypoint.sh ./ - -RUN chown -R testaustime:testaustime /app - -USER testaustime - -CMD [ "sh", "entrypoint.sh" ] diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index e7ec147..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -while [ 1 ]; -do - /app/diesel database setup && break; -done -/app/diesel migration run -/app/testaustime-rs diff --git a/flake.nix b/flake.nix index c222499..df6dd02 100644 --- a/flake.nix +++ b/flake.nix @@ -120,17 +120,7 @@ docker = pkgs.dockerTools.buildLayeredImage { name = "ghcr.io/testaustime/testaustime-backend"; tag = "nix"; - config.Cmd = - let - entrypoint = pkgs.writeShellScriptBin "entrypoint.sh" '' - while [ 1 ]; - do - ${pkgs.diesel-cli}/bin/diesel database setup --migration-dir ${./migrations} && break; - done - ${testaustime-backend}/bin/testaustime - ''; - in - [ "./${entrypoint}/bin/entrypoint.sh" ]; + config.Cmd = [ "${testaustime-backend}/bin/testaustime" ]; }; } ); diff --git a/src/main.rs b/src/main.rs index b6f09d5..2692ba5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,8 @@ use axum::{body::Body, Router}; use chrono::NaiveDateTime; use dashmap::DashMap; use database::Database; +use diesel::prelude::*; +use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; use governor::{Quota, RateLimiter}; use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor}; use models::UserIdentity; @@ -43,6 +45,8 @@ extern crate diesel; #[macro_use] extern crate serde_json; +const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); + #[derive(Debug, Deserialize)] pub struct TestaustimeConfig { pub bypass_token: String, @@ -258,6 +262,33 @@ async fn main() { toml::from_str(&std::fs::read_to_string("settings.toml").expect("Missing settings.toml")) .expect("Invalid Toml in settings.toml"); + { + use diesel::result::{DatabaseErrorKind, Error as DieselError}; + + let mut db_url = url::Url::parse(&config.database_url).expect("Invalid database URL"); + let db_name = db_url.path().trim_start_matches('/').to_owned(); + + db_url.set_path("/postgres"); + let mut admin_conn = diesel::pg::PgConnection::establish(db_url.as_str()) + .expect("Failed to connect to PostgreSQL server"); + + let create_db = format!("CREATE DATABASE \"{}\"", db_name.replace('"', "\"\"")); + match diesel::sql_query(&create_db).execute(&mut admin_conn) { + Ok(_) => info!("Created database \"{db_name}\""), + Err(DieselError::DatabaseError(DatabaseErrorKind::Unknown, ref info)) + if info.message().contains("already exists") => {} + Err(e) => panic!("Failed to create database: {e}"), + } + + drop(admin_conn); + + info!("Running pending database migrations"); + let mut conn = diesel::pg::PgConnection::establish(&config.database_url) + .expect("Failed to connect to database for migrations"); + conn.run_pending_migrations(MIGRATIONS) + .expect("Failed to run database migrations"); + } + let (router, openapi) = create_router_with_openapi(&config); let router = router.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", openapi.clone())); From 3d7b118502fd27057014914c41e6429c4aeb7831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Sat, 28 Mar 2026 15:10:11 +0200 Subject: [PATCH 34/36] fix: formatting --- flake.nix | 6 +++++- src/api/activity.rs | 2 +- src/api/auth.rs | 8 ++++---- src/api/friends.rs | 2 +- src/api/leaderboards.rs | 2 +- src/api/oauth.rs | 2 +- src/api/search.rs | 2 +- src/api/users.rs | 4 ++-- src/auth/mod.rs | 2 +- src/database/activity.rs | 2 +- src/database/auth.rs | 2 +- src/database/mod.rs | 6 +++--- src/error.rs | 2 +- src/main.rs | 8 ++++---- src/ratelimiter.rs | 6 +++--- src/state.rs | 2 +- src/tests/auth.rs | 24 ++++++++++++++---------- src/tests/mod.rs | 2 +- src/utils.rs | 2 +- 19 files changed, 47 insertions(+), 39 deletions(-) diff --git a/flake.nix b/flake.nix index df6dd02..6d7f88b 100644 --- a/flake.nix +++ b/flake.nix @@ -38,8 +38,12 @@ craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + sqlFilter = path: _type: builtins.match ".*\\.sql$" path != null; commonArgs = { - src = craneLib.cleanCargoSource ./.; + src = pkgs.lib.cleanSourceWith { + src = ./.; + filter = path: type: (sqlFilter path type) || (craneLib.filterCargoSources path type); + }; }; cargoArtifacts = craneLib.buildDepsOnly ( diff --git a/src/api/activity.rs b/src/api/activity.rs index 09e6fa8..72343e4 100644 --- a/src/api/activity.rs +++ b/src/api/activity.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{extract::State, Json}; +use axum::{Json, extract::State}; use chrono::{Duration, Local}; use dashmap::DashMap; use http::StatusCode; diff --git a/src/api/auth.rs b/src/api/auth.rs index 190df27..4366b76 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -1,25 +1,25 @@ use std::sync::Arc; use axum::{ - extract::{FromRequestParts, State}, Json, + extract::{FromRequestParts, State}, }; use chrono::{Duration, Local}; -use http::{request::Parts, StatusCode}; +use http::{StatusCode, request::Parts}; use lettre::{ - message::header::ContentType, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, + AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, message::header::ContentType, }; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::{ + PasswordReset, PasswordResetState, api::users::UserAuthentication, auth::Authentication, database::DatabaseWrapper, error::TimeError, models::{NewUserIdentity, SelfUser, UserId, UserIdentity}, utils::{generate_password_reset_token, validate_email}, - PasswordReset, PasswordResetState, }; impl FromRequestParts for UserId { diff --git a/src/api/friends.rs b/src/api/friends.rs index 6eed4ce..3ff5934 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use axum::{extract::State, Json}; +use axum::{Json, extract::State}; use diesel::result::DatabaseErrorKind; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/leaderboards.rs b/src/api/leaderboards.rs index a9bfa0e..a7b9a6d 100644 --- a/src/api/leaderboards.rs +++ b/src/api/leaderboards.rs @@ -1,4 +1,4 @@ -use axum::{extract::Path, Json}; +use axum::{Json, extract::Path}; use diesel::result::{DatabaseErrorKind, Error as DieselError}; use http::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/oauth.rs b/src/api/oauth.rs index 63a42f1..ee1aba5 100644 --- a/src/api/oauth.rs +++ b/src/api/oauth.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::LazyLock}; use axum::{extract::Query, response::Redirect}; -use axum_extra::extract::{cookie::Cookie, CookieJar}; +use axum_extra::extract::{CookieJar, cookie::Cookie}; use reqwest::Client; use serde_derive::Deserialize; diff --git a/src/api/search.rs b/src/api/search.rs index 396b599..a994085 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -1,4 +1,4 @@ -use axum::{extract::Query, Json}; +use axum::{Json, extract::Query}; use serde_derive::Deserialize; use utoipa::IntoParams; diff --git a/src/api/users.rs b/src/api/users.rs index 5e42a3d..b6d6b24 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -1,10 +1,10 @@ use std::{collections::HashMap, sync::Arc}; use axum::{ - extract::{Path, Query, State}, Json, + extract::{Path, Query, State}, }; -use chrono::{serde::ts_seconds_option, DateTime, Duration, Local, Utc}; +use chrono::{DateTime, Duration, Local, Utc, serde::ts_seconds_option}; use http::StatusCode; use serde::Serialize; use serde_derive::Deserialize; diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 54b58b8..f72fd5a 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -7,7 +7,7 @@ use axum::extract::Request; use futures_util::future::BoxFuture; use tower::{Layer, Service}; -use crate::{database::DatabaseWrapper, models::UserIdentity, TestaustimeState}; +use crate::{TestaustimeState, database::DatabaseWrapper, models::UserIdentity}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Authentication { diff --git a/src/database/activity.rs b/src/database/activity.rs index b1d60ca..970d401 100644 --- a/src/database/activity.rs +++ b/src/database/activity.rs @@ -1,4 +1,4 @@ -use chrono::{prelude::*, Duration}; +use chrono::{Duration, prelude::*}; use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/src/database/auth.rs b/src/database/auth.rs index 492156c..e7a9d2d 100644 --- a/src/database/auth.rs +++ b/src/database/auth.rs @@ -1,6 +1,6 @@ use argon2::{ - password_hash::{rand_core::OsRng, PasswordHasher, SaltString}, Algorithm, Argon2, Params, PasswordHash, PasswordVerifier, Version, + password_hash::{PasswordHasher, SaltString, rand_core::OsRng}, }; use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/src/database/mod.rs b/src/database/mod.rs index f3a0d9f..67dff37 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -2,15 +2,15 @@ use std::sync::Arc; use axum::extract::{FromRef, FromRequestParts}; use diesel_async::{ + AsyncPgConnection, pooled_connection::{ - deadpool::{Object, Pool}, AsyncDieselConnectionManager, + deadpool::{Object, Pool}, }, - AsyncPgConnection, }; use http::request::Parts; -use crate::{error::TimeError, TestaustimeState}; +use crate::{TestaustimeState, error::TimeError}; pub mod activity; pub mod auth; diff --git a/src/error.rs b/src/error.rs index b970bea..59b7bdf 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use axum::{ - response::{IntoResponse, Response}, Json, + response::{IntoResponse, Response}, }; use http::StatusCode; use thiserror::Error; diff --git a/src/main.rs b/src/main.rs index 2692ba5..b61332e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,14 +15,14 @@ use std::{net::SocketAddr, num::NonZeroU32, sync::Arc}; use api::activity::HeartBeatMemoryStore; use auth::{AuthMiddleware, Authentication}; -use axum::{body::Body, Router}; +use axum::{Router, body::Body}; use chrono::NaiveDateTime; use dashmap::DashMap; use database::Database; use diesel::prelude::*; -use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; +use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations}; use governor::{Quota, RateLimiter}; -use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor}; +use lettre::{AsyncSmtpTransport, Tokio1Executor, transport::smtp::authentication::Credentials}; use models::UserIdentity; use ratelimiter::TestaustimeRateLimiter; use serde_derive::Deserialize; @@ -30,8 +30,8 @@ use tower::ServiceBuilder; use tower_http::trace::TraceLayer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use utoipa::{ - openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, Modify, OpenApi, + openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, }; use utoipa_axum::{router::OpenApiRouter, routes}; use utoipa_swagger_ui::SwaggerUi; diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index 2188e6d..e8c2572 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -11,12 +11,12 @@ use axum::{ }; use futures_util::future::BoxFuture; use governor::{ - clock::DefaultClock, middleware::StateInformationMiddleware, - state::keyed::DefaultKeyedStateStore, RateLimiter, + RateLimiter, clock::DefaultClock, middleware::StateInformationMiddleware, + state::keyed::DefaultKeyedStateStore, }; use http::{ - header::{HeaderName, FORWARDED}, HeaderValue, StatusCode, + header::{FORWARDED, HeaderName}, }; use tower::{Layer, Service}; diff --git a/src/state.rs b/src/state.rs index 121cc2b..f0dbe9b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,7 +4,7 @@ use axum::extract::FromRef; use lettre::{AsyncSmtpTransport, Tokio1Executor}; use crate::{ - api::activity::HeartBeatMemoryStore, PasswordResetState, RegisterLimiter, TestaustimeState, + PasswordResetState, RegisterLimiter, TestaustimeState, api::activity::HeartBeatMemoryStore, }; impl FromRef for Arc { diff --git a/src/tests/auth.rs b/src/tests/auth.rs index e029d9b..80693d5 100644 --- a/src/tests/auth.rs +++ b/src/tests/auth.rs @@ -104,11 +104,13 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!(resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("username")); + assert!( + resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("username") + ); let body = json!({"username": "validusername", "password": "short"}); let resp = request!(app, POST, "/auth/register", body); @@ -118,11 +120,13 @@ async fn invalid_usernames_and_passwords_are_rejected() { ); let resp_body: serde_json::Value = body_to_json(resp).await; - assert!(resp_body["error"] - .as_str() - .unwrap() - .to_ascii_lowercase() - .contains("password")); + assert!( + resp_body["error"] + .as_str() + .unwrap() + .to_ascii_lowercase() + .contains("password") + ); } // TODO: test ratelimits diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 245df0e..8670eb6 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -9,7 +9,7 @@ mod friends; mod leaderboards; mod macros; -use axum::{body::Body, extract::connect_info::MockConnectInfo, response::Response, Router}; +use axum::{Router, body::Body, extract::connect_info::MockConnectInfo, response::Response}; use http::{Request, StatusCode}; use serde::de::DeserializeOwned; use tower::ServiceExt; diff --git a/src/utils.rs b/src/utils.rs index 43b23f7..8f9fe41 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use itertools::Itertools; use lettre::Address; -use rand::{distr::Alphanumeric, rng, Rng}; +use rand::{Rng, distr::Alphanumeric, rng}; use crate::models::CodingActivity; From d88248b744d2d6278f79dc4acaba6a058cb393e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Sat, 31 Jan 2026 22:17:14 +0100 Subject: [PATCH 35/36] fix(nix): link postgres client correctly --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 6d7f88b..a69ad09 100644 --- a/flake.nix +++ b/flake.nix @@ -44,6 +44,7 @@ src = ./.; filter = path: type: (sqlFilter path type) || (craneLib.filterCargoSources path type); }; + RUSTFLAGS = "-C link-arg=-Wl,-rpath,${pkgs.postgresql.lib}/lib"; }; cargoArtifacts = craneLib.buildDepsOnly ( From 64c634c6488120d15de5eeedf0452033f75db108 Mon Sep 17 00:00:00 2001 From: DrVilepis Date: Fri, 26 Jun 2026 23:24:05 +0300 Subject: [PATCH 36/36] fix email verification logic --- src/api/auth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/auth.rs b/src/api/auth.rs index 4366b76..7ee0f9b 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -162,7 +162,7 @@ pub async fn register( return Err(TimeError::BadUsername); } - if data.email.as_ref().is_some_and(|e| validate_email(e)) { + if data.email.as_ref().is_some_and(|e| !validate_email(e)) { return Err(TimeError::InvalidEmail); }