Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
rm old test
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkakkar committed May 1, 2024
1 parent b5591f5 commit b3308d3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 61 deletions.
2 changes: 1 addition & 1 deletion feature-flags/src/v0_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub async fn flags(

tracing::Span::current().record("user_agent", user_agent);
tracing::Span::current().record("content_encoding", content_encoding);
// tracing::Span::current().record("version", meta.lib_version.clone());
tracing::Span::current().record("version", meta.version.clone());
tracing::Span::current().record("method", method.as_str());
tracing::Span::current().record("path", path.as_str().trim_end_matches('/'));

Expand Down
60 changes: 0 additions & 60 deletions feature-flags/src/v0_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,63 +73,3 @@ impl FlagRequest {
Ok(token)
}
}

#[cfg(test)]
mod tests {
use base64::Engine as _;
use bytes::Bytes;
use rand::distributions::Alphanumeric;
use rand::Rng;
use serde_json::json;

use super::FlagError;
use super::FlagRequest;

#[test]
fn extract_and_verify_token() {
let parse_and_extract = |input: &'static str| -> Result<String, FlagError> {
FlagRequest::from_bytes(input.into())
.expect("failed to parse")
.extract_and_verify_token()
};

let assert_extracted_token = |input: &'static str, expected: &str| {
let id = parse_and_extract(input).expect("failed to extract");
assert_eq!(id, expected);
};

// Return NoTokenError if not found
assert!(matches!(
parse_and_extract(r#"{"distinct_id": "xyz"}"#),
Err(FlagError::NoTokenError)
));

// Return TokenValidationError if token empty
assert!(matches!(
parse_and_extract(r#"{"api_key": "", "batch":[{"event": "e"}]}"#),
Err(FlagError::TokenValidationError)
));

// Return TokenValidationError if personal apikey
assert!(matches!(
parse_and_extract(r#"[{"event": "e", "token": "phx_hellothere"}]"#),
Ok(_)
));

// Return token from array if consistent
assert_extracted_token(
r#"[{"event":"e","token":"token1"},{"event":"e","token":"token1"}]"#,
"token1",
);

// Return token from batch if present
assert_extracted_token(
r#"{"batch":[{"event":"e","token":"token1"}],"api_key":"batched"}"#,
"batched",
);

// Return token from single event if present
assert_extracted_token(r#"{"event":"e","$token":"single_token"}"#, "single_token");
assert_extracted_token(r#"{"event":"e","api_key":"single_token"}"#, "single_token");
}
}

0 comments on commit b3308d3

Please sign in to comment.