aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock84
-rw-r--r--Cargo.toml2
-rw-r--r--src/datastructures.rs2
-rw-r--r--src/main.rs86
4 files changed, 81 insertions, 93 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 918900a..121d8d3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -377,7 +377,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cgit-simple-authentication"
-version = "0.3.5"
+version = "0.3.6"
dependencies = [
"anyhow",
"argon2",
@@ -682,9 +682,9 @@ checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
[[package]]
name = "futures"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253"
+checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27"
dependencies = [
"futures-channel",
"futures-core",
@@ -697,9 +697,9 @@ dependencies = [
[[package]]
name = "futures-channel"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25"
+checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2"
dependencies = [
"futures-core",
"futures-sink",
@@ -707,15 +707,15 @@ dependencies = [
[[package]]
name = "futures-core"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815"
+checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1"
[[package]]
name = "futures-executor"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d"
+checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79"
dependencies = [
"futures-core",
"futures-task",
@@ -724,9 +724,9 @@ dependencies = [
[[package]]
name = "futures-io"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04"
+checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1"
[[package]]
name = "futures-lite"
@@ -745,10 +745,11 @@ dependencies = [
[[package]]
name = "futures-macro"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b"
+checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121"
dependencies = [
+ "autocfg",
"proc-macro-hack",
"proc-macro2",
"quote",
@@ -757,22 +758,23 @@ dependencies = [
[[package]]
name = "futures-sink"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23"
+checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282"
[[package]]
name = "futures-task"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc"
+checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae"
[[package]]
name = "futures-util"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025"
+checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967"
dependencies = [
+ "autocfg",
"futures-channel",
"futures-core",
"futures-io",
@@ -950,9 +952,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "js-sys"
-version = "0.3.50"
+version = "0.3.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c"
+checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062"
dependencies = [
"wasm-bindgen",
]
@@ -1003,9 +1005,9 @@ checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
[[package]]
name = "libsqlite3-sys"
-version = "0.22.1"
+version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19cb1effde5f834799ac5e5ef0e40d45027cd74f271b1de786ba8abb30e2164d"
+checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d"
dependencies = [
"cc",
"pkg-config",
@@ -1267,9 +1269,9 @@ dependencies = [
[[package]]
name = "openssl-probe"
-version = "0.1.2"
+version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
+checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a"
[[package]]
name = "openssl-src"
@@ -1778,9 +1780,9 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]]
name = "sha2"
-version = "0.9.4"
+version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d8f6b75b17576b792bef0db1bcc4b8b8bcdf9506744cf34b974195487af6cff2"
+checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
@@ -2300,9 +2302,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm-bindgen"
-version = "0.2.73"
+version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9"
+checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen-macro",
@@ -2310,9 +2312,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
-version = "0.2.73"
+version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae"
+checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900"
dependencies = [
"bumpalo",
"lazy_static",
@@ -2325,9 +2327,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
-version = "0.4.23"
+version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea"
+checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
@@ -2337,9 +2339,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
-version = "0.2.73"
+version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f"
+checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -2347,9 +2349,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
-version = "0.2.73"
+version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c"
+checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97"
dependencies = [
"proc-macro2",
"quote",
@@ -2360,15 +2362,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
-version = "0.2.73"
+version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489"
+checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f"
[[package]]
name = "web-sys"
-version = "0.3.50"
+version = "0.3.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be"
+checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582"
dependencies = [
"js-sys",
"wasm-bindgen",
diff --git a/Cargo.toml b/Cargo.toml
index faa01da..7987c94 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "cgit-simple-authentication"
-version = "0.3.5"
+version = "0.3.6"
authors = ["KunoiSayami <[email protected]>"]
edition = "2018"
diff --git a/src/datastructures.rs b/src/datastructures.rs
index e4bc879..0a2b9f1 100644
--- a/src/datastructures.rs
+++ b/src/datastructures.rs
@@ -147,7 +147,7 @@ impl Config {
pub fn get_copied_database_location(&self) -> PathBuf {
if self.test {
- return PathBuf::from(self.database.as_str())
+ return PathBuf::from(self.database.as_str());
}
std::path::Path::new(CACHE_DIR).join(
diff --git a/src/main.rs b/src/main.rs
index e92cbe1..2537301 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -40,7 +40,6 @@ use std::str::FromStr;
use tempdir::TempDir;
use tokio_stream::StreamExt as _;
-
struct IOModule<R, W> {
reader: R,
writer: W,
@@ -74,7 +73,7 @@ impl<R: BufRead, W: Write> IOModule<R, W> {
cookie.get_body(),
cfg.cookie_ttl as usize,
)
- .await?;
+ .await?;
let cookie_value = cookie.to_string();
@@ -87,9 +86,10 @@ impl<R: BufRead, W: Write> IOModule<R, W> {
writeln!(&mut self.writer, "Status: 302 Found")?;
writeln!(&mut self.writer, "Cache-Control: no-cache, no-store")?;
writeln!(&mut self.writer, "Location: {}", location)?;
- writeln!(&mut self.writer,
- "Set-Cookie: cgit_auth={}; Domain={}; Max-Age={}; HttpOnly{}",
- cookie_value, domain, cfg.cookie_ttl, cookie_suffix
+ writeln!(
+ &mut self.writer,
+ "Set-Cookie: cgit_auth={}; Domain={}; Max-Age={}; HttpOnly{}",
+ cookie_value, domain, cfg.cookie_ttl, cookie_suffix
)?;
} else {
writeln!(&mut self.writer, "Status: 403 Forbidden")?;
@@ -99,7 +99,6 @@ impl<R: BufRead, W: Write> IOModule<R, W> {
writeln!(&mut self.writer)?;
Ok(())
}
-
}
// Processing the `authenticate-cookie` called by cgit.
@@ -154,7 +153,7 @@ async fn cmd_init(cfg: Config) -> Result<()> {
.await?;
if !rows.is_empty() {
- return Ok(())
+ return Ok(());
}
}
@@ -182,25 +181,25 @@ async fn verify_login(cfg: &Config, data: &FormData, redis_conn: redis::Client)
let mut conn = sqlx::sqlite::SqliteConnectOptions::from_str(
cfg.get_copied_database_location().to_str().unwrap(),
)?
- .journal_mode(sqlx::sqlite::SqliteJournalMode::Off)
- .log_statements(log::LevelFilter::Trace)
- .connect()
- .await?;
+ .journal_mode(sqlx::sqlite::SqliteJournalMode::Off)
+ .log_statements(log::LevelFilter::Trace)
+ .connect()
+ .await?;
let (passwd_hash, uid) = sqlx::query_as::<_, (String, String)>(
r#"SELECT "password", "uid" FROM "accounts" WHERE "user" = ?"#,
)
- .bind(data.get_user())
- .fetch_one(&mut conn)
- .await?;
+ .bind(data.get_user())
+ .fetch_one(&mut conn)
+ .await?;
let key = format!("cgit_repo_{}", data.get_user());
if !rd.exists(&key).await? {
if let Some((repos,)) =
- sqlx::query_as::<_, (String,)>(r#"SELECT "repos" FROM "repo" WHERE "uid" = ? "#)
- .bind(uid)
- .fetch_optional(&mut conn)
- .await?
+ sqlx::query_as::<_, (String,)>(r#"SELECT "repos" FROM "repo" WHERE "uid" = ? "#)
+ .bind(uid)
+ .fetch_optional(&mut conn)
+ .await?
{
let iter = repos.split_whitespace().collect::<Vec<&str>>();
rd.sadd(&key, iter).await?;
@@ -370,9 +369,9 @@ async fn cmd_upgrade_database(cfg: Config) -> Result<()> {
let (v,) = sqlx::query_as::<_, (String,)>(
r#"SELECT "value" FROM "auth_meta" WHERE "key" = 'version' "#,
)
- .fetch_optional(&mut origin_conn)
- .await?
- .unwrap();
+ .fetch_optional(&mut origin_conn)
+ .await?
+ .unwrap();
#[allow(deprecated)]
if v.eq(database::previous::VERSION) {
@@ -434,7 +433,7 @@ async fn async_main(arg_matches: ArgMatches<'_>) -> Result<i32> {
let output = std::io::stdout();
let mut module = IOModule {
reader: input,
- writer: output
+ writer: output,
};
module.cmd_authenticate_post(matches, cfg).await?;
}
@@ -465,7 +464,6 @@ async fn async_main(arg_matches: ArgMatches<'_>) -> Result<i32> {
}
fn get_arg_matches(arguments: Option<Vec<&str>>) -> ArgMatches {
-
// Sub-arguments for each command, see cgi defines.
let sub_args = &[
Arg::with_name("http-cookie").required(true), // 2
@@ -531,7 +529,6 @@ fn get_arg_matches(arguments: Option<Vec<&str>>) -> ArgMatches {
}
fn process_arguments() -> Result<()> {
-
let ret = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
@@ -583,18 +580,18 @@ fn main() -> Result<()> {
#[cfg(test)]
mod test {
- use crate::{cmd_init, cmd_add_user};
- use std::path::PathBuf;
+ use crate::datastructures::{rand_str, Config};
+ use crate::{cmd_add_user, cmd_init};
+ use crate::{get_arg_matches, IOModule};
use argon2::{
- password_hash::{PasswordHash, PasswordVerifier, PasswordHasher, SaltString},
+ password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
Argon2,
};
- use crate::{IOModule, get_arg_matches};
- use crate::datastructures::{Config, rand_str};
use redis::AsyncCommands;
- use std::time::Duration;
- use std::thread::sleep;
use std::path::Path;
+ use std::path::PathBuf;
+ use std::thread::sleep;
+ use std::time::Duration;
#[test]
fn test_argon2() {
@@ -642,12 +639,9 @@ mod test {
.unwrap();
}
- fn write_test_result_to_redis() {
-
- }
+ fn write_test_result_to_redis() {}
fn test_auth_post() -> String {
-
let correct_input = br#"redirect=/&username=hunter2&password=hunter2"#;
let matches = get_arg_matches(Some(vec![
"a",
@@ -673,22 +667,18 @@ mod test {
let cfg = Config::generate_test_config();
match matches.subcommand() {
- ("authenticate-post", Some(matches)) => {
- tokio::runtime::Builder::new_current_thread()
- .enable_all()
- .build()
- .unwrap()
- .block_on(module.cmd_authenticate_post(matches, cfg))
- .unwrap()
- }
+ ("authenticate-post", Some(matches)) => tokio::runtime::Builder::new_current_thread()
+ .enable_all()
+ .build()
+ .unwrap()
+ .block_on(module.cmd_authenticate_post(matches, cfg))
+ .unwrap(),
_ => {}
}
String::from_utf8(output).unwrap()
-
}
-
#[test]
fn test_1_auth_failure() {
let out = test_auth_post();
@@ -712,12 +702,11 @@ mod test {
std::fs::File::create("test/DATABASE_INITED").unwrap();
}
-
fn lock(path: &std::path::PathBuf, sleep_length: usize) {
for _ in 0..(sleep_length * 100) {
sleep(Duration::from_millis(10));
if path.exists() {
- break
+ break;
}
}
@@ -746,14 +735,11 @@ mod test {
#[test]
fn test_3_auth_pass() {
-
lock(&PathBuf::from("test/USER_WRITTEN"), 15);
let s = test_auth_post();
println!("{}", s);
assert!(s.starts_with("Status: 302"))
-
}
-
}