-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add database tracking and report for Push Reliability #769
Changes from all commits
a8b64b7
dc1763a
14bd4fb
e914b14
4f25172
e9ff9f5
c9a3512
f8c7ee9
1dd624f
05e73cc
8291039
ed67eb4
588a4ea
1c7e26a
07e7db3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,9 +169,11 @@ impl Settings { | |
// public key, but that may not always be true. | ||
pub fn tracking_keys(&self) -> Vec<String> { | ||
let keys = &self.tracking_keys.replace(['"', ' '], ""); | ||
Self::read_list_from_str(keys, "Invalid AUTOEND_TRACKING_KEYS") | ||
.map(|v| v.to_owned()) | ||
.collect() | ||
let result = Self::read_list_from_str(keys, "Invalid AUTOEND_TRACKING_KEYS") | ||
.map(|v| v.to_owned().replace("=", "")) | ||
.collect(); | ||
trace!("🔍 tracking_keys: {result:?}"); | ||
result | ||
} | ||
|
||
/// Get the URL for this endpoint server | ||
|
@@ -193,11 +195,20 @@ impl VapidTracker { | |
pub fn is_trackable(&self, vapid: &VapidHeaderWithKey) -> bool { | ||
// ideally, [Settings.with_env_and_config_file()] does the work of pre-populating | ||
// the Settings.tracking_vapid_pubs cache, but we can't rely on that. | ||
self.0.contains(&vapid.public_key) | ||
let key = vapid.public_key.replace('=', ""); | ||
let result = self.0.contains(&key); | ||
debug!("🔍 Checking {key} {}", { | ||
jrconlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if result { | ||
"Match!" | ||
} else { | ||
"no match" | ||
} | ||
}); | ||
result | ||
} | ||
|
||
/// Extract the message Id from the headers (if present), otherwise just make one up. | ||
pub fn get_tracking_id(&self, headers: &HeaderMap) -> String { | ||
pub fn get_id(&self, headers: &HeaderMap) -> String { | ||
headers | ||
.get("X-MessageId") | ||
.and_then(|v| | ||
|
@@ -304,7 +315,7 @@ mod tests { | |
#[test] | ||
fn test_tracking_keys() -> ApiResult<()> { | ||
let settings = Settings{ | ||
tracking_keys: r#"["BLMymkOqvT6OZ1o9etCqV4jGPkvOXNz5FdBjsAR9zR5oeCV1x5CBKuSLTlHon-H_boHTzMtMoNHsAGDlDB6X7vI"]"#.to_owned(), | ||
tracking_keys: r#"["BLMymkOqvT6OZ1o9etCqV4jGPkvOXNz5FdBjsAR9zR5oeCV1x5CBKuSLTlHon-H_boHTzMtMoNHsAGDlDB6X7"]"#.to_owned(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified to check for padding stripping. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this one have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we were decoding the key from base64, yes. We're currently not doing that so just tweaking the string values to ensure that they match (with and without the padding) should be fine. If we ever decide to decode these strings and do a byte comparison of the decoded pairs, then we would have to revisit this test, but that's out of scope for this PR. |
||
..Default::default() | ||
}; | ||
|
||
|
@@ -314,7 +325,7 @@ mod tests { | |
token: "".to_owned(), | ||
version_data: crate::headers::vapid::VapidVersionData::Version1, | ||
}, | ||
public_key: "BLMymkOqvT6OZ1o9etCqV4jGPkvOXNz5FdBjsAR9zR5oeCV1x5CBKuSLTlHon-H_boHTzMtMoNHsAGDlDB6X7vI".to_owned() | ||
public_key: "BLMymkOqvT6OZ1o9etCqV4jGPkvOXNz5FdBjsAR9zR5oeCV1x5CBKuSLTlHon-H_boHTzMtMoNHsAGDlDB6X7==".to_owned() | ||
}; | ||
|
||
let key_set = settings.tracking_keys(); | ||
|
@@ -327,20 +338,20 @@ mod tests { | |
} | ||
|
||
#[test] | ||
fn test_tracking_id() -> ApiResult<()> { | ||
fn test_reliability_id() -> ApiResult<()> { | ||
let mut headers = HeaderMap::new(); | ||
let keys = Vec::new(); | ||
let reliability = VapidTracker(keys); | ||
|
||
let key = reliability.get_tracking_id(&headers); | ||
let key = reliability.get_id(&headers); | ||
assert!(!key.is_empty()); | ||
|
||
headers.insert( | ||
HeaderName::from_lowercase(b"x-messageid").unwrap(), | ||
HeaderValue::from_static("123foobar456"), | ||
); | ||
|
||
let key = reliability.get_tracking_id(&headers); | ||
let key = reliability.get_id(&headers); | ||
assert_eq!(key, "123foobar456".to_owned()); | ||
|
||
Ok(()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these features will be used in the next PR.