fix
This commit is contained in:
@@ -2,6 +2,7 @@ package company
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -101,3 +102,32 @@ func TestLocalizedContentRoundTrip(t *testing.T) {
|
||||
t.Fatalf("got %#v", f)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalizedContentPublicOmitsEnhanceHash(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := LocalizedContent{
|
||||
"sl": {
|
||||
ProcessedName: "Naslov",
|
||||
ProcessedDescription: "Opis",
|
||||
MetaTitle: "Meta",
|
||||
EnhanceInputHash: "deadbeef",
|
||||
},
|
||||
}
|
||||
pub := c.Public()
|
||||
if pub["sl"].EnhanceInputHash != "" {
|
||||
t.Fatalf("public hash leaked: %#v", pub["sl"])
|
||||
}
|
||||
if pub["sl"].ProcessedName != "Naslov" || pub["sl"].MetaTitle != "Meta" {
|
||||
t.Fatalf("public stripped too much: %#v", pub["sl"])
|
||||
}
|
||||
if c["sl"].EnhanceInputHash != "deadbeef" {
|
||||
t.Fatalf("Public must not mutate storage copy: %#v", c["sl"])
|
||||
}
|
||||
b, err := json.Marshal(pub)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(b), "enhance_input_hash") || strings.Contains(string(b), "deadbeef") {
|
||||
t.Fatalf("hash in JSON: %s", b)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user