sdkloom 0.0.0-stage → 0.1.0
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.
- package/LICENSE +202 -0
- package/README.md +239 -2
- package/kits/allowed-sources.json +24 -0
- package/kits/csharp/kit.json +6 -0
- package/kits/csharp/src/Runtime/Client.cs +295 -0
- package/kits/csharp/src/Runtime/Context.cs +216 -0
- package/kits/csharp/src/Runtime/Errors.cs +121 -0
- package/kits/csharp/src/Runtime/Http.cs +218 -0
- package/kits/csharp/src/Runtime/Json.cs +650 -0
- package/kits/csharp/src/Runtime/Lang.cs +212 -0
- package/kits/csharp/src/Runtime/Models.cs +206 -0
- package/kits/csharp/src/Runtime/Multipart.cs +108 -0
- package/kits/csharp/src/Runtime/Pagination.cs +122 -0
- package/kits/csharp/src/Runtime/Sse.cs +197 -0
- package/kits/csharp/src/Runtime/Testing.cs +375 -0
- package/kits/csharp/src/Runtime/Transport.cs +212 -0
- package/kits/csharp/src/Runtime/Wait.cs +57 -0
- package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
- package/kits/csharp/tests/ClientTests.cs +128 -0
- package/kits/csharp/tests/HttpTests.cs +44 -0
- package/kits/csharp/tests/JsonTests.cs +132 -0
- package/kits/csharp/tests/LangTests.cs +57 -0
- package/kits/csharp/tests/MultipartTests.cs +31 -0
- package/kits/csharp/tests/PaginationTests.cs +93 -0
- package/kits/csharp/tests/SseTests.cs +122 -0
- package/kits/csharp/tests/TestRunner.cs +93 -0
- package/kits/csharp/tests/TestingTests.cs +80 -0
- package/kits/csharp/tests/TransportTests.cs +145 -0
- package/kits/csharp/tests/WaitTests.cs +39 -0
- package/kits/csharp/tests/WebhooksTests.cs +46 -0
- package/kits/csharp/versions.json +12 -0
- package/kits/go/kit.json +6 -0
- package/kits/go/src/sdkruntime/client.go +322 -0
- package/kits/go/src/sdkruntime/context.go +207 -0
- package/kits/go/src/sdkruntime/errors.go +74 -0
- package/kits/go/src/sdkruntime/http.go +261 -0
- package/kits/go/src/sdkruntime/json.go +527 -0
- package/kits/go/src/sdkruntime/lang.go +462 -0
- package/kits/go/src/sdkruntime/multipart.go +75 -0
- package/kits/go/src/sdkruntime/pagination.go +150 -0
- package/kits/go/src/sdkruntime/sse.go +267 -0
- package/kits/go/src/sdkruntime/testing.go +343 -0
- package/kits/go/src/sdkruntime/transport.go +168 -0
- package/kits/go/src/sdkruntime/wait.go +49 -0
- package/kits/go/src/sdkruntime/webhooks.go +129 -0
- package/kits/go/tests/client_test.go +185 -0
- package/kits/go/tests/http_test.go +78 -0
- package/kits/go/tests/json_test.go +127 -0
- package/kits/go/tests/lang_test.go +98 -0
- package/kits/go/tests/multipart_test.go +29 -0
- package/kits/go/tests/pagination_test.go +69 -0
- package/kits/go/tests/sse_test.go +129 -0
- package/kits/go/tests/testing_test.go +121 -0
- package/kits/go/tests/transport_test.go +133 -0
- package/kits/go/tests/wait_test.go +46 -0
- package/kits/go/tests/webhooks_test.go +62 -0
- package/kits/go/versions.json +12 -0
- package/kits/java/kit.json +6 -0
- package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
- package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
- package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
- package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
- package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
- package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
- package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
- package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
- package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
- package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
- package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
- package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
- package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
- package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
- package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
- package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
- package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
- package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
- package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
- package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
- package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
- package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
- package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
- package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
- package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
- package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
- package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
- package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
- package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
- package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
- package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
- package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
- package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
- package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
- package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
- package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
- package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
- package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
- package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
- package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
- package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
- package/kits/java/versions.json +41 -0
- package/kits/python/kit.json +6 -0
- package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
- package/kits/python/src/sdkloom_runtime/client.py +232 -0
- package/kits/python/src/sdkloom_runtime/compat.py +195 -0
- package/kits/python/src/sdkloom_runtime/context.py +134 -0
- package/kits/python/src/sdkloom_runtime/errors.py +65 -0
- package/kits/python/src/sdkloom_runtime/http.py +192 -0
- package/kits/python/src/sdkloom_runtime/lang.py +207 -0
- package/kits/python/src/sdkloom_runtime/models.py +221 -0
- package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
- package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
- package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
- package/kits/python/src/sdkloom_runtime/sse.py +121 -0
- package/kits/python/src/sdkloom_runtime/testing.py +224 -0
- package/kits/python/src/sdkloom_runtime/transport.py +120 -0
- package/kits/python/src/sdkloom_runtime/wait.py +44 -0
- package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
- package/kits/python/tests/support.py +28 -0
- package/kits/python/tests/test_client.py +275 -0
- package/kits/python/tests/test_compat.py +87 -0
- package/kits/python/tests/test_http.py +94 -0
- package/kits/python/tests/test_lang.py +104 -0
- package/kits/python/tests/test_models.py +110 -0
- package/kits/python/tests/test_multipart.py +37 -0
- package/kits/python/tests/test_pagination.py +70 -0
- package/kits/python/tests/test_sse.py +61 -0
- package/kits/python/tests/test_testing.py +130 -0
- package/kits/python/tests/test_transport.py +124 -0
- package/kits/python/tests/test_wait.py +46 -0
- package/kits/python/tests/test_webhooks.py +57 -0
- package/kits/python/versions.json +33 -0
- package/kits/rust/kit.json +6 -0
- package/kits/rust/src/runtime/client.rs +212 -0
- package/kits/rust/src/runtime/context.rs +182 -0
- package/kits/rust/src/runtime/crypto.rs +84 -0
- package/kits/rust/src/runtime/errors.rs +147 -0
- package/kits/rust/src/runtime/http.rs +248 -0
- package/kits/rust/src/runtime/json.rs +424 -0
- package/kits/rust/src/runtime/lang.rs +296 -0
- package/kits/rust/src/runtime/mod.rs +30 -0
- package/kits/rust/src/runtime/models.rs +266 -0
- package/kits/rust/src/runtime/multipart.rs +81 -0
- package/kits/rust/src/runtime/pagination.rs +117 -0
- package/kits/rust/src/runtime/sse.rs +195 -0
- package/kits/rust/src/runtime/testing.rs +308 -0
- package/kits/rust/src/runtime/transport.rs +324 -0
- package/kits/rust/src/runtime/wait.rs +29 -0
- package/kits/rust/src/runtime/webhooks.rs +142 -0
- package/kits/rust/tests/client.rs +152 -0
- package/kits/rust/tests/http.rs +44 -0
- package/kits/rust/tests/json.rs +82 -0
- package/kits/rust/tests/lang.rs +74 -0
- package/kits/rust/tests/multipart.rs +21 -0
- package/kits/rust/tests/pagination.rs +61 -0
- package/kits/rust/tests/sse.rs +77 -0
- package/kits/rust/tests/testing.rs +90 -0
- package/kits/rust/tests/transport.rs +218 -0
- package/kits/rust/tests/wait.rs +32 -0
- package/kits/rust/tests/webhooks.rs +73 -0
- package/kits/rust/versions.json +6 -0
- package/kits/typescript/kit.json +6 -0
- package/kits/typescript/src/client.ts +223 -0
- package/kits/typescript/src/context.ts +108 -0
- package/kits/typescript/src/errors.ts +63 -0
- package/kits/typescript/src/helpers.ts +49 -0
- package/kits/typescript/src/http.ts +192 -0
- package/kits/typescript/src/models.ts +139 -0
- package/kits/typescript/src/multipart.ts +66 -0
- package/kits/typescript/src/pagination.ts +54 -0
- package/kits/typescript/src/pipeline.ts +25 -0
- package/kits/typescript/src/sse.ts +102 -0
- package/kits/typescript/src/testing.ts +217 -0
- package/kits/typescript/src/transport.ts +101 -0
- package/kits/typescript/src/wait.ts +36 -0
- package/kits/typescript/src/webhooks.ts +168 -0
- package/kits/typescript/tests/client.test.ts +269 -0
- package/kits/typescript/tests/helpers.test.ts +27 -0
- package/kits/typescript/tests/http.test.ts +80 -0
- package/kits/typescript/tests/models.test.ts +71 -0
- package/kits/typescript/tests/multipart.test.ts +28 -0
- package/kits/typescript/tests/pagination.test.ts +76 -0
- package/kits/typescript/tests/sse.test.ts +82 -0
- package/kits/typescript/tests/testing.test.ts +103 -0
- package/kits/typescript/tests/transport.test.ts +127 -0
- package/kits/typescript/tests/wait.test.ts +31 -0
- package/kits/typescript/tests/webhooks.test.ts +53 -0
- package/kits/typescript/versions.json +15 -0
- package/package.json +37 -4
- package/packages/cli/recipes/apiKeyHeader.ts +16 -0
- package/packages/cli/recipes/apiVersionHeader.ts +16 -0
- package/packages/cli/recipes/basic.ts +13 -0
- package/packages/cli/recipes/bearer.ts +10 -0
- package/packages/cli/recipes/hmacSign.ts +23 -0
- package/packages/cli/recipes/idempotencyKey.ts +19 -0
- package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
- package/packages/cli/recipes/retry.ts +42 -0
- package/packages/cli/recipes/timing.ts +12 -0
- package/packages/cli/recipes/userAgent.ts +8 -0
- package/packages/cli/src/build.js +93 -0
- package/packages/cli/src/commands/build.js +31 -0
- package/packages/cli/src/commands/conformance-check.js +50 -0
- package/packages/cli/src/commands/contract.js +181 -0
- package/packages/cli/src/commands/diff.js +113 -0
- package/packages/cli/src/commands/doctor.js +43 -0
- package/packages/cli/src/commands/import-openapi.js +42 -0
- package/packages/cli/src/commands/init.js +27 -0
- package/packages/cli/src/commands/kit-check.js +145 -0
- package/packages/cli/src/commands/publish.js +81 -0
- package/packages/cli/src/commands/recipe.js +49 -0
- package/packages/cli/src/commands/record.js +181 -0
- package/packages/cli/src/commands/serve.js +156 -0
- package/packages/cli/src/commands/spec-check.js +57 -0
- package/packages/cli/src/commands/test.js +177 -0
- package/packages/cli/src/commands/variants.js +32 -0
- package/packages/cli/src/commands/verify.js +57 -0
- package/packages/cli/src/commands/version.js +63 -0
- package/packages/cli/src/containers.js +82 -0
- package/packages/cli/src/coverage.js +72 -0
- package/packages/cli/src/git.js +25 -0
- package/packages/cli/src/io.js +50 -0
- package/packages/cli/src/java/ScenarioHarness.java +297 -0
- package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
- package/packages/cli/src/java.js +70 -0
- package/packages/cli/src/js/harness.mjs +120 -0
- package/packages/cli/src/kits.js +103 -0
- package/packages/cli/src/languages/csharp.js +274 -0
- package/packages/cli/src/languages/go.js +185 -0
- package/packages/cli/src/languages/index.js +18 -0
- package/packages/cli/src/languages/java.js +187 -0
- package/packages/cli/src/languages/python.js +120 -0
- package/packages/cli/src/languages/rust.js +189 -0
- package/packages/cli/src/languages/types.js +93 -0
- package/packages/cli/src/languages/typescript.js +112 -0
- package/packages/cli/src/main.js +13 -0
- package/packages/cli/src/packaging.js +39 -0
- package/packages/cli/src/portability.js +45 -0
- package/packages/cli/src/profiles.js +55 -0
- package/packages/cli/src/project.js +56 -0
- package/packages/cli/src/python/scenario_harness.py +162 -0
- package/packages/cli/src/python/schema_roundtrip.py +42 -0
- package/packages/cli/src/registries.js +214 -0
- package/packages/cli/src/resolve-core.js +39 -0
- package/packages/cli/src/run.js +133 -0
- package/packages/cli/src/runtimes.js +61 -0
- package/packages/cli/src/scenarios-java.js +82 -0
- package/packages/cli/src/scenarios-javascript.js +54 -0
- package/packages/cli/src/scenarios-python.js +90 -0
- package/packages/cli/src/scenarios.js +183 -0
- package/packages/cli/src/schema.js +84 -0
- package/packages/cli/src/templates.js +85 -0
- package/packages/cli/src/toolchains.js +68 -0
- package/packages/cli/src/transpiled-tests.js +92 -0
- package/packages/codegen/src/canonical-json.js +31 -0
- package/packages/codegen/src/capabilities.js +50 -0
- package/packages/codegen/src/code-writer.js +54 -0
- package/packages/codegen/src/file-tree.js +25 -0
- package/packages/codegen/src/hash.js +6 -0
- package/packages/codegen/src/index.js +16 -0
- package/packages/codegen/src/lock.js +106 -0
- package/packages/conformance/src/case.js +143 -0
- package/packages/conformance/src/checks.js +40 -0
- package/packages/conformance/src/index.js +3 -0
- package/packages/conformance/src/matrix.js +48 -0
- package/packages/conformance/src/suite.js +48 -0
- package/packages/differ/src/diff.js +500 -0
- package/packages/differ/src/index.js +3 -0
- package/packages/differ/src/notes.js +112 -0
- package/packages/differ/src/support.js +34 -0
- package/packages/gen-csharp/src/emit-client.js +397 -0
- package/packages/gen-csharp/src/emit-harness.js +333 -0
- package/packages/gen-csharp/src/emit-mock.js +111 -0
- package/packages/gen-csharp/src/emit-models.js +119 -0
- package/packages/gen-csharp/src/emit-webhooks.js +57 -0
- package/packages/gen-csharp/src/generate.js +245 -0
- package/packages/gen-csharp/src/index.js +5 -0
- package/packages/gen-csharp/src/names.js +284 -0
- package/packages/gen-go/src/emit-client.js +405 -0
- package/packages/gen-go/src/emit-harness.js +294 -0
- package/packages/gen-go/src/emit-mock.js +112 -0
- package/packages/gen-go/src/emit-models.js +146 -0
- package/packages/gen-go/src/emit-webhooks.js +58 -0
- package/packages/gen-go/src/generate.js +205 -0
- package/packages/gen-go/src/index.js +5 -0
- package/packages/gen-go/src/names.js +197 -0
- package/packages/gen-java/src/emit-client.js +441 -0
- package/packages/gen-java/src/emit-models.js +342 -0
- package/packages/gen-java/src/emit-testing.js +123 -0
- package/packages/gen-java/src/emit-webhooks.js +70 -0
- package/packages/gen-java/src/generate.js +244 -0
- package/packages/gen-java/src/index.js +4 -0
- package/packages/gen-java/src/names.js +197 -0
- package/packages/gen-python/src/emit-client.js +272 -0
- package/packages/gen-python/src/emit-models.js +139 -0
- package/packages/gen-python/src/emit-testing.js +93 -0
- package/packages/gen-python/src/emit-webhooks.js +48 -0
- package/packages/gen-python/src/generate.js +237 -0
- package/packages/gen-python/src/index.js +2 -0
- package/packages/gen-python/src/names.js +161 -0
- package/packages/gen-python/src/style.js +67 -0
- package/packages/gen-rust/src/emit-client.js +379 -0
- package/packages/gen-rust/src/emit-harness.js +278 -0
- package/packages/gen-rust/src/emit-mock.js +121 -0
- package/packages/gen-rust/src/emit-models.js +117 -0
- package/packages/gen-rust/src/emit-webhooks.js +58 -0
- package/packages/gen-rust/src/generate.js +243 -0
- package/packages/gen-rust/src/index.js +5 -0
- package/packages/gen-rust/src/names.js +223 -0
- package/packages/gen-typescript/src/emit-client.js +434 -0
- package/packages/gen-typescript/src/emit-models.js +93 -0
- package/packages/gen-typescript/src/emit-package.js +90 -0
- package/packages/gen-typescript/src/emit-testing.js +138 -0
- package/packages/gen-typescript/src/emit-webhooks.js +52 -0
- package/packages/gen-typescript/src/generate.js +70 -0
- package/packages/gen-typescript/src/index.js +3 -0
- package/packages/gen-typescript/src/naming.js +64 -0
- package/packages/gen-typescript/src/runtime.js +81 -0
- package/packages/gen-typescript/src/types.js +136 -0
- package/packages/ir/src/api-surface.js +22 -0
- package/packages/ir/src/checks.js +52 -0
- package/packages/ir/src/index.js +32 -0
- package/packages/ir/src/ir.js +214 -0
- package/packages/ir/src/pages.js +18 -0
- package/packages/ir/src/validate-ir.js +462 -0
- package/packages/ir/src/validate-types.js +140 -0
- package/packages/kit/src/block-parser.js +196 -0
- package/packages/kit/src/index.js +15 -0
- package/packages/kit/src/kit-check.js +203 -0
- package/packages/kit/src/sources.js +53 -0
- package/packages/kit/src/version-policy.js +133 -0
- package/packages/kit/src/version-range.js +132 -0
- package/packages/openapi/src/import.js +292 -0
- package/packages/openapi/src/index.js +1 -0
- package/packages/openapi/src/names.js +50 -0
- package/packages/openapi/src/schemas.js +264 -0
- package/packages/packager/src/archive.js +106 -0
- package/packages/packager/src/crate.js +39 -0
- package/packages/packager/src/gomodule.js +11 -0
- package/packages/packager/src/index.js +9 -0
- package/packages/packager/src/maven.js +85 -0
- package/packages/packager/src/metadata.js +34 -0
- package/packages/packager/src/npm.js +71 -0
- package/packages/packager/src/nuget.js +78 -0
- package/packages/packager/src/sbom.js +56 -0
- package/packages/packager/src/wheel.js +62 -0
- package/packages/spec/src/index.js +11 -0
- package/packages/spec/src/requirements.js +139 -0
- package/packages/transpile/src/ast.js +51 -0
- package/packages/transpile/src/check.js +669 -0
- package/packages/transpile/src/emit-csharp.js +469 -0
- package/packages/transpile/src/emit-go.js +529 -0
- package/packages/transpile/src/emit-java.js +360 -0
- package/packages/transpile/src/emit-python.js +320 -0
- package/packages/transpile/src/emit-rust.js +499 -0
- package/packages/transpile/src/errors.js +15 -0
- package/packages/transpile/src/index.js +13 -0
- package/packages/transpile/src/lexer.js +161 -0
- package/packages/transpile/src/parser.js +543 -0
- package/packages/transpile/src/tests/ast.js +46 -0
- package/packages/transpile/src/tests/parse.js +376 -0
- package/packages/transpile/src/tests/translate.js +849 -0
- package/packages/transpile/src/transpile.js +57 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// @requirement SDKL-MOCK-001
|
|
2
|
+
// @requirement SDKL-MOCK-002
|
|
3
|
+
package dev.sdkloom.runtime;
|
|
4
|
+
|
|
5
|
+
import static dev.sdkloom.runtime.TestData.mapOf;
|
|
6
|
+
import static dev.sdkloom.runtime.TestData.listOf;
|
|
7
|
+
import static dev.sdkloom.runtime.Assert.assertEquals;
|
|
8
|
+
import static dev.sdkloom.runtime.Assert.assertThrows;
|
|
9
|
+
import static dev.sdkloom.runtime.Assert.assertTrue;
|
|
10
|
+
|
|
11
|
+
import java.io.ByteArrayOutputStream;
|
|
12
|
+
import java.io.PrintStream;
|
|
13
|
+
import java.nio.charset.StandardCharsets;
|
|
14
|
+
import java.util.List;
|
|
15
|
+
import java.util.Map;
|
|
16
|
+
import java.util.function.Function;
|
|
17
|
+
|
|
18
|
+
public class TestingTest {
|
|
19
|
+
private final MockTransport transport = new MockTransport();
|
|
20
|
+
|
|
21
|
+
private HttpResponse send(String method, String url) {
|
|
22
|
+
return transport.send(new HttpRequest(method, url), new SendOptions(null));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Test
|
|
26
|
+
public void failsARequestNoRouteAnswers() {
|
|
27
|
+
AssertionError error = assertThrows(AssertionError.class, () -> send("GET", "https://a.test/x"));
|
|
28
|
+
|
|
29
|
+
assertEquals("no mock for GET /x", error.getMessage());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Test
|
|
33
|
+
public void routesMatchPathTemplatesAndRecordCalls() {
|
|
34
|
+
MockRoute route = transport.route("GET", "/orders/{id}").replyJson(200, mapOf("id", "1"));
|
|
35
|
+
|
|
36
|
+
assertEquals(200, send("GET", "https://a.test/orders/1?x=1").status());
|
|
37
|
+
assertThrows(AssertionError.class, () -> send("GET", "https://a.test/orders/1/items"));
|
|
38
|
+
assertThrows(AssertionError.class, () -> send("POST", "https://a.test/orders/1"));
|
|
39
|
+
assertEquals(1, route.calls().size());
|
|
40
|
+
assertEquals(3, transport.calls().size());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Test
|
|
44
|
+
public void answersComeInOrderAndTheLastRepeats() {
|
|
45
|
+
transport.route("GET", "/x").replyJson(503, null).replyJson(200, null);
|
|
46
|
+
|
|
47
|
+
assertEquals(503, send("GET", "https://a.test/x").status());
|
|
48
|
+
assertEquals(200, send("GET", "https://a.test/x").status());
|
|
49
|
+
assertEquals(200, send("GET", "https://a.test/x").status());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Test
|
|
53
|
+
public void aRouteWithAnswersBeatsALaterOneWithout() {
|
|
54
|
+
transport.route("GET", "/users/me").replyJson(200, null);
|
|
55
|
+
MockRoute byId = transport.route("GET", "/users/{id}");
|
|
56
|
+
|
|
57
|
+
assertEquals(200, send("GET", "https://a.test/users/me").status());
|
|
58
|
+
assertThrows(AssertionError.class, () -> send("GET", "https://a.test/users/7"));
|
|
59
|
+
byId.replyJson(204, null);
|
|
60
|
+
assertEquals(204, send("GET", "https://a.test/users/me").status());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test
|
|
64
|
+
public void aRouteWithoutAnswersFailsClearly() {
|
|
65
|
+
transport.route("GET", "/orders/{id}");
|
|
66
|
+
|
|
67
|
+
assertEquals("mock for GET /orders/{id} has no answer", assertThrows(AssertionError.class, () -> send("GET", "https://a.test/orders/1")).getMessage());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Test
|
|
71
|
+
public void operationMocksValidateFailRaiseAndRecord() {
|
|
72
|
+
OperationMock mock = new OperationMock("getOrder", transport.route("GET", "/orders/{id}"), Decode.mapOf(Decode.STRING));
|
|
73
|
+
|
|
74
|
+
assertThrows(DecodeException.class, () -> mock.returns(mapOf("id", 1)));
|
|
75
|
+
mock.fails(404, mapOf("message", "no")).then().raises(new TransportException("timeout", null)).then().returns(mapOf("id", "1"));
|
|
76
|
+
|
|
77
|
+
assertEquals(404, send("GET", "https://a.test/orders/1").status());
|
|
78
|
+
assertThrows(TransportException.class, () -> send("GET", "https://a.test/orders/1"));
|
|
79
|
+
assertEquals("{\"id\":\"1\"}", send("GET", "https://a.test/orders/1").text());
|
|
80
|
+
assertEquals(3, mock.calls().size());
|
|
81
|
+
assertEquals("getOrder", mock.name());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Test
|
|
85
|
+
public void anEncoderTurnsValuesIntoTheirWireFormBeforeTheyAreCheckedAndSent() {
|
|
86
|
+
Function<Object, Object> addTag = (value) -> value instanceof Map ? mapOf("kind", "leaf", "value", ((Map<?, ?>) value).get("value")) : value;
|
|
87
|
+
OperationMock mock = new OperationMock("getShape", transport.route("GET", "/shape"), Decode.mapOf(Decode.STRING), addTag);
|
|
88
|
+
|
|
89
|
+
mock.returns(mapOf("value", "v"));
|
|
90
|
+
|
|
91
|
+
assertEquals(Json.parse("{\"kind\":\"leaf\",\"value\":\"v\"}"), send("GET", "https://a.test/shape").json());
|
|
92
|
+
mock.when((request) -> true).returns(mapOf("value", "w"));
|
|
93
|
+
assertEquals(Json.parse("{\"kind\":\"leaf\",\"value\":\"w\"}"), send("GET", "https://a.test/shape").json());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Test
|
|
97
|
+
public void whenAnswersOnlyMatchingRequests() {
|
|
98
|
+
OperationMock mock = new OperationMock("getOrder", transport.route("GET", "/orders/{id}"), null);
|
|
99
|
+
mock.returns(mapOf("who", "anyone"));
|
|
100
|
+
mock.when((request) -> request.url().endsWith("/vip")).returns(mapOf("who", "vip"));
|
|
101
|
+
|
|
102
|
+
assertEquals("{\"who\":\"vip\"}", send("GET", "https://a.test/orders/vip").text());
|
|
103
|
+
assertEquals("{\"who\":\"anyone\"}", send("GET", "https://a.test/orders/1").text());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Test
|
|
107
|
+
public void bytesAreReturnedAsTheBody() {
|
|
108
|
+
new OperationMock("download", transport.route("GET", "/file"), null).returns(new byte[] {9});
|
|
109
|
+
|
|
110
|
+
assertEquals(new byte[] {9}, send("GET", "https://a.test/file").body());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@Test
|
|
114
|
+
public void theFakeClockMovesOnlyWhenSleptOrAdvanced() {
|
|
115
|
+
FakeClock clock = new FakeClock(10);
|
|
116
|
+
clock.sleep(5);
|
|
117
|
+
clock.advance(5);
|
|
118
|
+
|
|
119
|
+
assertEquals(20L, clock.now());
|
|
120
|
+
assertEquals("retry {a=1}", new RecordedEvent("retry", mapOf("a", 1)).toString());
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Used by theRunnerReportsPassesAndFailures. */
|
|
124
|
+
public static class Sample {
|
|
125
|
+
@Test
|
|
126
|
+
public void passes() {
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Test
|
|
130
|
+
public void fails() {
|
|
131
|
+
assertEquals(1, 2);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@Test
|
|
136
|
+
public void theRunnerReportsPassesAndFailures() throws java.io.UnsupportedEncodingException {
|
|
137
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
138
|
+
|
|
139
|
+
int failures = TestRunner.run(listOf(Sample.class), new PrintStream(out, true, "UTF-8"));
|
|
140
|
+
|
|
141
|
+
assertEquals(1, failures);
|
|
142
|
+
String text = out.toString("UTF-8");
|
|
143
|
+
assertTrue(text.contains("FAIL Sample.fails: java.lang.AssertionError: expected 1 but got 2"), text);
|
|
144
|
+
assertTrue(text.contains("ok Sample.passes"), text);
|
|
145
|
+
assertTrue(text.endsWith("Ran 2 tests\nFAILED (failures=1)\n"), text);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@Test
|
|
149
|
+
public void aReservedPlaceholderSpansSegmentsInUrlsAndRoutes() {
|
|
150
|
+
transport.route("GET", "/files/{+path}/meta").replyJson(200, mapOf("ok", true));
|
|
151
|
+
assertEquals(200, send("GET", "https://a.test/files/a/b/meta").status());
|
|
152
|
+
assertThrows(AssertionError.class, () -> send("GET", "https://a.test/files/meta"));
|
|
153
|
+
assertEquals("https://a.test/files/docs/a%20b/%C3%A7.txt", Urls.build("https://a.test", "/files/{+path}", mapOf("path", "docs/a b/\u00e7.txt"), TestData.<java.util.Map.Entry<String, ?>>listOf()));
|
|
154
|
+
assertThrows(ArgumentException.class, () -> Urls.build("https://a.test", "/files/{+path}", mapOf("path", "docs/../secret"), TestData.<java.util.Map.Entry<String, ?>>listOf()));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// @requirement SDKL-HTTP-004
|
|
2
|
+
package dev.sdkloom.runtime;
|
|
3
|
+
|
|
4
|
+
import static dev.sdkloom.runtime.TestData.entry;
|
|
5
|
+
import static dev.sdkloom.runtime.TestData.listOf;
|
|
6
|
+
import static dev.sdkloom.runtime.Assert.assertEquals;
|
|
7
|
+
import static dev.sdkloom.runtime.Assert.assertThrows;
|
|
8
|
+
|
|
9
|
+
import com.sun.net.httpserver.HttpServer;
|
|
10
|
+
import java.io.IOException;
|
|
11
|
+
import java.io.OutputStream;
|
|
12
|
+
import java.net.InetSocketAddress;
|
|
13
|
+
import java.net.Proxy;
|
|
14
|
+
import java.net.ProxySelector;
|
|
15
|
+
import java.net.SocketAddress;
|
|
16
|
+
import java.net.URI;
|
|
17
|
+
import java.nio.charset.StandardCharsets;
|
|
18
|
+
import java.util.Collections;
|
|
19
|
+
import java.util.List;
|
|
20
|
+
import java.util.Map;
|
|
21
|
+
import javax.net.ssl.SSLContext;
|
|
22
|
+
|
|
23
|
+
/** What every transport must do; JdkTransportTest and UrlConnectionTransportTest run it against their transport. */
|
|
24
|
+
public abstract class TransportContract {
|
|
25
|
+
protected abstract Transport transport(ProxySelector proxy, SSLContext sslContext);
|
|
26
|
+
|
|
27
|
+
private Transport transport() {
|
|
28
|
+
return transport(null, null);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A proxy selector that always answers the given local server (ProxySelector.of needs Java 9). */
|
|
32
|
+
private static ProxySelector proxyTo(final InetSocketAddress address) {
|
|
33
|
+
return new ProxySelector() {
|
|
34
|
+
@Override
|
|
35
|
+
public List<Proxy> select(URI uri) {
|
|
36
|
+
return Collections.singletonList(new Proxy(Proxy.Type.HTTP, address));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public void connectFailed(URI uri, SocketAddress socket, IOException error) {
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static String serve(HttpServer server) {
|
|
46
|
+
server.createContext("/", (exchange) -> {
|
|
47
|
+
byte[] request = TestData.readAll(exchange.getRequestBody());
|
|
48
|
+
String path = exchange.getRequestURI().toString();
|
|
49
|
+
int status = 200;
|
|
50
|
+
byte[] body;
|
|
51
|
+
if (path.equals("/slow")) {
|
|
52
|
+
try {
|
|
53
|
+
Thread.sleep(500);
|
|
54
|
+
} catch (InterruptedException error) {
|
|
55
|
+
Thread.currentThread().interrupt();
|
|
56
|
+
}
|
|
57
|
+
body = new byte[0];
|
|
58
|
+
} else if (path.equals("/missing")) {
|
|
59
|
+
status = 404;
|
|
60
|
+
body = "{\"message\":\"no\"}".getBytes(StandardCharsets.UTF_8);
|
|
61
|
+
} else if (!exchange.getRequestMethod().equals("GET")) {
|
|
62
|
+
status = 201;
|
|
63
|
+
exchange.getResponseHeaders().add("x-echo", String.valueOf(exchange.getRequestHeaders().getFirst("x-test")));
|
|
64
|
+
exchange.getResponseHeaders().add("x-method", exchange.getRequestMethod());
|
|
65
|
+
exchange.getResponseHeaders().add("x-length", String.valueOf(exchange.getRequestHeaders().getFirst("content-length")));
|
|
66
|
+
body = ("got:" + new String(request, StandardCharsets.UTF_8)).getBytes(StandardCharsets.UTF_8);
|
|
67
|
+
} else {
|
|
68
|
+
body = path.getBytes(StandardCharsets.UTF_8);
|
|
69
|
+
}
|
|
70
|
+
exchange.sendResponseHeaders(status, body.length == 0 ? -1 : body.length);
|
|
71
|
+
try (OutputStream out = exchange.getResponseBody()) {
|
|
72
|
+
out.write(body);
|
|
73
|
+
} catch (IOException error) {
|
|
74
|
+
// The client gave up (timeout test); nothing to do.
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
server.start();
|
|
78
|
+
return "http://127.0.0.1:" + server.getAddress().getPort();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static HttpServer server() throws IOException {
|
|
82
|
+
return HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Test
|
|
86
|
+
public void sendsMethodHeadersAndBody() throws IOException {
|
|
87
|
+
HttpServer server = server();
|
|
88
|
+
try {
|
|
89
|
+
String base = serve(server);
|
|
90
|
+
HttpRequest request = new HttpRequest("POST", base + "/echo", listOf(entry("x-test", "1")), "hi".getBytes(StandardCharsets.UTF_8));
|
|
91
|
+
|
|
92
|
+
HttpResponse response = transport().send(request, new SendOptions(null));
|
|
93
|
+
|
|
94
|
+
assertEquals(201, response.status());
|
|
95
|
+
assertEquals("1", response.header("x-echo"));
|
|
96
|
+
assertEquals("POST", response.header("X-Method"));
|
|
97
|
+
assertEquals("got:hi", response.text());
|
|
98
|
+
} finally {
|
|
99
|
+
server.stop(0);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Test
|
|
104
|
+
public void streamHandsOverASuccessfulBodyAsItArrivesAndStillReadsAnErrorBody() throws Exception {
|
|
105
|
+
HttpServer server = server();
|
|
106
|
+
java.util.concurrent.CountDownLatch release = new java.util.concurrent.CountDownLatch(1);
|
|
107
|
+
server.createContext("/events", (exchange) -> {
|
|
108
|
+
exchange.getResponseHeaders().add("content-type", "text/event-stream");
|
|
109
|
+
exchange.sendResponseHeaders(200, 0);
|
|
110
|
+
try (OutputStream out = exchange.getResponseBody()) {
|
|
111
|
+
out.write("data: one\n\n".getBytes(StandardCharsets.UTF_8));
|
|
112
|
+
out.flush();
|
|
113
|
+
release.await(5, java.util.concurrent.TimeUnit.SECONDS);
|
|
114
|
+
out.write("data: two\n\n".getBytes(StandardCharsets.UTF_8));
|
|
115
|
+
} catch (InterruptedException error) {
|
|
116
|
+
Thread.currentThread().interrupt();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
try {
|
|
120
|
+
String base = serve(server);
|
|
121
|
+
HttpResponse response = transport().send(new HttpRequest("GET", base + "/events"), new SendOptions(5000L, true));
|
|
122
|
+
EventStream<String> events = new EventStream<>(response.bodyStream(), null);
|
|
123
|
+
String first = events.next().data();
|
|
124
|
+
release.countDown();
|
|
125
|
+
String second = events.next().data();
|
|
126
|
+
HttpResponse missing = transport().send(new HttpRequest("GET", base + "/missing"), new SendOptions(null, true));
|
|
127
|
+
|
|
128
|
+
assertEquals("one", first);
|
|
129
|
+
assertEquals("two", second);
|
|
130
|
+
assertEquals(false, events.hasNext());
|
|
131
|
+
assertEquals(404, missing.status());
|
|
132
|
+
assertEquals(Json.parse("{\"message\":\"no\"}"), missing.json());
|
|
133
|
+
} finally {
|
|
134
|
+
server.stop(0);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@Test
|
|
139
|
+
public void anEmptyPostSendsContentLengthZero() throws IOException {
|
|
140
|
+
HttpServer server = server();
|
|
141
|
+
try {
|
|
142
|
+
HttpResponse response = transport().send(new HttpRequest("POST", serve(server) + "/empty"), new SendOptions(null));
|
|
143
|
+
|
|
144
|
+
assertEquals(201, response.status());
|
|
145
|
+
assertEquals("0", response.header("x-length"));
|
|
146
|
+
} finally {
|
|
147
|
+
server.stop(0);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Test
|
|
152
|
+
public void anErrorStatusIsAResponseNotAFailure() throws IOException {
|
|
153
|
+
HttpServer server = server();
|
|
154
|
+
try {
|
|
155
|
+
HttpResponse response = transport().send(new HttpRequest("GET", serve(server) + "/missing"), new SendOptions(null));
|
|
156
|
+
|
|
157
|
+
assertEquals(404, response.status());
|
|
158
|
+
assertEquals(Json.parse("{\"message\":\"no\"}"), response.json());
|
|
159
|
+
} finally {
|
|
160
|
+
server.stop(0);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@Test
|
|
165
|
+
public void reportsATimeout() throws IOException {
|
|
166
|
+
HttpServer server = server();
|
|
167
|
+
try {
|
|
168
|
+
String base = serve(server);
|
|
169
|
+
TransportException error = assertThrows(TransportException.class,
|
|
170
|
+
() -> transport().send(new HttpRequest("GET", base + "/slow"), new SendOptions(50L)));
|
|
171
|
+
|
|
172
|
+
assertEquals("timeout", error.reason());
|
|
173
|
+
assertEquals("TransportError", error.name());
|
|
174
|
+
} finally {
|
|
175
|
+
server.stop(0);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@Test
|
|
180
|
+
public void reportsANetworkFailure() {
|
|
181
|
+
TransportException error = assertThrows(TransportException.class,
|
|
182
|
+
() -> transport().send(new HttpRequest("GET", "http://127.0.0.1:1/"), new SendOptions(null)));
|
|
183
|
+
|
|
184
|
+
assertEquals("network", error.reason());
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@Test
|
|
188
|
+
public void routesRequestsThroughAProxy() throws Exception {
|
|
189
|
+
HttpServer server = server();
|
|
190
|
+
try {
|
|
191
|
+
String base = serve(server);
|
|
192
|
+
ProxySelector proxy = proxyTo(new InetSocketAddress("127.0.0.1", server.getAddress().getPort()));
|
|
193
|
+
|
|
194
|
+
HttpResponse response = transport(proxy, SSLContext.getDefault()).send(new HttpRequest("GET", "http://api.example.invalid/proxied"), new SendOptions(null));
|
|
195
|
+
|
|
196
|
+
assertEquals("http://api.example.invalid/proxied", response.text());
|
|
197
|
+
} finally {
|
|
198
|
+
server.stop(0);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @requirement SDKL-HTTP-004
|
|
2
|
+
package dev.sdkloom.runtime;
|
|
3
|
+
|
|
4
|
+
import static dev.sdkloom.runtime.Assert.assertEquals;
|
|
5
|
+
import static dev.sdkloom.runtime.Assert.assertThrows;
|
|
6
|
+
import static dev.sdkloom.runtime.Assert.assertTrue;
|
|
7
|
+
|
|
8
|
+
import com.sun.net.httpserver.HttpServer;
|
|
9
|
+
import java.io.IOException;
|
|
10
|
+
import java.net.ProxySelector;
|
|
11
|
+
import java.nio.charset.StandardCharsets;
|
|
12
|
+
import java.util.Collections;
|
|
13
|
+
import java.util.Map;
|
|
14
|
+
import javax.net.ssl.SSLContext;
|
|
15
|
+
|
|
16
|
+
public class UrlConnectionTransportTest extends TransportContract {
|
|
17
|
+
@Override
|
|
18
|
+
protected Transport transport(ProxySelector proxy, SSLContext sslContext) {
|
|
19
|
+
return new UrlConnectionTransport(proxy, sslContext);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** HttpURLConnection would silently turn a GET with a body into a POST; the transport refuses it instead. */
|
|
23
|
+
@Test
|
|
24
|
+
public void aGetWithABodyIsRefusedNotSentAsPost() {
|
|
25
|
+
HttpRequest request = new HttpRequest("GET", "http://127.0.0.1:1/x", Collections.<Map.Entry<String, String>>emptyList(), "x".getBytes(StandardCharsets.UTF_8));
|
|
26
|
+
|
|
27
|
+
TransportException error = assertThrows(TransportException.class, () -> new UrlConnectionTransport().send(request, new SendOptions(null)));
|
|
28
|
+
|
|
29
|
+
assertTrue(error.getCause().getMessage().contains("cannot send a body with GET"));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** HttpURLConnection refuses PATCH; Java 8 to 15 allow setting it anyway, newer JVMs get a clear error. */
|
|
33
|
+
@Test
|
|
34
|
+
public void sendsPatchWhereTheJvmAllowsIt() throws IOException {
|
|
35
|
+
HttpServer server = server();
|
|
36
|
+
try {
|
|
37
|
+
String base = serve(server);
|
|
38
|
+
HttpRequest request = new HttpRequest("PATCH", base + "/thing", Collections.<Map.Entry<String, String>>emptyList(), "x".getBytes(StandardCharsets.UTF_8));
|
|
39
|
+
try {
|
|
40
|
+
HttpResponse response = new UrlConnectionTransport().send(request, new SendOptions(null));
|
|
41
|
+
assertEquals("PATCH", response.header("x-method"));
|
|
42
|
+
} catch (TransportException error) {
|
|
43
|
+
assertTrue(String.valueOf(error.getCause().getMessage()).contains("use the Java 11+ package"));
|
|
44
|
+
}
|
|
45
|
+
} finally {
|
|
46
|
+
server.stop(0);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @requirement SDKL-WAIT-001
|
|
2
|
+
package dev.sdkloom.runtime;
|
|
3
|
+
|
|
4
|
+
import static dev.sdkloom.runtime.Assert.assertEquals;
|
|
5
|
+
import static dev.sdkloom.runtime.Assert.assertThrows;
|
|
6
|
+
|
|
7
|
+
import java.util.ArrayList;
|
|
8
|
+
import java.util.Arrays;
|
|
9
|
+
import java.util.LinkedList;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
public final class WaitsTest {
|
|
13
|
+
@Test
|
|
14
|
+
public void pollsOnTheClockUntilDoneAndReturnsADoneResultWithoutPolling() {
|
|
15
|
+
FakeClock clock = new FakeClock();
|
|
16
|
+
LinkedList<String> states = new LinkedList<>(Arrays.asList("running", "running", "done"));
|
|
17
|
+
List<String> polled = new ArrayList<>();
|
|
18
|
+
String result = Waits.until("pending", (String current) -> {
|
|
19
|
+
String status = states.removeFirst();
|
|
20
|
+
polled.add(status);
|
|
21
|
+
return status;
|
|
22
|
+
}, "done"::equals, clock, 500, 10000);
|
|
23
|
+
String immediate = Waits.until("done", (String current) -> {
|
|
24
|
+
throw new AssertionError("polled");
|
|
25
|
+
}, "done"::equals, clock, 500, 10000);
|
|
26
|
+
|
|
27
|
+
assertEquals("done", result);
|
|
28
|
+
assertEquals(Arrays.asList("running", "running", "done"), polled);
|
|
29
|
+
assertEquals(1500L, clock.now());
|
|
30
|
+
assertEquals("done", immediate);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Test
|
|
34
|
+
public void throwsWaitTimeoutExceptionKeepingTheLastResult() {
|
|
35
|
+
FakeClock clock = new FakeClock();
|
|
36
|
+
int[] polls = {0};
|
|
37
|
+
Waits.WaitTimeoutException error = assertThrows(Waits.WaitTimeoutException.class, () -> Waits.until("pending", (String current) -> "running " + (++polls[0]), (String current) -> false, clock, 400, 1000));
|
|
38
|
+
|
|
39
|
+
assertEquals("running 2", error.last());
|
|
40
|
+
assertEquals("WaitTimeoutError", error.name());
|
|
41
|
+
assertEquals(800L, clock.now());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @requirement SDKL-HOOK-001
|
|
2
|
+
package dev.sdkloom.runtime;
|
|
3
|
+
|
|
4
|
+
import static dev.sdkloom.runtime.Assert.assertEquals;
|
|
5
|
+
import static dev.sdkloom.runtime.Assert.assertThrows;
|
|
6
|
+
import static dev.sdkloom.runtime.TestData.mapOf;
|
|
7
|
+
|
|
8
|
+
import java.nio.charset.StandardCharsets;
|
|
9
|
+
import java.util.Map;
|
|
10
|
+
|
|
11
|
+
public final class WebhooksTest {
|
|
12
|
+
private static final Webhooks.Signature STANDARD = new Webhooks.Signature("webhook-signature", "base64", "v1,", " ", "{webhook-id}.{webhook-timestamp}.{body}", "webhook-timestamp", 300, "base64", "whsec_");
|
|
13
|
+
private static final String SECRET = "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw";
|
|
14
|
+
private static final byte[] BODY = "{\"test\": 2432232314}".getBytes(StandardCharsets.UTF_8);
|
|
15
|
+
private static final Map<String, String> HEADERS = mapOf("Webhook-Id", "msg_p5jXN8AQM9LWM0D4loKWxJek", "webhook-timestamp", "1614265330", "webhook-signature", "v1,bad v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=");
|
|
16
|
+
|
|
17
|
+
@Test
|
|
18
|
+
public void verifiesTheStandardWebhooksExample() {
|
|
19
|
+
Webhooks.verify(STANDARD, BODY, HEADERS, SECRET, 1614265330L);
|
|
20
|
+
Webhooks.verify(STANDARD, BODY, HEADERS, SECRET, 1614265330L + 300);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
public void refusesChangesWrongSecretsOldTimestampsAndMissingHeaders() {
|
|
25
|
+
byte[] changed = "{\"test\": 3432232314}".getBytes(StandardCharsets.UTF_8);
|
|
26
|
+
assertEquals("no signature matches: the webhook was not signed with this secret, or was changed after signing",
|
|
27
|
+
assertThrows(WebhookSignatureException.class, () -> Webhooks.verify(STANDARD, changed, HEADERS, SECRET, 1614265330L)).getMessage());
|
|
28
|
+
assertThrows(WebhookSignatureException.class, () -> Webhooks.verify(STANDARD, BODY, HEADERS, "whsec_AAAA", 1614265330L));
|
|
29
|
+
assertEquals("the webhook was signed at 1614265330, more than 300 s from now",
|
|
30
|
+
assertThrows(WebhookSignatureException.class, () -> Webhooks.verify(STANDARD, BODY, HEADERS, SECRET, 1614265330L + 301)).getMessage());
|
|
31
|
+
assertEquals("missing or invalid webhook-timestamp header",
|
|
32
|
+
assertThrows(WebhookSignatureException.class, () -> Webhooks.verify(STANDARD, BODY, mapOf("webhook-signature", "v1,x"), SECRET, 1614265330L)).getMessage());
|
|
33
|
+
assertEquals("WebhookSignatureError", new WebhookSignatureException("x").name());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Test
|
|
37
|
+
public void verifiesAHexSignatureOfTheBodyWithATextSecret() {
|
|
38
|
+
Webhooks.Signature github = new Webhooks.Signature("x-hub-signature-256", "hex", "sha256=", null, "{body}", null, 0, "text", null);
|
|
39
|
+
byte[] body = "{\"zen\":\"Design for failure.\"}".getBytes(StandardCharsets.UTF_8);
|
|
40
|
+
String signature = "sha256=fb962995c1234ec94fb7a13c015a044d2d0ef7e076c0b619d419a8bf068cc218";
|
|
41
|
+
|
|
42
|
+
Webhooks.verify(github, body, mapOf("x-hub-signature-256", signature), "It is a secret", 0L);
|
|
43
|
+
assertThrows(WebhookSignatureException.class, () -> Webhooks.verify(github, body, mapOf("x-hub-signature-256", signature.replace("sha256=", "sha1=")), "It is a secret", 0L));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"default": {
|
|
3
|
+
"range": ">=11",
|
|
4
|
+
"test": [
|
|
5
|
+
"11",
|
|
6
|
+
"21"
|
|
7
|
+
],
|
|
8
|
+
"strategies": {
|
|
9
|
+
"release": "11",
|
|
10
|
+
"transport": "JdkTransport"
|
|
11
|
+
},
|
|
12
|
+
"exclude": [
|
|
13
|
+
"UrlConnectionTransport.java"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"variants": {
|
|
17
|
+
"jdk8": {
|
|
18
|
+
"range": ">=8 <11",
|
|
19
|
+
"test": [
|
|
20
|
+
"8"
|
|
21
|
+
],
|
|
22
|
+
"strategies": {
|
|
23
|
+
"release": "8",
|
|
24
|
+
"transport": "UrlConnectionTransport"
|
|
25
|
+
},
|
|
26
|
+
"exclude": [
|
|
27
|
+
"JdkTransport.java"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"notes": {
|
|
32
|
+
"8": {
|
|
33
|
+
"text": "Oracle Premier Support ended March 2022; Extended Support runs until December 2030.",
|
|
34
|
+
"source": "https://www.oracle.com/java/technologies/java-se-support-roadmap.html"
|
|
35
|
+
},
|
|
36
|
+
"11": {
|
|
37
|
+
"text": "Oracle Premier Support ended September 2023; Extended Support runs until January 2032.",
|
|
38
|
+
"source": "https://www.oracle.com/java/technologies/java-se-support-roadmap.html"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""sdkloom Python kit: the runtime vendored into every generated Python SDK. Runs on Python 2.7 and 3."""
|