Validate auth cookies
This commit is contained in:
parent
fa178b92be
commit
9df21737fa
3 changed files with 15 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1521,6 +1521,7 @@ dependencies = [
|
||||||
"ape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"diesel 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"diesel 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"flame 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"flame 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -15,6 +15,7 @@ anyhow = "1.0"
|
||||||
ape = "0.2.0"
|
ape = "0.2.0"
|
||||||
app_dirs = "1.1.1"
|
app_dirs = "1.1.1"
|
||||||
base64 = "0.11.0"
|
base64 = "0.11.0"
|
||||||
|
cookie = "0.12.0"
|
||||||
diesel = { version = "1.4", features = ["sqlite", "r2d2"] }
|
diesel = { version = "1.4", features = ["sqlite", "r2d2"] }
|
||||||
diesel_migrations = { version = "1.4", features = ["sqlite"] }
|
diesel_migrations = { version = "1.4", features = ["sqlite"] }
|
||||||
flame = { version = "0.2.2", optional = true }
|
flame = { version = "0.2.2", optional = true }
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use cookie::Cookie;
|
||||||
use function_name::named;
|
use function_name::named;
|
||||||
use http::header::*;
|
use http::header::*;
|
||||||
use http::{HeaderMap, HeaderValue, Response, StatusCode};
|
use http::{HeaderMap, HeaderValue, Response, StatusCode};
|
||||||
|
@ -7,6 +8,7 @@ use serde::Serialize;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::service::constants::*;
|
||||||
use crate::service::dto;
|
use crate::service::dto;
|
||||||
use crate::{config, ddns, index, vfs};
|
use crate::{config, ddns, index, vfs};
|
||||||
|
|
||||||
|
@ -264,8 +266,17 @@ fn test_service_auth() {
|
||||||
username: TEST_USERNAME.into(),
|
username: TEST_USERNAME.into(),
|
||||||
password: TEST_PASSWORD.into(),
|
password: TEST_PASSWORD.into(),
|
||||||
};
|
};
|
||||||
assert!(service.post_json("/api/auth", &credentials).status() == StatusCode::OK);
|
let response = service.post_json("/api/auth", &credentials);
|
||||||
// TODO validate cookies
|
assert!(response.status() == StatusCode::OK);
|
||||||
|
let cookies: Vec<Cookie> = response
|
||||||
|
.headers()
|
||||||
|
.get_all(SET_COOKIE)
|
||||||
|
.iter()
|
||||||
|
.map(|c| Cookie::parse(c.to_str().unwrap()).unwrap())
|
||||||
|
.collect();
|
||||||
|
assert!(cookies.iter().any(|c| c.name() == COOKIE_SESSION));
|
||||||
|
assert!(cookies.iter().any(|c| c.name() == COOKIE_USERNAME));
|
||||||
|
assert!(cookies.iter().any(|c| c.name() == COOKIE_ADMIN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue