kreuzberg 4.0.0.pre.rc.13 → 4.0.0.pre.rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +14 -14
- data/.rspec +3 -3
- data/.rubocop.yaml +1 -1
- data/.rubocop.yml +538 -538
- data/Gemfile +8 -8
- data/Gemfile.lock +104 -2
- data/README.md +454 -454
- data/Rakefile +33 -25
- data/Steepfile +47 -47
- data/examples/async_patterns.rb +341 -341
- data/ext/kreuzberg_rb/extconf.rb +45 -45
- data/ext/kreuzberg_rb/native/.cargo/config.toml +2 -2
- data/ext/kreuzberg_rb/native/Cargo.lock +6750 -6941
- data/ext/kreuzberg_rb/native/Cargo.toml +53 -54
- data/ext/kreuzberg_rb/native/README.md +425 -425
- data/ext/kreuzberg_rb/native/build.rs +52 -15
- data/ext/kreuzberg_rb/native/include/ieeefp.h +11 -11
- data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +14 -14
- data/ext/kreuzberg_rb/native/include/strings.h +20 -20
- data/ext/kreuzberg_rb/native/include/unistd.h +47 -47
- data/ext/kreuzberg_rb/native/src/lib.rs +3158 -3158
- data/extconf.rb +28 -28
- data/kreuzberg.gemspec +214 -214
- data/lib/kreuzberg/api_proxy.rb +142 -142
- data/lib/kreuzberg/cache_api.rb +81 -81
- data/lib/kreuzberg/cli.rb +55 -55
- data/lib/kreuzberg/cli_proxy.rb +127 -127
- data/lib/kreuzberg/config.rb +724 -724
- data/lib/kreuzberg/error_context.rb +80 -80
- data/lib/kreuzberg/errors.rb +118 -118
- data/lib/kreuzberg/extraction_api.rb +340 -340
- data/lib/kreuzberg/mcp_proxy.rb +186 -186
- data/lib/kreuzberg/ocr_backend_protocol.rb +113 -113
- data/lib/kreuzberg/post_processor_protocol.rb +86 -86
- data/lib/kreuzberg/result.rb +279 -279
- data/lib/kreuzberg/setup_lib_path.rb +80 -80
- data/lib/kreuzberg/validator_protocol.rb +89 -89
- data/lib/kreuzberg/version.rb +5 -5
- data/lib/kreuzberg.rb +109 -109
- data/lib/{pdfium.dll → libpdfium.so} +0 -0
- data/sig/kreuzberg/internal.rbs +184 -184
- data/sig/kreuzberg.rbs +546 -546
- data/spec/binding/cache_spec.rb +227 -227
- data/spec/binding/cli_proxy_spec.rb +85 -85
- data/spec/binding/cli_spec.rb +55 -55
- data/spec/binding/config_spec.rb +345 -345
- data/spec/binding/config_validation_spec.rb +283 -283
- data/spec/binding/error_handling_spec.rb +213 -213
- data/spec/binding/errors_spec.rb +66 -66
- data/spec/binding/plugins/ocr_backend_spec.rb +307 -307
- data/spec/binding/plugins/postprocessor_spec.rb +269 -269
- data/spec/binding/plugins/validator_spec.rb +274 -274
- data/spec/fixtures/config.toml +39 -39
- data/spec/fixtures/config.yaml +41 -41
- data/spec/fixtures/invalid_config.toml +4 -4
- data/spec/smoke/package_spec.rb +178 -178
- data/spec/spec_helper.rb +42 -42
- data/vendor/Cargo.toml +2 -2
- data/vendor/kreuzberg/Cargo.toml +5 -5
- data/vendor/kreuzberg/README.md +230 -230
- data/vendor/kreuzberg/benches/otel_overhead.rs +48 -48
- data/vendor/kreuzberg/build.rs +887 -843
- data/vendor/kreuzberg/src/api/error.rs +81 -81
- data/vendor/kreuzberg/src/api/handlers.rs +199 -199
- data/vendor/kreuzberg/src/api/mod.rs +87 -79
- data/vendor/kreuzberg/src/api/server.rs +353 -353
- data/vendor/kreuzberg/src/api/types.rs +170 -170
- data/vendor/kreuzberg/src/cache/mod.rs +1167 -1167
- data/vendor/kreuzberg/src/chunking/mod.rs +1877 -1877
- data/vendor/kreuzberg/src/chunking/processor.rs +220 -220
- data/vendor/kreuzberg/src/core/batch_mode.rs +95 -95
- data/vendor/kreuzberg/src/core/config.rs +1080 -1080
- data/vendor/kreuzberg/src/core/extractor.rs +1156 -1156
- data/vendor/kreuzberg/src/core/io.rs +329 -329
- data/vendor/kreuzberg/src/core/mime.rs +605 -605
- data/vendor/kreuzberg/src/core/mod.rs +47 -47
- data/vendor/kreuzberg/src/core/pipeline.rs +1184 -1184
- data/vendor/kreuzberg/src/embeddings.rs +500 -500
- data/vendor/kreuzberg/src/error.rs +431 -431
- data/vendor/kreuzberg/src/extraction/archive.rs +954 -954
- data/vendor/kreuzberg/src/extraction/docx.rs +398 -398
- data/vendor/kreuzberg/src/extraction/email.rs +854 -854
- data/vendor/kreuzberg/src/extraction/excel.rs +688 -688
- data/vendor/kreuzberg/src/extraction/html.rs +634 -601
- data/vendor/kreuzberg/src/extraction/image.rs +491 -491
- data/vendor/kreuzberg/src/extraction/libreoffice.rs +574 -574
- data/vendor/kreuzberg/src/extraction/markdown.rs +213 -213
- data/vendor/kreuzberg/src/extraction/mod.rs +81 -81
- data/vendor/kreuzberg/src/extraction/office_metadata/app_properties.rs +398 -398
- data/vendor/kreuzberg/src/extraction/office_metadata/core_properties.rs +247 -247
- data/vendor/kreuzberg/src/extraction/office_metadata/custom_properties.rs +240 -240
- data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +130 -130
- data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +284 -284
- data/vendor/kreuzberg/src/extraction/pptx.rs +3100 -3100
- data/vendor/kreuzberg/src/extraction/structured.rs +490 -490
- data/vendor/kreuzberg/src/extraction/table.rs +328 -328
- data/vendor/kreuzberg/src/extraction/text.rs +269 -269
- data/vendor/kreuzberg/src/extraction/xml.rs +333 -333
- data/vendor/kreuzberg/src/extractors/archive.rs +447 -447
- data/vendor/kreuzberg/src/extractors/bibtex.rs +470 -470
- data/vendor/kreuzberg/src/extractors/docbook.rs +504 -504
- data/vendor/kreuzberg/src/extractors/docx.rs +400 -400
- data/vendor/kreuzberg/src/extractors/email.rs +157 -157
- data/vendor/kreuzberg/src/extractors/epub.rs +708 -708
- data/vendor/kreuzberg/src/extractors/excel.rs +345 -345
- data/vendor/kreuzberg/src/extractors/fictionbook.rs +492 -492
- data/vendor/kreuzberg/src/extractors/html.rs +407 -407
- data/vendor/kreuzberg/src/extractors/image.rs +219 -219
- data/vendor/kreuzberg/src/extractors/jats.rs +1054 -1054
- data/vendor/kreuzberg/src/extractors/jupyter.rs +368 -368
- data/vendor/kreuzberg/src/extractors/latex.rs +653 -653
- data/vendor/kreuzberg/src/extractors/markdown.rs +701 -701
- data/vendor/kreuzberg/src/extractors/mod.rs +429 -429
- data/vendor/kreuzberg/src/extractors/odt.rs +628 -628
- data/vendor/kreuzberg/src/extractors/opml.rs +635 -635
- data/vendor/kreuzberg/src/extractors/orgmode.rs +529 -529
- data/vendor/kreuzberg/src/extractors/pdf.rs +749 -749
- data/vendor/kreuzberg/src/extractors/pptx.rs +267 -267
- data/vendor/kreuzberg/src/extractors/rst.rs +577 -577
- data/vendor/kreuzberg/src/extractors/rtf.rs +809 -809
- data/vendor/kreuzberg/src/extractors/security.rs +484 -484
- data/vendor/kreuzberg/src/extractors/security_tests.rs +367 -367
- data/vendor/kreuzberg/src/extractors/structured.rs +142 -142
- data/vendor/kreuzberg/src/extractors/text.rs +265 -265
- data/vendor/kreuzberg/src/extractors/typst.rs +651 -651
- data/vendor/kreuzberg/src/extractors/xml.rs +147 -147
- data/vendor/kreuzberg/src/image/dpi.rs +164 -164
- data/vendor/kreuzberg/src/image/mod.rs +6 -6
- data/vendor/kreuzberg/src/image/preprocessing.rs +417 -417
- data/vendor/kreuzberg/src/image/resize.rs +89 -89
- data/vendor/kreuzberg/src/keywords/config.rs +154 -154
- data/vendor/kreuzberg/src/keywords/mod.rs +237 -237
- data/vendor/kreuzberg/src/keywords/processor.rs +275 -275
- data/vendor/kreuzberg/src/keywords/rake.rs +293 -293
- data/vendor/kreuzberg/src/keywords/types.rs +68 -68
- data/vendor/kreuzberg/src/keywords/yake.rs +163 -163
- data/vendor/kreuzberg/src/language_detection/mod.rs +985 -985
- data/vendor/kreuzberg/src/language_detection/processor.rs +219 -219
- data/vendor/kreuzberg/src/lib.rs +113 -113
- data/vendor/kreuzberg/src/mcp/mod.rs +35 -35
- data/vendor/kreuzberg/src/mcp/server.rs +2076 -2076
- data/vendor/kreuzberg/src/ocr/cache.rs +469 -469
- data/vendor/kreuzberg/src/ocr/error.rs +37 -37
- data/vendor/kreuzberg/src/ocr/hocr.rs +216 -216
- data/vendor/kreuzberg/src/ocr/mod.rs +58 -58
- data/vendor/kreuzberg/src/ocr/processor.rs +863 -863
- data/vendor/kreuzberg/src/ocr/table/mod.rs +4 -4
- data/vendor/kreuzberg/src/ocr/table/tsv_parser.rs +144 -144
- data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +452 -452
- data/vendor/kreuzberg/src/ocr/types.rs +393 -393
- data/vendor/kreuzberg/src/ocr/utils.rs +47 -47
- data/vendor/kreuzberg/src/ocr/validation.rs +206 -206
- data/vendor/kreuzberg/src/panic_context.rs +154 -154
- data/vendor/kreuzberg/src/pdf/bindings.rs +44 -44
- data/vendor/kreuzberg/src/pdf/bundled.rs +452 -346
- data/vendor/kreuzberg/src/pdf/error.rs +130 -130
- data/vendor/kreuzberg/src/pdf/images.rs +139 -139
- data/vendor/kreuzberg/src/pdf/metadata.rs +489 -489
- data/vendor/kreuzberg/src/pdf/mod.rs +68 -68
- data/vendor/kreuzberg/src/pdf/rendering.rs +368 -368
- data/vendor/kreuzberg/src/pdf/table.rs +420 -420
- data/vendor/kreuzberg/src/pdf/text.rs +240 -240
- data/vendor/kreuzberg/src/plugins/extractor.rs +1044 -1044
- data/vendor/kreuzberg/src/plugins/mod.rs +212 -212
- data/vendor/kreuzberg/src/plugins/ocr.rs +639 -639
- data/vendor/kreuzberg/src/plugins/processor.rs +650 -650
- data/vendor/kreuzberg/src/plugins/registry.rs +1339 -1339
- data/vendor/kreuzberg/src/plugins/traits.rs +258 -258
- data/vendor/kreuzberg/src/plugins/validator.rs +967 -967
- data/vendor/kreuzberg/src/stopwords/mod.rs +1470 -1470
- data/vendor/kreuzberg/src/text/mod.rs +25 -25
- data/vendor/kreuzberg/src/text/quality.rs +697 -697
- data/vendor/kreuzberg/src/text/quality_processor.rs +219 -219
- data/vendor/kreuzberg/src/text/string_utils.rs +217 -217
- data/vendor/kreuzberg/src/text/token_reduction/cjk_utils.rs +164 -164
- data/vendor/kreuzberg/src/text/token_reduction/config.rs +100 -100
- data/vendor/kreuzberg/src/text/token_reduction/core.rs +796 -796
- data/vendor/kreuzberg/src/text/token_reduction/filters.rs +902 -902
- data/vendor/kreuzberg/src/text/token_reduction/mod.rs +160 -160
- data/vendor/kreuzberg/src/text/token_reduction/semantic.rs +619 -619
- data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +147 -147
- data/vendor/kreuzberg/src/types.rs +1055 -1055
- data/vendor/kreuzberg/src/utils/mod.rs +17 -17
- data/vendor/kreuzberg/src/utils/quality.rs +959 -959
- data/vendor/kreuzberg/src/utils/string_utils.rs +381 -381
- data/vendor/kreuzberg/stopwords/af_stopwords.json +53 -53
- data/vendor/kreuzberg/stopwords/ar_stopwords.json +482 -482
- data/vendor/kreuzberg/stopwords/bg_stopwords.json +261 -261
- data/vendor/kreuzberg/stopwords/bn_stopwords.json +400 -400
- data/vendor/kreuzberg/stopwords/br_stopwords.json +1205 -1205
- data/vendor/kreuzberg/stopwords/ca_stopwords.json +280 -280
- data/vendor/kreuzberg/stopwords/cs_stopwords.json +425 -425
- data/vendor/kreuzberg/stopwords/da_stopwords.json +172 -172
- data/vendor/kreuzberg/stopwords/de_stopwords.json +622 -622
- data/vendor/kreuzberg/stopwords/el_stopwords.json +849 -849
- data/vendor/kreuzberg/stopwords/en_stopwords.json +1300 -1300
- data/vendor/kreuzberg/stopwords/eo_stopwords.json +175 -175
- data/vendor/kreuzberg/stopwords/es_stopwords.json +734 -734
- data/vendor/kreuzberg/stopwords/et_stopwords.json +37 -37
- data/vendor/kreuzberg/stopwords/eu_stopwords.json +100 -100
- data/vendor/kreuzberg/stopwords/fa_stopwords.json +801 -801
- data/vendor/kreuzberg/stopwords/fi_stopwords.json +849 -849
- data/vendor/kreuzberg/stopwords/fr_stopwords.json +693 -693
- data/vendor/kreuzberg/stopwords/ga_stopwords.json +111 -111
- data/vendor/kreuzberg/stopwords/gl_stopwords.json +162 -162
- data/vendor/kreuzberg/stopwords/gu_stopwords.json +226 -226
- data/vendor/kreuzberg/stopwords/ha_stopwords.json +41 -41
- data/vendor/kreuzberg/stopwords/he_stopwords.json +196 -196
- data/vendor/kreuzberg/stopwords/hi_stopwords.json +227 -227
- data/vendor/kreuzberg/stopwords/hr_stopwords.json +181 -181
- data/vendor/kreuzberg/stopwords/hu_stopwords.json +791 -791
- data/vendor/kreuzberg/stopwords/hy_stopwords.json +47 -47
- data/vendor/kreuzberg/stopwords/id_stopwords.json +760 -760
- data/vendor/kreuzberg/stopwords/it_stopwords.json +634 -634
- data/vendor/kreuzberg/stopwords/ja_stopwords.json +136 -136
- data/vendor/kreuzberg/stopwords/kn_stopwords.json +84 -84
- data/vendor/kreuzberg/stopwords/ko_stopwords.json +681 -681
- data/vendor/kreuzberg/stopwords/ku_stopwords.json +64 -64
- data/vendor/kreuzberg/stopwords/la_stopwords.json +51 -51
- data/vendor/kreuzberg/stopwords/lt_stopwords.json +476 -476
- data/vendor/kreuzberg/stopwords/lv_stopwords.json +163 -163
- data/vendor/kreuzberg/stopwords/ml_stopwords.json +1 -1
- data/vendor/kreuzberg/stopwords/mr_stopwords.json +101 -101
- data/vendor/kreuzberg/stopwords/ms_stopwords.json +477 -477
- data/vendor/kreuzberg/stopwords/ne_stopwords.json +490 -490
- data/vendor/kreuzberg/stopwords/nl_stopwords.json +415 -415
- data/vendor/kreuzberg/stopwords/no_stopwords.json +223 -223
- data/vendor/kreuzberg/stopwords/pl_stopwords.json +331 -331
- data/vendor/kreuzberg/stopwords/pt_stopwords.json +562 -562
- data/vendor/kreuzberg/stopwords/ro_stopwords.json +436 -436
- data/vendor/kreuzberg/stopwords/ru_stopwords.json +561 -561
- data/vendor/kreuzberg/stopwords/si_stopwords.json +193 -193
- data/vendor/kreuzberg/stopwords/sk_stopwords.json +420 -420
- data/vendor/kreuzberg/stopwords/sl_stopwords.json +448 -448
- data/vendor/kreuzberg/stopwords/so_stopwords.json +32 -32
- data/vendor/kreuzberg/stopwords/st_stopwords.json +33 -33
- data/vendor/kreuzberg/stopwords/sv_stopwords.json +420 -420
- data/vendor/kreuzberg/stopwords/sw_stopwords.json +76 -76
- data/vendor/kreuzberg/stopwords/ta_stopwords.json +129 -129
- data/vendor/kreuzberg/stopwords/te_stopwords.json +54 -54
- data/vendor/kreuzberg/stopwords/th_stopwords.json +118 -118
- data/vendor/kreuzberg/stopwords/tl_stopwords.json +149 -149
- data/vendor/kreuzberg/stopwords/tr_stopwords.json +506 -506
- data/vendor/kreuzberg/stopwords/uk_stopwords.json +75 -75
- data/vendor/kreuzberg/stopwords/ur_stopwords.json +519 -519
- data/vendor/kreuzberg/stopwords/vi_stopwords.json +647 -647
- data/vendor/kreuzberg/stopwords/yo_stopwords.json +62 -62
- data/vendor/kreuzberg/stopwords/zh_stopwords.json +796 -796
- data/vendor/kreuzberg/stopwords/zu_stopwords.json +31 -31
- data/vendor/kreuzberg/tests/api_extract_multipart.rs +52 -52
- data/vendor/kreuzberg/tests/api_tests.rs +966 -966
- data/vendor/kreuzberg/tests/archive_integration.rs +545 -545
- data/vendor/kreuzberg/tests/batch_orchestration.rs +556 -556
- data/vendor/kreuzberg/tests/batch_processing.rs +318 -318
- data/vendor/kreuzberg/tests/bibtex_parity_test.rs +421 -421
- data/vendor/kreuzberg/tests/concurrency_stress.rs +533 -533
- data/vendor/kreuzberg/tests/config_features.rs +612 -612
- data/vendor/kreuzberg/tests/config_loading_tests.rs +416 -416
- data/vendor/kreuzberg/tests/core_integration.rs +510 -510
- data/vendor/kreuzberg/tests/csv_integration.rs +414 -414
- data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +500 -500
- data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +122 -122
- data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +370 -370
- data/vendor/kreuzberg/tests/email_integration.rs +327 -327
- data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +275 -275
- data/vendor/kreuzberg/tests/error_handling.rs +402 -402
- data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +228 -228
- data/vendor/kreuzberg/tests/format_integration.rs +165 -164
- data/vendor/kreuzberg/tests/helpers/mod.rs +142 -142
- data/vendor/kreuzberg/tests/html_table_test.rs +551 -551
- data/vendor/kreuzberg/tests/image_integration.rs +255 -255
- data/vendor/kreuzberg/tests/instrumentation_test.rs +139 -139
- data/vendor/kreuzberg/tests/jats_extractor_tests.rs +639 -639
- data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +704 -704
- data/vendor/kreuzberg/tests/keywords_integration.rs +479 -479
- data/vendor/kreuzberg/tests/keywords_quality.rs +509 -509
- data/vendor/kreuzberg/tests/latex_extractor_tests.rs +496 -496
- data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +490 -490
- data/vendor/kreuzberg/tests/mime_detection.rs +429 -429
- data/vendor/kreuzberg/tests/ocr_configuration.rs +514 -514
- data/vendor/kreuzberg/tests/ocr_errors.rs +698 -698
- data/vendor/kreuzberg/tests/ocr_quality.rs +629 -629
- data/vendor/kreuzberg/tests/ocr_stress.rs +469 -469
- data/vendor/kreuzberg/tests/odt_extractor_tests.rs +674 -674
- data/vendor/kreuzberg/tests/opml_extractor_tests.rs +616 -616
- data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +822 -822
- data/vendor/kreuzberg/tests/pdf_integration.rs +45 -45
- data/vendor/kreuzberg/tests/pdfium_linking.rs +374 -374
- data/vendor/kreuzberg/tests/pipeline_integration.rs +1436 -1436
- data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +776 -776
- data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +560 -560
- data/vendor/kreuzberg/tests/plugin_system.rs +927 -927
- data/vendor/kreuzberg/tests/plugin_validator_test.rs +783 -783
- data/vendor/kreuzberg/tests/registry_integration_tests.rs +587 -587
- data/vendor/kreuzberg/tests/rst_extractor_tests.rs +694 -694
- data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +775 -775
- data/vendor/kreuzberg/tests/security_validation.rs +416 -416
- data/vendor/kreuzberg/tests/stopwords_integration_test.rs +888 -888
- data/vendor/kreuzberg/tests/test_fastembed.rs +631 -631
- data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +1260 -1260
- data/vendor/kreuzberg/tests/typst_extractor_tests.rs +648 -648
- data/vendor/kreuzberg/tests/xlsx_metadata_extraction_test.rs +87 -87
- data/vendor/kreuzberg-tesseract/.commitlintrc.json +13 -13
- data/vendor/kreuzberg-tesseract/.crate-ignore +2 -2
- data/vendor/kreuzberg-tesseract/Cargo.lock +2933 -2933
- data/vendor/kreuzberg-tesseract/Cargo.toml +2 -2
- data/vendor/kreuzberg-tesseract/LICENSE +22 -22
- data/vendor/kreuzberg-tesseract/README.md +399 -399
- data/vendor/kreuzberg-tesseract/build.rs +1354 -1354
- data/vendor/kreuzberg-tesseract/patches/README.md +71 -71
- data/vendor/kreuzberg-tesseract/patches/tesseract.diff +199 -199
- data/vendor/kreuzberg-tesseract/src/api.rs +1371 -1371
- data/vendor/kreuzberg-tesseract/src/choice_iterator.rs +77 -77
- data/vendor/kreuzberg-tesseract/src/enums.rs +297 -297
- data/vendor/kreuzberg-tesseract/src/error.rs +81 -81
- data/vendor/kreuzberg-tesseract/src/lib.rs +145 -145
- data/vendor/kreuzberg-tesseract/src/monitor.rs +57 -57
- data/vendor/kreuzberg-tesseract/src/mutable_iterator.rs +197 -197
- data/vendor/kreuzberg-tesseract/src/page_iterator.rs +253 -253
- data/vendor/kreuzberg-tesseract/src/result_iterator.rs +286 -286
- data/vendor/kreuzberg-tesseract/src/result_renderer.rs +183 -183
- data/vendor/kreuzberg-tesseract/tests/integration_test.rs +211 -211
- data/vendor/rb-sys/.cargo_vcs_info.json +5 -5
- data/vendor/rb-sys/Cargo.lock +393 -393
- data/vendor/rb-sys/Cargo.toml +70 -70
- data/vendor/rb-sys/Cargo.toml.orig +57 -57
- data/vendor/rb-sys/LICENSE-APACHE +190 -190
- data/vendor/rb-sys/LICENSE-MIT +21 -21
- data/vendor/rb-sys/build/features.rs +111 -111
- data/vendor/rb-sys/build/main.rs +286 -286
- data/vendor/rb-sys/build/stable_api_config.rs +155 -155
- data/vendor/rb-sys/build/version.rs +50 -50
- data/vendor/rb-sys/readme.md +36 -36
- data/vendor/rb-sys/src/bindings.rs +21 -21
- data/vendor/rb-sys/src/hidden.rs +11 -11
- data/vendor/rb-sys/src/lib.rs +35 -35
- data/vendor/rb-sys/src/macros.rs +371 -371
- data/vendor/rb-sys/src/memory.rs +53 -53
- data/vendor/rb-sys/src/ruby_abi_version.rs +38 -38
- data/vendor/rb-sys/src/special_consts.rs +31 -31
- data/vendor/rb-sys/src/stable_api/compiled.c +179 -179
- data/vendor/rb-sys/src/stable_api/compiled.rs +257 -257
- data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +324 -324
- data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +332 -332
- data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +325 -325
- data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +323 -323
- data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +339 -339
- data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +339 -339
- data/vendor/rb-sys/src/stable_api.rs +260 -260
- data/vendor/rb-sys/src/symbol.rs +31 -31
- data/vendor/rb-sys/src/tracking_allocator.rs +330 -330
- data/vendor/rb-sys/src/utils.rs +89 -89
- data/vendor/rb-sys/src/value_type.rs +7 -7
- metadata +81 -22
- data/vendor/kreuzberg-ffi/Cargo.toml +0 -63
- data/vendor/kreuzberg-ffi/README.md +0 -851
- data/vendor/kreuzberg-ffi/build.rs +0 -176
- data/vendor/kreuzberg-ffi/cbindgen.toml +0 -27
- data/vendor/kreuzberg-ffi/kreuzberg-ffi-install.pc +0 -12
- data/vendor/kreuzberg-ffi/kreuzberg-ffi.pc.in +0 -12
- data/vendor/kreuzberg-ffi/kreuzberg.h +0 -1087
- data/vendor/kreuzberg-ffi/src/lib.rs +0 -3616
- data/vendor/kreuzberg-ffi/src/panic_shield.rs +0 -247
- data/vendor/kreuzberg-ffi/tests.disabled/README.md +0 -48
- data/vendor/kreuzberg-ffi/tests.disabled/config_loading_tests.rs +0 -299
- data/vendor/kreuzberg-ffi/tests.disabled/config_tests.rs +0 -346
- data/vendor/kreuzberg-ffi/tests.disabled/extractor_tests.rs +0 -232
- data/vendor/kreuzberg-ffi/tests.disabled/plugin_registration_tests.rs +0 -470
|
@@ -1,966 +1,966 @@
|
|
|
1
|
-
//! Integration tests for the API module.
|
|
2
|
-
|
|
3
|
-
#![cfg(feature = "api")]
|
|
4
|
-
|
|
5
|
-
use axum::{
|
|
6
|
-
body::Body,
|
|
7
|
-
http::{Request, StatusCode},
|
|
8
|
-
};
|
|
9
|
-
use serde_json::json;
|
|
10
|
-
use tower::ServiceExt;
|
|
11
|
-
|
|
12
|
-
use kreuzberg::{
|
|
13
|
-
ExtractionConfig,
|
|
14
|
-
api::{HealthResponse, InfoResponse, create_router},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/// Test the health check endpoint.
|
|
18
|
-
#[tokio::test]
|
|
19
|
-
async fn test_health_endpoint() {
|
|
20
|
-
let app = create_router(ExtractionConfig::default());
|
|
21
|
-
|
|
22
|
-
let response = app
|
|
23
|
-
.oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
|
|
24
|
-
.await
|
|
25
|
-
.unwrap();
|
|
26
|
-
|
|
27
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
28
|
-
|
|
29
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
30
|
-
let health: HealthResponse = serde_json::from_slice(&body).unwrap();
|
|
31
|
-
|
|
32
|
-
assert_eq!(health.status, "healthy");
|
|
33
|
-
assert!(!health.version.is_empty());
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/// Test the info endpoint.
|
|
37
|
-
#[tokio::test]
|
|
38
|
-
async fn test_info_endpoint() {
|
|
39
|
-
let app = create_router(ExtractionConfig::default());
|
|
40
|
-
|
|
41
|
-
let response = app
|
|
42
|
-
.oneshot(Request::builder().uri("/info").body(Body::empty()).unwrap())
|
|
43
|
-
.await
|
|
44
|
-
.unwrap();
|
|
45
|
-
|
|
46
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
47
|
-
|
|
48
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
49
|
-
let info: InfoResponse = serde_json::from_slice(&body).unwrap();
|
|
50
|
-
|
|
51
|
-
assert!(!info.version.is_empty());
|
|
52
|
-
assert!(info.rust_backend);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/// Test extract endpoint with no files returns 400.
|
|
56
|
-
#[tokio::test]
|
|
57
|
-
async fn test_extract_no_files() {
|
|
58
|
-
let app = create_router(ExtractionConfig::default());
|
|
59
|
-
|
|
60
|
-
let boundary = "----boundary";
|
|
61
|
-
let body_content = format!("--{}--\r\n", boundary);
|
|
62
|
-
|
|
63
|
-
let response = app
|
|
64
|
-
.oneshot(
|
|
65
|
-
Request::builder()
|
|
66
|
-
.method("POST")
|
|
67
|
-
.uri("/extract")
|
|
68
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
69
|
-
.body(Body::from(body_content))
|
|
70
|
-
.unwrap(),
|
|
71
|
-
)
|
|
72
|
-
.await
|
|
73
|
-
.unwrap();
|
|
74
|
-
|
|
75
|
-
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/// Test extract endpoint with a simple text file.
|
|
79
|
-
#[tokio::test]
|
|
80
|
-
async fn test_extract_text_file() {
|
|
81
|
-
let app = create_router(ExtractionConfig::default());
|
|
82
|
-
|
|
83
|
-
let boundary = "----boundary";
|
|
84
|
-
let file_content = "Hello, world!";
|
|
85
|
-
|
|
86
|
-
let body_content = format!(
|
|
87
|
-
"--{}\r\n\
|
|
88
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
89
|
-
Content-Type: text/plain\r\n\
|
|
90
|
-
\r\n\
|
|
91
|
-
{}\r\n\
|
|
92
|
-
--{}--\r\n",
|
|
93
|
-
boundary, file_content, boundary
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
let response = app
|
|
97
|
-
.oneshot(
|
|
98
|
-
Request::builder()
|
|
99
|
-
.method("POST")
|
|
100
|
-
.uri("/extract")
|
|
101
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
102
|
-
.body(Body::from(body_content))
|
|
103
|
-
.unwrap(),
|
|
104
|
-
)
|
|
105
|
-
.await
|
|
106
|
-
.unwrap();
|
|
107
|
-
|
|
108
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
109
|
-
|
|
110
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
111
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
112
|
-
|
|
113
|
-
assert_eq!(results.len(), 1);
|
|
114
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
115
|
-
assert!(results[0]["content"].as_str().unwrap().contains("Hello, world!"));
|
|
116
|
-
|
|
117
|
-
assert!(
|
|
118
|
-
results[0]["chunks"].is_null(),
|
|
119
|
-
"Chunks should be null without chunking config"
|
|
120
|
-
);
|
|
121
|
-
assert!(
|
|
122
|
-
results[0]["detected_languages"].is_null(),
|
|
123
|
-
"Language detection not enabled"
|
|
124
|
-
);
|
|
125
|
-
assert!(results[0]["tables"].is_array(), "Tables field should be present");
|
|
126
|
-
assert!(results[0]["metadata"].is_object(), "Metadata field should be present");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/// Test extract endpoint with JSON config.
|
|
130
|
-
#[tokio::test]
|
|
131
|
-
async fn test_extract_with_config() {
|
|
132
|
-
let app = create_router(ExtractionConfig::default());
|
|
133
|
-
|
|
134
|
-
let boundary = "----boundary";
|
|
135
|
-
let file_content = "Hello, world!";
|
|
136
|
-
let config = json!({
|
|
137
|
-
"force_ocr": false
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
let body_content = format!(
|
|
141
|
-
"--{}\r\n\
|
|
142
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
143
|
-
Content-Type: text/plain\r\n\
|
|
144
|
-
\r\n\
|
|
145
|
-
{}\r\n\
|
|
146
|
-
--{}\r\n\
|
|
147
|
-
Content-Disposition: form-data; name=\"config\"\r\n\
|
|
148
|
-
\r\n\
|
|
149
|
-
{}\r\n\
|
|
150
|
-
--{}--\r\n",
|
|
151
|
-
boundary, file_content, boundary, config, boundary
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
let response = app
|
|
155
|
-
.oneshot(
|
|
156
|
-
Request::builder()
|
|
157
|
-
.method("POST")
|
|
158
|
-
.uri("/extract")
|
|
159
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
160
|
-
.body(Body::from(body_content))
|
|
161
|
-
.unwrap(),
|
|
162
|
-
)
|
|
163
|
-
.await
|
|
164
|
-
.unwrap();
|
|
165
|
-
|
|
166
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
167
|
-
|
|
168
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
169
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
170
|
-
|
|
171
|
-
assert_eq!(results.len(), 1);
|
|
172
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
173
|
-
assert!(results[0]["content"].as_str().unwrap().contains("Hello, world!"));
|
|
174
|
-
|
|
175
|
-
assert!(
|
|
176
|
-
results[0]["chunks"].is_null(),
|
|
177
|
-
"Chunks should be null without chunking config"
|
|
178
|
-
);
|
|
179
|
-
assert!(
|
|
180
|
-
results[0]["detected_languages"].is_null(),
|
|
181
|
-
"Language detection not enabled"
|
|
182
|
-
);
|
|
183
|
-
assert!(results[0]["tables"].is_array(), "Tables field should be present");
|
|
184
|
-
assert!(results[0]["metadata"].is_object(), "Metadata field should be present");
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/// Test extract endpoint with invalid config returns 400.
|
|
188
|
-
#[tokio::test]
|
|
189
|
-
async fn test_extract_invalid_config() {
|
|
190
|
-
let app = create_router(ExtractionConfig::default());
|
|
191
|
-
|
|
192
|
-
let boundary = "----boundary";
|
|
193
|
-
let file_content = "Hello, world!";
|
|
194
|
-
let invalid_config = "not valid json";
|
|
195
|
-
|
|
196
|
-
let body_content = format!(
|
|
197
|
-
"--{}\r\n\
|
|
198
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
199
|
-
Content-Type: text/plain\r\n\
|
|
200
|
-
\r\n\
|
|
201
|
-
{}\r\n\
|
|
202
|
-
--{}\r\n\
|
|
203
|
-
Content-Disposition: form-data; name=\"config\"\r\n\
|
|
204
|
-
\r\n\
|
|
205
|
-
{}\r\n\
|
|
206
|
-
--{}--\r\n",
|
|
207
|
-
boundary, file_content, boundary, invalid_config, boundary
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
let response = app
|
|
211
|
-
.oneshot(
|
|
212
|
-
Request::builder()
|
|
213
|
-
.method("POST")
|
|
214
|
-
.uri("/extract")
|
|
215
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
216
|
-
.body(Body::from(body_content))
|
|
217
|
-
.unwrap(),
|
|
218
|
-
)
|
|
219
|
-
.await
|
|
220
|
-
.unwrap();
|
|
221
|
-
|
|
222
|
-
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/// Test extract endpoint with multiple files.
|
|
226
|
-
#[tokio::test]
|
|
227
|
-
async fn test_extract_multiple_files() {
|
|
228
|
-
let app = create_router(ExtractionConfig::default());
|
|
229
|
-
|
|
230
|
-
let boundary = "----boundary";
|
|
231
|
-
let file1_content = "First file content";
|
|
232
|
-
let file2_content = "Second file content";
|
|
233
|
-
|
|
234
|
-
let body_content = format!(
|
|
235
|
-
"--{}\r\n\
|
|
236
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test1.txt\"\r\n\
|
|
237
|
-
Content-Type: text/plain\r\n\
|
|
238
|
-
\r\n\
|
|
239
|
-
{}\r\n\
|
|
240
|
-
--{}\r\n\
|
|
241
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test2.txt\"\r\n\
|
|
242
|
-
Content-Type: text/plain\r\n\
|
|
243
|
-
\r\n\
|
|
244
|
-
{}\r\n\
|
|
245
|
-
--{}--\r\n",
|
|
246
|
-
boundary, file1_content, boundary, file2_content, boundary
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
let response = app
|
|
250
|
-
.oneshot(
|
|
251
|
-
Request::builder()
|
|
252
|
-
.method("POST")
|
|
253
|
-
.uri("/extract")
|
|
254
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
255
|
-
.body(Body::from(body_content))
|
|
256
|
-
.unwrap(),
|
|
257
|
-
)
|
|
258
|
-
.await
|
|
259
|
-
.unwrap();
|
|
260
|
-
|
|
261
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
262
|
-
|
|
263
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
264
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
265
|
-
|
|
266
|
-
assert_eq!(results.len(), 2);
|
|
267
|
-
assert!(results[0]["content"].as_str().unwrap().contains("First file"));
|
|
268
|
-
assert!(results[1]["content"].as_str().unwrap().contains("Second file"));
|
|
269
|
-
|
|
270
|
-
for result in &results {
|
|
271
|
-
assert!(
|
|
272
|
-
result["chunks"].is_null(),
|
|
273
|
-
"Chunks should be null without chunking config"
|
|
274
|
-
);
|
|
275
|
-
assert!(result["detected_languages"].is_null(), "Language detection not enabled");
|
|
276
|
-
assert!(result["tables"].is_array(), "Tables field should be present");
|
|
277
|
-
assert!(result["metadata"].is_object(), "Metadata field should be present");
|
|
278
|
-
assert_eq!(result["mime_type"], "text/plain");
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/// Test extract endpoint with markdown content.
|
|
283
|
-
#[tokio::test]
|
|
284
|
-
async fn test_extract_markdown_file() {
|
|
285
|
-
let app = create_router(ExtractionConfig::default());
|
|
286
|
-
|
|
287
|
-
let boundary = "----boundary";
|
|
288
|
-
let file_content = "# Heading\n\nSome **bold** text.";
|
|
289
|
-
|
|
290
|
-
let body_content = format!(
|
|
291
|
-
"--{}\r\n\
|
|
292
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.md\"\r\n\
|
|
293
|
-
Content-Type: text/markdown\r\n\
|
|
294
|
-
\r\n\
|
|
295
|
-
{}\r\n\
|
|
296
|
-
--{}--\r\n",
|
|
297
|
-
boundary, file_content, boundary
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
let response = app
|
|
301
|
-
.oneshot(
|
|
302
|
-
Request::builder()
|
|
303
|
-
.method("POST")
|
|
304
|
-
.uri("/extract")
|
|
305
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
306
|
-
.body(Body::from(body_content))
|
|
307
|
-
.unwrap(),
|
|
308
|
-
)
|
|
309
|
-
.await
|
|
310
|
-
.unwrap();
|
|
311
|
-
|
|
312
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
313
|
-
|
|
314
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
315
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
316
|
-
|
|
317
|
-
assert_eq!(results.len(), 1);
|
|
318
|
-
assert_eq!(results[0]["mime_type"], "text/markdown");
|
|
319
|
-
assert!(results[0]["content"].as_str().unwrap().contains("Heading"));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/// Test extract endpoint with JSON content.
|
|
323
|
-
#[tokio::test]
|
|
324
|
-
async fn test_extract_json_file() {
|
|
325
|
-
let app = create_router(ExtractionConfig::default());
|
|
326
|
-
|
|
327
|
-
let boundary = "----boundary";
|
|
328
|
-
let file_content = r#"{"key": "value", "number": 42}"#;
|
|
329
|
-
|
|
330
|
-
let body_content = format!(
|
|
331
|
-
"--{}\r\n\
|
|
332
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.json\"\r\n\
|
|
333
|
-
Content-Type: application/json\r\n\
|
|
334
|
-
\r\n\
|
|
335
|
-
{}\r\n\
|
|
336
|
-
--{}--\r\n",
|
|
337
|
-
boundary, file_content, boundary
|
|
338
|
-
);
|
|
339
|
-
|
|
340
|
-
let response = app
|
|
341
|
-
.oneshot(
|
|
342
|
-
Request::builder()
|
|
343
|
-
.method("POST")
|
|
344
|
-
.uri("/extract")
|
|
345
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
346
|
-
.body(Body::from(body_content))
|
|
347
|
-
.unwrap(),
|
|
348
|
-
)
|
|
349
|
-
.await
|
|
350
|
-
.unwrap();
|
|
351
|
-
|
|
352
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
353
|
-
|
|
354
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
355
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
356
|
-
|
|
357
|
-
assert_eq!(results.len(), 1);
|
|
358
|
-
assert_eq!(results[0]["mime_type"], "application/json");
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/// Test extract endpoint with XML content.
|
|
362
|
-
#[tokio::test]
|
|
363
|
-
#[cfg(feature = "xml")]
|
|
364
|
-
async fn test_extract_xml_file() {
|
|
365
|
-
let app = create_router(ExtractionConfig::default());
|
|
366
|
-
|
|
367
|
-
let boundary = "----boundary";
|
|
368
|
-
let file_content = r#"<?xml version="1.0"?><root><item>test</item></root>"#;
|
|
369
|
-
|
|
370
|
-
let body_content = format!(
|
|
371
|
-
"--{}\r\n\
|
|
372
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.xml\"\r\n\
|
|
373
|
-
Content-Type: application/xml\r\n\
|
|
374
|
-
\r\n\
|
|
375
|
-
{}\r\n\
|
|
376
|
-
--{}--\r\n",
|
|
377
|
-
boundary, file_content, boundary
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
let response = app
|
|
381
|
-
.oneshot(
|
|
382
|
-
Request::builder()
|
|
383
|
-
.method("POST")
|
|
384
|
-
.uri("/extract")
|
|
385
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
386
|
-
.body(Body::from(body_content))
|
|
387
|
-
.unwrap(),
|
|
388
|
-
)
|
|
389
|
-
.await
|
|
390
|
-
.unwrap();
|
|
391
|
-
|
|
392
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
393
|
-
|
|
394
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
395
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
396
|
-
|
|
397
|
-
assert_eq!(results.len(), 1);
|
|
398
|
-
assert_eq!(results[0]["mime_type"], "application/xml");
|
|
399
|
-
assert!(results[0]["content"].as_str().unwrap().contains("test"));
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/// Test extract endpoint with HTML content.
|
|
403
|
-
#[tokio::test]
|
|
404
|
-
#[cfg(feature = "html")]
|
|
405
|
-
async fn test_extract_html_file() {
|
|
406
|
-
let app = create_router(ExtractionConfig::default());
|
|
407
|
-
|
|
408
|
-
let boundary = "----boundary";
|
|
409
|
-
let file_content = r#"<html><body><h1>Title</h1><p>Content</p></body></html>"#;
|
|
410
|
-
|
|
411
|
-
let body_content = format!(
|
|
412
|
-
"--{}\r\n\
|
|
413
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.html\"\r\n\
|
|
414
|
-
Content-Type: text/html\r\n\
|
|
415
|
-
\r\n\
|
|
416
|
-
{}\r\n\
|
|
417
|
-
--{}--\r\n",
|
|
418
|
-
boundary, file_content, boundary
|
|
419
|
-
);
|
|
420
|
-
|
|
421
|
-
let response = app
|
|
422
|
-
.oneshot(
|
|
423
|
-
Request::builder()
|
|
424
|
-
.method("POST")
|
|
425
|
-
.uri("/extract")
|
|
426
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
427
|
-
.body(Body::from(body_content))
|
|
428
|
-
.unwrap(),
|
|
429
|
-
)
|
|
430
|
-
.await
|
|
431
|
-
.unwrap();
|
|
432
|
-
|
|
433
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
434
|
-
|
|
435
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
436
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
437
|
-
|
|
438
|
-
assert_eq!(results.len(), 1);
|
|
439
|
-
assert_eq!(results[0]["mime_type"], "text/html");
|
|
440
|
-
assert!(results[0]["content"].as_str().unwrap().contains("Title"));
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/// Test extract endpoint with missing Content-Type header.
|
|
444
|
-
#[tokio::test]
|
|
445
|
-
async fn test_extract_missing_content_type() {
|
|
446
|
-
let app = create_router(ExtractionConfig::default());
|
|
447
|
-
|
|
448
|
-
let response = app
|
|
449
|
-
.oneshot(
|
|
450
|
-
Request::builder()
|
|
451
|
-
.method("POST")
|
|
452
|
-
.uri("/extract")
|
|
453
|
-
.body(Body::from("some data"))
|
|
454
|
-
.unwrap(),
|
|
455
|
-
)
|
|
456
|
-
.await
|
|
457
|
-
.unwrap();
|
|
458
|
-
|
|
459
|
-
assert!(response.status() == StatusCode::BAD_REQUEST || response.status() == StatusCode::UNSUPPORTED_MEDIA_TYPE);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/// Test extract endpoint with empty file.
|
|
463
|
-
#[tokio::test]
|
|
464
|
-
async fn test_extract_empty_file() {
|
|
465
|
-
let app = create_router(ExtractionConfig::default());
|
|
466
|
-
|
|
467
|
-
let boundary = "----boundary";
|
|
468
|
-
let file_content = "";
|
|
469
|
-
|
|
470
|
-
let body_content = format!(
|
|
471
|
-
"--{}\r\n\
|
|
472
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"empty.txt\"\r\n\
|
|
473
|
-
Content-Type: text/plain\r\n\
|
|
474
|
-
\r\n\
|
|
475
|
-
{}\r\n\
|
|
476
|
-
--{}--\r\n",
|
|
477
|
-
boundary, file_content, boundary
|
|
478
|
-
);
|
|
479
|
-
|
|
480
|
-
let response = app
|
|
481
|
-
.oneshot(
|
|
482
|
-
Request::builder()
|
|
483
|
-
.method("POST")
|
|
484
|
-
.uri("/extract")
|
|
485
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
486
|
-
.body(Body::from(body_content))
|
|
487
|
-
.unwrap(),
|
|
488
|
-
)
|
|
489
|
-
.await
|
|
490
|
-
.unwrap();
|
|
491
|
-
|
|
492
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
493
|
-
|
|
494
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
495
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
496
|
-
|
|
497
|
-
assert_eq!(results.len(), 1);
|
|
498
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/// Test extract endpoint with unsupported MIME type.
|
|
502
|
-
#[tokio::test]
|
|
503
|
-
async fn test_extract_unsupported_mime_type() {
|
|
504
|
-
let app = create_router(ExtractionConfig::default());
|
|
505
|
-
|
|
506
|
-
let boundary = "----boundary";
|
|
507
|
-
let file_content = "Binary data";
|
|
508
|
-
|
|
509
|
-
let body_content = format!(
|
|
510
|
-
"--{}\r\n\
|
|
511
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.bin\"\r\n\
|
|
512
|
-
Content-Type: application/x-unknown-binary\r\n\
|
|
513
|
-
\r\n\
|
|
514
|
-
{}\r\n\
|
|
515
|
-
--{}--\r\n",
|
|
516
|
-
boundary, file_content, boundary
|
|
517
|
-
);
|
|
518
|
-
|
|
519
|
-
let response = app
|
|
520
|
-
.oneshot(
|
|
521
|
-
Request::builder()
|
|
522
|
-
.method("POST")
|
|
523
|
-
.uri("/extract")
|
|
524
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
525
|
-
.body(Body::from(body_content))
|
|
526
|
-
.unwrap(),
|
|
527
|
-
)
|
|
528
|
-
.await
|
|
529
|
-
.unwrap();
|
|
530
|
-
|
|
531
|
-
assert!(
|
|
532
|
-
response.status() == StatusCode::UNPROCESSABLE_ENTITY || response.status() == StatusCode::INTERNAL_SERVER_ERROR
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
/// Test extract endpoint without filename in multipart field.
|
|
537
|
-
#[tokio::test]
|
|
538
|
-
async fn test_extract_without_filename() {
|
|
539
|
-
let app = create_router(ExtractionConfig::default());
|
|
540
|
-
|
|
541
|
-
let boundary = "----boundary";
|
|
542
|
-
let file_content = "Test content";
|
|
543
|
-
|
|
544
|
-
let body_content = format!(
|
|
545
|
-
"--{}\r\n\
|
|
546
|
-
Content-Disposition: form-data; name=\"files\"\r\n\
|
|
547
|
-
Content-Type: text/plain\r\n\
|
|
548
|
-
\r\n\
|
|
549
|
-
{}\r\n\
|
|
550
|
-
--{}--\r\n",
|
|
551
|
-
boundary, file_content, boundary
|
|
552
|
-
);
|
|
553
|
-
|
|
554
|
-
let response = app
|
|
555
|
-
.oneshot(
|
|
556
|
-
Request::builder()
|
|
557
|
-
.method("POST")
|
|
558
|
-
.uri("/extract")
|
|
559
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
560
|
-
.body(Body::from(body_content))
|
|
561
|
-
.unwrap(),
|
|
562
|
-
)
|
|
563
|
-
.await
|
|
564
|
-
.unwrap();
|
|
565
|
-
|
|
566
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/// Test extract endpoint with malformed multipart data.
|
|
570
|
-
#[tokio::test]
|
|
571
|
-
async fn test_extract_malformed_multipart() {
|
|
572
|
-
let app = create_router(ExtractionConfig::default());
|
|
573
|
-
|
|
574
|
-
let boundary = "----boundary";
|
|
575
|
-
let body_content = format!("--{}\r\nmalformed data\r\n", boundary);
|
|
576
|
-
|
|
577
|
-
let response = app
|
|
578
|
-
.oneshot(
|
|
579
|
-
Request::builder()
|
|
580
|
-
.method("POST")
|
|
581
|
-
.uri("/extract")
|
|
582
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
583
|
-
.body(Body::from(body_content))
|
|
584
|
-
.unwrap(),
|
|
585
|
-
)
|
|
586
|
-
.await
|
|
587
|
-
.unwrap();
|
|
588
|
-
|
|
589
|
-
assert!(response.status().is_client_error() || response.status().is_server_error());
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
/// Test CORS headers are present.
|
|
593
|
-
#[tokio::test]
|
|
594
|
-
async fn test_cors_headers() {
|
|
595
|
-
let app = create_router(ExtractionConfig::default());
|
|
596
|
-
|
|
597
|
-
let response = app
|
|
598
|
-
.oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
|
|
599
|
-
.await
|
|
600
|
-
.unwrap();
|
|
601
|
-
|
|
602
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
603
|
-
|
|
604
|
-
let headers = response.headers();
|
|
605
|
-
assert!(headers.contains_key("access-control-allow-origin") || headers.contains_key("Access-Control-Allow-Origin"));
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/// Test OPTIONS preflight request for CORS.
|
|
609
|
-
#[tokio::test]
|
|
610
|
-
async fn test_cors_preflight() {
|
|
611
|
-
let app = create_router(ExtractionConfig::default());
|
|
612
|
-
|
|
613
|
-
let response = app
|
|
614
|
-
.oneshot(
|
|
615
|
-
Request::builder()
|
|
616
|
-
.method("OPTIONS")
|
|
617
|
-
.uri("/extract")
|
|
618
|
-
.header("origin", "http://example.com")
|
|
619
|
-
.header("access-control-request-method", "POST")
|
|
620
|
-
.body(Body::empty())
|
|
621
|
-
.unwrap(),
|
|
622
|
-
)
|
|
623
|
-
.await
|
|
624
|
-
.unwrap();
|
|
625
|
-
|
|
626
|
-
assert!(response.status().is_success() || response.status() == StatusCode::NO_CONTENT);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
/// Test error response format for validation errors.
|
|
630
|
-
#[tokio::test]
|
|
631
|
-
async fn test_error_response_format_validation() {
|
|
632
|
-
let app = create_router(ExtractionConfig::default());
|
|
633
|
-
|
|
634
|
-
let boundary = "----boundary";
|
|
635
|
-
let body_content = format!("--{}--\r\n", boundary);
|
|
636
|
-
|
|
637
|
-
let response = app
|
|
638
|
-
.oneshot(
|
|
639
|
-
Request::builder()
|
|
640
|
-
.method("POST")
|
|
641
|
-
.uri("/extract")
|
|
642
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
643
|
-
.body(Body::from(body_content))
|
|
644
|
-
.unwrap(),
|
|
645
|
-
)
|
|
646
|
-
.await
|
|
647
|
-
.unwrap();
|
|
648
|
-
|
|
649
|
-
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
|
650
|
-
|
|
651
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
652
|
-
let error: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
653
|
-
|
|
654
|
-
assert!(error["error_type"].is_string());
|
|
655
|
-
assert!(error["message"].is_string());
|
|
656
|
-
assert_eq!(error["status_code"], 400);
|
|
657
|
-
assert_eq!(error["error_type"], "ValidationError");
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
/// Test error response format for parsing errors.
|
|
661
|
-
#[tokio::test]
|
|
662
|
-
async fn test_error_response_format_parsing() {
|
|
663
|
-
let app = create_router(ExtractionConfig::default());
|
|
664
|
-
|
|
665
|
-
let boundary = "----boundary";
|
|
666
|
-
let invalid_config = "not valid json";
|
|
667
|
-
|
|
668
|
-
let body_content = format!(
|
|
669
|
-
"--{}\r\n\
|
|
670
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
671
|
-
Content-Type: text/plain\r\n\
|
|
672
|
-
\r\n\
|
|
673
|
-
content\r\n\
|
|
674
|
-
--{}\r\n\
|
|
675
|
-
Content-Disposition: form-data; name=\"config\"\r\n\
|
|
676
|
-
\r\n\
|
|
677
|
-
{}\r\n\
|
|
678
|
-
--{}--\r\n",
|
|
679
|
-
boundary, boundary, invalid_config, boundary
|
|
680
|
-
);
|
|
681
|
-
|
|
682
|
-
let response = app
|
|
683
|
-
.oneshot(
|
|
684
|
-
Request::builder()
|
|
685
|
-
.method("POST")
|
|
686
|
-
.uri("/extract")
|
|
687
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
688
|
-
.body(Body::from(body_content))
|
|
689
|
-
.unwrap(),
|
|
690
|
-
)
|
|
691
|
-
.await
|
|
692
|
-
.unwrap();
|
|
693
|
-
|
|
694
|
-
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
|
695
|
-
|
|
696
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
697
|
-
let error: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
698
|
-
|
|
699
|
-
assert_eq!(error["error_type"], "ValidationError");
|
|
700
|
-
assert!(error["message"].as_str().unwrap().contains("configuration"));
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
/// Test 404 error for non-existent endpoint.
|
|
704
|
-
#[tokio::test]
|
|
705
|
-
async fn test_not_found_endpoint() {
|
|
706
|
-
let app = create_router(ExtractionConfig::default());
|
|
707
|
-
|
|
708
|
-
let response = app
|
|
709
|
-
.oneshot(Request::builder().uri("/nonexistent").body(Body::empty()).unwrap())
|
|
710
|
-
.await
|
|
711
|
-
.unwrap();
|
|
712
|
-
|
|
713
|
-
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
/// Test extract endpoint with very large text content.
|
|
717
|
-
#[tokio::test]
|
|
718
|
-
async fn test_extract_large_file() {
|
|
719
|
-
let app = create_router(ExtractionConfig::default());
|
|
720
|
-
|
|
721
|
-
let boundary = "----boundary";
|
|
722
|
-
let large_content = "A".repeat(1024 * 1024);
|
|
723
|
-
|
|
724
|
-
let body_content = format!(
|
|
725
|
-
"--{}\r\n\
|
|
726
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"large.txt\"\r\n\
|
|
727
|
-
Content-Type: text/plain\r\n\
|
|
728
|
-
\r\n\
|
|
729
|
-
{}\r\n\
|
|
730
|
-
--{}--\r\n",
|
|
731
|
-
boundary, large_content, boundary
|
|
732
|
-
);
|
|
733
|
-
|
|
734
|
-
let response = app
|
|
735
|
-
.oneshot(
|
|
736
|
-
Request::builder()
|
|
737
|
-
.method("POST")
|
|
738
|
-
.uri("/extract")
|
|
739
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
740
|
-
.body(Body::from(body_content))
|
|
741
|
-
.unwrap(),
|
|
742
|
-
)
|
|
743
|
-
.await
|
|
744
|
-
.unwrap();
|
|
745
|
-
|
|
746
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
747
|
-
|
|
748
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
749
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
750
|
-
|
|
751
|
-
assert_eq!(results.len(), 1);
|
|
752
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
/// Test concurrent requests to extract endpoint.
|
|
756
|
-
#[tokio::test]
|
|
757
|
-
async fn test_concurrent_requests() {
|
|
758
|
-
use tower::ServiceExt;
|
|
759
|
-
|
|
760
|
-
let app = create_router(ExtractionConfig::default());
|
|
761
|
-
|
|
762
|
-
let boundary = "----boundary";
|
|
763
|
-
let file_content = "Concurrent test";
|
|
764
|
-
|
|
765
|
-
let body_content = format!(
|
|
766
|
-
"--{}\r\n\
|
|
767
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
768
|
-
Content-Type: text/plain\r\n\
|
|
769
|
-
\r\n\
|
|
770
|
-
{}\r\n\
|
|
771
|
-
--{}--\r\n",
|
|
772
|
-
boundary, file_content, boundary
|
|
773
|
-
);
|
|
774
|
-
|
|
775
|
-
let mut handles = vec![];
|
|
776
|
-
|
|
777
|
-
for _ in 0..5 {
|
|
778
|
-
let app_clone = app.clone();
|
|
779
|
-
let body_clone = body_content.clone();
|
|
780
|
-
|
|
781
|
-
let handle = tokio::spawn(async move {
|
|
782
|
-
app_clone
|
|
783
|
-
.oneshot(
|
|
784
|
-
Request::builder()
|
|
785
|
-
.method("POST")
|
|
786
|
-
.uri("/extract")
|
|
787
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
788
|
-
.body(Body::from(body_clone))
|
|
789
|
-
.unwrap(),
|
|
790
|
-
)
|
|
791
|
-
.await
|
|
792
|
-
});
|
|
793
|
-
|
|
794
|
-
handles.push(handle);
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
for handle in handles {
|
|
798
|
-
let response = handle.await.unwrap().unwrap();
|
|
799
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
/// Test cache stats endpoint.
|
|
804
|
-
#[tokio::test]
|
|
805
|
-
async fn test_cache_stats_endpoint() {
|
|
806
|
-
let app = create_router(ExtractionConfig::default());
|
|
807
|
-
|
|
808
|
-
let response = app
|
|
809
|
-
.oneshot(Request::builder().uri("/cache/stats").body(Body::empty()).unwrap())
|
|
810
|
-
.await
|
|
811
|
-
.unwrap();
|
|
812
|
-
|
|
813
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
814
|
-
|
|
815
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
816
|
-
let stats: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
817
|
-
|
|
818
|
-
assert!(stats["directory"].is_string());
|
|
819
|
-
assert!(stats["total_files"].is_number());
|
|
820
|
-
assert!(stats["total_size_mb"].is_number());
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
/// Test cache clear endpoint.
|
|
824
|
-
#[tokio::test]
|
|
825
|
-
async fn test_cache_clear_endpoint() {
|
|
826
|
-
let app = create_router(ExtractionConfig::default());
|
|
827
|
-
|
|
828
|
-
let response = app
|
|
829
|
-
.oneshot(
|
|
830
|
-
Request::builder()
|
|
831
|
-
.method("DELETE")
|
|
832
|
-
.uri("/cache/clear")
|
|
833
|
-
.body(Body::empty())
|
|
834
|
-
.unwrap(),
|
|
835
|
-
)
|
|
836
|
-
.await
|
|
837
|
-
.unwrap();
|
|
838
|
-
|
|
839
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
840
|
-
|
|
841
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
842
|
-
let clear_result: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
843
|
-
|
|
844
|
-
assert!(clear_result["directory"].is_string());
|
|
845
|
-
assert!(clear_result["removed_files"].is_number());
|
|
846
|
-
assert!(clear_result["freed_mb"].is_number());
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
/// Test extract endpoint with mixed content types.
|
|
850
|
-
#[tokio::test]
|
|
851
|
-
async fn test_extract_mixed_content_types() {
|
|
852
|
-
let app = create_router(ExtractionConfig::default());
|
|
853
|
-
|
|
854
|
-
let boundary = "----boundary";
|
|
855
|
-
let text_content = "Text file";
|
|
856
|
-
let json_content = r#"{"test": "data"}"#;
|
|
857
|
-
|
|
858
|
-
let body_content = format!(
|
|
859
|
-
"--{}\r\n\
|
|
860
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
861
|
-
Content-Type: text/plain\r\n\
|
|
862
|
-
\r\n\
|
|
863
|
-
{}\r\n\
|
|
864
|
-
--{}\r\n\
|
|
865
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.json\"\r\n\
|
|
866
|
-
Content-Type: application/json\r\n\
|
|
867
|
-
\r\n\
|
|
868
|
-
{}\r\n\
|
|
869
|
-
--{}--\r\n",
|
|
870
|
-
boundary, text_content, boundary, json_content, boundary
|
|
871
|
-
);
|
|
872
|
-
|
|
873
|
-
let response = app
|
|
874
|
-
.oneshot(
|
|
875
|
-
Request::builder()
|
|
876
|
-
.method("POST")
|
|
877
|
-
.uri("/extract")
|
|
878
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
879
|
-
.body(Body::from(body_content))
|
|
880
|
-
.unwrap(),
|
|
881
|
-
)
|
|
882
|
-
.await
|
|
883
|
-
.unwrap();
|
|
884
|
-
|
|
885
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
886
|
-
|
|
887
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
888
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
889
|
-
|
|
890
|
-
assert_eq!(results.len(), 2);
|
|
891
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
892
|
-
assert_eq!(results[1]["mime_type"], "application/json");
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
/// Test extract endpoint with unknown field in multipart.
|
|
896
|
-
#[tokio::test]
|
|
897
|
-
async fn test_extract_unknown_multipart_field() {
|
|
898
|
-
let app = create_router(ExtractionConfig::default());
|
|
899
|
-
|
|
900
|
-
let boundary = "----boundary";
|
|
901
|
-
let file_content = "Test content";
|
|
902
|
-
|
|
903
|
-
let body_content = format!(
|
|
904
|
-
"--{}\r\n\
|
|
905
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
906
|
-
Content-Type: text/plain\r\n\
|
|
907
|
-
\r\n\
|
|
908
|
-
{}\r\n\
|
|
909
|
-
--{}\r\n\
|
|
910
|
-
Content-Disposition: form-data; name=\"unknown_field\"\r\n\
|
|
911
|
-
\r\n\
|
|
912
|
-
some value\r\n\
|
|
913
|
-
--{}--\r\n",
|
|
914
|
-
boundary, file_content, boundary, boundary
|
|
915
|
-
);
|
|
916
|
-
|
|
917
|
-
let response = app
|
|
918
|
-
.oneshot(
|
|
919
|
-
Request::builder()
|
|
920
|
-
.method("POST")
|
|
921
|
-
.uri("/extract")
|
|
922
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
923
|
-
.body(Body::from(body_content))
|
|
924
|
-
.unwrap(),
|
|
925
|
-
)
|
|
926
|
-
.await
|
|
927
|
-
.unwrap();
|
|
928
|
-
|
|
929
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
/// Test extract endpoint with default MIME type (application/octet-stream).
|
|
933
|
-
#[tokio::test]
|
|
934
|
-
async fn test_extract_default_mime_type() {
|
|
935
|
-
let app = create_router(ExtractionConfig::default());
|
|
936
|
-
|
|
937
|
-
let boundary = "----boundary";
|
|
938
|
-
let file_content = "Test content";
|
|
939
|
-
|
|
940
|
-
let body_content = format!(
|
|
941
|
-
"--{}\r\n\
|
|
942
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
943
|
-
\r\n\
|
|
944
|
-
{}\r\n\
|
|
945
|
-
--{}--\r\n",
|
|
946
|
-
boundary, file_content, boundary
|
|
947
|
-
);
|
|
948
|
-
|
|
949
|
-
let response = app
|
|
950
|
-
.oneshot(
|
|
951
|
-
Request::builder()
|
|
952
|
-
.method("POST")
|
|
953
|
-
.uri("/extract")
|
|
954
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
955
|
-
.body(Body::from(body_content))
|
|
956
|
-
.unwrap(),
|
|
957
|
-
)
|
|
958
|
-
.await
|
|
959
|
-
.unwrap();
|
|
960
|
-
|
|
961
|
-
assert!(
|
|
962
|
-
response.status() == StatusCode::OK
|
|
963
|
-
|| response.status() == StatusCode::UNPROCESSABLE_ENTITY
|
|
964
|
-
|| response.status() == StatusCode::INTERNAL_SERVER_ERROR
|
|
965
|
-
);
|
|
966
|
-
}
|
|
1
|
+
//! Integration tests for the API module.
|
|
2
|
+
|
|
3
|
+
#![cfg(feature = "api")]
|
|
4
|
+
|
|
5
|
+
use axum::{
|
|
6
|
+
body::Body,
|
|
7
|
+
http::{Request, StatusCode},
|
|
8
|
+
};
|
|
9
|
+
use serde_json::json;
|
|
10
|
+
use tower::ServiceExt;
|
|
11
|
+
|
|
12
|
+
use kreuzberg::{
|
|
13
|
+
ExtractionConfig,
|
|
14
|
+
api::{HealthResponse, InfoResponse, create_router},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/// Test the health check endpoint.
|
|
18
|
+
#[tokio::test]
|
|
19
|
+
async fn test_health_endpoint() {
|
|
20
|
+
let app = create_router(ExtractionConfig::default());
|
|
21
|
+
|
|
22
|
+
let response = app
|
|
23
|
+
.oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
|
|
24
|
+
.await
|
|
25
|
+
.unwrap();
|
|
26
|
+
|
|
27
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
28
|
+
|
|
29
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
30
|
+
let health: HealthResponse = serde_json::from_slice(&body).unwrap();
|
|
31
|
+
|
|
32
|
+
assert_eq!(health.status, "healthy");
|
|
33
|
+
assert!(!health.version.is_empty());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Test the info endpoint.
|
|
37
|
+
#[tokio::test]
|
|
38
|
+
async fn test_info_endpoint() {
|
|
39
|
+
let app = create_router(ExtractionConfig::default());
|
|
40
|
+
|
|
41
|
+
let response = app
|
|
42
|
+
.oneshot(Request::builder().uri("/info").body(Body::empty()).unwrap())
|
|
43
|
+
.await
|
|
44
|
+
.unwrap();
|
|
45
|
+
|
|
46
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
47
|
+
|
|
48
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
49
|
+
let info: InfoResponse = serde_json::from_slice(&body).unwrap();
|
|
50
|
+
|
|
51
|
+
assert!(!info.version.is_empty());
|
|
52
|
+
assert!(info.rust_backend);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Test extract endpoint with no files returns 400.
|
|
56
|
+
#[tokio::test]
|
|
57
|
+
async fn test_extract_no_files() {
|
|
58
|
+
let app = create_router(ExtractionConfig::default());
|
|
59
|
+
|
|
60
|
+
let boundary = "----boundary";
|
|
61
|
+
let body_content = format!("--{}--\r\n", boundary);
|
|
62
|
+
|
|
63
|
+
let response = app
|
|
64
|
+
.oneshot(
|
|
65
|
+
Request::builder()
|
|
66
|
+
.method("POST")
|
|
67
|
+
.uri("/extract")
|
|
68
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
69
|
+
.body(Body::from(body_content))
|
|
70
|
+
.unwrap(),
|
|
71
|
+
)
|
|
72
|
+
.await
|
|
73
|
+
.unwrap();
|
|
74
|
+
|
|
75
|
+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// Test extract endpoint with a simple text file.
|
|
79
|
+
#[tokio::test]
|
|
80
|
+
async fn test_extract_text_file() {
|
|
81
|
+
let app = create_router(ExtractionConfig::default());
|
|
82
|
+
|
|
83
|
+
let boundary = "----boundary";
|
|
84
|
+
let file_content = "Hello, world!";
|
|
85
|
+
|
|
86
|
+
let body_content = format!(
|
|
87
|
+
"--{}\r\n\
|
|
88
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
89
|
+
Content-Type: text/plain\r\n\
|
|
90
|
+
\r\n\
|
|
91
|
+
{}\r\n\
|
|
92
|
+
--{}--\r\n",
|
|
93
|
+
boundary, file_content, boundary
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
let response = app
|
|
97
|
+
.oneshot(
|
|
98
|
+
Request::builder()
|
|
99
|
+
.method("POST")
|
|
100
|
+
.uri("/extract")
|
|
101
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
102
|
+
.body(Body::from(body_content))
|
|
103
|
+
.unwrap(),
|
|
104
|
+
)
|
|
105
|
+
.await
|
|
106
|
+
.unwrap();
|
|
107
|
+
|
|
108
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
109
|
+
|
|
110
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
111
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
112
|
+
|
|
113
|
+
assert_eq!(results.len(), 1);
|
|
114
|
+
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
115
|
+
assert!(results[0]["content"].as_str().unwrap().contains("Hello, world!"));
|
|
116
|
+
|
|
117
|
+
assert!(
|
|
118
|
+
results[0]["chunks"].is_null(),
|
|
119
|
+
"Chunks should be null without chunking config"
|
|
120
|
+
);
|
|
121
|
+
assert!(
|
|
122
|
+
results[0]["detected_languages"].is_null(),
|
|
123
|
+
"Language detection not enabled"
|
|
124
|
+
);
|
|
125
|
+
assert!(results[0]["tables"].is_array(), "Tables field should be present");
|
|
126
|
+
assert!(results[0]["metadata"].is_object(), "Metadata field should be present");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// Test extract endpoint with JSON config.
|
|
130
|
+
#[tokio::test]
|
|
131
|
+
async fn test_extract_with_config() {
|
|
132
|
+
let app = create_router(ExtractionConfig::default());
|
|
133
|
+
|
|
134
|
+
let boundary = "----boundary";
|
|
135
|
+
let file_content = "Hello, world!";
|
|
136
|
+
let config = json!({
|
|
137
|
+
"force_ocr": false
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
let body_content = format!(
|
|
141
|
+
"--{}\r\n\
|
|
142
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
143
|
+
Content-Type: text/plain\r\n\
|
|
144
|
+
\r\n\
|
|
145
|
+
{}\r\n\
|
|
146
|
+
--{}\r\n\
|
|
147
|
+
Content-Disposition: form-data; name=\"config\"\r\n\
|
|
148
|
+
\r\n\
|
|
149
|
+
{}\r\n\
|
|
150
|
+
--{}--\r\n",
|
|
151
|
+
boundary, file_content, boundary, config, boundary
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
let response = app
|
|
155
|
+
.oneshot(
|
|
156
|
+
Request::builder()
|
|
157
|
+
.method("POST")
|
|
158
|
+
.uri("/extract")
|
|
159
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
160
|
+
.body(Body::from(body_content))
|
|
161
|
+
.unwrap(),
|
|
162
|
+
)
|
|
163
|
+
.await
|
|
164
|
+
.unwrap();
|
|
165
|
+
|
|
166
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
167
|
+
|
|
168
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
169
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
170
|
+
|
|
171
|
+
assert_eq!(results.len(), 1);
|
|
172
|
+
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
173
|
+
assert!(results[0]["content"].as_str().unwrap().contains("Hello, world!"));
|
|
174
|
+
|
|
175
|
+
assert!(
|
|
176
|
+
results[0]["chunks"].is_null(),
|
|
177
|
+
"Chunks should be null without chunking config"
|
|
178
|
+
);
|
|
179
|
+
assert!(
|
|
180
|
+
results[0]["detected_languages"].is_null(),
|
|
181
|
+
"Language detection not enabled"
|
|
182
|
+
);
|
|
183
|
+
assert!(results[0]["tables"].is_array(), "Tables field should be present");
|
|
184
|
+
assert!(results[0]["metadata"].is_object(), "Metadata field should be present");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// Test extract endpoint with invalid config returns 400.
|
|
188
|
+
#[tokio::test]
|
|
189
|
+
async fn test_extract_invalid_config() {
|
|
190
|
+
let app = create_router(ExtractionConfig::default());
|
|
191
|
+
|
|
192
|
+
let boundary = "----boundary";
|
|
193
|
+
let file_content = "Hello, world!";
|
|
194
|
+
let invalid_config = "not valid json";
|
|
195
|
+
|
|
196
|
+
let body_content = format!(
|
|
197
|
+
"--{}\r\n\
|
|
198
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
199
|
+
Content-Type: text/plain\r\n\
|
|
200
|
+
\r\n\
|
|
201
|
+
{}\r\n\
|
|
202
|
+
--{}\r\n\
|
|
203
|
+
Content-Disposition: form-data; name=\"config\"\r\n\
|
|
204
|
+
\r\n\
|
|
205
|
+
{}\r\n\
|
|
206
|
+
--{}--\r\n",
|
|
207
|
+
boundary, file_content, boundary, invalid_config, boundary
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
let response = app
|
|
211
|
+
.oneshot(
|
|
212
|
+
Request::builder()
|
|
213
|
+
.method("POST")
|
|
214
|
+
.uri("/extract")
|
|
215
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
216
|
+
.body(Body::from(body_content))
|
|
217
|
+
.unwrap(),
|
|
218
|
+
)
|
|
219
|
+
.await
|
|
220
|
+
.unwrap();
|
|
221
|
+
|
|
222
|
+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/// Test extract endpoint with multiple files.
|
|
226
|
+
#[tokio::test]
|
|
227
|
+
async fn test_extract_multiple_files() {
|
|
228
|
+
let app = create_router(ExtractionConfig::default());
|
|
229
|
+
|
|
230
|
+
let boundary = "----boundary";
|
|
231
|
+
let file1_content = "First file content";
|
|
232
|
+
let file2_content = "Second file content";
|
|
233
|
+
|
|
234
|
+
let body_content = format!(
|
|
235
|
+
"--{}\r\n\
|
|
236
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test1.txt\"\r\n\
|
|
237
|
+
Content-Type: text/plain\r\n\
|
|
238
|
+
\r\n\
|
|
239
|
+
{}\r\n\
|
|
240
|
+
--{}\r\n\
|
|
241
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test2.txt\"\r\n\
|
|
242
|
+
Content-Type: text/plain\r\n\
|
|
243
|
+
\r\n\
|
|
244
|
+
{}\r\n\
|
|
245
|
+
--{}--\r\n",
|
|
246
|
+
boundary, file1_content, boundary, file2_content, boundary
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
let response = app
|
|
250
|
+
.oneshot(
|
|
251
|
+
Request::builder()
|
|
252
|
+
.method("POST")
|
|
253
|
+
.uri("/extract")
|
|
254
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
255
|
+
.body(Body::from(body_content))
|
|
256
|
+
.unwrap(),
|
|
257
|
+
)
|
|
258
|
+
.await
|
|
259
|
+
.unwrap();
|
|
260
|
+
|
|
261
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
262
|
+
|
|
263
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
264
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
265
|
+
|
|
266
|
+
assert_eq!(results.len(), 2);
|
|
267
|
+
assert!(results[0]["content"].as_str().unwrap().contains("First file"));
|
|
268
|
+
assert!(results[1]["content"].as_str().unwrap().contains("Second file"));
|
|
269
|
+
|
|
270
|
+
for result in &results {
|
|
271
|
+
assert!(
|
|
272
|
+
result["chunks"].is_null(),
|
|
273
|
+
"Chunks should be null without chunking config"
|
|
274
|
+
);
|
|
275
|
+
assert!(result["detected_languages"].is_null(), "Language detection not enabled");
|
|
276
|
+
assert!(result["tables"].is_array(), "Tables field should be present");
|
|
277
|
+
assert!(result["metadata"].is_object(), "Metadata field should be present");
|
|
278
|
+
assert_eq!(result["mime_type"], "text/plain");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/// Test extract endpoint with markdown content.
|
|
283
|
+
#[tokio::test]
|
|
284
|
+
async fn test_extract_markdown_file() {
|
|
285
|
+
let app = create_router(ExtractionConfig::default());
|
|
286
|
+
|
|
287
|
+
let boundary = "----boundary";
|
|
288
|
+
let file_content = "# Heading\n\nSome **bold** text.";
|
|
289
|
+
|
|
290
|
+
let body_content = format!(
|
|
291
|
+
"--{}\r\n\
|
|
292
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.md\"\r\n\
|
|
293
|
+
Content-Type: text/markdown\r\n\
|
|
294
|
+
\r\n\
|
|
295
|
+
{}\r\n\
|
|
296
|
+
--{}--\r\n",
|
|
297
|
+
boundary, file_content, boundary
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
let response = app
|
|
301
|
+
.oneshot(
|
|
302
|
+
Request::builder()
|
|
303
|
+
.method("POST")
|
|
304
|
+
.uri("/extract")
|
|
305
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
306
|
+
.body(Body::from(body_content))
|
|
307
|
+
.unwrap(),
|
|
308
|
+
)
|
|
309
|
+
.await
|
|
310
|
+
.unwrap();
|
|
311
|
+
|
|
312
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
313
|
+
|
|
314
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
315
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
316
|
+
|
|
317
|
+
assert_eq!(results.len(), 1);
|
|
318
|
+
assert_eq!(results[0]["mime_type"], "text/markdown");
|
|
319
|
+
assert!(results[0]["content"].as_str().unwrap().contains("Heading"));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/// Test extract endpoint with JSON content.
|
|
323
|
+
#[tokio::test]
|
|
324
|
+
async fn test_extract_json_file() {
|
|
325
|
+
let app = create_router(ExtractionConfig::default());
|
|
326
|
+
|
|
327
|
+
let boundary = "----boundary";
|
|
328
|
+
let file_content = r#"{"key": "value", "number": 42}"#;
|
|
329
|
+
|
|
330
|
+
let body_content = format!(
|
|
331
|
+
"--{}\r\n\
|
|
332
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.json\"\r\n\
|
|
333
|
+
Content-Type: application/json\r\n\
|
|
334
|
+
\r\n\
|
|
335
|
+
{}\r\n\
|
|
336
|
+
--{}--\r\n",
|
|
337
|
+
boundary, file_content, boundary
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
let response = app
|
|
341
|
+
.oneshot(
|
|
342
|
+
Request::builder()
|
|
343
|
+
.method("POST")
|
|
344
|
+
.uri("/extract")
|
|
345
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
346
|
+
.body(Body::from(body_content))
|
|
347
|
+
.unwrap(),
|
|
348
|
+
)
|
|
349
|
+
.await
|
|
350
|
+
.unwrap();
|
|
351
|
+
|
|
352
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
353
|
+
|
|
354
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
355
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
356
|
+
|
|
357
|
+
assert_eq!(results.len(), 1);
|
|
358
|
+
assert_eq!(results[0]["mime_type"], "application/json");
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/// Test extract endpoint with XML content.
|
|
362
|
+
#[tokio::test]
|
|
363
|
+
#[cfg(feature = "xml")]
|
|
364
|
+
async fn test_extract_xml_file() {
|
|
365
|
+
let app = create_router(ExtractionConfig::default());
|
|
366
|
+
|
|
367
|
+
let boundary = "----boundary";
|
|
368
|
+
let file_content = r#"<?xml version="1.0"?><root><item>test</item></root>"#;
|
|
369
|
+
|
|
370
|
+
let body_content = format!(
|
|
371
|
+
"--{}\r\n\
|
|
372
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.xml\"\r\n\
|
|
373
|
+
Content-Type: application/xml\r\n\
|
|
374
|
+
\r\n\
|
|
375
|
+
{}\r\n\
|
|
376
|
+
--{}--\r\n",
|
|
377
|
+
boundary, file_content, boundary
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
let response = app
|
|
381
|
+
.oneshot(
|
|
382
|
+
Request::builder()
|
|
383
|
+
.method("POST")
|
|
384
|
+
.uri("/extract")
|
|
385
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
386
|
+
.body(Body::from(body_content))
|
|
387
|
+
.unwrap(),
|
|
388
|
+
)
|
|
389
|
+
.await
|
|
390
|
+
.unwrap();
|
|
391
|
+
|
|
392
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
393
|
+
|
|
394
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
395
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
396
|
+
|
|
397
|
+
assert_eq!(results.len(), 1);
|
|
398
|
+
assert_eq!(results[0]["mime_type"], "application/xml");
|
|
399
|
+
assert!(results[0]["content"].as_str().unwrap().contains("test"));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/// Test extract endpoint with HTML content.
|
|
403
|
+
#[tokio::test]
|
|
404
|
+
#[cfg(feature = "html")]
|
|
405
|
+
async fn test_extract_html_file() {
|
|
406
|
+
let app = create_router(ExtractionConfig::default());
|
|
407
|
+
|
|
408
|
+
let boundary = "----boundary";
|
|
409
|
+
let file_content = r#"<html><body><h1>Title</h1><p>Content</p></body></html>"#;
|
|
410
|
+
|
|
411
|
+
let body_content = format!(
|
|
412
|
+
"--{}\r\n\
|
|
413
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.html\"\r\n\
|
|
414
|
+
Content-Type: text/html\r\n\
|
|
415
|
+
\r\n\
|
|
416
|
+
{}\r\n\
|
|
417
|
+
--{}--\r\n",
|
|
418
|
+
boundary, file_content, boundary
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
let response = app
|
|
422
|
+
.oneshot(
|
|
423
|
+
Request::builder()
|
|
424
|
+
.method("POST")
|
|
425
|
+
.uri("/extract")
|
|
426
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
427
|
+
.body(Body::from(body_content))
|
|
428
|
+
.unwrap(),
|
|
429
|
+
)
|
|
430
|
+
.await
|
|
431
|
+
.unwrap();
|
|
432
|
+
|
|
433
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
434
|
+
|
|
435
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
436
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
437
|
+
|
|
438
|
+
assert_eq!(results.len(), 1);
|
|
439
|
+
assert_eq!(results[0]["mime_type"], "text/html");
|
|
440
|
+
assert!(results[0]["content"].as_str().unwrap().contains("Title"));
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/// Test extract endpoint with missing Content-Type header.
|
|
444
|
+
#[tokio::test]
|
|
445
|
+
async fn test_extract_missing_content_type() {
|
|
446
|
+
let app = create_router(ExtractionConfig::default());
|
|
447
|
+
|
|
448
|
+
let response = app
|
|
449
|
+
.oneshot(
|
|
450
|
+
Request::builder()
|
|
451
|
+
.method("POST")
|
|
452
|
+
.uri("/extract")
|
|
453
|
+
.body(Body::from("some data"))
|
|
454
|
+
.unwrap(),
|
|
455
|
+
)
|
|
456
|
+
.await
|
|
457
|
+
.unwrap();
|
|
458
|
+
|
|
459
|
+
assert!(response.status() == StatusCode::BAD_REQUEST || response.status() == StatusCode::UNSUPPORTED_MEDIA_TYPE);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/// Test extract endpoint with empty file.
|
|
463
|
+
#[tokio::test]
|
|
464
|
+
async fn test_extract_empty_file() {
|
|
465
|
+
let app = create_router(ExtractionConfig::default());
|
|
466
|
+
|
|
467
|
+
let boundary = "----boundary";
|
|
468
|
+
let file_content = "";
|
|
469
|
+
|
|
470
|
+
let body_content = format!(
|
|
471
|
+
"--{}\r\n\
|
|
472
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"empty.txt\"\r\n\
|
|
473
|
+
Content-Type: text/plain\r\n\
|
|
474
|
+
\r\n\
|
|
475
|
+
{}\r\n\
|
|
476
|
+
--{}--\r\n",
|
|
477
|
+
boundary, file_content, boundary
|
|
478
|
+
);
|
|
479
|
+
|
|
480
|
+
let response = app
|
|
481
|
+
.oneshot(
|
|
482
|
+
Request::builder()
|
|
483
|
+
.method("POST")
|
|
484
|
+
.uri("/extract")
|
|
485
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
486
|
+
.body(Body::from(body_content))
|
|
487
|
+
.unwrap(),
|
|
488
|
+
)
|
|
489
|
+
.await
|
|
490
|
+
.unwrap();
|
|
491
|
+
|
|
492
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
493
|
+
|
|
494
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
495
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
496
|
+
|
|
497
|
+
assert_eq!(results.len(), 1);
|
|
498
|
+
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/// Test extract endpoint with unsupported MIME type.
|
|
502
|
+
#[tokio::test]
|
|
503
|
+
async fn test_extract_unsupported_mime_type() {
|
|
504
|
+
let app = create_router(ExtractionConfig::default());
|
|
505
|
+
|
|
506
|
+
let boundary = "----boundary";
|
|
507
|
+
let file_content = "Binary data";
|
|
508
|
+
|
|
509
|
+
let body_content = format!(
|
|
510
|
+
"--{}\r\n\
|
|
511
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.bin\"\r\n\
|
|
512
|
+
Content-Type: application/x-unknown-binary\r\n\
|
|
513
|
+
\r\n\
|
|
514
|
+
{}\r\n\
|
|
515
|
+
--{}--\r\n",
|
|
516
|
+
boundary, file_content, boundary
|
|
517
|
+
);
|
|
518
|
+
|
|
519
|
+
let response = app
|
|
520
|
+
.oneshot(
|
|
521
|
+
Request::builder()
|
|
522
|
+
.method("POST")
|
|
523
|
+
.uri("/extract")
|
|
524
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
525
|
+
.body(Body::from(body_content))
|
|
526
|
+
.unwrap(),
|
|
527
|
+
)
|
|
528
|
+
.await
|
|
529
|
+
.unwrap();
|
|
530
|
+
|
|
531
|
+
assert!(
|
|
532
|
+
response.status() == StatusCode::UNPROCESSABLE_ENTITY || response.status() == StatusCode::INTERNAL_SERVER_ERROR
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/// Test extract endpoint without filename in multipart field.
|
|
537
|
+
#[tokio::test]
|
|
538
|
+
async fn test_extract_without_filename() {
|
|
539
|
+
let app = create_router(ExtractionConfig::default());
|
|
540
|
+
|
|
541
|
+
let boundary = "----boundary";
|
|
542
|
+
let file_content = "Test content";
|
|
543
|
+
|
|
544
|
+
let body_content = format!(
|
|
545
|
+
"--{}\r\n\
|
|
546
|
+
Content-Disposition: form-data; name=\"files\"\r\n\
|
|
547
|
+
Content-Type: text/plain\r\n\
|
|
548
|
+
\r\n\
|
|
549
|
+
{}\r\n\
|
|
550
|
+
--{}--\r\n",
|
|
551
|
+
boundary, file_content, boundary
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
let response = app
|
|
555
|
+
.oneshot(
|
|
556
|
+
Request::builder()
|
|
557
|
+
.method("POST")
|
|
558
|
+
.uri("/extract")
|
|
559
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
560
|
+
.body(Body::from(body_content))
|
|
561
|
+
.unwrap(),
|
|
562
|
+
)
|
|
563
|
+
.await
|
|
564
|
+
.unwrap();
|
|
565
|
+
|
|
566
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/// Test extract endpoint with malformed multipart data.
|
|
570
|
+
#[tokio::test]
|
|
571
|
+
async fn test_extract_malformed_multipart() {
|
|
572
|
+
let app = create_router(ExtractionConfig::default());
|
|
573
|
+
|
|
574
|
+
let boundary = "----boundary";
|
|
575
|
+
let body_content = format!("--{}\r\nmalformed data\r\n", boundary);
|
|
576
|
+
|
|
577
|
+
let response = app
|
|
578
|
+
.oneshot(
|
|
579
|
+
Request::builder()
|
|
580
|
+
.method("POST")
|
|
581
|
+
.uri("/extract")
|
|
582
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
583
|
+
.body(Body::from(body_content))
|
|
584
|
+
.unwrap(),
|
|
585
|
+
)
|
|
586
|
+
.await
|
|
587
|
+
.unwrap();
|
|
588
|
+
|
|
589
|
+
assert!(response.status().is_client_error() || response.status().is_server_error());
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/// Test CORS headers are present.
|
|
593
|
+
#[tokio::test]
|
|
594
|
+
async fn test_cors_headers() {
|
|
595
|
+
let app = create_router(ExtractionConfig::default());
|
|
596
|
+
|
|
597
|
+
let response = app
|
|
598
|
+
.oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
|
|
599
|
+
.await
|
|
600
|
+
.unwrap();
|
|
601
|
+
|
|
602
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
603
|
+
|
|
604
|
+
let headers = response.headers();
|
|
605
|
+
assert!(headers.contains_key("access-control-allow-origin") || headers.contains_key("Access-Control-Allow-Origin"));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/// Test OPTIONS preflight request for CORS.
|
|
609
|
+
#[tokio::test]
|
|
610
|
+
async fn test_cors_preflight() {
|
|
611
|
+
let app = create_router(ExtractionConfig::default());
|
|
612
|
+
|
|
613
|
+
let response = app
|
|
614
|
+
.oneshot(
|
|
615
|
+
Request::builder()
|
|
616
|
+
.method("OPTIONS")
|
|
617
|
+
.uri("/extract")
|
|
618
|
+
.header("origin", "http://example.com")
|
|
619
|
+
.header("access-control-request-method", "POST")
|
|
620
|
+
.body(Body::empty())
|
|
621
|
+
.unwrap(),
|
|
622
|
+
)
|
|
623
|
+
.await
|
|
624
|
+
.unwrap();
|
|
625
|
+
|
|
626
|
+
assert!(response.status().is_success() || response.status() == StatusCode::NO_CONTENT);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/// Test error response format for validation errors.
|
|
630
|
+
#[tokio::test]
|
|
631
|
+
async fn test_error_response_format_validation() {
|
|
632
|
+
let app = create_router(ExtractionConfig::default());
|
|
633
|
+
|
|
634
|
+
let boundary = "----boundary";
|
|
635
|
+
let body_content = format!("--{}--\r\n", boundary);
|
|
636
|
+
|
|
637
|
+
let response = app
|
|
638
|
+
.oneshot(
|
|
639
|
+
Request::builder()
|
|
640
|
+
.method("POST")
|
|
641
|
+
.uri("/extract")
|
|
642
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
643
|
+
.body(Body::from(body_content))
|
|
644
|
+
.unwrap(),
|
|
645
|
+
)
|
|
646
|
+
.await
|
|
647
|
+
.unwrap();
|
|
648
|
+
|
|
649
|
+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
|
650
|
+
|
|
651
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
652
|
+
let error: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
653
|
+
|
|
654
|
+
assert!(error["error_type"].is_string());
|
|
655
|
+
assert!(error["message"].is_string());
|
|
656
|
+
assert_eq!(error["status_code"], 400);
|
|
657
|
+
assert_eq!(error["error_type"], "ValidationError");
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/// Test error response format for parsing errors.
|
|
661
|
+
#[tokio::test]
|
|
662
|
+
async fn test_error_response_format_parsing() {
|
|
663
|
+
let app = create_router(ExtractionConfig::default());
|
|
664
|
+
|
|
665
|
+
let boundary = "----boundary";
|
|
666
|
+
let invalid_config = "not valid json";
|
|
667
|
+
|
|
668
|
+
let body_content = format!(
|
|
669
|
+
"--{}\r\n\
|
|
670
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
671
|
+
Content-Type: text/plain\r\n\
|
|
672
|
+
\r\n\
|
|
673
|
+
content\r\n\
|
|
674
|
+
--{}\r\n\
|
|
675
|
+
Content-Disposition: form-data; name=\"config\"\r\n\
|
|
676
|
+
\r\n\
|
|
677
|
+
{}\r\n\
|
|
678
|
+
--{}--\r\n",
|
|
679
|
+
boundary, boundary, invalid_config, boundary
|
|
680
|
+
);
|
|
681
|
+
|
|
682
|
+
let response = app
|
|
683
|
+
.oneshot(
|
|
684
|
+
Request::builder()
|
|
685
|
+
.method("POST")
|
|
686
|
+
.uri("/extract")
|
|
687
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
688
|
+
.body(Body::from(body_content))
|
|
689
|
+
.unwrap(),
|
|
690
|
+
)
|
|
691
|
+
.await
|
|
692
|
+
.unwrap();
|
|
693
|
+
|
|
694
|
+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
|
695
|
+
|
|
696
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
697
|
+
let error: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
698
|
+
|
|
699
|
+
assert_eq!(error["error_type"], "ValidationError");
|
|
700
|
+
assert!(error["message"].as_str().unwrap().contains("configuration"));
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/// Test 404 error for non-existent endpoint.
|
|
704
|
+
#[tokio::test]
|
|
705
|
+
async fn test_not_found_endpoint() {
|
|
706
|
+
let app = create_router(ExtractionConfig::default());
|
|
707
|
+
|
|
708
|
+
let response = app
|
|
709
|
+
.oneshot(Request::builder().uri("/nonexistent").body(Body::empty()).unwrap())
|
|
710
|
+
.await
|
|
711
|
+
.unwrap();
|
|
712
|
+
|
|
713
|
+
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/// Test extract endpoint with very large text content.
|
|
717
|
+
#[tokio::test]
|
|
718
|
+
async fn test_extract_large_file() {
|
|
719
|
+
let app = create_router(ExtractionConfig::default());
|
|
720
|
+
|
|
721
|
+
let boundary = "----boundary";
|
|
722
|
+
let large_content = "A".repeat(1024 * 1024);
|
|
723
|
+
|
|
724
|
+
let body_content = format!(
|
|
725
|
+
"--{}\r\n\
|
|
726
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"large.txt\"\r\n\
|
|
727
|
+
Content-Type: text/plain\r\n\
|
|
728
|
+
\r\n\
|
|
729
|
+
{}\r\n\
|
|
730
|
+
--{}--\r\n",
|
|
731
|
+
boundary, large_content, boundary
|
|
732
|
+
);
|
|
733
|
+
|
|
734
|
+
let response = app
|
|
735
|
+
.oneshot(
|
|
736
|
+
Request::builder()
|
|
737
|
+
.method("POST")
|
|
738
|
+
.uri("/extract")
|
|
739
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
740
|
+
.body(Body::from(body_content))
|
|
741
|
+
.unwrap(),
|
|
742
|
+
)
|
|
743
|
+
.await
|
|
744
|
+
.unwrap();
|
|
745
|
+
|
|
746
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
747
|
+
|
|
748
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
749
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
750
|
+
|
|
751
|
+
assert_eq!(results.len(), 1);
|
|
752
|
+
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/// Test concurrent requests to extract endpoint.
|
|
756
|
+
#[tokio::test]
|
|
757
|
+
async fn test_concurrent_requests() {
|
|
758
|
+
use tower::ServiceExt;
|
|
759
|
+
|
|
760
|
+
let app = create_router(ExtractionConfig::default());
|
|
761
|
+
|
|
762
|
+
let boundary = "----boundary";
|
|
763
|
+
let file_content = "Concurrent test";
|
|
764
|
+
|
|
765
|
+
let body_content = format!(
|
|
766
|
+
"--{}\r\n\
|
|
767
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
768
|
+
Content-Type: text/plain\r\n\
|
|
769
|
+
\r\n\
|
|
770
|
+
{}\r\n\
|
|
771
|
+
--{}--\r\n",
|
|
772
|
+
boundary, file_content, boundary
|
|
773
|
+
);
|
|
774
|
+
|
|
775
|
+
let mut handles = vec![];
|
|
776
|
+
|
|
777
|
+
for _ in 0..5 {
|
|
778
|
+
let app_clone = app.clone();
|
|
779
|
+
let body_clone = body_content.clone();
|
|
780
|
+
|
|
781
|
+
let handle = tokio::spawn(async move {
|
|
782
|
+
app_clone
|
|
783
|
+
.oneshot(
|
|
784
|
+
Request::builder()
|
|
785
|
+
.method("POST")
|
|
786
|
+
.uri("/extract")
|
|
787
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
788
|
+
.body(Body::from(body_clone))
|
|
789
|
+
.unwrap(),
|
|
790
|
+
)
|
|
791
|
+
.await
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
handles.push(handle);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
for handle in handles {
|
|
798
|
+
let response = handle.await.unwrap().unwrap();
|
|
799
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/// Test cache stats endpoint.
|
|
804
|
+
#[tokio::test]
|
|
805
|
+
async fn test_cache_stats_endpoint() {
|
|
806
|
+
let app = create_router(ExtractionConfig::default());
|
|
807
|
+
|
|
808
|
+
let response = app
|
|
809
|
+
.oneshot(Request::builder().uri("/cache/stats").body(Body::empty()).unwrap())
|
|
810
|
+
.await
|
|
811
|
+
.unwrap();
|
|
812
|
+
|
|
813
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
814
|
+
|
|
815
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
816
|
+
let stats: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
817
|
+
|
|
818
|
+
assert!(stats["directory"].is_string());
|
|
819
|
+
assert!(stats["total_files"].is_number());
|
|
820
|
+
assert!(stats["total_size_mb"].is_number());
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/// Test cache clear endpoint.
|
|
824
|
+
#[tokio::test]
|
|
825
|
+
async fn test_cache_clear_endpoint() {
|
|
826
|
+
let app = create_router(ExtractionConfig::default());
|
|
827
|
+
|
|
828
|
+
let response = app
|
|
829
|
+
.oneshot(
|
|
830
|
+
Request::builder()
|
|
831
|
+
.method("DELETE")
|
|
832
|
+
.uri("/cache/clear")
|
|
833
|
+
.body(Body::empty())
|
|
834
|
+
.unwrap(),
|
|
835
|
+
)
|
|
836
|
+
.await
|
|
837
|
+
.unwrap();
|
|
838
|
+
|
|
839
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
840
|
+
|
|
841
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
842
|
+
let clear_result: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
843
|
+
|
|
844
|
+
assert!(clear_result["directory"].is_string());
|
|
845
|
+
assert!(clear_result["removed_files"].is_number());
|
|
846
|
+
assert!(clear_result["freed_mb"].is_number());
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/// Test extract endpoint with mixed content types.
|
|
850
|
+
#[tokio::test]
|
|
851
|
+
async fn test_extract_mixed_content_types() {
|
|
852
|
+
let app = create_router(ExtractionConfig::default());
|
|
853
|
+
|
|
854
|
+
let boundary = "----boundary";
|
|
855
|
+
let text_content = "Text file";
|
|
856
|
+
let json_content = r#"{"test": "data"}"#;
|
|
857
|
+
|
|
858
|
+
let body_content = format!(
|
|
859
|
+
"--{}\r\n\
|
|
860
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
861
|
+
Content-Type: text/plain\r\n\
|
|
862
|
+
\r\n\
|
|
863
|
+
{}\r\n\
|
|
864
|
+
--{}\r\n\
|
|
865
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.json\"\r\n\
|
|
866
|
+
Content-Type: application/json\r\n\
|
|
867
|
+
\r\n\
|
|
868
|
+
{}\r\n\
|
|
869
|
+
--{}--\r\n",
|
|
870
|
+
boundary, text_content, boundary, json_content, boundary
|
|
871
|
+
);
|
|
872
|
+
|
|
873
|
+
let response = app
|
|
874
|
+
.oneshot(
|
|
875
|
+
Request::builder()
|
|
876
|
+
.method("POST")
|
|
877
|
+
.uri("/extract")
|
|
878
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
879
|
+
.body(Body::from(body_content))
|
|
880
|
+
.unwrap(),
|
|
881
|
+
)
|
|
882
|
+
.await
|
|
883
|
+
.unwrap();
|
|
884
|
+
|
|
885
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
886
|
+
|
|
887
|
+
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
888
|
+
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
889
|
+
|
|
890
|
+
assert_eq!(results.len(), 2);
|
|
891
|
+
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
892
|
+
assert_eq!(results[1]["mime_type"], "application/json");
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/// Test extract endpoint with unknown field in multipart.
|
|
896
|
+
#[tokio::test]
|
|
897
|
+
async fn test_extract_unknown_multipart_field() {
|
|
898
|
+
let app = create_router(ExtractionConfig::default());
|
|
899
|
+
|
|
900
|
+
let boundary = "----boundary";
|
|
901
|
+
let file_content = "Test content";
|
|
902
|
+
|
|
903
|
+
let body_content = format!(
|
|
904
|
+
"--{}\r\n\
|
|
905
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
906
|
+
Content-Type: text/plain\r\n\
|
|
907
|
+
\r\n\
|
|
908
|
+
{}\r\n\
|
|
909
|
+
--{}\r\n\
|
|
910
|
+
Content-Disposition: form-data; name=\"unknown_field\"\r\n\
|
|
911
|
+
\r\n\
|
|
912
|
+
some value\r\n\
|
|
913
|
+
--{}--\r\n",
|
|
914
|
+
boundary, file_content, boundary, boundary
|
|
915
|
+
);
|
|
916
|
+
|
|
917
|
+
let response = app
|
|
918
|
+
.oneshot(
|
|
919
|
+
Request::builder()
|
|
920
|
+
.method("POST")
|
|
921
|
+
.uri("/extract")
|
|
922
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
923
|
+
.body(Body::from(body_content))
|
|
924
|
+
.unwrap(),
|
|
925
|
+
)
|
|
926
|
+
.await
|
|
927
|
+
.unwrap();
|
|
928
|
+
|
|
929
|
+
assert_eq!(response.status(), StatusCode::OK);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/// Test extract endpoint with default MIME type (application/octet-stream).
|
|
933
|
+
#[tokio::test]
|
|
934
|
+
async fn test_extract_default_mime_type() {
|
|
935
|
+
let app = create_router(ExtractionConfig::default());
|
|
936
|
+
|
|
937
|
+
let boundary = "----boundary";
|
|
938
|
+
let file_content = "Test content";
|
|
939
|
+
|
|
940
|
+
let body_content = format!(
|
|
941
|
+
"--{}\r\n\
|
|
942
|
+
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
943
|
+
\r\n\
|
|
944
|
+
{}\r\n\
|
|
945
|
+
--{}--\r\n",
|
|
946
|
+
boundary, file_content, boundary
|
|
947
|
+
);
|
|
948
|
+
|
|
949
|
+
let response = app
|
|
950
|
+
.oneshot(
|
|
951
|
+
Request::builder()
|
|
952
|
+
.method("POST")
|
|
953
|
+
.uri("/extract")
|
|
954
|
+
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
955
|
+
.body(Body::from(body_content))
|
|
956
|
+
.unwrap(),
|
|
957
|
+
)
|
|
958
|
+
.await
|
|
959
|
+
.unwrap();
|
|
960
|
+
|
|
961
|
+
assert!(
|
|
962
|
+
response.status() == StatusCode::OK
|
|
963
|
+
|| response.status() == StatusCode::UNPROCESSABLE_ENTITY
|
|
964
|
+
|| response.status() == StatusCode::INTERNAL_SERVER_ERROR
|
|
965
|
+
);
|
|
966
|
+
}
|