Skip to content

Commit

Permalink
Fixed build. (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 authored Jan 1, 2024
1 parent 7103b64 commit 7f9d87d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/controllers/sys_info_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use actix_web::{web, HttpResponse, Responder};
use fs_extra::dir::get_size;
use sha256::digest;

use sysinfo::{System};
use sysinfo::System;
pub mod built_info {
// The file has been placed there by the build script.
include!(concat!(env!("OUT_DIR"), "/built.rs"));
Expand Down
36 changes: 20 additions & 16 deletions src/gpodder/auth/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,31 @@ pub async fn login(
if let Some(admin_username) = &env.username {
if admin_username == &unwrapped_username {
if let Some(admin_password) = &env.password {
if admin_password == &digest(password) {
if admin_password == &digest(password.clone()) {
return Ok(HttpResponse::Ok().json("Login successful"));
}
}
}
} else {
let user = User::find_by_username(
&unwrapped_username,
conn.get().map_err(map_r2d2_error)?.deref_mut(),
)?;
if user.clone().password.unwrap() == digest(password) {
let session = Session::new(user.username);
Session::insert_session(&session, conn.get().map_err(map_r2d2_error)?.deref_mut())
.expect("Error inserting session");
let user_cookie = create_session_cookie(session);
return Ok(HttpResponse::Ok().cookie(user_cookie).finish());
} else {
return Err(CustomError::Forbidden);
}
}
Err(CustomError::Forbidden)

let user = User::find_by_username(
&unwrapped_username,
conn.get().map_err(map_r2d2_error)?.deref_mut(),
)?;
return match user.password {
Some(p) => {
if p == digest(password) {
let session = Session::new(user.username);
Session::insert_session(&session, conn.get().map_err(map_r2d2_error)?.deref_mut())
.expect("Error inserting session");
let user_cookie = create_session_cookie(session);
Ok(HttpResponse::Ok().cookie(user_cookie).finish())
} else {
Err(CustomError::Forbidden)
}
}
None => Err(CustomError::Forbidden),
};
}

fn create_session_cookie(session: Session) -> Cookie<'static> {
Expand Down
24 changes: 9 additions & 15 deletions src/service/environment_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,15 @@ impl EnvironmentService {

#[cfg(test)]
mod tests {
use crate::constants::inner_constants::{BASIC_AUTH, OIDC_AUTH, OIDC_AUTHORITY, OIDC_CLIENT_ID, OIDC_JWKS,
OIDC_REDIRECT_URI, OIDC_SCOPE, PASSWORD, PODINDEX_API_KEY, PODINDEX_API_SECRET, POLLING_INTERVAL, SERVER_URL, USERNAME};
use crate::constants::inner_constants::{
BASIC_AUTH, OIDC_AUTH, OIDC_AUTHORITY, OIDC_CLIENT_ID, OIDC_JWKS, OIDC_REDIRECT_URI,
OIDC_SCOPE, PASSWORD, PODINDEX_API_KEY, PODINDEX_API_SECRET, POLLING_INTERVAL, SERVER_URL,
USERNAME,
};

use crate::service::environment_service::EnvironmentService;
use serial_test::serial;
use std::env::{remove_var, set_var};
use crate::service::environment_service::EnvironmentService;

fn do_env_cleanup() {
remove_var(SERVER_URL);
Expand Down Expand Up @@ -266,10 +269,7 @@ mod tests {
set_var(SERVER_URL, "http://localhost:8000");

let env_service = EnvironmentService::new();
assert_eq!(
env_service.get_server_url(),
"http://localhost:8000/"
);
assert_eq!(env_service.get_server_url(), "http://localhost:8000/");
}

#[test]
Expand Down Expand Up @@ -300,20 +300,14 @@ mod tests {

let env_service = EnvironmentService::new();
assert_eq!(env_service.podindex_api_key, "test");
assert_eq!(
env_service.podindex_api_secret,
"testsecret"
);
assert_eq!(env_service.podindex_api_secret, "testsecret");
}

#[test]
#[serial]
fn test_get_polling_interval() {
do_env_cleanup();
set_var(POLLING_INTERVAL, "20");
assert_eq!(
EnvironmentService::new().polling_interval,
20
);
assert_eq!(EnvironmentService::new().polling_interval, 20);
}
}

0 comments on commit 7f9d87d

Please sign in to comment.