Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/glean-probe-scraper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
permissions:
contents: read
checks: write
uses: mozilla/probe-scraper/.github/workflows/glean.yaml@6cb549542a9d81fddbbaa8d5e6fdf95bf4761488 # v1.0
uses: mozilla/probe-scraper/.github/workflows/glean.yaml@78f5c5f20dfca6bcb68138a1122dae5acfd06605 # v1.0
7 changes: 5 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ slog-term = "2.9"
temp-env = { version = "0.3", features = ["async_closure"] }
tokio = "1"
thiserror = "2.0.18"
time = "0.3.47"
utoipa = "5.4.0"
utoipa-swagger-ui = { version = "9", features = ["actix-web"] }
uuid = { version = "1.20", features = ["serde", "v4"] }
Expand Down
1 change: 0 additions & 1 deletion syncserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ syncserver-db-common = { path = "../syncserver-db-common" }
syncserver-settings = { path = "../syncserver-settings" }
syncstorage-db = { path = "../syncstorage-db" }
syncstorage-settings = { path = "../syncstorage-settings" }
time.workspace = true
tokenserver-auth = { path = "../tokenserver-auth" }
tokenserver-common = { path = "../tokenserver-common" }
tokenserver-db = { path = "../tokenserver-db" }
Expand Down
7 changes: 3 additions & 4 deletions syncserver/src/tokenserver/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ mod tests {

use crate::tokenserver::ServerState;

use chrono::Utc;
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};

