Skip to content

Commit 905ebfa

Browse files
committed
Add dummy auth middleware
It makes no checks and accepts everything, for now.
1 parent 7e1522d commit 905ebfa

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ actix-web = "1.0.5"
1212
serde = "1.0.98"
1313
futures = "0.1.28"
1414
rand = "0.7.0"
15+
actix-web-httpauth = "0.3.2"
1516

1617
[dev-dependencies]
1718
tempfile = "3.1.0"

src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
use actix_web::dev::ServiceRequest;
12
use actix_web::{get, web, App, HttpResponse, HttpServer};
2-
use futures::Future;
3+
use actix_web_httpauth::extractors::basic::BasicAuth;
4+
use actix_web_httpauth::middleware::HttpAuthentication;
5+
use futures::{future, Future};
36
use rand::distributions::Alphanumeric;
47
use rand::{thread_rng, Rng};
58
use serde::Deserialize;
@@ -13,9 +16,14 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
1316
let config = web::Data::new(config);
1417

1518
HttpServer::new(move || {
19+
let basic_auth = HttpAuthentication::basic(authenticate);
1620
App::new()
1721
.register_data(config.clone())
18-
.service(web::resource("/").route(web::post().to_async(new_paste)))
22+
.service(
23+
web::resource("/")
24+
.route(web::post().to_async(new_paste))
25+
.wrap(basic_auth),
26+
)
1927
.service(send_paste)
2028
})
2129
.bind("127.0.0.1:8080")
@@ -29,7 +37,8 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
2937
pub struct Config {
3038
pub paste_dir: String,
3139
pub url_base: String,
32-
// TODO: Fields for HTTP auth (user/pass)
40+
pub username: String,
41+
pub password: String,
3342
}
3443

3544
impl Config {
@@ -38,9 +47,13 @@ impl Config {
3847
// TODO: Parse command line arguments
3948
let paste_dir = String::from("./pastes");
4049
let url_base = String::from("https://localhost");
50+
let username = String::from("tansly");
51+
let password = String::from("hebele");
4152
Ok(Config {
4253
paste_dir,
4354
url_base,
55+
username,
56+
password,
4457
})
4558
}
4659
}
@@ -100,6 +113,13 @@ fn send_paste(
100113
})
101114
}
102115

116+
fn authenticate(
117+
req: ServiceRequest,
118+
_credentials: BasicAuth,
119+
) -> impl Future<Item = ServiceRequest, Error = actix_web::Error> {
120+
future::ok(req)
121+
}
122+
103123
#[cfg(test)]
104124
mod tests {
105125
use super::*;
@@ -113,6 +133,8 @@ mod tests {
113133
Config {
114134
paste_dir: String::from(paste_dir),
115135
url_base: String::from("https://testurl"),
136+
username: String::from("tansly"),
137+
password: String::from("hebele"),
116138
}
117139
}
118140

0 commit comments

Comments
 (0)