From 1307a80e0704858a0ed0de6b1486b1a6d0d0d161 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 23 Jul 2024 19:58:47 -0400 Subject: [PATCH] rpc: Add regression tests for encoding/decoding public keys (#15054) This PR adds some tests to ensure we don't regress in our public key encoding/decoding capabilities when making changes in this area. Release Notes: - N/A --- crates/rpc/src/auth.rs | 14 ++++++++++++++ typos.toml | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/crates/rpc/src/auth.rs b/crates/rpc/src/auth.rs index ac7bbcebec..56525983fb 100644 --- a/crates/rpc/src/auth.rs +++ b/crates/rpc/src/auth.rs @@ -107,6 +107,20 @@ mod tests { assert_eq!(decrypted_token, token); } + #[test] + fn test_encode_and_decode_base64_public_key() { + // A base64-encoded public key. + // + // We're using a literal string to ensure that encoding and decoding works across differences in implementations. + let encoded_public_key = "MIGJAoGBAMPvufou8wOuUIF1Wlkbtn0ZMM9nC55QJ06nTZvgMfZv5esFVU9-cQO_JC1P9ZoEcMDJweFERnQuQLqzsrMDLFbkdgL128ZU43WOLiQraxaICFIZsPUeTtWMKp2D5bPWsNxs-lnCma7vCAry6fpXuj5AKQdk7cTZJNucgvZQ0uUfAgMBAAE=".to_string(); + + // Make sure we can parse the public key. + let public_key = PublicKey::try_from(encoded_public_key.clone()).unwrap(); + + // Make sure we re-encode to the same format. + assert_eq!(encoded_public_key, String::try_from(public_key).unwrap()); + } + #[test] fn test_tokens_are_always_url_safe() { for _ in 0..5 { diff --git a/typos.toml b/typos.toml index c52c9e9eae..9e2763eac2 100644 --- a/typos.toml +++ b/typos.toml @@ -15,6 +15,11 @@ extend-exclude = [ "crates/editor/src/editor_tests.rs", # Clojure uses .edn filename extension, which is not a misspelling of "end" "extensions/clojure/languages/clojure/config.toml", + # There are some names in the test data that are incorrectly flagged as typos. + "crates/git/test_data/blame_incremental_complex", + "crates/git/test_data/golden/blame_incremental_complex.json", + # We have some base64-encoded data that is incorrectly being flagged. + "crates/rpc/src/auth.rs", # glsl isn't recognized by this tool "extensions/glsl/languages/glsl/", # Windows likes its abbreviations