Skip to content

Commit

Permalink
fix: timeline should not overwrite existing data (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury authored Sep 19, 2024
1 parent 481d139 commit 704a1b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Types of changes
- `Fixed` performance issue with `pipe` mask
- `Fixed` performance issue with selectors
- `Fixed` URI resources will be loaded in-memory only once instead of once per mask
- `Fixed` `timeline` should not overwrite existing data

## [1.26.2]

Expand Down
6 changes: 5 additions & 1 deletion pkg/timeline/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,23 @@ func (me MaskEngine) Mask(e model.Entry, context ...model.Dictionary) (model.Ent
}
}

var result model.Dictionary

initialState := map[string]*int64{}
if dict, ok := e.(model.Dictionary); ok {
result = dict
for _, key := range dict.Keys() {
initialState[key] = me.formatTimestamp(dict.Get(key))
}
} else {
result = model.NewDictionary()
}

timestamps, err := me.Generate(me.rand, initialState)
if err != nil {
return nil, err
}

result := model.NewDictionary()
result.Set(me.Generator.Origin(), me.formatDate(*(timestamps[me.Generator.Origin()])))
for _, point := range me.points {
value := timestamps[point]
Expand Down
33 changes: 33 additions & 0 deletions test/suites/masking_timeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,36 @@ testcases:
- result.code ShouldEqual 0
- result.systemoutjson.timeline.birth ShouldEqual "1985-06-09"
- result.systemerr ShouldBeEmpty

- name: should not overwrite existing data
steps:
- script: rm -f masking.yml
- script: |-
cat > masking.yml <<EOF
version: "1"
masking:
- selector:
jsonpath: "timeline"
masks:
- add:
departure: ""
arrival: ""
status: "COMPLETED"
- timeline:
format: "2006-01-02T15:04"
start:
name: "now"
points:
- name: "departure"
min: "-P1Y"
max: "P0"
- name: "arrival"
from: "departure"
min: "P0"
max: "PT10H"
EOF
- script: pimo --empty-input
assertions:
- result.code ShouldEqual 0
- result.systemoutjson.timeline.status ShouldEqual "COMPLETED"
- result.systemerr ShouldBeEmpty

0 comments on commit 704a1b5

Please sign in to comment.