Skip to content

Updated to latest actix-session and sqlx #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,632 changes: 1,284 additions & 348 deletions Cargo.lock

Large diffs are not rendered by default.

38 changes: 25 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -2,25 +2,37 @@
name = "actix-session-sqlx-postgres"
version = "0.1.4"
edition = "2021"
authors = ["Christopher Kolstad <git@chriswk.no>", "Simon Hornby <liquidwicked64@gmail.com>"]
authors = [
"Christopher Kolstad <git@chriswk.no>",
"Simon Hornby <liquidwicked64@gmail.com>",
]
description = "Actix Session Sqlx Postgres is a Sqlx Postgres implementation of the ActixSession Store trait"
license = "Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-session = "0.7.2"
anyhow = "1.0.71"
async-trait = "0.1.68"
chrono = { version = "0.4.26", features = ["serde"] }
actix-session = "0.10.1"
anyhow = "1.0.89"
chrono = { version = "0.4.38", features = ["serde"] }
rand = "0.8.5"
serde = { version = "1.0.164", features = ["derive"]}
serde_json = { version = "1.0.99" }
sqlx = { version = "0.6", features = ["json", "chrono", "runtime-actix-rustls", "time", "postgres"] }
time = "0.3.19"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = { version = "1.0.128" }
sqlx = { version = "0.8.2", features = [
"json",
"chrono",
"runtime-tokio",
"time",
"postgres",
] }
time = "0.3.36"

[dev-dependencies]
testcontainers = { version ="0.14.0"}
actix-test = "0.1.1"
actix-web = { version = "4", default_features = false, features = ["cookies", "secure-cookies", "macros"] }
actix-session = { version = "0.7.1" }
testcontainers = { version = "0.22.0" }
actix-test = "0.1.5"
actix-web = { version = "4", default_features = false, features = [
"cookies",
"secure-cookies",
"macros",
] }
actix-session = { version = "0.10.1" }
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -157,7 +157,6 @@ impl SqlxPostgresqlSessionStoreBuilder {
}
pub(crate) type SessionState = HashMap<String, String>;

#[async_trait::async_trait(?Send)]
impl SessionStore for SqlxPostgresqlSessionStore {
async fn load(&self, session_key: &SessionKey) -> Result<Option<SessionState>, LoadError> {
let key = (self.configuration.cache_keygen)(session_key.as_ref());
36 changes: 21 additions & 15 deletions tests/session_store.rs
Original file line number Diff line number Diff line change
@@ -3,30 +3,36 @@ use actix_session::storage::SessionStore;
use actix_session_sqlx_postgres::SqlxPostgresqlSessionStore;
use sqlx::postgres::PgPoolOptions;
use std::collections::HashMap;
use testcontainers::clients;
use testcontainers::core::WaitFor;
use testcontainers::images::generic;
use testcontainers::{
core::{IntoContainerPort, WaitFor},
runners::AsyncRunner,
GenericImage, ImageExt,
};

async fn postgres_store(url: String) -> SqlxPostgresqlSessionStore {
SqlxPostgresqlSessionStore::new(url).await.expect("")
}

#[actix_web::test]
async fn test_session_workflow() {
let docker = clients::Cli::default();
let postgres = docker.run(
generic::GenericImage::new("postgres", "15-alpine")
.with_wait_for(WaitFor::message_on_stderr(
"database system is ready to accept connections",
))
.with_env_var("POSTGRES_DB", "sessions")
.with_env_var("POSTGRES_PASSWORD", "example")
.with_env_var("POSTGRES_HOST_AUTH_METHOD", "trust")
.with_env_var("POSTGRES_USER", "tests"),
);
let postgres = GenericImage::new("postgres", "15-alpine")
.with_exposed_port(5432.tcp())
.with_wait_for(WaitFor::message_on_stderr(
"database system is ready to accept connections",
))
.with_env_var("POSTGRES_DB", "sessions")
.with_env_var("POSTGRES_PASSWORD", "example")
.with_env_var("POSTGRES_HOST_AUTH_METHOD", "trust")
.with_env_var("POSTGRES_USER", "tests")
.start()
.await
.expect("Postgres started");
let url = format!(
"postgres://tests:example@localhost:{}/sessions",
postgres.get_host_port_ipv4(5432)
postgres
.get_host_port_ipv4(5432)
.await
.expect("Failed to get port")
);

let postgres_store = postgres_store(url.clone()).await;