From 3c6a25907791d3200739e121a89cde4e30046781 Mon Sep 17 00:00:00 2001 From: eXenon Date: Wed, 8 Nov 2023 10:48:10 +0100 Subject: [PATCH 1/5] Add compatibility with SeaweedFS --- cs_api_core/cs_api_core.ml | 2 +- test/test_key_extractor.ml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cs_api_core/cs_api_core.ml b/cs_api_core/cs_api_core.ml index 9c4b5d9..51e5f60 100644 --- a/cs_api_core/cs_api_core.ml +++ b/cs_api_core/cs_api_core.ml @@ -191,7 +191,7 @@ let parse_s3_signature_request ~body = let parse_s3_response ~body = try - let key_extractor = Str.regexp "\\([^<>]*\\)" in + let key_extractor = Str.regexp "<.*Key>\\([^<>]*\\)" in let _ = Str.search_forward key_extractor body 0 in Ok (Str.matched_group 1 body) with diff --git a/test/test_key_extractor.ml b/test/test_key_extractor.ml index c0dc0ab..603d1e5 100644 --- a/test/test_key_extractor.ml +++ b/test/test_key_extractor.ml @@ -24,5 +24,12 @@ let tests = cryptosense-tracesuploads/784f2aa928404db3a958fbd779a44156"82887f4dd13a80e182aa01efc0a59e9e"http://localhost:9000/cryptosense-traces/uploads/784f2aa928404db3a958fbd779a44156 |} ~expected:(Ok "uploads/784f2aa928404db3a958fbd779a44156") + ; test_body ~name:"Valid SeaweedFS body" + ~body: + {| + +cryptosense-tracesuploads/784f2aa928404db3a958fbd779a44156"82887f4dd13a80e182aa01efc0a59e9e"http://localhost:9000/cryptosense-traces/uploads/784f2aa928404db3a958fbd779a44156 + |} + ~expected:(Ok "uploads/784f2aa928404db3a958fbd779a44156") ; test_body ~name:"Invalid body" ~body:"This\ndoes not\ncontain a key." ~expected:(Error "Key could not be extracted from S3 response.") ] From 99b9995598fc7d3a729e12f8e8bdf1d6c15b3550 Mon Sep 17 00:00:00 2001 From: eXenon Date: Wed, 8 Nov 2023 10:52:42 +0100 Subject: [PATCH 2/5] Add changelog --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6d1ee30..0e1fb22 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,12 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). _There are no unreleased changes at the moment._ +## [2.5.1] - 2023-11-08 + +### Fixed + +* Fix compatibility with SeaweedFS API responses + ## [2.5.0] - 2023-10-19 ### Fixed From 2875b91086e968332922f306398379974eb11e0a Mon Sep 17 00:00:00 2001 From: eXenon Date: Wed, 8 Nov 2023 11:48:16 +0100 Subject: [PATCH 3/5] Update CI Fix SeaweedFS response parsing --- .github/workflows/main.yml | 11 ++++++++++- cs_api_core/cs_api_core.ml | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bdcb3ec..9dbfcad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Retrieve new lists of system packages if: runner.os != 'Windows' run: sudo apt-get update @@ -38,4 +38,13 @@ jobs: - run: opam pin add cs_api_client.dev . --no-action - run: opam depext cs_api_client --yes --with-test - run: opam install . --deps-only --with-test + - name: Tag substitution + run: bash ./ci/subst.bash "${{ github.ref_name }}" + if: startsWith(github.ref, 'refs/tags/') - run: opam exec -- dune build @all @fmt @runtest + - name: Upload compiled binary + uses: actions/upload-artifact@v3 + with: + name: cs-api-${{ matrix.os }} + path: _build/install/default/bin/* + if-no-files-found: error diff --git a/cs_api_core/cs_api_core.ml b/cs_api_core/cs_api_core.ml index 51e5f60..f541fcb 100644 --- a/cs_api_core/cs_api_core.ml +++ b/cs_api_core/cs_api_core.ml @@ -191,7 +191,7 @@ let parse_s3_signature_request ~body = let parse_s3_response ~body = try - let key_extractor = Str.regexp "<.*Key>\\([^<>]*\\)" in + let key_extractor = Str.regexp "<.*Key.*>\\([^<>]*\\)" in let _ = Str.search_forward key_extractor body 0 in Ok (Str.matched_group 1 body) with From 201e7b41ebad4e9de1ddc184ca62f15ae6841dcd Mon Sep 17 00:00:00 2001 From: eXenon Date: Fri, 10 Nov 2023 10:35:34 +0100 Subject: [PATCH 4/5] Realistic SeaweedFS test --- test/test_key_extractor.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_key_extractor.ml b/test/test_key_extractor.ml index 603d1e5..d7b8b2c 100644 --- a/test/test_key_extractor.ml +++ b/test/test_key_extractor.ml @@ -28,8 +28,8 @@ let tests = ~body: {| -cryptosense-tracesuploads/784f2aa928404db3a958fbd779a44156"82887f4dd13a80e182aa01efc0a59e9e"http://localhost:9000/cryptosense-traces/uploads/784f2aa928404db3a958fbd779a44156 +storage-tracesuploads/48db212785054589966f84565a263e90"4425e01772cfdca990eff5f085d05414" |} - ~expected:(Ok "uploads/784f2aa928404db3a958fbd779a44156") + ~expected:(Ok "uploads/48db212785054589966f84565a263e90") ; test_body ~name:"Invalid body" ~body:"This\ndoes not\ncontain a key." ~expected:(Error "Key could not be extracted from S3 response.") ] From 4e6547c0463123fcc6e516b7d37c4d6e9fdd2f02 Mon Sep 17 00:00:00 2001 From: eXenon Date: Fri, 10 Nov 2023 11:08:03 +0100 Subject: [PATCH 5/5] Make regex stricter --- cs_api_core/cs_api_core.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cs_api_core/cs_api_core.ml b/cs_api_core/cs_api_core.ml index f541fcb..c4c3db0 100644 --- a/cs_api_core/cs_api_core.ml +++ b/cs_api_core/cs_api_core.ml @@ -191,7 +191,7 @@ let parse_s3_signature_request ~body = let parse_s3_response ~body = try - let key_extractor = Str.regexp "<.*Key.*>\\([^<>]*\\)" in + let key_extractor = Str.regexp "\\([^<>]*\\)" in let _ = Str.search_forward key_extractor body 0 in Ok (Str.matched_group 1 body) with