wiremock icon indicating copy to clipboard operation
wiremock copied to clipboard

Make checking for duplicate IDs optional

Open kesslerj opened this issue 1 year ago • 3 comments

Proposal

Since version 3.7.0, stub mappings may no longer use the same Id. I understand the background, but for us this is a breaking change. We work a lot with json stub mapping. When creating new stub mappings, we often copy existing files and then adapt the url, response or something else. Previously, it was not necessary to change the Id in each case.

It would be great if there was a way to disable this check.

The review was introduced with this PR, which refers to this issue.

References

No response

kesslerj avatar Jun 26 '24 08:06 kesslerj

Seems like the features also creates issues, if mappings are created from a config map in k8s: https://github.com/holomekc/wiremock/issues/269

holomekc avatar Jul 07 '24 11:07 holomekc

Kubernetes mounts a ConfigMap containing just 2 unique stub mappings like this:

root@wiremock-66dc8ccf9b-2z8m2:/home/wiremock/mappings# ls -laR
.:
total 0
drwxrwxrwx. 3 root root 152 Jul  5 13:51 .
drwxr-xr-x. 1 root root  25 Jul  5 13:52 ..
drwxr-xr-x. 2 root root  98 Jul  5 13:51 ..2024_07_05_13_51_53.2567708330
lrwxrwxrwx. 1 root root  32 Jul  5 13:51 ..data -> ..2024_07_05_13_51_53.2567708330
lrwxrwxrwx. 1 root root  23 Jul  5 13:51 jwks.json -> ..data/jwks.json
lrwxrwxrwx. 1 root root  31 Jul  5 13:51 webhook-test.json -> ..data/webhook-test.json

./..2024_07_05_13_51_53.2567708330:
total 12
drwxr-xr-x. 2 root root   98 Jul  5 13:51 .
drwxrwxrwx. 3 root root  152 Jul  5 13:51 ..
-rw-r--r--. 1 root root  264 Jul  5 13:51 jwks.json
-rw-r--r--. 1 root root  432 Jul  5 13:51 webhook-test.json

Wiremock detects soft-linked files as well as the 'real' files inside the hierarchy as duplicates regardless of the file type and identical MD5 checksum:

MB-79-P16:wiremock $ md5sum mappings/..2024_07_05_13_51_53.2567708330/webhook-test.json mappings/webhook-test.json 

eb58ef4b72a411579d764c4d540ca1ae  mappings/..2024_07_05_13_51_53.2567708330/webhook-test.json
eb58ef4b72a411579d764c4d540ca1ae  mappings/webhook-test.json
Exception in thread "main" com.github.tomakehurst.wiremock.common.InvalidInputException: {
  "errors" : [ {
    "code" : 109,
    "title" : "Duplicate stub mapping ID",
    "detail" : "ID of the provided stub mapping '64c23b4a-5f94-427b-8b6e-f8c43ed5529d' is already taken by another stub mapping"
  } ]
}
        at com.github.tomakehurst.wiremock.stubbing.AbstractStubMappings.addMapping(AbstractStubMappings.java:169)
        at com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource.loadMappingsInto(JsonFileMappingsSource.java:120)
        at com.github.tomakehurst.wiremock.core.WireMockApp.loadMappingsUsing(WireMockApp.java:288)
        at com.github.tomakehurst.wiremock.core.WireMockApp.loadDefaultMappings(WireMockApp.java:282)
        at com.github.tomakehurst.wiremock.core.WireMockApp.<init>(WireMockApp.java:143)
        at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:74)
        at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:71)
        at wiremock.Run.main(Run.java:23)

My current work-around is using an init-container which find and copy just all real files from the k8s mounted directory to the mappings directory (find /home/wiremock/configmap-mappings/ -type f -exec cp '{}' /home/wiremock/mappings/ \;), which is somehow cumbersome.

jrs666666 avatar Jul 10 '24 08:07 jrs666666

Facing same issue. Do we have any workaround for this?

umeshmishra099 avatar Mar 21 '25 18:03 umeshmishra099