@voxgig/sdkgen 4.35.3 → 4.37.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/bin/voxgig-sdkgen +1 -1
- package/dist/cmp/ReadmeTop.js +1 -1
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/helpers/opExample.d.ts +4 -1
- package/dist/helpers/opExample.js +11 -1
- package/dist/helpers/opExample.js.map +1 -1
- package/dist/helpers/opShape.d.ts +2 -1
- package/dist/helpers/opShape.js +53 -26
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/pointPath.d.ts +2 -1
- package/dist/helpers/pointPath.js +17 -0
- package/dist/helpers/pointPath.js.map +1 -1
- package/dist/helpers/testPolicy.d.ts +48 -2
- package/dist/helpers/testPolicy.js +265 -0
- package/dist/helpers/testPolicy.js.map +1 -1
- package/dist/sdkgen.d.ts +7 -7
- package/dist/sdkgen.js +26 -4
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/c/PrepareAuth_c.ts +10 -4
- package/project/.sdk/src/cmp/c/ReadmeEntity_c.ts +2 -2
- package/project/.sdk/src/cmp/c/ReadmeHowto_c.ts +2 -2
- package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +6 -5
- package/project/.sdk/src/cmp/c/ReadmeRef_c.ts +3 -3
- package/project/.sdk/src/cmp/c/ReadmeTopQuick_c.ts +2 -2
- package/project/.sdk/src/cmp/c/ReadmeTopTest_c.ts +2 -2
- package/project/.sdk/src/cmp/c/TestDirect_c.ts +2 -6
- package/project/.sdk/src/cmp/clojure/ReadmeEntity_clojure.ts +2 -2
- package/project/.sdk/src/cmp/clojure/ReadmeHowto_clojure.ts +2 -2
- package/project/.sdk/src/cmp/clojure/ReadmeQuick_clojure.ts +4 -4
- package/project/.sdk/src/cmp/clojure/ReadmeRef_clojure.ts +3 -3
- package/project/.sdk/src/cmp/clojure/ReadmeTopQuick_clojure.ts +2 -2
- package/project/.sdk/src/cmp/clojure/ReadmeTopTest_clojure.ts +2 -2
- package/project/.sdk/src/cmp/cpp/ReadmeEntity_cpp.ts +2 -2
- package/project/.sdk/src/cmp/cpp/ReadmeHowto_cpp.ts +2 -2
- package/project/.sdk/src/cmp/cpp/ReadmeQuick_cpp.ts +4 -4
- package/project/.sdk/src/cmp/cpp/ReadmeRef_cpp.ts +3 -3
- package/project/.sdk/src/cmp/cpp/ReadmeTopQuick_cpp.ts +2 -2
- package/project/.sdk/src/cmp/cpp/ReadmeTopTest_cpp.ts +2 -2
- package/project/.sdk/src/cmp/cpp/TestDirect_cpp.ts +2 -6
- package/project/.sdk/src/cmp/cpp/TestEntity_cpp.ts +51 -3
- package/project/.sdk/src/cmp/csharp/ReadmeEntity_csharp.ts +2 -2
- package/project/.sdk/src/cmp/csharp/ReadmeHowto_csharp.ts +2 -2
- package/project/.sdk/src/cmp/csharp/ReadmeQuick_csharp.ts +5 -5
- package/project/.sdk/src/cmp/csharp/ReadmeRef_csharp.ts +3 -3
- package/project/.sdk/src/cmp/csharp/ReadmeTopQuick_csharp.ts +3 -3
- package/project/.sdk/src/cmp/csharp/ReadmeTopTest_csharp.ts +2 -2
- package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +41 -19
- package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +105 -27
- package/project/.sdk/src/cmp/elixir/ReadmeEntity_elixir.ts +2 -2
- package/project/.sdk/src/cmp/elixir/ReadmeHowto_elixir.ts +2 -2
- package/project/.sdk/src/cmp/elixir/ReadmeQuick_elixir.ts +4 -4
- package/project/.sdk/src/cmp/elixir/ReadmeRef_elixir.ts +3 -3
- package/project/.sdk/src/cmp/elixir/ReadmeTopQuick_elixir.ts +2 -2
- package/project/.sdk/src/cmp/elixir/ReadmeTopTest_elixir.ts +2 -2
- package/project/.sdk/src/cmp/go/EntityOperation_go.ts +2 -2
- package/project/.sdk/src/cmp/go/Entity_go.ts +5 -4
- package/project/.sdk/src/cmp/go/MainEntity_go.ts +1 -1
- package/project/.sdk/src/cmp/go/Main_go.ts +9 -5
- package/project/.sdk/src/cmp/go/PrepareAuth_go.ts +24 -15
- package/project/.sdk/src/cmp/go/ReadmeEntity_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +3 -3
- package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +4 -4
- package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +4 -4
- package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +2 -2
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +61 -26
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +115 -32
- package/project/.sdk/src/cmp/go-cli/fragment/words.fragment.go +1 -1
- package/project/.sdk/src/cmp/go-mcp/fragment/tools.fragment.go +1 -1
- package/project/.sdk/src/cmp/java/ReadmeEntity_java.ts +2 -2
- package/project/.sdk/src/cmp/java/ReadmeHowto_java.ts +2 -2
- package/project/.sdk/src/cmp/java/ReadmeQuick_java.ts +5 -5
- package/project/.sdk/src/cmp/java/ReadmeRef_java.ts +3 -3
- package/project/.sdk/src/cmp/java/ReadmeTopQuick_java.ts +3 -3
- package/project/.sdk/src/cmp/java/ReadmeTopTest_java.ts +2 -2
- package/project/.sdk/src/cmp/java/TestDirect_java.ts +40 -20
- package/project/.sdk/src/cmp/java/TestEntity_java.ts +107 -26
- package/project/.sdk/src/cmp/js/ReadmeEntity_js.ts +2 -2
- package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +2 -2
- package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +4 -4
- package/project/.sdk/src/cmp/js/ReadmeRef_js.ts +3 -3
- package/project/.sdk/src/cmp/js/ReadmeTopTest_js.ts +2 -2
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +68 -13
- package/project/.sdk/src/cmp/js/TestEntity_js.ts +46 -4
- package/project/.sdk/src/cmp/kotlin/ReadmeEntity_kotlin.ts +2 -2
- package/project/.sdk/src/cmp/kotlin/ReadmeHowto_kotlin.ts +2 -2
- package/project/.sdk/src/cmp/kotlin/ReadmeQuick_kotlin.ts +5 -5
- package/project/.sdk/src/cmp/kotlin/ReadmeRef_kotlin.ts +3 -3
- package/project/.sdk/src/cmp/kotlin/ReadmeTopQuick_kotlin.ts +3 -3
- package/project/.sdk/src/cmp/kotlin/ReadmeTopTest_kotlin.ts +2 -2
- package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +41 -21
- package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +99 -22
- package/project/.sdk/src/cmp/lua/ReadmeEntity_lua.ts +2 -2
- package/project/.sdk/src/cmp/lua/ReadmeHowto_lua.ts +2 -2
- package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +4 -4
- package/project/.sdk/src/cmp/lua/ReadmeRef_lua.ts +3 -3
- package/project/.sdk/src/cmp/lua/ReadmeTopQuick_lua.ts +3 -3
- package/project/.sdk/src/cmp/lua/ReadmeTopTest_lua.ts +2 -2
- package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +40 -16
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +108 -30
- package/project/.sdk/src/cmp/ocaml/ReadmeEntity_ocaml.ts +2 -2
- package/project/.sdk/src/cmp/ocaml/ReadmeHowto_ocaml.ts +2 -2
- package/project/.sdk/src/cmp/ocaml/ReadmeQuick_ocaml.ts +4 -4
- package/project/.sdk/src/cmp/ocaml/ReadmeRef_ocaml.ts +3 -3
- package/project/.sdk/src/cmp/ocaml/ReadmeTopQuick_ocaml.ts +2 -2
- package/project/.sdk/src/cmp/ocaml/ReadmeTopTest_ocaml.ts +2 -2
- package/project/.sdk/src/cmp/perl/ReadmeEntity_perl.ts +2 -2
- package/project/.sdk/src/cmp/perl/ReadmeHowto_perl.ts +2 -2
- package/project/.sdk/src/cmp/perl/ReadmeQuick_perl.ts +4 -4
- package/project/.sdk/src/cmp/perl/ReadmeRef_perl.ts +3 -3
- package/project/.sdk/src/cmp/perl/ReadmeTopQuick_perl.ts +2 -2
- package/project/.sdk/src/cmp/perl/ReadmeTopTest_perl.ts +2 -2
- package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +35 -16
- package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +98 -22
- package/project/.sdk/src/cmp/php/ReadmeEntity_php.ts +2 -2
- package/project/.sdk/src/cmp/php/ReadmeHowto_php.ts +2 -2
- package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +4 -4
- package/project/.sdk/src/cmp/php/ReadmeRef_php.ts +3 -3
- package/project/.sdk/src/cmp/php/ReadmeTopQuick_php.ts +2 -2
- package/project/.sdk/src/cmp/php/ReadmeTopTest_php.ts +2 -2
- package/project/.sdk/src/cmp/php/TestDirect_php.ts +33 -16
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +98 -29
- package/project/.sdk/src/cmp/py/ReadmeEntity_py.ts +2 -2
- package/project/.sdk/src/cmp/py/ReadmeHowto_py.ts +2 -2
- package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +4 -4
- package/project/.sdk/src/cmp/py/ReadmeRef_py.ts +3 -3
- package/project/.sdk/src/cmp/py/ReadmeTopQuick_py.ts +2 -2
- package/project/.sdk/src/cmp/py/ReadmeTopTest_py.ts +2 -2
- package/project/.sdk/src/cmp/py/TestDirect_py.ts +39 -16
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +90 -27
- package/project/.sdk/src/cmp/rb/ReadmeEntity_rb.ts +2 -2
- package/project/.sdk/src/cmp/rb/ReadmeHowto_rb.ts +2 -2
- package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +4 -4
- package/project/.sdk/src/cmp/rb/ReadmeRef_rb.ts +3 -3
- package/project/.sdk/src/cmp/rb/ReadmeTopQuick_rb.ts +2 -2
- package/project/.sdk/src/cmp/rb/ReadmeTopTest_rb.ts +2 -2
- package/project/.sdk/src/cmp/rb/TestClean_rb.ts +1 -1
- package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +33 -16
- package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +90 -25
- package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +3 -3
- package/project/.sdk/src/cmp/rust/EntityOperation_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/Main_rust.ts +3 -1
- package/project/.sdk/src/cmp/rust/ReadmeEntity_rust.ts +2 -2
- package/project/.sdk/src/cmp/rust/ReadmeHowto_rust.ts +3 -3
- package/project/.sdk/src/cmp/rust/ReadmeModel_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +5 -5
- package/project/.sdk/src/cmp/rust/ReadmeRef_rust.ts +4 -4
- package/project/.sdk/src/cmp/rust/ReadmeTopQuick_rust.ts +3 -3
- package/project/.sdk/src/cmp/rust/ReadmeTopTest_rust.ts +3 -3
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +40 -12
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +109 -26
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +2 -2
- package/project/.sdk/src/cmp/scala/ReadmeEntity_scala.ts +2 -2
- package/project/.sdk/src/cmp/scala/ReadmeHowto_scala.ts +2 -2
- package/project/.sdk/src/cmp/scala/ReadmeQuick_scala.ts +5 -5
- package/project/.sdk/src/cmp/scala/ReadmeRef_scala.ts +3 -3
- package/project/.sdk/src/cmp/scala/ReadmeTopQuick_scala.ts +3 -3
- package/project/.sdk/src/cmp/scala/ReadmeTopTest_scala.ts +2 -2
- package/project/.sdk/src/cmp/scala/TestDirect_scala.ts +2 -6
- package/project/.sdk/src/cmp/scala/TestEntity_scala.ts +36 -7
- package/project/.sdk/src/cmp/swift/ReadmeEntity_swift.ts +2 -2
- package/project/.sdk/src/cmp/swift/ReadmeHowto_swift.ts +2 -2
- package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +5 -5
- package/project/.sdk/src/cmp/swift/ReadmeRef_swift.ts +3 -3
- package/project/.sdk/src/cmp/swift/ReadmeTopQuick_swift.ts +2 -2
- package/project/.sdk/src/cmp/swift/ReadmeTopTest_swift.ts +2 -2
- package/project/.sdk/src/cmp/ts/ReadmeEntity_ts.ts +2 -2
- package/project/.sdk/src/cmp/ts/ReadmeExamplesTest_ts.ts +49 -19
- package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +2 -2
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +4 -4
- package/project/.sdk/src/cmp/ts/ReadmeRef_ts.ts +3 -3
- package/project/.sdk/src/cmp/ts/ReadmeTopTest_ts.ts +3 -3
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +54 -23
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +49 -4
- package/project/.sdk/src/cmp/zig/ReadmeEntity_zig.ts +2 -2
- package/project/.sdk/src/cmp/zig/ReadmeHowto_zig.ts +2 -2
- package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +4 -4
- package/project/.sdk/src/cmp/zig/ReadmeRef_zig.ts +3 -3
- package/project/.sdk/src/cmp/zig/ReadmeTopQuick_zig.ts +2 -2
- package/project/.sdk/src/cmp/zig/ReadmeTopTest_zig.ts +2 -2
- package/project/.sdk/tm/c/core/sdk.h +2 -2
- package/project/.sdk/tm/c/tests/primary_utility_test.c +37 -0
- package/project/.sdk/tm/c/utility/fetcher.c +31 -1
- package/project/.sdk/tm/c/utility/make_url.c +6 -2
- package/project/.sdk/tm/clojure/src/sdk/core.clj +21 -3
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +34 -0
- package/project/.sdk/tm/cpp/test/primary_utility_test.cpp +37 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +28 -2
- package/project/.sdk/tm/csharp/test/PrimaryUtilityTest.cs +40 -0
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +27 -0
- package/project/.sdk/tm/csharp/utility/MakeUrl.cs +7 -2
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +30 -3
- package/project/.sdk/tm/elixir/test/pipeline_test.exs +23 -0
- package/project/.sdk/tm/go/core/helpers.go +1 -1
- package/project/.sdk/tm/go/core/types.go +9 -1
- package/project/.sdk/tm/go/test/feature_corpus_test.go +3 -4
- package/project/.sdk/tm/go/test/primary_utility_test.go +28 -0
- package/project/.sdk/tm/go/utility/fetcher.go +26 -0
- package/project/.sdk/tm/go/utility/make_url.go +5 -2
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +4 -5
- package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +49 -0
- package/project/.sdk/tm/java/utility/Fetcher.java +24 -0
- package/project/.sdk/tm/java/utility/MakeUrl.java +6 -2
- package/project/.sdk/tm/js/src/utility/FetcherUtility.js +24 -0
- package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +6 -2
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +7 -6
- package/project/.sdk/tm/js/test/live-entity.js +18 -6
- package/project/.sdk/tm/js/test/live-runner.js +15 -3
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +25 -0
- package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +48 -0
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +20 -0
- package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +6 -2
- package/project/.sdk/tm/lua/test/pipeline_test.lua +27 -0
- package/project/.sdk/tm/lua/test/primary_utility_test.lua +36 -0
- package/project/.sdk/tm/lua/utility/fetcher.lua +31 -0
- package/project/.sdk/tm/lua/utility/make_url.lua +6 -2
- package/project/.sdk/tm/ocaml/Makefile +5 -1
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +36 -4
- package/project/.sdk/tm/ocaml/test/t_pipeline.ml +22 -0
- package/project/.sdk/tm/perl/t/primary_utility.t +22 -0
- package/project/.sdk/tm/perl/utility/fetcher.pm +18 -0
- package/project/.sdk/tm/perl/utility/make_url.pm +4 -2
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +6 -5
- package/project/.sdk/tm/php/test/PipelineTest.php +31 -7
- package/project/.sdk/tm/php/utility/Fetcher.php +34 -27
- package/project/.sdk/tm/php/utility/MakeOptions.php +2 -1
- package/project/.sdk/tm/php/utility/MakeUrl.php +6 -2
- package/project/.sdk/tm/py/pkg/utility/fetcher.py +23 -0
- package/project/.sdk/tm/py/pkg/utility/make_url.py +5 -2
- package/project/.sdk/tm/py/test/test_feature_corpus.py +5 -5
- package/project/.sdk/tm/py/test/test_primary_utility.py +21 -0
- package/project/.sdk/tm/rb/core/context.rb +1 -1
- package/project/.sdk/tm/rb/core/error.rb +20 -1
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +4 -5
- package/project/.sdk/tm/rb/test/feature_test.rb +2 -2
- package/project/.sdk/tm/rb/test/omni.rb +1 -1
- package/project/.sdk/tm/rb/test/pipeline_test.rb +19 -2
- package/project/.sdk/tm/rb/test/primary_utility_test.rb +28 -1
- package/project/.sdk/tm/rb/utility/fetcher.rb +20 -1
- package/project/.sdk/tm/rb/utility/make_error.rb +1 -1
- package/project/.sdk/tm/rb/utility/make_url.rb +4 -2
- package/project/.sdk/tm/rust/core/helpers.rs +1 -1
- package/project/.sdk/tm/rust/core/types.rs +2 -2
- package/project/.sdk/tm/rust/tests/primary_utility_test.rs +34 -0
- package/project/.sdk/tm/rust/utility/fetcher.rs +27 -0
- package/project/.sdk/tm/rust/utility/make_url.rs +7 -2
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +51 -1
- package/project/.sdk/tm/scala/utility/Fetcher.scala +16 -0
- package/project/.sdk/tm/scala/utility/Make.scala +6 -2
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +24 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +6 -2
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/PrimaryUtilityTest.swift +34 -0
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +24 -0
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +6 -2
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +7 -6
- package/project/.sdk/tm/ts/test/live-entity.ts +20 -5
- package/project/.sdk/tm/ts/test/live-runner.ts +17 -3
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +25 -0
- package/project/.sdk/tm/zig/core/utility.zig +30 -3
- package/project/.sdk/tm/zig/test/primary_utility_test.zig +28 -0
- package/project/sdkgen-package.json +1 -1
- package/src/cmp/ReadmeTop.ts +3 -3
- package/src/helpers/opExample.ts +16 -1
- package/src/helpers/opShape.ts +64 -30
- package/src/helpers/pointPath.ts +19 -0
- package/src/helpers/testPolicy.ts +316 -2
- package/src/sdkgen.ts +37 -5
|
@@ -333,7 +333,7 @@ voxgig_value* utility_fetch(Utility* u, Context* ctx, const char* url,
|
|
|
333
333
|
voxgig_value* fetchdef, PNError** err);
|
|
334
334
|
|
|
335
335
|
// ===========================================================================
|
|
336
|
-
// Entity (vtable; mirrors core/types.rs Entity +
|
|
336
|
+
// Entity (vtable; mirrors core/types.rs Entity + ProjectNameEntityBase)
|
|
337
337
|
// ===========================================================================
|
|
338
338
|
|
|
339
339
|
// Every operation resolves to the ENTITY, not the raw data. `list` resolves
|
|
@@ -356,7 +356,7 @@ typedef struct EntityVT {
|
|
|
356
356
|
void (*mark_deleted)(Entity*);
|
|
357
357
|
bool (*deleted)(Entity*);
|
|
358
358
|
|
|
359
|
-
// CRUD ops (
|
|
359
|
+
// CRUD ops (ProjectNameEntityBase). On error set *err and return NULL.
|
|
360
360
|
Entity* (*load)(Entity*, voxgig_value* reqmatch, voxgig_value* ctrl, PNError** err);
|
|
361
361
|
// Returns a NULL-terminated Entity* array (never NULL on success).
|
|
362
362
|
Entity** (*list)(Entity*, voxgig_value* reqmatch, voxgig_value* ctrl, PNError** err);
|
|
@@ -527,6 +527,42 @@ static void test_primary_fetcher_blocked_test_mode(void) {
|
|
|
527
527
|
CHECK(has_blocked, "fetcher blocked: message contains 'blocked'");
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
531
|
+
static void test_primary_fetcher_getonly_guard(void) {
|
|
532
|
+
ProjectNameSDK* live = projectname_sdk_new(cmap(1, "base", v_str("http://127.0.0.1:9")));
|
|
533
|
+
Utility* util = sdk_get_utility(live);
|
|
534
|
+
CtxSpec cs;
|
|
535
|
+
memset(&cs, 0, sizeof(cs));
|
|
536
|
+
cs.opname = "create";
|
|
537
|
+
cs.client = live;
|
|
538
|
+
cs.utility = util;
|
|
539
|
+
Context* ctx = make_context_util(cs, NULL);
|
|
540
|
+
const char* url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01";
|
|
541
|
+
const char* prior = getenv("VOXGIG_GETONLY_GUARD");
|
|
542
|
+
char* saved = NULL == prior ? NULL : strdup(prior);
|
|
543
|
+
setenv("VOXGIG_GETONLY_GUARD", "TRUE", 1);
|
|
544
|
+
|
|
545
|
+
PNError* err = NULL;
|
|
546
|
+
utility_fetch(util, ctx, url, cmap(2, "method", v_str("POST"), "headers", v_map()), &err);
|
|
547
|
+
CHECK(err && err->code && 0 == strcmp(err->code, "fetch_getonly_block"),
|
|
548
|
+
"fetcher getonly: a POST is refused");
|
|
549
|
+
CHECK(err && err->msg && strstr(err->msg, "[GET-ONLY GUARD] blocked POST /planet/p1"),
|
|
550
|
+
"fetcher getonly: names the path");
|
|
551
|
+
CHECK(err && err->msg && !strstr(err->msg, "GUARDKEY01"), "fetcher getonly: leaves out the query");
|
|
552
|
+
|
|
553
|
+
PNError* geterr = NULL;
|
|
554
|
+
utility_fetch(util, ctx, url, cmap(2, "method", v_str("GET"), "headers", v_map()), &geterr);
|
|
555
|
+
CHECK(geterr && geterr->code && 0 != strcmp(geterr->code, "fetch_getonly_block"),
|
|
556
|
+
"fetcher getonly: a GET reaches the closed port");
|
|
557
|
+
|
|
558
|
+
if (NULL == saved) {
|
|
559
|
+
unsetenv("VOXGIG_GETONLY_GUARD");
|
|
560
|
+
} else {
|
|
561
|
+
setenv("VOXGIG_GETONLY_GUARD", saved, 1);
|
|
562
|
+
free(saved);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
530
566
|
static void test_primary_new_sdk_smoke(void) {
|
|
531
567
|
ProjectNameSDK* client = projectname_sdk_new(cmap(1, "base", v_str(PU_LIVE_BASE)));
|
|
532
568
|
CHECK_STR_EQ(client->mode, "live", "new sdk mode live");
|
|
@@ -573,6 +609,7 @@ int main(void) {
|
|
|
573
609
|
RUN(test_primary_feature_init_inactive);
|
|
574
610
|
RUN(test_primary_fetcher_live);
|
|
575
611
|
RUN(test_primary_fetcher_blocked_test_mode);
|
|
612
|
+
RUN(test_primary_fetcher_getonly_guard);
|
|
576
613
|
RUN(test_primary_new_sdk_smoke);
|
|
577
614
|
|
|
578
615
|
printf("primary: %d unit tests run\n", TESTS);
|
|
@@ -4,9 +4,38 @@
|
|
|
4
4
|
|
|
5
5
|
#include "sdk.h"
|
|
6
6
|
|
|
7
|
+
#include <ctype.h>
|
|
7
8
|
#include <stdio.h>
|
|
9
|
+
#include <stdlib.h>
|
|
8
10
|
#include <string.h>
|
|
9
11
|
|
|
12
|
+
#define GETONLY_ENV "VOXGIG_GETONLY_GUARD"
|
|
13
|
+
|
|
14
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
15
|
+
// names the path alone: the query can carry a credential.
|
|
16
|
+
static PNError* getonly_refusal(Context* ctx, const char* fullurl, voxgig_value* fetchdef) {
|
|
17
|
+
const char* flag = getenv(GETONLY_ENV);
|
|
18
|
+
const char* raw = get_str(fetchdef, "method");
|
|
19
|
+
char method[16] = "GET";
|
|
20
|
+
if (NULL != raw && '\0' != raw[0]) {
|
|
21
|
+
size_t n = 0;
|
|
22
|
+
for (; '\0' != raw[n] && n < sizeof(method) - 1; n++) {
|
|
23
|
+
method[n] = (char)toupper((unsigned char)raw[n]);
|
|
24
|
+
}
|
|
25
|
+
method[n] = '\0';
|
|
26
|
+
}
|
|
27
|
+
if (NULL == flag || 0 != strcmp(flag, "TRUE") || 0 == strcmp(method, "GET")) {
|
|
28
|
+
return NULL;
|
|
29
|
+
}
|
|
30
|
+
const char* scheme = strstr(fullurl, "://");
|
|
31
|
+
const char* path = NULL == scheme ? fullurl : scheme + 3 + strcspn(scheme + 3, "/?#");
|
|
32
|
+
int plen = (int)strcspn(path, "?#");
|
|
33
|
+
char buf[512];
|
|
34
|
+
snprintf(buf, sizeof(buf), "[GET-ONLY GUARD] blocked %s %.*s", method,
|
|
35
|
+
0 == plen ? 1 : plen, 0 == plen ? "/" : path);
|
|
36
|
+
return context_make_error(ctx, "fetch_getonly_block", buf);
|
|
37
|
+
}
|
|
38
|
+
|
|
10
39
|
voxgig_value* fetcher_util(Fetcher* self, Context* ctx, const char* fullurl,
|
|
11
40
|
voxgig_value* fetchdef, PNError** err) {
|
|
12
41
|
(void)self;
|
|
@@ -44,7 +73,8 @@ voxgig_value* fetcher_util(Fetcher* self, Context* ctx, const char* fullurl,
|
|
|
44
73
|
voxgig_value* sys_fetch = getpath2(options, "system", "fetch");
|
|
45
74
|
|
|
46
75
|
if (v_is_noval(sys_fetch) || v_is_null(sys_fetch)) {
|
|
47
|
-
|
|
76
|
+
*err = getonly_refusal(ctx, fullurl, fetchdef);
|
|
77
|
+
return NULL != *err ? NULL : http_fetch(ctx, fullurl, fetchdef, err);
|
|
48
78
|
}
|
|
49
79
|
|
|
50
80
|
if (voxgig_is_func(sys_fetch)) {
|
|
@@ -58,8 +58,8 @@ char* make_url_util(Context* ctx, PNError** err) {
|
|
|
58
58
|
char* url = str_append(NULL, joined ? joined : "");
|
|
59
59
|
free(joined);
|
|
60
60
|
|
|
61
|
-
// A route the definition ends with a slash keeps it
|
|
62
|
-
//
|
|
61
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
62
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
63
63
|
voxgig_value* orig = getp(ctx->point, "orig");
|
|
64
64
|
if (voxgig_is_string(orig) && (NULL == spec->suffix || '\0' == spec->suffix[0])) {
|
|
65
65
|
const char* o = voxgig_as_string(orig);
|
|
@@ -68,6 +68,10 @@ char* make_url_util(Context* ctx, PNError** err) {
|
|
|
68
68
|
url = str_append(url, "/");
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
const char* authority = strstr(url, "://");
|
|
72
|
+
if (NULL != authority && url < authority && NULL == strpbrk(authority + 3, "/?#")) {
|
|
73
|
+
url = str_append(url, "/");
|
|
74
|
+
}
|
|
71
75
|
|
|
72
76
|
voxgig_value* resmatch = voxgig_new_map();
|
|
73
77
|
|
|
@@ -1359,11 +1359,14 @@
|
|
|
1359
1359
|
authquery (set (oget spec :authquery []))
|
|
1360
1360
|
point (oget ctx :point)
|
|
1361
1361
|
orig (when point (vs/getprop point "orig"))]
|
|
1362
|
-
;; A route the definition ends with a slash keeps it
|
|
1363
|
-
;;
|
|
1362
|
+
;; A route the definition ends with a slash keeps it, for a Django REST server,
|
|
1363
|
+
;; and a host with no path takes /, or luasocket reads a query as the host.
|
|
1364
1364
|
(when (and (string? orig) (str/ends-with? orig "/") (empty? (str (oget spec :suffix)))
|
|
1365
1365
|
(not (str/ends-with? @url "/")))
|
|
1366
1366
|
(swap! url str "/"))
|
|
1367
|
+
(let [authority (str/index-of @url "://")]
|
|
1368
|
+
(when (and authority (pos? authority) (not (re-find #"[/?#]" (subs @url (+ authority 3)))))
|
|
1369
|
+
(swap! url str "/")))
|
|
1367
1370
|
(doseq [item (or (vs/items (oget spec :params)) [])]
|
|
1368
1371
|
(let [k (vs/getprop item 0) v (vs/getprop item 1)]
|
|
1369
1372
|
(when (and (some? v) (string? k))
|
|
@@ -1809,6 +1812,19 @@
|
|
|
1809
1812
|
(HttpRequest$BodyPublishers/ofByteArray (.readAllBytes ^java.io.InputStream body))
|
|
1810
1813
|
:else (HttpRequest$BodyPublishers/noBody)))
|
|
1811
1814
|
|
|
1815
|
+
;; A GET-only live run refuses any other method before it is sent. The error
|
|
1816
|
+
;; names the path alone: the query can carry a credential.
|
|
1817
|
+
(defn getonly-refusal [ctx fullurl method-str]
|
|
1818
|
+
(let [method (str/upper-case (str method-str))
|
|
1819
|
+
method (if (= "" method) "GET" method)]
|
|
1820
|
+
(when (and (= "TRUE" (System/getenv "VOXGIG_GETONLY_GUARD")) (not= "GET" method))
|
|
1821
|
+
(let [rest-url (if (str/includes? fullurl "://")
|
|
1822
|
+
(str/replace-first (second (str/split fullurl #"://" 2)) #"^[^/?#]*" "")
|
|
1823
|
+
fullurl)
|
|
1824
|
+
path (first (str/split rest-url #"[?#]" 2))]
|
|
1825
|
+
(ctx-error ctx "fetch_getonly_block"
|
|
1826
|
+
(str "[GET-ONLY GUARD] blocked " method " " (if (str/blank? path) "/" path)))))))
|
|
1827
|
+
|
|
1812
1828
|
(defn default-http-fetch [fullurl fetchdef]
|
|
1813
1829
|
(let [method-str (or (vs/getprop fetchdef "method") "GET")
|
|
1814
1830
|
headers (or (vs/getprop fetchdef "headers") (vs/jm))]
|
|
@@ -1853,7 +1869,9 @@
|
|
|
1853
1869
|
(str "Request blocked as test feature is active (URL was: \"" fullurl "\")"))]
|
|
1854
1870
|
(let [sys-fetch (vs/getpath options "system.fetch")]
|
|
1855
1871
|
(cond
|
|
1856
|
-
(nil? sys-fetch) (
|
|
1872
|
+
(nil? sys-fetch) (if-let [refused (getonly-refusal ctx fullurl (vs/getprop fetchdef "method"))]
|
|
1873
|
+
[nil refused]
|
|
1874
|
+
(default-http-fetch fullurl fetchdef))
|
|
1857
1875
|
(vs/isfunc sys-fetch) (sys-fetch fullurl fetchdef)
|
|
1858
1876
|
:else [nil (ctx-error ctx "fetch_invalid" "system.fetch is not a valid function")])))))))
|
|
1859
1877
|
|
|
@@ -30,11 +30,45 @@
|
|
|
30
30
|
|
|
31
31
|
(defn- fake-client-opts [opts] {:options (atom opts) :mode (atom "test") :features (atom []) :store (atom {})})
|
|
32
32
|
|
|
33
|
+
;; A POST, then a GET, to a closed port: the guard's code and message, or
|
|
34
|
+
;; "sent" for a request it let through.
|
|
35
|
+
(defn getonly-probe []
|
|
36
|
+
(let [sdk (client/make-sdk (vs/jm "base" "http://127.0.0.1:9"))
|
|
37
|
+
ctx (make-ctx sdk "create")
|
|
38
|
+
url "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01"]
|
|
39
|
+
(apply str (for [method ["POST" "GET"]]
|
|
40
|
+
(let [[_ err] ((core/uget ctx :fetcher) ctx url (vs/jm "method" method "headers" (vs/jm)))]
|
|
41
|
+
(if (= "fetch_getonly_block" (:code err))
|
|
42
|
+
(str (:code err) " " (:msg err) "\n")
|
|
43
|
+
"sent\n"))))))
|
|
44
|
+
|
|
45
|
+
;; A JVM cannot set its own environment, so the probe runs in a child JVM.
|
|
46
|
+
(defn- getonly-child []
|
|
47
|
+
(let [pb (ProcessBuilder. ^java.util.List
|
|
48
|
+
[(.orElse (.command (.info (java.lang.ProcessHandle/current))) "java")
|
|
49
|
+
"-cp" (System/getProperty "java.class.path") "clojure.main" "-e"
|
|
50
|
+
"(require 'sdk.test.pipeline) (print (sdk.test.pipeline/getonly-probe)) (flush) (System/exit 0)"])
|
|
51
|
+
_ (.put (.environment pb) "VOXGIG_GETONLY_GUARD" "TRUE")
|
|
52
|
+
_ (.redirectErrorStream pb true)
|
|
53
|
+
proc (.start pb)
|
|
54
|
+
text (slurp (.getInputStream proc))]
|
|
55
|
+
(t/is-eq (.waitFor proc) 0 text)
|
|
56
|
+
text))
|
|
57
|
+
|
|
33
58
|
(defn run [rec]
|
|
34
59
|
(let [sdk (client/test-sdk nil nil)
|
|
35
60
|
utility (core/get-utility sdk)]
|
|
36
61
|
(letfn [(chk [name thunk] (t/run-check rec name thunk))]
|
|
37
62
|
|
|
63
|
+
;; ---- fetcher ----
|
|
64
|
+
;; Nothing listens on port 9: a request the guard let through fails there.
|
|
65
|
+
(chk "fetcher-getonly-guard"
|
|
66
|
+
(fn [] (let [out (if (= "TRUE" (System/getenv "VOXGIG_GETONLY_GUARD")) (getonly-probe) (getonly-child))]
|
|
67
|
+
(t/is-true (clojure.string/starts-with?
|
|
68
|
+
out "fetch_getonly_block [GET-ONLY GUARD] blocked POST /planet/p1\n") out)
|
|
69
|
+
(t/is-true (clojure.string/ends-with? (clojure.string/trim out) "\nsent") out)
|
|
70
|
+
(t/is-true (not (clojure.string/includes? out "GUARDKEY01")) out))))
|
|
71
|
+
|
|
38
72
|
;; ---- make-point ----
|
|
39
73
|
(chk "point-rejects-disallowed-op"
|
|
40
74
|
(fn [] (let [ctx (make-ctx sdk "nope")
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// throws omni::OmniError naming the entry, which T_RUN records.
|
|
12
12
|
|
|
13
13
|
#include <algorithm>
|
|
14
|
+
#include <cstdlib>
|
|
14
15
|
#include <memory>
|
|
15
16
|
#include <set>
|
|
16
17
|
#include <string>
|
|
@@ -365,6 +366,41 @@ static void fetcherBlockedTestMode() {
|
|
|
365
366
|
ASSERT_TRUE(msg.find("blocked") != std::string::npos, "expected error containing 'blocked'");
|
|
366
367
|
}
|
|
367
368
|
|
|
369
|
+
// Nothing listens on port 9; this target has no transport of its own, so a
|
|
370
|
+
// request the guard let through fails as fetch_no_transport.
|
|
371
|
+
static void fetcherGetOnlyGuard() {
|
|
372
|
+
auto liveClient = std::make_shared<ProjectNameSDK>(fhMap({{"base", Value("http://127.0.0.1:9")}}));
|
|
373
|
+
UtilityPtr liveUtility = liveClient->getUtility();
|
|
374
|
+
CtxSpec cs;
|
|
375
|
+
cs.setOpname("create");
|
|
376
|
+
cs.client = liveClient.get();
|
|
377
|
+
cs.utility = liveUtility;
|
|
378
|
+
CtxPtr ctx = liveUtility->makeContext(cs, nullptr);
|
|
379
|
+
std::string url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01";
|
|
380
|
+
const char* prior = std::getenv("VOXGIG_GETONLY_GUARD");
|
|
381
|
+
std::string saved = nullptr == prior ? "" : prior;
|
|
382
|
+
setenv("VOXGIG_GETONLY_GUARD", "TRUE", 1);
|
|
383
|
+
|
|
384
|
+
std::string codes[2];
|
|
385
|
+
std::string msg;
|
|
386
|
+
const char* methods[2] = {"POST", "GET"};
|
|
387
|
+
for (int i = 0; i < 2; i++) {
|
|
388
|
+
try {
|
|
389
|
+
liveUtility->fetcher(ctx, url, fhMap({{"method", Value(methods[i])}, {"headers", vmap()}}));
|
|
390
|
+
} catch (const SdkErrorPtr& e) {
|
|
391
|
+
codes[i] = e->code;
|
|
392
|
+
if (0 == i) msg = e->getMessage();
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (nullptr == prior) unsetenv("VOXGIG_GETONLY_GUARD");
|
|
396
|
+
else setenv("VOXGIG_GETONLY_GUARD", saved.c_str(), 1);
|
|
397
|
+
|
|
398
|
+
ASSERT_TRUE(codes[0] == "fetch_getonly_block", "expected the POST to be refused");
|
|
399
|
+
ASSERT_TRUE(msg.find("[GET-ONLY GUARD] blocked POST /planet/p1") != std::string::npos, "expected the path");
|
|
400
|
+
ASSERT_TRUE(msg.find("GUARDKEY01") == std::string::npos, "expected no query");
|
|
401
|
+
ASSERT_TRUE(codes[1] == "fetch_no_transport", "expected the GET to pass the guard");
|
|
402
|
+
}
|
|
403
|
+
|
|
368
404
|
// --- makeContext ------------------------------------------------------------
|
|
369
405
|
|
|
370
406
|
static void makeContextBasic() {
|
|
@@ -876,6 +912,7 @@ int main(int argc, char** argv) {
|
|
|
876
912
|
T_RUN(featureInitInactive);
|
|
877
913
|
T_RUN(fetcherLive);
|
|
878
914
|
T_RUN(fetcherBlockedTestMode);
|
|
915
|
+
T_RUN(fetcherGetOnlyGuard);
|
|
879
916
|
T_RUN(makeContextBasic);
|
|
880
917
|
T_RUN(makeFetchDefBasic);
|
|
881
918
|
T_RUN(makeFetchDefWithBody);
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#define SDK_UTILITY_PIPELINE_HPP
|
|
9
9
|
|
|
10
10
|
#include <algorithm>
|
|
11
|
+
#include <cstdlib>
|
|
11
12
|
#include <memory>
|
|
12
13
|
#include <mutex>
|
|
13
14
|
#include <shared_mutex>
|
|
@@ -565,6 +566,25 @@ inline void featureHook(CtxPtr ctx, const std::string& name) {
|
|
|
565
566
|
|
|
566
567
|
// ---- fetcher ----------------------------------------------------------
|
|
567
568
|
|
|
569
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
570
|
+
// names the path alone: the query can carry a credential.
|
|
571
|
+
inline SdkErrorPtr getOnlyRefusal(CtxPtr ctx, const std::string& fullurl, const Value& fetchdef) {
|
|
572
|
+
Value raw = getp(fetchdef, "method");
|
|
573
|
+
std::string method = raw.is_string() && !raw.as_string().empty() ? raw.as_string() : "GET";
|
|
574
|
+
for (auto& c : method) c = (char)std::toupper((unsigned char)c);
|
|
575
|
+
const char* flag = std::getenv("VOXGIG_GETONLY_GUARD");
|
|
576
|
+
if (nullptr == flag || std::string(flag) != "TRUE" || "GET" == method) return nullptr;
|
|
577
|
+
std::string rest = fullurl;
|
|
578
|
+
size_t scheme = rest.find("://");
|
|
579
|
+
if (std::string::npos != scheme) {
|
|
580
|
+
rest = rest.substr(scheme + 3);
|
|
581
|
+
rest = rest.substr(std::min(rest.find_first_of("/?#"), rest.size()));
|
|
582
|
+
}
|
|
583
|
+
std::string path = rest.substr(0, rest.find_first_of("?#"));
|
|
584
|
+
return ctx->makeError("fetch_getonly_block",
|
|
585
|
+
"[GET-ONLY GUARD] blocked " + method + " " + (path.empty() ? "/" : path));
|
|
586
|
+
}
|
|
587
|
+
|
|
568
588
|
inline Value fetcher(CtxPtr ctx, const std::string& fullurl, const Value& fetchdef) {
|
|
569
589
|
if (ctx->client->mode != "live") {
|
|
570
590
|
throw ctx->makeError("fetch_mode_block",
|
|
@@ -586,6 +606,7 @@ inline Value fetcher(CtxPtr ctx, const std::string& fullurl, const Value& fetchd
|
|
|
586
606
|
}
|
|
587
607
|
|
|
588
608
|
if (is_nullish(sysFetch)) {
|
|
609
|
+
if (SdkErrorPtr refused = getOnlyRefusal(ctx, fullurl, fetchdef)) throw refused;
|
|
589
610
|
// No live HTTP transport is built into the generated C++ SDK; supply a
|
|
590
611
|
// system.fetch callable for live requests.
|
|
591
612
|
throw ctx->makeError("fetch_no_transport",
|
|
@@ -643,13 +664,18 @@ inline std::string makeUrl(CtxPtr ctx) {
|
|
|
643
664
|
Value joinParts = vlist({Value(spec->base), Value(spec->prefix), Value(spec->path), Value(spec->suffix)});
|
|
644
665
|
std::string url = Struct::join(joinParts, "/", true);
|
|
645
666
|
|
|
646
|
-
// A route the definition ends with a slash keeps it
|
|
647
|
-
//
|
|
667
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
668
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
648
669
|
Value orig = ctx->point.is_map() ? getp(ctx->point, "orig") : Value::undef();
|
|
649
670
|
if (orig.is_string() && !orig.as_string().empty() && '/' == orig.as_string().back() &&
|
|
650
671
|
spec->suffix.empty() && (url.empty() || '/' != url.back())) {
|
|
651
672
|
url += "/";
|
|
652
673
|
}
|
|
674
|
+
const size_t authority = url.find("://");
|
|
675
|
+
if (std::string::npos != authority && 0 < authority &&
|
|
676
|
+
std::string::npos == url.find_first_of("/?#", authority + 3)) {
|
|
677
|
+
url += "/";
|
|
678
|
+
}
|
|
653
679
|
|
|
654
680
|
Value resmatch = vmap();
|
|
655
681
|
|
|
@@ -428,6 +428,46 @@ public class PrimaryUtilityTest
|
|
|
428
428
|
Assert.Contains("blocked", err.Message);
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
432
|
+
[Fact]
|
|
433
|
+
public void FetcherGetOnlyGuard()
|
|
434
|
+
{
|
|
435
|
+
var liveClient = new ProjectNameSDK(new Dictionary<string, object?>
|
|
436
|
+
{
|
|
437
|
+
["base"] = "http://127.0.0.1:9",
|
|
438
|
+
});
|
|
439
|
+
var liveUtility = liveClient.GetUtility();
|
|
440
|
+
var ctx = liveUtility.MakeContext(new Dictionary<string, object?>
|
|
441
|
+
{
|
|
442
|
+
["opname"] = "create",
|
|
443
|
+
["client"] = liveClient,
|
|
444
|
+
["utility"] = liveUtility,
|
|
445
|
+
}, null);
|
|
446
|
+
var url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01";
|
|
447
|
+
Dictionary<string, object?> Def(string method) => new()
|
|
448
|
+
{
|
|
449
|
+
["method"] = method,
|
|
450
|
+
["headers"] = new Dictionary<string, object?>(),
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
var prior = Environment.GetEnvironmentVariable("VOXGIG_GETONLY_GUARD");
|
|
454
|
+
Environment.SetEnvironmentVariable("VOXGIG_GETONLY_GUARD", "TRUE");
|
|
455
|
+
try
|
|
456
|
+
{
|
|
457
|
+
var refused = Assert.Throws<ProjectNameError>(() => liveUtility.Fetcher(ctx, url, Def("POST")));
|
|
458
|
+
Assert.Equal("fetch_getonly_block", refused.Code);
|
|
459
|
+
Assert.Contains("[GET-ONLY GUARD] blocked POST /planet/p1", refused.Message);
|
|
460
|
+
Assert.DoesNotContain("GUARDKEY01", refused.Message);
|
|
461
|
+
|
|
462
|
+
var sent = Assert.ThrowsAny<Exception>(() => liveUtility.Fetcher(ctx, url, Def("GET")));
|
|
463
|
+
Assert.False(sent is ProjectNameError, sent.Message);
|
|
464
|
+
}
|
|
465
|
+
finally
|
|
466
|
+
{
|
|
467
|
+
Environment.SetEnvironmentVariable("VOXGIG_GETONLY_GUARD", prior);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
431
471
|
[Fact]
|
|
432
472
|
public void MakeContextBasic()
|
|
433
473
|
{
|
|
@@ -64,11 +64,38 @@ public static partial class SdkUtility
|
|
|
64
64
|
return manual ? ManualRedirectHttpClient : DefaultHttpClient;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
internal const string GetOnlyEnv = "VOXGIG_GETONLY_GUARD";
|
|
68
|
+
|
|
69
|
+
// A GET-only live run refuses any other method before it is sent. The
|
|
70
|
+
// error names the path alone: the query can carry a credential.
|
|
71
|
+
internal static ProjectNameError? GetOnlyRefusal(string fullurl, string method)
|
|
72
|
+
{
|
|
73
|
+
var upper = method.ToUpperInvariant();
|
|
74
|
+
if (Environment.GetEnvironmentVariable(GetOnlyEnv) != "TRUE" || upper == "GET")
|
|
75
|
+
{
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
var rest = fullurl;
|
|
79
|
+
var scheme = rest.IndexOf("://", StringComparison.Ordinal);
|
|
80
|
+
if (scheme >= 0)
|
|
81
|
+
{
|
|
82
|
+
rest = System.Text.RegularExpressions.Regex.Replace(rest.Substring(scheme + 3), "^[^/?#]*", "");
|
|
83
|
+
}
|
|
84
|
+
var path = rest.Split(new[] { '?', '#' }, 2)[0];
|
|
85
|
+
return new ProjectNameError("fetch_getonly_block",
|
|
86
|
+
"[GET-ONLY GUARD] blocked " + upper + " " + (path == "" ? "/" : path), null);
|
|
87
|
+
}
|
|
88
|
+
|
|
67
89
|
internal static Dictionary<string, object?> DefaultHttpFetch(
|
|
68
90
|
string fullurl, Dictionary<string, object?> fetchdef)
|
|
69
91
|
{
|
|
70
92
|
var method = fetchdef.TryGetValue("method", out var mraw) && mraw is string m && m != ""
|
|
71
93
|
? m : "GET";
|
|
94
|
+
var refused = GetOnlyRefusal(fullurl, method);
|
|
95
|
+
if (refused != null)
|
|
96
|
+
{
|
|
97
|
+
throw refused;
|
|
98
|
+
}
|
|
72
99
|
|
|
73
100
|
using var req = new HttpRequestMessage(new HttpMethod(method), fullurl);
|
|
74
101
|
|
|
@@ -25,13 +25,18 @@ public static partial class SdkUtility
|
|
|
25
25
|
// Sent with the request, never recorded as the entity's match.
|
|
26
26
|
var authquery = spec.AuthQuery;
|
|
27
27
|
|
|
28
|
-
// A route the definition ends with a slash keeps it
|
|
29
|
-
// a
|
|
28
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
29
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
30
30
|
if (ctx.Point != null && StructUtils.GetProp(ctx.Point, "orig") is string orig &&
|
|
31
31
|
orig.EndsWith("/") && string.IsNullOrEmpty(spec.Suffix) && !url.EndsWith("/"))
|
|
32
32
|
{
|
|
33
33
|
url += "/";
|
|
34
34
|
}
|
|
35
|
+
var authority = url.IndexOf("://", System.StringComparison.Ordinal);
|
|
36
|
+
if (0 < authority && url.IndexOfAny(new[] { '/', '?', '#' }, authority + 3) < 0)
|
|
37
|
+
{
|
|
38
|
+
url += "/";
|
|
39
|
+
}
|
|
35
40
|
|
|
36
41
|
foreach (var item in StructUtils.Items(spec.Params))
|
|
37
42
|
{
|
|
@@ -1525,8 +1525,8 @@ defmodule ProjectName.Utility do
|
|
|
1525
1525
|
true
|
|
1526
1526
|
)
|
|
1527
1527
|
|
|
1528
|
-
# A route the definition ends with a slash keeps it
|
|
1529
|
-
#
|
|
1528
|
+
# A route the definition ends with a slash keeps it, for a Django REST server,
|
|
1529
|
+
# and a host with no path takes /, or luasocket reads a query as the host.
|
|
1530
1530
|
orig = S.getprop(S.getprop(ctx, "point"), "orig")
|
|
1531
1531
|
suffix = S.getprop(spec, "suffix")
|
|
1532
1532
|
|
|
@@ -1535,6 +1535,15 @@ defmodule ProjectName.Utility do
|
|
|
1535
1535
|
not String.ends_with?(joined, "/"),
|
|
1536
1536
|
do: joined <> "/",
|
|
1537
1537
|
else: joined
|
|
1538
|
+
url0 =
|
|
1539
|
+
case :binary.match(url0, "://") do
|
|
1540
|
+
{authority, 3} when 0 < authority ->
|
|
1541
|
+
rest = binary_part(url0, authority + 3, byte_size(url0) - authority - 3)
|
|
1542
|
+
if String.contains?(rest, ["/", "?", "#"]), do: url0, else: url0 <> "/"
|
|
1543
|
+
|
|
1544
|
+
_ ->
|
|
1545
|
+
url0
|
|
1546
|
+
end
|
|
1538
1547
|
|
|
1539
1548
|
resmatch = S.jm([])
|
|
1540
1549
|
|
|
@@ -2445,7 +2454,7 @@ defmodule ProjectName.Utility do
|
|
|
2445
2454
|
sys_fetch = S.getpath(options, "system.fetch")
|
|
2446
2455
|
|
|
2447
2456
|
cond do
|
|
2448
|
-
sys_fetch == nil -> default_http_fetch(fullurl, fetchdef)
|
|
2457
|
+
sys_fetch == nil -> getonly_refusal(ctx, fullurl, fetchdef) || default_http_fetch(fullurl, fetchdef)
|
|
2449
2458
|
S.isfunc(sys_fetch) -> sys_fetch.(fullurl, fetchdef)
|
|
2450
2459
|
true -> {nil, Context.make_error(ctx, "fetch_invalid", "system.fetch is not a valid function")}
|
|
2451
2460
|
end
|
|
@@ -2453,6 +2462,24 @@ defmodule ProjectName.Utility do
|
|
|
2453
2462
|
end
|
|
2454
2463
|
end
|
|
2455
2464
|
|
|
2465
|
+
# A GET-only live run refuses any other method before it is sent. The error
|
|
2466
|
+
# names the path alone: the query can carry a credential.
|
|
2467
|
+
defp getonly_refusal(ctx, fullurl, fetchdef) do
|
|
2468
|
+
method = H.or_(S.getprop(fetchdef, "method"), "GET") |> to_string() |> String.upcase()
|
|
2469
|
+
|
|
2470
|
+
if System.get_env("VOXGIG_GETONLY_GUARD") == "TRUE" and method not in ["", "GET"] do
|
|
2471
|
+
rest =
|
|
2472
|
+
case String.split(fullurl, "://", parts: 2) do
|
|
2473
|
+
[_, tail] -> Regex.replace(~r/^[^\/?#]*/, tail, "")
|
|
2474
|
+
[whole] -> whole
|
|
2475
|
+
end
|
|
2476
|
+
|
|
2477
|
+
path = rest |> String.split(["?", "#"], parts: 2) |> hd()
|
|
2478
|
+
path = if path == "", do: "/", else: path
|
|
2479
|
+
{nil, Context.make_error(ctx, "fetch_getonly_block", "[GET-ONLY GUARD] blocked #{method} #{path}")}
|
|
2480
|
+
end
|
|
2481
|
+
end
|
|
2482
|
+
|
|
2456
2483
|
defp default_http_fetch(fullurl, fetchdef) do
|
|
2457
2484
|
Application.ensure_all_started(:inets)
|
|
2458
2485
|
Application.ensure_all_started(:ssl)
|
|
@@ -296,6 +296,29 @@ defmodule ProjectName.PipelineTest do
|
|
|
296
296
|
assert err.code == "request_no_spec"
|
|
297
297
|
end
|
|
298
298
|
|
|
299
|
+
# Nothing listens on port 9: a request the guard let through fails there.
|
|
300
|
+
test "fetcher refuses a non-GET under the GET-only guard" do
|
|
301
|
+
c = ProjectName.new(S.jm(["base", "http://127.0.0.1:9"]))
|
|
302
|
+
ctx = make_ctx(c, "create")
|
|
303
|
+
url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01"
|
|
304
|
+
fetchdef = fn method -> S.jm(["method", method, "headers", S.jm([])]) end
|
|
305
|
+
prior = System.get_env("VOXGIG_GETONLY_GUARD")
|
|
306
|
+
System.put_env("VOXGIG_GETONLY_GUARD", "TRUE")
|
|
307
|
+
|
|
308
|
+
try do
|
|
309
|
+
{_, refused} = Utility.fetcher(ctx, url, fetchdef.("POST"))
|
|
310
|
+
assert refused.code == "fetch_getonly_block"
|
|
311
|
+
assert refused.msg =~ "[GET-ONLY GUARD] blocked POST /planet/p1"
|
|
312
|
+
refute refused.msg =~ "GUARDKEY01"
|
|
313
|
+
|
|
314
|
+
{_, sent} = Utility.fetcher(ctx, url, fetchdef.("GET"))
|
|
315
|
+
assert sent != nil
|
|
316
|
+
refute match?(%ProjectName.Error{code: "fetch_getonly_block"}, sent)
|
|
317
|
+
after
|
|
318
|
+
if prior, do: System.put_env("VOXGIG_GETONLY_GUARD", prior), else: System.delete_env("VOXGIG_GETONLY_GUARD")
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
299
322
|
test "make_request a transport error tuple lands on the response" do
|
|
300
323
|
boom = ProjectName.Error.new("boom", "boom")
|
|
301
324
|
c = util_override(client(), "fetcher", fn _c, _u, _f -> {nil, boom} end)
|
|
@@ -6,7 +6,7 @@ import (
|
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
// UnsupportedOp is returned by entity stub methods for operations the
|
|
9
|
-
// underlying API spec doesn't define. The static
|
|
9
|
+
// underlying API spec doesn't define. The static ProjectNameEntityBase interface
|
|
10
10
|
// requires every CRUD method on every entity, so absent ops must still be
|
|
11
11
|
// callable — they error at runtime instead of failing to compile.
|
|
12
12
|
func UnsupportedOp(opname, entityname string) (any, error) {
|
|
@@ -33,7 +33,10 @@ type Entity interface {
|
|
|
33
33
|
Deleted() bool
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// ProjectNameEntityBase is the full CRUD contract every generated entity
|
|
37
|
+
// implements. Named `...Base`, as in the other targets, because an entity
|
|
38
|
+
// struct is `<Entity>Entity`.
|
|
39
|
+
type ProjectNameEntityBase interface {
|
|
37
40
|
Entity
|
|
38
41
|
Load(reqmatch map[string]any, ctrl map[string]any) (any, error)
|
|
39
42
|
List(reqmatch map[string]any, ctrl map[string]any) (any, error)
|
|
@@ -52,3 +55,8 @@ type StreamItem struct {
|
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
type FetcherFunc func(ctx *Context, fullurl string, fetchdef map[string]any) (any, error)
|
|
58
|
+
|
|
59
|
+
// ProjectNameEntity is the former name of ProjectNameEntityBase.
|
|
60
|
+
//
|
|
61
|
+
// Deprecated: use ProjectNameEntityBase.
|
|
62
|
+
type ProjectNameEntity = ProjectNameEntityBase
|
|
@@ -430,11 +430,10 @@ func TestFeatureCorpus(t *testing.T) {
|
|
|
430
430
|
ops := fcUsableOps(2)
|
|
431
431
|
have := map[string]bool{}
|
|
432
432
|
|
|
433
|
-
//
|
|
434
|
-
//
|
|
433
|
+
// With every operation needing an argument there is nothing to drive:
|
|
434
|
+
// skip and say so, as the clean test does, rather than fail.
|
|
435
435
|
if len(ops) == 0 {
|
|
436
|
-
t.
|
|
437
|
-
"corpus cannot exercise a feature without one")
|
|
436
|
+
t.Skip("no declared operation completes against a plain 200 with no arguments (each needs a path parameter or a body); nothing for the corpus to drive")
|
|
438
437
|
}
|
|
439
438
|
|
|
440
439
|
featureCorpusNames := make([]string, 0, len(featureSection))
|
|
@@ -331,6 +331,34 @@ func TestPrimaryUtility(t *testing.T) {
|
|
|
331
331
|
}
|
|
332
332
|
})
|
|
333
333
|
|
|
334
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
335
|
+
t.Run("fetcher-getonly-guard", func(t *testing.T) {
|
|
336
|
+
liveClient := sdk.NewProjectNameSDK(map[string]any{"base": "http://127.0.0.1:9"})
|
|
337
|
+
liveUtility := liveClient.GetUtility()
|
|
338
|
+
ctx := liveUtility.MakeContext(map[string]any{
|
|
339
|
+
"opname": "create",
|
|
340
|
+
"client": liveClient,
|
|
341
|
+
"utility": liveUtility,
|
|
342
|
+
}, nil)
|
|
343
|
+
url := "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01"
|
|
344
|
+
t.Setenv("VOXGIG_GETONLY_GUARD", "TRUE")
|
|
345
|
+
|
|
346
|
+
_, err := liveUtility.Fetcher(ctx, url, map[string]any{"method": "POST", "headers": map[string]any{}})
|
|
347
|
+
var sdkerr *sdk.ProjectNameError
|
|
348
|
+
if !errors.As(err, &sdkerr) || sdkerr.Code != "fetch_getonly_block" {
|
|
349
|
+
t.Fatalf("expected fetch_getonly_block, got: %v", err)
|
|
350
|
+
}
|
|
351
|
+
if !strings.Contains(sdkerr.Msg, "[GET-ONLY GUARD] blocked POST /planet/p1") ||
|
|
352
|
+
strings.Contains(sdkerr.Msg, "GUARDKEY01") {
|
|
353
|
+
t.Errorf("unexpected guard message: %s", sdkerr.Msg)
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
_, err = liveUtility.Fetcher(ctx, url, map[string]any{"method": "GET", "headers": map[string]any{}})
|
|
357
|
+
if err == nil || errors.As(err, &sdkerr) {
|
|
358
|
+
t.Errorf("expected a GET to reach the closed port, got: %v", err)
|
|
359
|
+
}
|
|
360
|
+
})
|
|
361
|
+
|
|
334
362
|
t.Run("makeContext-basic", func(t *testing.T) {
|
|
335
363
|
runsection(t, "makeContext", func(args ...any) (any, error) {
|
|
336
364
|
if inMap, ok := args[0].(map[string]any); ok {
|