-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement anonymisation proof writer
- Loading branch information
solnicki
committed
Nov 12, 2024
1 parent
cc41366
commit f6842be
Showing
14 changed files
with
315 additions
and
108 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
|
@@ -7,22 +7,31 @@ import ( | |
|
||
"github.com/logmanager-oss/logveil/internal/anonymizer" | ||
"github.com/logmanager-oss/logveil/internal/parser" | ||
"github.com/logmanager-oss/logveil/internal/proof" | ||
"github.com/logmanager-oss/logveil/internal/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLmExport(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputFilename string | ||
outputFilename string | ||
anonDataDir string | ||
expectedOutput string | ||
name string | ||
isProofWriterEnabled bool | ||
inputFilename string | ||
anonDataDir string | ||
expectedOutput string | ||
expectedProof []map[string]interface{} | ||
}{ | ||
{ | ||
name: "Test LM Export Anonymizer", | ||
inputFilename: "../../examples/logs/example_logs.csv", | ||
anonDataDir: "../../examples/anon_data", | ||
expectedOutput: "{\"@timestamp\": \"2024-06-05T14:59:27.000+00:00\", \"msg.src_ip\":\"10.20.0.53\", \"username\":\"ladislav.dosek\", \"organization\":\"Apple\"}\n", | ||
name: "Test LM Export Anonymizer", | ||
isProofWriterEnabled: true, | ||
inputFilename: "../../examples/logs/example_logs.csv", | ||
anonDataDir: "../../examples/anon_data", | ||
expectedOutput: "{\"@timestamp\": \"2024-06-05T14:59:27.000+00:00\", \"msg.src_ip\":\"10.20.0.53\", \"username\":\"ladislav.dosek\", \"organization\":\"Apple\"}\n", | ||
expectedProof: []map[string]interface{}{ | ||
{"original": "89.239.31.49", "new": "10.20.0.53"}, | ||
{"original": "[email protected]", "new": "ladislav.dosek"}, | ||
{"original": "TESTuser.test.com", "new": "Apple"}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
|
@@ -33,22 +42,33 @@ func TestLmExport(t *testing.T) { | |
} | ||
defer input.Close() | ||
|
||
var output bytes.Buffer | ||
|
||
anonData, err := parser.LoadAnonData(tt.anonDataDir) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
anonymizer := anonymizer.New(anonData) | ||
|
||
proofWriter := proof.New(tt.isProofWriterEnabled) | ||
anonymizer := anonymizer.New(anonData, proofWriter) | ||
// Disabling randomization so we know which values to expect | ||
anonymizer.SetRandFunc(func(int) int { return 1 }) | ||
|
||
var output bytes.Buffer | ||
err = AnonymizeLmExport(input, &output, anonymizer) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assert.Equal(t, tt.expectedOutput, output.String()) | ||
|
||
proofWriter.Close() | ||
|
||
actualProof, err := utils.UnpackProofOutput() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assert.ElementsMatch(t, tt.expectedProof, actualProof) | ||
|
||
os.Remove("proof.json") | ||
}) | ||
} | ||
} |
Oops, something went wrong.