diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..774bea6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +name: Tests and Formatting + +on: + workflow_dispatch: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + everything: + name: Rust/JS Checks/Formatting + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Run cargo fmt + id: fmt + run: cargo fmt --all -- --check + continue-on-error: true + - name: Run cargo clippy + id: clippy + continue-on-error: true + run: cargo clippy --all -- -D warnings + - name: Run cargo test + id: test + continue-on-error: true + run: cargo test + - name: Check if code is properly formatted + if: steps.fmt.outcome != 'success' + run: exit 1 + - name: Check if clippy is happy + if: steps.clippy.outcome != 'success' + run: exit 1 + - name: Check if test succeeded + if: steps.test.outcome != 'success' + run: exit 1 diff --git a/Cargo.lock b/Cargo.lock index 33e184a..07f1cef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,6 +93,16 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "cookie" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" +dependencies = [ + "time", + "version_check", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -134,6 +144,15 @@ dependencies = [ "syn", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "diesel" version = "2.2.4" @@ -238,6 +257,7 @@ dependencies = [ "anyhow", "bytes", "chrono", + "cookie", "diesel", "ft-derive", "ft-sys", @@ -435,6 +455,12 @@ dependencies = [ "include_dir", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-traits" version = "0.2.19" @@ -462,6 +488,12 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "pretty_assertions" version = "1.4.1" @@ -609,6 +641,37 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "unicode-ident" version = "1.0.13" diff --git a/examples/003-migration/src/lib.rs b/examples/003-migration/src/lib.rs index b464045..515f141 100644 --- a/examples/003-migration/src/lib.rs +++ b/examples/003-migration/src/lib.rs @@ -16,7 +16,7 @@ fn create_account( return Err(username.error("username 'admin' is not allowed").into()); } - let _res = conn.transaction::<_, ft_sdk::Error, _>(|c| { + conn.transaction::<_, ft_sdk::Error, _>(|c| { // do a select query to see if username is already taken if diesel::select(diesel::dsl::exists( account_user::table.filter(account_user::username.eq(&username.0)), diff --git a/ft-sdk/Cargo.toml b/ft-sdk/Cargo.toml index c068962..6dbd508 100644 --- a/ft-sdk/Cargo.toml +++ b/ft-sdk/Cargo.toml @@ -36,3 +36,4 @@ uuid.workspace = true [dev-dependencies] pretty_assertions = "1" +cookie.workspace = true diff --git a/ft-sdk/src/data.rs b/ft-sdk/src/data.rs index dc2ec3c..341125a 100644 --- a/ft-sdk/src/data.rs +++ b/ft-sdk/src/data.rs @@ -113,13 +113,13 @@ pub fn binary>(content: bytes::Bytes, content_type: S) -> Result { /// a 200-OK response, with an HTML meta-refresh tag to redirect the browser. /// /// ```rust -/// let cookie = cookie::Cookie::build((ft_sdk::auth::SESSION_KEY, sid)) -/// .domain(host.without_port()) -/// .path("/") +/// let cookie = cookie::Cookie::build((ft_sdk::auth::SESSION_KEY, "some-uniq-key")) +/// .domain("127.0.0.1") +/// .path("") /// .max_age(cookie::time::Duration::seconds(34560000)) /// .same_site(cookie::SameSite::Strict) /// .build(); -/// ft_sdk::data::browser_redirect_with_cookie("/", cookie) +/// ft_sdk::data::browser_redirect_with_cookie("/", http::HeaderValue::from_str(cookie.to_string().as_str()).unwrap()); /// ``` pub fn browser_redirect_with_cookie>(url: S, c: http::HeaderValue) -> Result { Ok(ft_sdk::chr::CHR::new(Output::Redirect( diff --git a/ft-sys/src/diesel_sqlite/mod.rs b/ft-sys/src/diesel_sqlite/mod.rs index 9bff81a..bcf0a3f 100644 --- a/ft-sys/src/diesel_sqlite/mod.rs +++ b/ft-sys/src/diesel_sqlite/mod.rs @@ -8,5 +8,5 @@ mod types; pub use backend::Sqlite; pub use connection::SqliteConnection; -pub use sqlite_value::{Cursor, SqliteValue}; pub(crate) use no_instrumentation::NoInstrumentation; +pub use sqlite_value::{Cursor, SqliteValue};