You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
819 B
26 lines
819 B
|
2 months ago
|
package api
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
"tera-clone/services/tera-api/internal/domain"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestPortLogDisplayPreservesASCIIAndUppercasesHEX(t *testing.T) {
|
||
|
|
event := domain.PortLogEvent{Payload: []byte("MiXeD\r\nnext\rline"), DisplayFormat: "ascii"}
|
||
|
|
result := portLogDisplay(event)
|
||
|
|
if result.DisplayText != "MiXeD\nnext\nline" || result.Payload != nil {
|
||
|
|
t.Fatalf("display: %+v", result)
|
||
|
|
}
|
||
|
|
event.Payload = []byte{0xab, 0xcd, 0xef}
|
||
|
|
event.DisplayFormat = "hex"
|
||
|
|
if result = portLogDisplay(event); result.DisplayText != "AB CD EF" {
|
||
|
|
t.Fatal(result.DisplayText)
|
||
|
|
}
|
||
|
|
event.Payload = []byte("password=supersecret")
|
||
|
|
event.DisplayFormat = "ascii"
|
||
|
|
if result = portLogDisplay(event); strings.Contains(result.DisplayText, "supersecret") || !result.Redacted {
|
||
|
|
t.Fatalf("secret not redacted: %+v", result)
|
||
|
|
}
|
||
|
|
}
|