Skip to content

Commit

Permalink
fix: misc, readme, tests, schema
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Dec 18, 2024
1 parent 77036e3 commit b2f7a5a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You can use [LINO](https://github.com/CGI-FR/LINO) to extract sample data from a
You can also generate data with a simple yaml configuration file.

**Capabilities**

- credibility : generated data is not distinguishable from real data
- data synthesis : generate data from nothing
- data masking, including
Expand Down Expand Up @@ -163,6 +164,7 @@ The following types of masks can be used :
* [`fluxUri`](#fluxuri) is to replace by a sequence of values defined in an external resource.
* [`replacement`](#replacement) is to mask a data with another data from the jsonline.
* [`pipe`](#pipe) is a mask to handle complex nested array structures, it can read an array as an object stream and process it with a sub-pipeline.
* [`apply`](#apply) process selected data with a sub-pipeline.
* [`luhn`](#luhn) can generate valid numbers using the Luhn algorithm (e.g. french SIRET or SIREN).
* [`markov`](#markov) can generate pseudo text based on a sample text.
* [`findInCSV`](#findincsv) get one or multiple csv lines which matched with Json entry value from CSV files.
Expand Down Expand Up @@ -928,6 +930,24 @@ Be sure to check [demo](demo/demo8) to get more details about this mask.

[Return to list of masks](#possible-masks)

### Apply

[![Try it](https://img.shields.io/badge/-Try%20it%20in%20PIMO%20Play-brightgreen)](https://cgi-fr.github.io/pimo-play/#c=G4UwTgzglg9gdgLgAQCICMKBQBbAhhAayjgHMFMkkBaJCEAGxAGMAXGMcyrpAKwngAOuFgAtkKKACNccLNzyFO3JLgED6ATyXKkAVzBRxAOgD09KWFxgNJhUVJUpMoxuz0sQA&i=N4KABGBECWBGCGA7SAuKkQF8g)

This mask helps you organize your masking configuration in different files, enablig reuse and mutualisation of masks.

```yaml
version: "1"
masking:
- selector:
jsonpath: "iban"
mask:
apply:
uri: "./library/masking-iban.yml" # list of mask to apply on iban is declared in an external masking file
```

[Return to list of masks](#possible-masks)

### Luhn

[![Try it](https://img.shields.io/badge/-Try%20it%20in%20PIMO%20Play-brightgreen)](https://cgi-fr.github.io/pimo-play/#c=G4UwTgzglg9gdgLgAQCICMKBQEQgCbIAsATJgLYCGEA1lHAOYKZJIC0SOANiAMYAuMMExYikAKwjwADhT4ALZCmhgQfLKMo1hopJwCucxEgDeAXyA&i=N4KABGBEDOCWBOBTALpAXFAjAJgMwBYBWANgHYAOATgAYddIQBfIA)
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ type MaskType struct {
TimeLine TimeLineType `yaml:"timeline,omitempty" json:"timeline,omitempty" jsonschema:"oneof_required=TimeLine,title=TimeLine Mask" jsonschema_description:"Generate a timeline under constraints and rules"`
Sequence SequenceType `yaml:"sequence,omitempty" json:"sequence,omitempty" jsonschema:"oneof_required=Sequence,title=Sequence Mask" jsonschema_description:"Generate a sequenced ID that follows specified format"`
Sha3 Sha3Type `yaml:"sha3,omitempty" json:"sha3,omitempty" jsonschema:"oneof_required=Sha3,title=Sha3 Mask" jsonschema_description:"Generate a variable-length crytographic hash (collision resistant)"`
Apply ApplyType `yaml:"apply,omitempty" json:"apply,omitempty" jsonschema:""`
Apply ApplyType `yaml:"apply,omitempty" json:"apply,omitempty" jsonschema:"oneof_required=Apply,title=Apply Mask" jsonschema_description:"Call external masking file"`
}

type Masking struct {
Expand Down
10 changes: 9 additions & 1 deletion schema/v1/pimo.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,12 @@
"sha3"
],
"title": "Sha3"
},
{
"required": [
"apply"
],
"title": "Apply"
}
],
"properties": {
Expand Down Expand Up @@ -769,7 +775,9 @@
"description": "Generate a variable-length crytographic hash (collision resistant)"
},
"apply": {
"$ref": "#/$defs/ApplyType"
"$ref": "#/$defs/ApplyType",
"title": "Apply Mask",
"description": "Call external masking file"
}
},
"additionalProperties": false,
Expand Down
39 changes: 39 additions & 0 deletions test/suites/mock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,42 @@ testcases:
- result.code ShouldEqual 0
- result.systemerr ShouldContainSubstring Origin request={"body":"","captures":{"name":"hello"},"headers":{"Accept":["*/*"],"User-Agent":["curl/8.9.1"]},"method":"GET","protocol":"HTTP/1.1","url":{"path":"/hello"}}
- result.systemerr ShouldContainSubstring Masked request={"body":"","captures":{"name":"intercepted"},"headers":{"Accept":["*/*"],"User-Agent":["curl/8.9.1"]},"method":"GET","protocol":"HTTP/1.1","url":{"path":"/intercepted"}}
- name: set global seed
steps:
- script: |-
cat > routes.yaml <<EOF
routes:
- method: "GET"
path: "/{name}"
masking:
response: "response.yaml"
EOF
- script: |-
cat > response.yaml <<EOF
version: "1"
masking:
- selector:
jsonpath: "body.name"
mask:
randomChoice: ["one", "two", "three"]
seed:
field: "body.name"
EOF
- script: |
pimo --serve ":8080" --seed 1 --mask 'name=[{add: true}, {randomChoiceInUri: "pimo://nameFR"}]' --mask 'origin=[{add: "{{.name}}"}]' &
pimo --seed 2 -v5 mock -p :8081 http://localhost:8080 &
sleep 1
curl -s http://localhost:8081/
curl -s http://localhost:8081/
curl -s http://localhost:8081/
curl -s http://localhost:8081/
curl -s http://localhost:8081/
kill %1 %2
assertions:
- result.code ShouldEqual 0
- result.systemerr ShouldContainSubstring Masked response={"body":{"name":"three","origin":"Gwenaëlle"},"headers":{"Content-Length":["44"],"Content-Type":["application/json"]
- result.systemerr ShouldContainSubstring Masked response={"body":{"name":"one","origin":"Éléonore"},"headers":{"Content-Length":["44"],"Content-Type":["application/json"]
- result.systemerr ShouldContainSubstring Masked response={"body":{"name":"three","origin":"Marie-Noëlle"},"headers":{"Content-Length":["50"],"Content-Type":["application/json"]
- result.systemerr ShouldContainSubstring Masked response={"body":{"name":"one","origin":"Hugo"},"headers":{"Content-Length":["32"],"Content-Type":["application/json"]
- result.systemerr ShouldContainSubstring Masked response={"body":{"name":"three","origin":"Mathurin"},"headers":{"Content-Length":["40"],"Content-Type":["application/json"]

0 comments on commit b2f7a5a

Please sign in to comment.