Skip to content

Commit

Permalink
Revert "chore: Removed noisy test log (newrelic#2583)"
Browse files Browse the repository at this point in the history
This reverts commit dc9cd2c.
  • Loading branch information
sumitsuthar committed Sep 20, 2024
1 parent 4eae46f commit 5d2d31d
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions test/unit/util/obfuscate-sql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const tests = require('../../lib/cross_agent_tests/sql_obfuscation/sql_obfuscati
const obfuscate = require('../../../lib/util/sql/obfuscate')

function runTest(t, testCase, dialect) {
t.diagnostic(dialect)
const obfuscated = obfuscate(testCase.sql, dialect)
if (testCase.obfuscated.length === 1) {
assert.equal(obfuscated, testCase.obfuscated[0])
Expand All @@ -18,24 +19,28 @@ function runTest(t, testCase, dialect) {
}
}

for (const testCase of tests) {
for (const dialect of testCase.dialects) {
test(`${dialect}: ${testCase.name}`, (t) => {
runTest(t, testCase, dialect)
test('sql obfuscation', async (t) => {
await Promise.all(
tests.map(async (tc) => {
await t.test(tc.name, (t) => {
for (let i = 0; i < tc.dialects.length; ++i) {
runTest(t, tc, tc.dialects[i])
}
})
})
}
}
)

test('should handle line endings', () => {
const result = obfuscate('select * from foo where --abc\r\nbar=5', 'mysql')
assert.equal(result, 'select * from foo where ?\r\nbar=?')
})
await t.test('should handle line endings', () => {
const result = obfuscate('select * from foo where --abc\r\nbar=5', 'mysql')
assert.equal(result, 'select * from foo where ?\r\nbar=?')
})

test('should handle large JSON inserts', () => {
const JSONData = '{"data": "' + new Array(8400000).fill('a').join('') + '"}'
const result = obfuscate(
'INSERT INTO "Documents" ("data") VALUES (\'' + JSONData + "')",
'postgres'
)
assert.equal(result, 'INSERT INTO "Documents" ("data") VALUES (?)')
await t.test('should handle large JSON inserts', () => {
const JSONData = '{"data": "' + new Array(8400000).fill('a').join('') + '"}'
const result = obfuscate(
'INSERT INTO "Documents" ("data") VALUES (\'' + JSONData + "')",
'postgres'
)
assert.equal(result, 'INSERT INTO "Documents" ("data") VALUES (?)')
})
})

0 comments on commit 5d2d31d

Please sign in to comment.