From 26f5ee4e45a86a85644e4e94e9f23aef1bfd11fb Mon Sep 17 00:00:00 2001 From: Hendrik Schlehlein Date: Wed, 1 Feb 2023 21:47:58 +0100 Subject: [PATCH] fix: api docs and wildcards --- configs/plugins/api.yml | 19 +- go.mod | 1 + go.sum | 36 +++ internal/app/infrared/server.go | 6 +- internal/pkg/java/config.go | 8 +- internal/plugin/api/api.go | 6 +- internal/plugin/api/handler.go | 6 +- pkg/wildcard/match.go | 69 ---- pkg/wildcard/match_test.go | 555 -------------------------------- 9 files changed, 70 insertions(+), 636 deletions(-) delete mode 100644 pkg/wildcard/match.go delete mode 100644 pkg/wildcard/match_test.go diff --git a/configs/plugins/api.yml b/configs/plugins/api.yml index a1ec91da..e302ce60 100644 --- a/configs/plugins/api.yml +++ b/configs/plugins/api.yml @@ -13,4 +13,21 @@ api: # allowedOrigins: - "http://*" - - "https://*" \ No newline at end of file + - "https://*" + + # Sets this in the allowed methods header + # + allowedMethods: + - GET + - POST + - PUT + - DELETE + - OPTIONS + + # Sets this in the allowed headers header + # + allowedHeaders: + - Accept + - Content-Type + - Authorization + - X-CSRF-Token \ No newline at end of file diff --git a/go.mod b/go.mod index 87f76b7e..b1af188b 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/df-mc/atomic v1.10.0 github.com/docker/docker v20.10.20+incompatible github.com/fsnotify/fsnotify v1.6.0 + github.com/gertd/wild v0.0.1 github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.1 github.com/go-chi/render v1.0.2 diff --git a/go.sum b/go.sum index d8912128..b1777a84 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +cloud.google.com/go v0.0.0-20170206221025-ce650573d812/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= @@ -35,10 +36,14 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20190129172621-c8b1d7a94ddf/go.mod h1:aJ4qN3TfrelA6NZ6AXsXRfmEVaYin3EDbSPJrKS8OXo= github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= +github.com/aclements/go-gg v0.0.0-20170118225347-6dbb4e4fefb0/go.mod h1:55qNq4vcpkIuHowELi5C8e+1yUHtoLoOUR9QU5j7Tes= +github.com/aclements/go-moremath v0.0.0-20161014184102-0ff62e0875ff/go.mod h1:idZL3yvz4kzx1dsBOAC+oYv6L92P1oFEhUXUB1A/lwQ= github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +github.com/ajstarks/svgo v0.0.0-20200725142600-7a3c8b57fecb/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -82,8 +87,11 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/gertd/wild v0.0.1 h1:GIS4NSMcOgS80515QP7ZY8CeJ1BX3hEvwMEPyO00C0U= +github.com/gertd/wild v0.0.1/go.mod h1:x60mlQynht6enk2xcruLToNem4cd/2zh+xN7eTUkKo4= github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= @@ -103,6 +111,7 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-redis/redis/v9 v9.0.0-rc.2 h1:IN1eI8AvJJeWHjMW/hlFAv2sAfvTun2DVksDDJ3a6a0= github.com/go-redis/redis/v9 v9.0.0-rc.2/go.mod h1:cgBknjwcBJa2prbnuHH/4k/Mlj4r0pWNV2HBanHujfY= +github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gofrs/uuid v4.3.0+incompatible h1:CaSVZxm5B+7o45rtab4jC2G37WGYX1zQfuU2i6DSvnc= github.com/gofrs/uuid v4.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -143,6 +152,11 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc= +github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg= +github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks= +github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= +github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -166,6 +180,8 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= +github.com/googleapis/gax-go v0.0.0-20161107002406-da06d194a00e/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc= @@ -177,6 +193,8 @@ github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/jonboulle/clockwork v0.2.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -198,6 +216,13 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-sqlite3 v0.0.0-20161215041557-2d44decb4941/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2 h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM= github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= @@ -304,6 +329,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -372,6 +398,7 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/oauth2 v0.0.0-20170207211851-4464e7848382/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -379,6 +406,7 @@ golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4Iltr golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= +golang.org/x/perf v0.0.0-20200318175901-9c9101da8316/go.mod h1:FrqOtQDO3iMDVUtw5nNTDFpR1HUCGh00M3kj2wiSzLQ= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -394,6 +422,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -403,10 +432,12 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -421,6 +452,7 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200808120158-1030fc2bf1d9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -493,6 +525,7 @@ golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200809012840-6f4f008689da/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= @@ -503,6 +536,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.0.0-20170206182103-3d017632ea10/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -554,6 +588,7 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v0.0.0-20170208002647-2a6bf6142e96/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -599,6 +634,7 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/gotestsum v0.5.2/go.mod h1:hC9TQserDVTWcJuARh76Ydp3ZwuE+pIIWpt2BzDLD6M= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= diff --git a/internal/app/infrared/server.go b/internal/app/infrared/server.go index 5b32ac43..0764a028 100644 --- a/internal/app/infrared/server.go +++ b/internal/app/infrared/server.go @@ -5,8 +5,8 @@ import ( "net" "sync" + "github.com/gertd/wild" "github.com/haveachin/infrared/pkg/event" - "github.com/haveachin/infrared/pkg/wildcard" "go.uber.org/zap" ) @@ -77,7 +77,7 @@ func (sg *ServerGateway) compileDomainExprs() { func (sg *ServerGateway) findServer(gatewayID, domain string) (Server, string) { for _, srvID := range sg.gwIDSrvIDs[gatewayID] { for _, srvExpr := range sg.srvExprs[srvID] { - if wildcard.Match(srvExpr, domain) { + if wild.Match(srvExpr, domain, true) { return sg.srvs[srvID], srvExpr } } @@ -103,7 +103,7 @@ func (sg *ServerGateway) Start() { logger := sg.Logger.With(logProcessedConn(player)...) logger.Debug("looking up server address") - srv, matchedDomain := sg.findServer(player.GatewayID(), player.MatchedAddr()) + srv, matchedDomain := sg.findServer(player.GatewayID(), player.RequestedAddr()) if srv == nil { logger.Info("failed to find server; disconnecting client") _ = player.DisconnectServerNotFound() diff --git a/internal/pkg/java/config.go b/internal/pkg/java/config.go index 74b2d75c..055f3e05 100644 --- a/internal/pkg/java/config.go +++ b/internal/pkg/java/config.go @@ -26,12 +26,12 @@ type ServerConfig struct { SendProxyProtocol bool `mapstructure:"sendProxyProtocol"` SendRealIP bool `mapstructure:"sendRealIP"` OverrideAddress bool `mapstructure:"overrideAddress"` - DialTimeout time.Duration `mapstructure:"dialTimeout"` + DialTimeout time.Duration `mapstructure:"dialTimeout" swaggertype:"primitive,string"` DialTimeoutMessage string `mapstructure:"dialTimeoutMessage"` OverrideStatus OverrideServerStatusConfig `mapstructure:"overrideStatus"` DialTimeoutStatus ServerStatusConfig `mapstructure:"dialTimeoutStatus"` Gateways []string `mapstructure:"gateways"` - StatusCacheTTL time.Duration `mapstructure:"statusCacheTTL"` + StatusCacheTTL time.Duration `mapstructure:"statusCacheTTL" swaggertype:"primitive,string"` } type OverrideServerStatusConfig struct { @@ -74,7 +74,7 @@ type GatewayConfig struct { type ConnProcessorConfig struct { Count int `mapstructure:"count"` - ClientTimeout time.Duration `mapstructure:"clientTimeout"` + ClientTimeout time.Duration `mapstructure:"clientTimeout" swaggertype:"primitive,string"` } type ChanCapsConfig struct { @@ -90,7 +90,7 @@ type MiddlewareSettings struct { type RateLimiterSettings struct { Enable bool `mapstructure:"enable"` RequestLimit int `mapstructure:"requestLimit"` - WindowLength time.Duration `mapstructure:"windowLength"` + WindowLength time.Duration `mapstructure:"windowLength" swaggertype:"primitive,string"` } type ProxyConfig struct { diff --git a/internal/plugin/api/api.go b/internal/plugin/api/api.go index fca676ee..68bde3a4 100644 --- a/internal/plugin/api/api.go +++ b/internal/plugin/api/api.go @@ -21,6 +21,8 @@ type PluginConfig struct { Enable bool `mapstructure:"enable"` Bind string `mapstructure:"bind"` AllowedOrigins []string `mapstructure:"allowedOrigins"` + AllowedMethods []string `mapstructure:"allowedMethods"` + AllowedHeaders []string `mapstructure:"allowedHeaders"` } `mapstructure:"api"` } @@ -136,8 +138,8 @@ func (p Plugin) router() http.Handler { r.Use(middleware.Recoverer) r.Use(cors.Handler(cors.Options{ AllowedOrigins: p.Config.API.AllowedOrigins, - AllowedMethods: []string{"GET", "DELETE"}, - AllowedHeaders: []string{"Accept", "Content-Type"}, + AllowedMethods: p.Config.API.AllowedMethods, + AllowedHeaders: p.Config.API.AllowedHeaders, AllowCredentials: false, })) diff --git a/internal/plugin/api/handler.go b/internal/plugin/api/handler.go index a491df82..3fa9903a 100644 --- a/internal/plugin/api/handler.go +++ b/internal/plugin/api/handler.go @@ -234,9 +234,11 @@ func getConfigs(cfg config.Config) http.HandlerFunc { // @Summary Create/Update a config // @Description Create/Update a config via ID // @Tags Config +// @Accept json // @Produce json -// @Param configId path string true "Config ID" -// @Success 201 {string} string "See the documentation or configs folder for more info on this complex struct" +// @Param request body map[string]any true "Config" +// @Param configId path string true "Config ID" +// @Success 201 {string} string "See the documentation or configs folder for more info on this complex struct" // @Failure 400 {object} api.errorDTO // @Failure 500 {object} api.errorDTO // @Router /configs/{configId} [put] diff --git a/pkg/wildcard/match.go b/pkg/wildcard/match.go deleted file mode 100644 index 9c3f48f0..00000000 --- a/pkg/wildcard/match.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2015-2021 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package wildcard - -// MatchSimple - finds whether the text matches/satisfies the pattern string. -// supports '*' wildcard in the pattern and ? for single characters. -// Only difference to Match is that `?` at the end is optional, -// meaning `a?` pattern will match name `a`. -func MatchSimple(pattern, name string) bool { - if pattern == "" { - return name == pattern - } - if pattern == "*" { - return true - } - // Do an extended wildcard '*' and '?' match. - return deepMatchRune([]rune(name), []rune(pattern), true) -} - -// Match - finds whether the text matches/satisfies the pattern string. -// supports '*' and '?' wildcards in the pattern string. -// unlike path.Match(), considers a path as a flat name space while matching the pattern. -// The difference is illustrated in the example here https://play.golang.org/p/Ega9qgD4Qz . -func Match(pattern, name string) (matched bool) { - if pattern == "" { - return name == pattern - } - if pattern == "*" { - return true - } - // Do an extended wildcard '*' and '?' match. - return deepMatchRune([]rune(name), []rune(pattern), false) -} - -func deepMatchRune(str, pattern []rune, simple bool) bool { - for len(pattern) > 0 { - switch pattern[0] { - default: - if len(str) == 0 || str[0] != pattern[0] { - return false - } - case '?': - if len(str) == 0 { - return simple - } - case '*': - return deepMatchRune(str, pattern[1:], simple) || - (len(str) > 0 && deepMatchRune(str[1:], pattern, simple)) - } - str = str[1:] - pattern = pattern[1:] - } - return len(str) == 0 && len(pattern) == 0 -} diff --git a/pkg/wildcard/match_test.go b/pkg/wildcard/match_test.go deleted file mode 100644 index 31478d53..00000000 --- a/pkg/wildcard/match_test.go +++ /dev/null @@ -1,555 +0,0 @@ -// Copyright (c) 2015-2021 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package wildcard_test - -import ( - "testing" - - "github.com/haveachin/infrared/pkg/wildcard" -) - -// TestMatch - Tests validate the logic of wild card matching. -// `Match` supports '*' and '?' wildcards. -// Sample usage: In resource matching for bucket policy validation. -func TestMatch(t *testing.T) { - testCases := []struct { - pattern string - text string - matched bool - }{ - // Test case - 1. - // Test case with pattern "*". Expected to match any text. - { - pattern: "*", - text: "s3:GetObject", - matched: true, - }, - // Test case - 2. - // Test case with empty pattern. This only matches empty string. - { - pattern: "", - text: "s3:GetObject", - matched: false, - }, - // Test case - 3. - // Test case with empty pattern. This only matches empty string. - { - pattern: "", - text: "", - matched: true, - }, - // Test case - 4. - // Test case with single "*" at the end. - { - pattern: "s3:*", - text: "s3:ListMultipartUploadParts", - matched: true, - }, - // Test case - 5. - // Test case with a no "*". In this case the pattern and text should be the same. - { - pattern: "s3:ListBucketMultipartUploads", - text: "s3:ListBucket", - matched: false, - }, - // Test case - 6. - // Test case with a no "*". In this case the pattern and text should be the same. - { - pattern: "s3:ListBucket", - text: "s3:ListBucket", - matched: true, - }, - // Test case - 7. - // Test case with a no "*". In this case the pattern and text should be the same. - { - pattern: "s3:ListBucketMultipartUploads", - text: "s3:ListBucketMultipartUploads", - matched: true, - }, - // Test case - 8. - // Test case with pattern containing key name with a prefix. Should accept the same text without a "*". - { - pattern: "my-bucket/oo*", - text: "my-bucket/oo", - matched: true, - }, - // Test case - 9. - // Test case with "*" at the end of the pattern. - { - pattern: "my-bucket/In*", - text: "my-bucket/India/Karnataka/", - matched: true, - }, - // Test case - 10. - // Test case with prefixes shuffled. - // This should fail. - { - pattern: "my-bucket/In*", - text: "my-bucket/Karnataka/India/", - matched: false, - }, - // Test case - 11. - // Test case with text expanded to the wildcards in the pattern. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/Karnataka/Ban", - matched: true, - }, - // Test case - 12. - // Test case with the keyname part is repeated as prefix several times. - // This is valid. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/Karnataka/Ban/Ban/Ban/Ban/Ban", - matched: true, - }, - // Test case - 13. - // Test case to validate that `*` can be expanded into multiple prefixes. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/Karnataka/Area1/Area2/Area3/Ban", - matched: true, - }, - // Test case - 14. - // Test case to validate that `*` can be expanded into multiple prefixes. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/State1/State2/Karnataka/Area1/Area2/Area3/Ban", - matched: true, - }, - // Test case - 15. - // Test case where the keyname part of the pattern is expanded in the text. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/Karnataka/Bangalore", - matched: false, - }, - // Test case - 16. - // Test case with prefixes and wildcard expanded for all "*". - { - pattern: "my-bucket/In*/Ka*/Ban*", - text: "my-bucket/India/Karnataka/Bangalore", - matched: true, - }, - // Test case - 17. - // Test case with keyname part being a wildcard in the pattern. - { - pattern: "my-bucket/*", - text: "my-bucket/India", - matched: true, - }, - // Test case - 18. - { - pattern: "my-bucket/oo*", - text: "my-bucket/odo", - matched: false, - }, - - // Test case with pattern containing wildcard '?'. - // Test case - 19. - // "my-bucket?/" matches "my-bucket1/", "my-bucket2/", "my-bucket3" etc... - // doesn't match "mybucket/". - { - pattern: "my-bucket?/abc*", - text: "mybucket/abc", - matched: false, - }, - // Test case - 20. - { - pattern: "my-bucket?/abc*", - text: "my-bucket1/abc", - matched: true, - }, - // Test case - 21. - { - pattern: "my-?-bucket/abc*", - text: "my--bucket/abc", - matched: false, - }, - // Test case - 22. - { - pattern: "my-?-bucket/abc*", - text: "my-1-bucket/abc", - matched: true, - }, - // Test case - 23. - { - pattern: "my-?-bucket/abc*", - text: "my-k-bucket/abc", - matched: true, - }, - // Test case - 24. - { - pattern: "my??bucket/abc*", - text: "mybucket/abc", - matched: false, - }, - // Test case - 25. - { - pattern: "my??bucket/abc*", - text: "my4abucket/abc", - matched: true, - }, - // Test case - 26. - { - pattern: "my-bucket?abc*", - text: "my-bucket/abc", - matched: true, - }, - // Test case 27-28. - // '?' matches '/' too. (works with s3). - // This is because the namespace is considered flat. - // "abc?efg" matches both "abcdefg" and "abc/efg". - { - pattern: "my-bucket/abc?efg", - text: "my-bucket/abcdefg", - matched: true, - }, - { - pattern: "my-bucket/abc?efg", - text: "my-bucket/abc/efg", - matched: true, - }, - // Test case - 29. - { - pattern: "my-bucket/abc????", - text: "my-bucket/abc", - matched: false, - }, - // Test case - 30. - { - pattern: "my-bucket/abc????", - text: "my-bucket/abcde", - matched: false, - }, - // Test case - 31. - { - pattern: "my-bucket/abc????", - text: "my-bucket/abcdefg", - matched: true, - }, - // Test case 32-34. - // test case with no '*'. - { - pattern: "my-bucket/abc?", - text: "my-bucket/abc", - matched: false, - }, - { - pattern: "my-bucket/abc?", - text: "my-bucket/abcd", - matched: true, - }, - { - pattern: "my-bucket/abc?", - text: "my-bucket/abcde", - matched: false, - }, - // Test case 35. - { - pattern: "my-bucket/mnop*?", - text: "my-bucket/mnop", - matched: false, - }, - // Test case 36. - { - pattern: "my-bucket/mnop*?", - text: "my-bucket/mnopqrst/mnopqr", - matched: true, - }, - // Test case 37. - { - pattern: "my-bucket/mnop*?", - text: "my-bucket/mnopqrst/mnopqrs", - matched: true, - }, - // Test case 38. - { - pattern: "my-bucket/mnop*?", - text: "my-bucket/mnop", - matched: false, - }, - // Test case 39. - { - pattern: "my-bucket/mnop*?", - text: "my-bucket/mnopq", - matched: true, - }, - // Test case 40. - { - pattern: "my-bucket/mnop*?", - text: "my-bucket/mnopqr", - matched: true, - }, - // Test case 41. - { - pattern: "my-bucket/mnop*?and", - text: "my-bucket/mnopqand", - matched: true, - }, - // Test case 42. - { - pattern: "my-bucket/mnop*?and", - text: "my-bucket/mnopand", - matched: false, - }, - // Test case 43. - { - pattern: "my-bucket/mnop*?and", - text: "my-bucket/mnopqand", - matched: true, - }, - // Test case 44. - { - pattern: "my-bucket/mnop*?", - text: "my-bucket/mn", - matched: false, - }, - // Test case 45. - { - pattern: "my-bucket/mnop*?", - text: "my-bucket/mnopqrst/mnopqrs", - matched: true, - }, - // Test case 46. - { - pattern: "my-bucket/mnop*??", - text: "my-bucket/mnopqrst", - matched: true, - }, - // Test case 47. - { - pattern: "my-bucket/mnop*qrst", - text: "my-bucket/mnopabcdegqrst", - matched: true, - }, - // Test case 48. - { - pattern: "my-bucket/mnop*?and", - text: "my-bucket/mnopqand", - matched: true, - }, - // Test case 49. - { - pattern: "my-bucket/mnop*?and", - text: "my-bucket/mnopand", - matched: false, - }, - // Test case 50. - { - pattern: "my-bucket/mnop*?and?", - text: "my-bucket/mnopqanda", - matched: true, - }, - // Test case 51. - { - pattern: "my-bucket/mnop*?and", - text: "my-bucket/mnopqanda", - matched: false, - }, - // Test case 52. - - { - pattern: "my-?-bucket/abc*", - text: "my-bucket/mnopqanda", - matched: false, - }, - // Test case - 53: - { - pattern: "a?", - text: "a", - matched: false, - }, - } - // Iterating over the test cases, call the function under test and assert the output. - for i, testCase := range testCases { - actualResult := wildcard.Match(testCase.pattern, testCase.text) - if testCase.matched != actualResult { - t.Errorf("Test %d: Expected the result to be `%v`, but instead found it to be `%v`", i+1, testCase.matched, actualResult) - } - } -} - -// TestMatchSimple - Tests validate the logic of wild card matching. -// `MatchSimple` supports matching for only '*' in the pattern string. -func TestMatchSimple(t *testing.T) { - testCases := []struct { - pattern string - text string - matched bool - }{ - // Test case - 1. - // Test case with pattern "*". Expected to match any text. - { - pattern: "*", - text: "s3:GetObject", - matched: true, - }, - // Test case - 2. - // Test case with empty pattern. This only matches empty string. - { - pattern: "", - text: "s3:GetObject", - matched: false, - }, - // Test case - 3. - // Test case with empty pattern. This only matches empty string. - { - pattern: "", - text: "", - matched: true, - }, - // Test case - 4. - // Test case with single "*" at the end. - { - pattern: "s3:*", - text: "s3:ListMultipartUploadParts", - matched: true, - }, - // Test case - 5. - // Test case with a no "*". In this case the pattern and text should be the same. - { - pattern: "s3:ListBucketMultipartUploads", - text: "s3:ListBucket", - matched: false, - }, - // Test case - 6. - // Test case with a no "*". In this case the pattern and text should be the same. - { - pattern: "s3:ListBucket", - text: "s3:ListBucket", - matched: true, - }, - // Test case - 7. - // Test case with a no "*". In this case the pattern and text should be the same. - { - pattern: "s3:ListBucketMultipartUploads", - text: "s3:ListBucketMultipartUploads", - matched: true, - }, - // Test case - 8. - // Test case with pattern containing key name with a prefix. Should accept the same text without a "*". - { - pattern: "my-bucket/oo*", - text: "my-bucket/oo", - matched: true, - }, - // Test case - 9. - // Test case with "*" at the end of the pattern. - { - pattern: "my-bucket/In*", - text: "my-bucket/India/Karnataka/", - matched: true, - }, - // Test case - 10. - // Test case with prefixes shuffled. - // This should fail. - { - pattern: "my-bucket/In*", - text: "my-bucket/Karnataka/India/", - matched: false, - }, - // Test case - 11. - // Test case with text expanded to the wildcards in the pattern. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/Karnataka/Ban", - matched: true, - }, - // Test case - 12. - // Test case with the keyname part is repeated as prefix several times. - // This is valid. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/Karnataka/Ban/Ban/Ban/Ban/Ban", - matched: true, - }, - // Test case - 13. - // Test case to validate that `*` can be expanded into multiple prefixes. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/Karnataka/Area1/Area2/Area3/Ban", - matched: true, - }, - // Test case - 14. - // Test case to validate that `*` can be expanded into multiple prefixes. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/State1/State2/Karnataka/Area1/Area2/Area3/Ban", - matched: true, - }, - // Test case - 15. - // Test case where the keyname part of the pattern is expanded in the text. - { - pattern: "my-bucket/In*/Ka*/Ban", - text: "my-bucket/India/Karnataka/Bangalore", - matched: false, - }, - // Test case - 16. - // Test case with prefixes and wildcard expanded for all "*". - { - pattern: "my-bucket/In*/Ka*/Ban*", - text: "my-bucket/India/Karnataka/Bangalore", - matched: true, - }, - // Test case - 17. - // Test case with keyname part being a wildcard in the pattern. - { - pattern: "my-bucket/*", - text: "my-bucket/India", - matched: true, - }, - // Test case - 18. - { - pattern: "my-bucket/oo*", - text: "my-bucket/odo", - matched: false, - }, - // Test case - 19. - { - pattern: "my-bucket/oo?*", - text: "my-bucket/oo???", - matched: true, - }, - // Test case - 20: - { - pattern: "my-bucket/oo??*", - text: "my-bucket/odo", - matched: false, - }, - // Test case - 21: - { - pattern: "?h?*", - text: "?h?hello", - matched: true, - }, - // Test case - 22: - { - pattern: "a?", - text: "a", - matched: true, - }, - } - // Iterating over the test cases, call the function under test and assert the output. - for i, testCase := range testCases { - actualResult := wildcard.MatchSimple(testCase.pattern, testCase.text) - if testCase.matched != actualResult { - t.Errorf("Test %d: Expected the result to be `%v`, but instead found it to be `%v`", i+1, testCase.matched, actualResult) - } - } -}