mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 10:19:54 +00:00
fixing tests
This commit is contained in:
@@ -44,8 +44,7 @@ pwd=somethinggoeshere;`,
|
||||
want: map[string]string{
|
||||
"data/datacollectorname": ` 123
|
||||
another***HIDDEN***here
|
||||
pwd=***HIDDEN***;
|
||||
`,
|
||||
pwd=***HIDDEN***;`,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -78,8 +77,7 @@ pwd=somethinggoeshere;`,
|
||||
want: map[string]string{
|
||||
"data/datacollectorname": `abc 123
|
||||
another***HIDDEN***here
|
||||
pwd=***HIDDEN***;
|
||||
`,
|
||||
pwd=***HIDDEN***;`,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -112,8 +110,7 @@ pwd=somethinggoeshere;`,
|
||||
want: map[string]string{
|
||||
"data/datacollectorname": `abc 123
|
||||
another line here
|
||||
pwd=***HIDDEN***;
|
||||
`,
|
||||
pwd=***HIDDEN***;`,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -149,8 +146,7 @@ pwd=somethinggoeshere;`,
|
||||
want: map[string]string{
|
||||
"data/datacollectorname": `abc 123
|
||||
another***HIDDEN***here
|
||||
pwd=***HIDDEN***;
|
||||
`,
|
||||
pwd=***HIDDEN***;`,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -186,8 +182,7 @@ pwd=somethinggoeshere;`,
|
||||
want: map[string]string{
|
||||
"data/data/collectorname": `***HIDDEN*** ***HIDDEN***
|
||||
***HIDDEN*** line here
|
||||
pwd=***HIDDEN***;
|
||||
`,
|
||||
pwd=***HIDDEN***;`,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -213,8 +208,7 @@ another line here`,
|
||||
},
|
||||
want: map[string]string{
|
||||
"data/datacollectorname": `abc 123
|
||||
another line here
|
||||
`,
|
||||
another line here`,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -249,8 +243,7 @@ abc`,
|
||||
abc
|
||||
123
|
||||
xyz123
|
||||
abc
|
||||
`,
|
||||
abc`,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -299,4 +299,3 @@ func BenchmarkLineReader(b *testing.B) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -333,4 +333,3 @@ func TestLiteralRedactor_PartialMatchNotReplaced(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "***HIDDEN*** ***HIDDEN***ive ***HIDDEN***s", string(result))
|
||||
}
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ func Test_writeBytes(t *testing.T) {
|
||||
func TestMultiLineRedactor_BinaryFile(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
// Binary content with no newlines - the bug that caused 2 extra bytes
|
||||
binaryData := []byte{0x01, 0x02, 0x03, 0x04, 0x00, 0xFF, 0xFE, 0xAB, 0xCD}
|
||||
|
||||
@@ -179,7 +179,7 @@ func TestMultiLineRedactor_BinaryFile(t *testing.T) {
|
||||
func TestMultiLineRedactor_SingleLineWithNewline(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
input := "single line\n"
|
||||
|
||||
redactor, err := NewMultiLineRedactor(
|
||||
@@ -200,7 +200,7 @@ func TestMultiLineRedactor_SingleLineWithNewline(t *testing.T) {
|
||||
func TestMultiLineRedactor_SingleLineWithoutNewline(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
input := "single line"
|
||||
|
||||
redactor, err := NewMultiLineRedactor(
|
||||
@@ -221,7 +221,7 @@ func TestMultiLineRedactor_SingleLineWithoutNewline(t *testing.T) {
|
||||
func TestMultiLineRedactor_EmptyFile(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
input := ""
|
||||
|
||||
redactor, err := NewMultiLineRedactor(
|
||||
@@ -242,7 +242,7 @@ func TestMultiLineRedactor_EmptyFile(t *testing.T) {
|
||||
func TestMultiLineRedactor_TwoLinesMatch(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
input := `"name": "PASSWORD"
|
||||
"value": "secret123"`
|
||||
|
||||
@@ -266,7 +266,7 @@ func TestMultiLineRedactor_TwoLinesMatch(t *testing.T) {
|
||||
func TestMultiLineRedactor_TwoLinesNoMatch(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
input := `"name": "USERNAME"
|
||||
"value": "admin"`
|
||||
|
||||
@@ -290,7 +290,7 @@ func TestMultiLineRedactor_TwoLinesNoMatch(t *testing.T) {
|
||||
func TestMultiLineRedactor_MultiplePairs(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
input := `"name": "PASSWORD"
|
||||
"value": "secret1"
|
||||
"name": "TOKEN"
|
||||
@@ -324,7 +324,7 @@ func TestMultiLineRedactor_MultiplePairs(t *testing.T) {
|
||||
func TestMultiLineRedactor_ThreeLines(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
input := `"name": "PASSWORD"
|
||||
"value": "secret"
|
||||
unpaired line`
|
||||
@@ -350,7 +350,7 @@ unpaired line`
|
||||
func TestMultiLineRedactor_LargeFile(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
|
||||
var input strings.Builder
|
||||
for i := 0; i < 1000; i++ {
|
||||
input.WriteString(`"name": "PASSWORD"` + "\n")
|
||||
@@ -368,7 +368,7 @@ func TestMultiLineRedactor_LargeFile(t *testing.T) {
|
||||
result, err := io.ReadAll(out)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
// Verify all secrets were redacted
|
||||
require.NotContains(t, string(result), `"value": "secret"`)
|
||||
require.Contains(t, string(result), `"value": "***HIDDEN***"`)
|
||||
|
||||
@@ -337,6 +337,9 @@ func TestNewSingleLineRedactor(t *testing.T) {
|
||||
|
||||
// Test 2.15: Binary file (no newlines) → unchanged
|
||||
func TestSingleLineRedactor_BinaryFile(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
// Binary content with no newlines
|
||||
binaryData := []byte{0x01, 0x02, 0x03, 0x04, 0x00, 0xFF, 0xFE, 0xAB, 0xCD}
|
||||
|
||||
@@ -355,6 +358,9 @@ func TestSingleLineRedactor_BinaryFile(t *testing.T) {
|
||||
|
||||
// Test 2.16: Text file with \n → preserved
|
||||
func TestSingleLineRedactor_TextFileWithNewline(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
input := "hello world\n"
|
||||
|
||||
redactor, err := NewSingleLineRedactor(
|
||||
@@ -372,6 +378,9 @@ func TestSingleLineRedactor_TextFileWithNewline(t *testing.T) {
|
||||
|
||||
// Test 2.17: Text file without \n → preserved
|
||||
func TestSingleLineRedactor_TextFileWithoutNewline(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
input := "hello world"
|
||||
|
||||
redactor, err := NewSingleLineRedactor(
|
||||
@@ -389,6 +398,9 @@ func TestSingleLineRedactor_TextFileWithoutNewline(t *testing.T) {
|
||||
|
||||
// Test 2.18: Empty file → unchanged
|
||||
func TestSingleLineRedactor_EmptyFile(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
input := ""
|
||||
|
||||
redactor, err := NewSingleLineRedactor(
|
||||
@@ -406,6 +418,9 @@ func TestSingleLineRedactor_EmptyFile(t *testing.T) {
|
||||
|
||||
// Test 2.19: Single line with secret → redacted correctly
|
||||
func TestSingleLineRedactor_SingleLineWithSecret(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
input := "password=secret123"
|
||||
|
||||
redactor, err := NewSingleLineRedactor(
|
||||
@@ -423,6 +438,9 @@ func TestSingleLineRedactor_SingleLineWithSecret(t *testing.T) {
|
||||
|
||||
// Test 2.20: Multiple lines with secrets → all redacted
|
||||
func TestSingleLineRedactor_MultipleLinesWithSecrets(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
input := "password=secret1\npassword=secret2\npassword=secret3\n"
|
||||
|
||||
redactor, err := NewSingleLineRedactor(
|
||||
@@ -441,6 +459,9 @@ func TestSingleLineRedactor_MultipleLinesWithSecrets(t *testing.T) {
|
||||
|
||||
// Test 2.21: Scan pattern filters correctly
|
||||
func TestSingleLineRedactor_ScanPatternFilters(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
input := "password=secret\nusername=admin\n"
|
||||
|
||||
redactor, err := NewSingleLineRedactor(
|
||||
@@ -462,6 +483,9 @@ func TestSingleLineRedactor_ScanPatternFilters(t *testing.T) {
|
||||
|
||||
// Test 2.22: File with only one newline \n → one newline out
|
||||
func TestSingleLineRedactor_OnlyNewline(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
input := "\n"
|
||||
|
||||
redactor, err := NewSingleLineRedactor(
|
||||
@@ -479,6 +503,9 @@ func TestSingleLineRedactor_OnlyNewline(t *testing.T) {
|
||||
|
||||
// Test 2.23: Mixed binary/text content
|
||||
func TestSingleLineRedactor_MixedContent(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
// Binary data with embedded newline
|
||||
input := []byte{0x01, 0x02, '\n', 0x03, 0x04}
|
||||
|
||||
@@ -497,6 +524,9 @@ func TestSingleLineRedactor_MixedContent(t *testing.T) {
|
||||
|
||||
// Test 2.24: Large binary file (1MB, no newlines) → preserved
|
||||
func TestSingleLineRedactor_LargeBinaryFile(t *testing.T) {
|
||||
ResetRedactionList()
|
||||
defer ResetRedactionList()
|
||||
|
||||
// Create 1MB of binary data
|
||||
largeData := make([]byte, 1024*1024)
|
||||
for i := range largeData {
|
||||
|
||||
Reference in New Issue
Block a user