lazy_static! {
static ref SECRETS: Arc<Secrets> = Arc::new(Secrets::new("Ted Koppel is a robot").unwrap());
Expand Down Expand Up @@ -886,11 +886,10 @@ mod tests {
fn build_request() -> TestRequest {
let fxa_uid = "test123";
let oauth_verifier = {
let start = SystemTime::now();
let current_time = start.duration_since(UNIX_EPOCH).unwrap();
let current_time = Utc::now().timestamp();
let verify_output = oauth::VerifyOutput {
fxa_uid: fxa_uid.to_owned(),
generation: Some(current_time.as_secs() as i64),
generation: Some(current_time),
};
let valid = true;

Expand Down
24 changes: 5 additions & 19 deletions syncserver/src/tokenserver/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::{
collections::HashMap,
time::{Duration, SystemTime, UNIX_EPOCH},
};
use std::{collections::HashMap, time::Duration};

use actix_web::{Error, HttpResponse, http::StatusCode};
use base64::{Engine, engine};
use chrono::{TimeDelta, Utc};
use serde::Serialize;
use serde_json::Value;
use tokenserver_auth::{MakeTokenPlaintext, Tokenlib, TokenserverOrigin};
Expand Down Expand Up @@ -79,10 +77,7 @@ pub async fn get_tokenserver_result(
node_type: req.node_type,
};

let timestamp = {
let start = SystemTime::now();
start.duration_since(UNIX_EPOCH).unwrap().as_secs()
};
let timestamp = Utc::now().timestamp() as u64;

Ok(HttpResponse::build(StatusCode::OK)
.insert_header(("X-Timestamp", timestamp.to_string()))
Expand Down Expand Up @@ -116,13 +111,7 @@ fn get_token_plaintext(
)
};

let expires = {
let start = SystemTime::now();
let current_time = start.duration_since(UNIX_EPOCH).unwrap();
let expires = current_time + Duration::from_secs(req.duration);

expires.as_secs()
};
let expires = (Utc::now() + TimeDelta::seconds(req.duration as i64)).timestamp() as u64;

Ok(MakeTokenPlaintext {
node: req.user.node.to_owned(),
Expand Down Expand Up @@ -226,10 +215,7 @@ async fn update_user(
// If the client state changed, we need to mark the current user as "replaced" and create a
// new user record. Otherwise, we can update the user in place.
if req.auth_data.client_state != req.user.client_state {
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as i64;
let timestamp = Utc::now().timestamp_millis();

// Create new user record with updated generation/keys_changed_at
let post_user_params = PostUser {
Expand Down
9 changes: 3 additions & 6 deletions syncserver/src/web/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
allow(dead_code, unused_imports, unused_variables)
)]

use std::convert::TryInto;

use base64::{Engine, engine};
use chrono::offset::Utc;
use chrono::{TimeDelta, offset::Utc};
use hawk::{self, Header as HawkHeader, Key, RequestBuilder};
use hmac::{Hmac, Mac};
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use syncserver_common;
use syncserver_settings::Secrets;
use time::Duration;
use tokenserver_auth::TokenserverOrigin;

use actix_web::dev::ConnectionInfo;
Expand Down Expand Up @@ -104,8 +101,8 @@ impl HawkPayload {

#[cfg(not(feature = "no_auth"))]
{
let mut duration: std::time::Duration = Duration::weeks(52)
.try_into()
let mut duration = TimeDelta::weeks(52)
.to_std()
.map_err(|_| ApiErrorKind::Internal("Duration::weeks".to_owned()))?;
if cfg!(test) {
// test cases are valid until 3018. Add millenia as required.
Expand Down
1 change: 0 additions & 1 deletion syncstorage-settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ rand.workspace=true
serde.workspace=true

syncserver-common = { path = "../syncserver-common" }
time.workspace = true
1 change: 1 addition & 0 deletions syncstorage-spanner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition.workspace = true
actix-web.workspace = true
async-trait.workspace = true
backtrace.workspace = true
chrono.workspace = true
deadpool.workspace = true
futures.workspace = true
http.workspace = true
Expand Down
8 changes: 3 additions & 5 deletions syncstorage-spanner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::SystemTime;
use chrono::Utc;

#[macro_use]
extern crate slog_scope;
Expand All @@ -18,9 +18,7 @@ pub use pool::SpannerDbPool;

type DbResult<T> = Result<T, error::DbError>;

/// Return a timestamp of the seconds since Epoch, repr as `i64`.
fn now() -> i64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64
Utc::now().timestamp()
}
1 change: 1 addition & 0 deletions tokenserver-db-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license.workspace = true
[dependencies]
async-trait.workspace = true
backtrace.workspace = true
chrono.workspace = true
deadpool.workspace = true
diesel.workspace = true
diesel-async.workspace = true
Expand Down
11 changes: 3 additions & 8 deletions tokenserver-db-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ mod error;
pub mod params;
pub mod results;

use std::{
cmp,
time::{Duration, SystemTime, UNIX_EPOCH},
};
use std::{cmp, time::Duration};

use async_trait::async_trait;
use chrono::Utc;
use syncserver_common::Metrics;
use syncserver_db_common::{GetPoolState, PoolState};

Expand Down Expand Up @@ -248,10 +246,7 @@ pub trait Db {
})
.await?;

let created_at = {
let start = SystemTime::now();
start.duration_since(UNIX_EPOCH).unwrap().as_millis() as i64
};
let created_at: i64 = Utc::now().timestamp_millis();
let uid = self
.post_user(params::PostUser {
service_id: params.service_id,
Expand Down
1 change: 1 addition & 0 deletions tokenserver-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition.workspace = true

[dependencies]
async-trait.workspace = true
chrono.workspace = true
syncserver-common = { path = "../syncserver-common" }
syncserver-db-common = { path = "../syncserver-db-common" }
tokenserver-db-common = { path = "../tokenserver-db-common" }
Expand Down
21 changes: 6 additions & 15 deletions tokenserver-db/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{
thread,
time::{Duration, SystemTime, UNIX_EPOCH},
};
use chrono::{TimeDelta, Utc};
use std::thread;

use syncserver_common::Metrics;
use syncserver_settings::Settings;
Expand Down Expand Up @@ -160,10 +158,7 @@ async fn replace_users() -> DbResult<()> {

let pool = db_pool().await?;
let mut db = pool.get().await?;
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as i64;
let now: i64 = Utc::now().timestamp_millis();
let an_hour_ago = now - MILLISECONDS_IN_AN_HOUR;

let service_id = db
Expand Down Expand Up @@ -1198,7 +1193,7 @@ async fn test_correct_created_at_used_during_node_reassignment() -> DbResult<()>

// Sleep very briefly to ensure the timestamp created during node reassignment is greater
// than the timestamp created during user creation
thread::sleep(Duration::from_millis(5));
thread::sleep(TimeDelta::milliseconds(5).to_std().unwrap());

// Get the user, prompting the user's reassignment to the same node
let user2 = db
Expand Down Expand Up @@ -1255,7 +1250,7 @@ async fn test_correct_created_at_used_during_user_retrieval() -> DbResult<()> {

// Sleep very briefly to ensure that any timestamp that might be created below is greater
// than the timestamp created during user creation
thread::sleep(Duration::from_millis(5));
thread::sleep(TimeDelta::milliseconds(5).to_std().unwrap());

// Get the user
let user2 = db
Expand Down Expand Up @@ -1301,11 +1296,7 @@ async fn test_latest_created_at() -> DbResult<()> {
.id;

let email = "test_user";
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as i64;

let now: i64 = Utc::now().timestamp_millis();
// Add a user marked as replaced
let post_user = params::PostUser {
service_id,
Expand Down
1 change: 1 addition & 0 deletions tokenserver-mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license.workspace = true

[dependencies]
async-trait.workspace = true
chrono.workspace = true
deadpool.workspace = true
diesel.workspace = true
diesel-async.workspace = true
Expand Down
9 changes: 3 additions & 6 deletions tokenserver-mysql/src/db/db_impl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::time::Duration;
#[cfg(debug_assertions)]
use std::time::{SystemTime, UNIX_EPOCH};

use async_trait::async_trait;
#[cfg(debug_assertions)]
use chrono::Utc;
use diesel::{
OptionalExtension,
sql_types::{Bigint, Float, Integer, Nullable, Text},
Expand Down Expand Up @@ -448,10 +448,7 @@ impl Db for TokenserverDb {
WHERE nodeid = ?
"#;

let current_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as i64;
let current_time = Utc::now().timestamp_millis();

diesel::sql_query(QUERY)
.bind::<Bigint, _>(current_time)
Expand Down
1 change: 1 addition & 0 deletions tokenserver-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license.workspace = true

[dependencies]
async-trait.workspace = true
chrono.workspace = true
deadpool.workspace = true
diesel = { workspace = true, features = ["postgres"] }
diesel-async = { workspace = true, features = ["postgres"] }
Expand Down
9 changes: 3 additions & 6 deletions tokenserver-postgres/src/db/db_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/// imports only to be added during debug builds.
/// cargo build --release will not include this code in the binary.
use std::time::Duration;
#[cfg(debug_assertions)]
use std::time::{SystemTime, UNIX_EPOCH};

use async_trait::async_trait;
#[cfg(debug_assertions)]
use chrono::Utc;
use diesel::{
OptionalExtension,
sql_types::{BigInt, Float, Integer, Nullable, Text},
Expand Down Expand Up @@ -461,10 +461,7 @@ impl Db for TokenserverPgDb {
WHERE nodeid = $2
"#;

let current_time: i64 = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as i64;
let current_time = Utc::now().timestamp_millis();

diesel::sql_query(QUERY)
.bind::<BigInt, _>(current_time)
Expand Down
Loading