Skip to content
Merged
Show file tree
Hide file tree
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
187 changes: 97 additions & 90 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ openid = ["dep:openidconnect"]
worker = []
wireguard = []

[profile.dev]
strip = "debuginfo"

[profile.release]
lto = "thin"
strip = "symbols"
1 change: 1 addition & 0 deletions src/db/models/polling_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct PollingToken {
}

impl PollingToken {
#[must_use]
pub fn new(device_id: i64) -> Self {
Self {
id: None,
Expand Down
3 changes: 1 addition & 2 deletions src/db/models/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ impl WireguardNetwork {

/// Try to set `address` from `&str`.
pub fn try_set_address(&mut self, address: &str) -> Result<IpNetwork, IpNetworkError> {
IpNetwork::from_str(address).map(|network| {
IpNetwork::from_str(address).inspect(|&network| {
self.address = network;
network
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/enterprise/handlers/openid_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub async fn auth_callback(
user
}
Ok(None) => {
if let Some(mut user) = User::find_by_email(&appstate.pool, &email).await? {
if let Some(mut user) = User::find_by_email(&appstate.pool, email).await? {
// User with the same email already exists, merge the accounts
info!(
"User with email address {} is logging in through OpenID Connect for the first time and we've found an existing account with the same email address. Merging accounts.",
Expand Down
6 changes: 4 additions & 2 deletions src/grpc/enrollment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl EnrollmentServer {
"Retrieving instance info for user {}({:?}).",
user.username, user.id
);
let instance_info = InstanceInfo::new(settings, &user.username, enterprise_settings);
let instance_info = InstanceInfo::new(settings, &user.username, &enterprise_settings);
debug!("Instance info {instance_info:?}");

debug!(
Expand Down Expand Up @@ -594,7 +594,9 @@ impl EnrollmentServer {
let response = DeviceConfigResponse {
device: Some(device.into()),
configs: configs.into_iter().map(Into::into).collect(),
instance: Some(InstanceInfo::new(settings, &user.username, enterprise_settings).into()),
instance: Some(
InstanceInfo::new(settings, &user.username, &enterprise_settings).into(),
),
token: Some(token.token),
};
debug!("{response:?}.");
Expand Down
2 changes: 1 addition & 1 deletion src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ impl InstanceInfo {
pub fn new<S: Into<String>>(
settings: Settings,
username: S,
enterprise_settings: EnterpriseSettings,
enterprise_settings: &EnterpriseSettings,
) -> Self {
let config = server_config();
InstanceInfo {
Expand Down
2 changes: 1 addition & 1 deletion src/grpc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub(crate) async fn build_device_config_response(
Ok(DeviceConfigResponse {
device: Some(device.into()),
configs,
instance: Some(InstanceInfo::new(settings, &user.username, enterprise_settings).into()),
instance: Some(InstanceInfo::new(settings, &user.username, &enterprise_settings).into()),
token,
})
}
2 changes: 1 addition & 1 deletion src/handlers/ssh_authorized_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub async fn add_authentication_key(
return Err(WebError::ModelError("Model returned without ID".into()));
};

let trimmed_key = data.key.trim_end_matches(|c| c == '\n' || c == '\r');
let trimmed_key = data.key.trim_end_matches(['\n', '\r']);

// verify key
match data.key_type {
Expand Down
30 changes: 11 additions & 19 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn create_user_agent_parser() -> Arc<UserAgentParser> {
}

#[must_use]
pub fn parse_user_agent<'a>(
pub(crate) fn parse_user_agent<'a>(
user_parser: &UserAgentParser,
user_agent: &'a str,
) -> Option<Client<'a>> {
Expand All @@ -29,23 +29,15 @@ pub fn parse_user_agent<'a>(
}

#[must_use]
pub fn get_device_info(user_agent_parser: &UserAgentParser, user_agent: &str) -> Option<String> {
let agent = parse_user_agent(user_agent_parser, user_agent);

agent.map(|v| get_user_agent_device(&v))
}

#[must_use]
pub fn get_device_type(user_agent_client: Option<Client>) -> String {
if let Some(client) = user_agent_client {
get_user_agent_device(&client)
} else {
String::new()
}
pub(crate) fn get_device_info(
user_agent_parser: &UserAgentParser,
user_agent: &str,
) -> Option<String> {
parse_user_agent(user_agent_parser, user_agent).map(|v| get_user_agent_device(&v))
}

#[must_use]
pub fn get_user_agent_device(user_agent_client: &Client) -> String {
pub(crate) fn get_user_agent_device(user_agent_client: &Client) -> String {
let device_type = user_agent_client
.device
.model
Expand Down Expand Up @@ -77,7 +69,7 @@ pub fn get_user_agent_device(user_agent_client: &Client) -> String {
}

#[must_use]
pub fn get_device_login_event(
pub(crate) fn get_device_login_event(
user_id: i64,
ip_address: String,
event_type: String,
Expand All @@ -87,7 +79,7 @@ pub fn get_device_login_event(
.map(|client| get_user_agent_device_login_data(user_id, ip_address, event_type, &client))
}

pub fn get_user_agent_device_login_data(
pub(crate) fn get_user_agent_device_login_data(
user_id: i64,
ip_address: String,
event_type: String,
Expand All @@ -114,7 +106,7 @@ pub fn get_user_agent_device_login_data(
)
}

pub async fn check_new_device_login(
pub(crate) async fn check_new_device_login(
pool: &DbPool,
mail_tx: &UnboundedSender<Mail>,
session: &Session,
Expand All @@ -125,7 +117,7 @@ pub async fn check_new_device_login(
) -> Result<(), TemplateError> {
if let Some(user_id) = user.id {
if let Some(device_login_event) =
get_device_login_event(user_id, ip_address, event_type, agent.clone())
get_device_login_event(user_id, ip_address, event_type, agent)
{
if let Ok(Some(created_device_login_event)) = device_login_event
.check_if_device_already_logged_in(pool)
Expand Down
5 changes: 1 addition & 4 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ static MAIL_PASSWORD_RESET_START: &str =
static MAIL_PASSWORD_RESET_SUCCESS: &str =
include_str!("../templates/mail_password_reset_success.tera");

#[allow(dead_code)]
static MAIL_DATE_FORMAT: &str = "%Y-%m-%dT%H:%M:00Z";

#[derive(Error, Debug)]
pub enum TemplateError {
#[error("Failed to generate email MFA code")]
Expand All @@ -56,7 +53,7 @@ pub fn get_base_tera(
// supply context required by base
context.insert("application_version", &VERSION);
let now = Utc::now();
let current_year = format!("{:04}", &now.year());
let current_year = format!("{:04}", now.year());
context.insert("current_year", &current_year);
context.insert("date_now", &now.format("%A, %B %d, %Y at %r").to_string());

Expand Down
6 changes: 3 additions & 3 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ pub async fn init_test_db() -> (DbPool, DefGuardConfig) {
)
.await;

initialize_users(&pool, config.clone()).await;
initialize_users(&pool, &config).await;

(pool, config)
}

async fn initialize_users(pool: &DbPool, config: DefGuardConfig) {
async fn initialize_users(pool: &DbPool, config: &DefGuardConfig) {
User::init_admin_user(pool, config.default_admin_password.expose_secret())
.await
.unwrap();
Expand Down Expand Up @@ -177,7 +177,7 @@ pub async fn make_test_client() -> (TestClient, ClientState) {

#[allow(dead_code)]
pub async fn fetch_user_details(client: &TestClient, username: &str) -> UserDetails {
let response = client.get(&format!("/api/v1/user/{username}")).send().await;
let response = client.get(format!("/api/v1/user/{username}")).send().await;
assert_eq!(response.status(), StatusCode::OK);
response.json().await
}
10 changes: 6 additions & 4 deletions tests/wireguard_network_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use serde_json::{json, Value};

use self::common::make_test_client;

static DATE_FORMAT: &str = "%Y-%m-%dT%H:%M:00Z";

fn make_network() -> Value {
json!({
"name": "network",
Expand Down Expand Up @@ -86,7 +88,7 @@ async fn test_stats() {
let response = client
.get(format!(
"/api/v1/network/1/stats/users?from={}",
hour_ago.format("%Y-%m-%dT%H:%M:00Z"),
hour_ago.format(DATE_FORMAT),
))
.send()
.await;
Expand Down Expand Up @@ -117,7 +119,7 @@ async fn test_stats() {
let response = client
.get(format!(
"/api/v1/network/1/stats/users?from={}",
hour_ago.format("%Y-%m-%dT%H:%M:00Z"),
hour_ago.format(DATE_FORMAT),
))
.send()
.await;
Expand Down Expand Up @@ -221,7 +223,7 @@ async fn test_stats() {
let response = client
.get(format!(
"/api/v1/network/1/stats/users?from={}",
ten_hours_ago.format("%Y-%m-%dT%H:%M:00Z"),
ten_hours_ago.format(DATE_FORMAT),
))
.send()
.await;
Expand Down Expand Up @@ -252,7 +254,7 @@ async fn test_stats() {
let response = client
.get(format!(
"/api/v1/network/1/stats?from={}",
ten_hours_ago.format("%Y-%m-%dT%H:%M:00Z"),
ten_hours_ago.format(DATE_FORMAT),
))
.send()
.await;
Expand Down
4 changes: 2 additions & 2 deletions web/src/i18n/pl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const pl: Translation = {
},
lastName: {
placeholder: 'Nazwisko',
label: 'Ostatnie imię',
label: 'Nazwisko',
},
phone: {
placeholder: 'Telefon',
Expand Down Expand Up @@ -819,7 +819,7 @@ Uwaga, podane tutaj konfiguracje nie posiadają klucza prywatnego. Musisz uzupe
copy: 'Kopiuj',
saveChanges: 'Zapisz zmiany',
submit: 'Zapisz',
login: 'Zaloguj sie',
login: 'Zaloguj się',
cancel: 'Anuluj',
close: 'Zamknij',
placeholders: {
Expand Down