-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Return message when obfuscation limit hit
When the obfusaction limit is hit, return a message stating this and do not attempt to obfuscate
- Loading branch information
1 parent
9a4fe90
commit 74ffb88
Showing
2 changed files
with
7 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,26 +18,26 @@ def test_named_arg_defaults_obfuscates | |
assert_equal(expected, result) | ||
end | ||
|
||
def test_obfuscation_limit_truncates_query_after_first_match | ||
def test_obfuscation_limit_returns_truncation_message | ||
sql = "SELECT * from users where users.id = 1 and users.email = '[email protected]'" | ||
expected = "SELECT * from users where users.id = ...\nSQL truncated (> 42 characters)" | ||
expected = "SQL truncated (> 42 characters)" | ||
result = OpenTelemetry::Helpers::SqlObfuscation.obfuscate_sql(sql, obfuscation_limit: 42) | ||
|
||
assert_equal(expected, result) | ||
end | ||
|
||
def test_obfuscation_limit_obfuscates_and_truncates_when_query_has_prepended_comment | ||
def test_obfuscation_limit_returns_truncation_message_when_query_has_prepended_comment | ||
comment = '/*service.name:foo,deployment.environtment:production,tracecontext:00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00,rails.route:examples/bars#index,host.name:baz-abc123.example.com*/' | ||
sql = "#{comment} SELECT user.id FROM users where user.login = 'secretUserNameThatShouldBeObfuscated'" | ||
expected = "? SELECT user.id FROM users where user.login = ...\nSQL truncated (> 42 characters)" | ||
expected = "SQL truncated (> 42 characters)" | ||
result = OpenTelemetry::Helpers::SqlObfuscation.obfuscate_sql(sql, obfuscation_limit: 42) | ||
|
||
assert_equal(expected, result) | ||
end | ||
|
||
def test_obfuscation_limit_truncates_when_query_not_encoded_with_utf8 | ||
def test_obfuscation_limit_returns_truncation_message_when_not_utf8 | ||
sql = "SELECT * from 😄 where users.id = 1 and users.😄 = '[email protected]'" | ||
expected = "SELECT * from where users.id = ...\nSQL truncated (> 42 characters)" | ||
expected = "SQL truncated (> 42 characters)" | ||
result = OpenTelemetry::Helpers::SqlObfuscation.obfuscate_sql(sql, obfuscation_limit: 42) | ||
|
||
assert_equal(expected, result) | ||
|