@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
|
@@ -6,6 +6,7 @@ import (
|
|
|
6
6
|
"io"
|
|
7
7
|
"net/http"
|
|
8
8
|
"net/url"
|
|
9
|
+
"os"
|
|
9
10
|
"strings"
|
|
10
11
|
"sync"
|
|
11
12
|
|
|
@@ -53,11 +54,36 @@ func clientFor(fetchdef map[string]any) *http.Client {
|
|
|
53
54
|
return client
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
const getOnlyEnv = "VOXGIG_GETONLY_GUARD"
|
|
58
|
+
|
|
59
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
60
|
+
// names the path alone: the query can carry a credential.
|
|
61
|
+
func getOnlyRefusal(fullurl string, method string) error {
|
|
62
|
+
method = strings.ToUpper(method)
|
|
63
|
+
if os.Getenv(getOnlyEnv) != "TRUE" || method == "GET" {
|
|
64
|
+
return nil
|
|
65
|
+
}
|
|
66
|
+
rest := fullurl
|
|
67
|
+
if i := strings.Index(rest, "://"); i >= 0 {
|
|
68
|
+
rest = rest[i+3:]
|
|
69
|
+
rest = rest[strings.IndexAny(rest+"/", "/?#"):]
|
|
70
|
+
}
|
|
71
|
+
path := rest[:strings.IndexAny(rest+"?", "?#")]
|
|
72
|
+
if path == "" {
|
|
73
|
+
path = "/"
|
|
74
|
+
}
|
|
75
|
+
return core.NewProjectNameError("fetch_getonly_block",
|
|
76
|
+
"[GET-ONLY GUARD] blocked "+method+" "+path, nil)
|
|
77
|
+
}
|
|
78
|
+
|
|
56
79
|
func defaultHTTPFetch(fullurl string, fetchdef map[string]any) (map[string]any, error) {
|
|
57
80
|
method, _ := fetchdef["method"].(string)
|
|
58
81
|
if method == "" {
|
|
59
82
|
method = "GET"
|
|
60
83
|
}
|
|
84
|
+
if err := getOnlyRefusal(fullurl, method); err != nil {
|
|
85
|
+
return nil, err
|
|
86
|
+
}
|
|
61
87
|
|
|
62
88
|
var bodyReader io.Reader
|
|
63
89
|
switch body := fetchdef["body"].(type) {
|
|
@@ -27,12 +27,15 @@ func makeUrlUtil(ctx *core.Context) (string, error) {
|
|
|
27
27
|
url := vs.Join([]any{spec.Base, spec.Prefix, spec.Path, spec.Suffix}, "/", true)
|
|
28
28
|
resmatch := map[string]any{}
|
|
29
29
|
|
|
30
|
-
// A route the definition ends with a slash keeps it
|
|
31
|
-
//
|
|
30
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
31
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
32
32
|
if orig, _ := vs.GetProp(ctx.Point, "orig").(string); strings.HasSuffix(orig, "/") &&
|
|
33
33
|
spec.Suffix == "" && !strings.HasSuffix(url, "/") {
|
|
34
34
|
url += "/"
|
|
35
35
|
}
|
|
36
|
+
if authority := strings.Index(url, "://"); 0 < authority && !strings.ContainsAny(url[authority+3:], "/?#") {
|
|
37
|
+
url += "/"
|
|
38
|
+
}
|
|
36
39
|
|
|
37
40
|
params := spec.Params
|
|
38
41
|
for _, item := range vs.Items(params) {
|
|
@@ -395,13 +395,12 @@ public class FeatureCorpusTest {
|
|
|
395
395
|
assertNotNull(corpus().get("feature"));
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
-
//
|
|
399
|
-
//
|
|
398
|
+
// With every operation needing an argument there is nothing to drive:
|
|
399
|
+
// skip and say so, as the clean test does, rather than fail.
|
|
400
400
|
@Test
|
|
401
401
|
public void sdkHasAnOperationTheCorpusCanDrive() {
|
|
402
|
-
|
|
403
|
-
"no declared operation
|
|
404
|
-
+ "cannot exercise a feature without one");
|
|
402
|
+
org.junit.jupiter.api.Assumptions.assumeTrue(0 < usableOps(2).size(),
|
|
403
|
+
"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");
|
|
405
404
|
}
|
|
406
405
|
|
|
407
406
|
@Test
|
|
@@ -414,6 +414,55 @@ public class PrimaryUtilityTest {
|
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
418
|
+
// A JVM cannot set its own environment, so the probe runs in a child JVM.
|
|
419
|
+
@Test
|
|
420
|
+
public void fetcherGetOnlyGuard() throws Exception {
|
|
421
|
+
String out;
|
|
422
|
+
if ("TRUE".equals(System.getenv("VOXGIG_GETONLY_GUARD"))) {
|
|
423
|
+
out = getOnlyProbe();
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
ProcessBuilder pb = new ProcessBuilder(
|
|
427
|
+
ProcessHandle.current().info().command().orElse("java"),
|
|
428
|
+
"-cp", System.getProperty("java.class.path"), PrimaryUtilityTest.class.getName());
|
|
429
|
+
pb.environment().put("VOXGIG_GETONLY_GUARD", "TRUE");
|
|
430
|
+
pb.redirectErrorStream(true);
|
|
431
|
+
Process proc = pb.start();
|
|
432
|
+
out = new String(proc.getInputStream().readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
|
|
433
|
+
assertEquals(0, proc.waitFor(), out);
|
|
434
|
+
}
|
|
435
|
+
assertTrue(out.startsWith("fetch_getonly_block [GET-ONLY GUARD] blocked POST /planet/p1\n"), out);
|
|
436
|
+
assertTrue(out.trim().endsWith("\nsent"), out);
|
|
437
|
+
assertFalse(out.contains("GUARDKEY01"), out);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
public static void main(String[] args) {
|
|
441
|
+
System.out.print(getOnlyProbe());
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
static String getOnlyProbe() {
|
|
445
|
+
ProjectNameSDK liveClient = new ProjectNameSDK(fhMap("base", "http://127.0.0.1:9"));
|
|
446
|
+
Utility liveUtility = liveClient.getUtility();
|
|
447
|
+
Context ctx = liveUtility.makeContext.apply(fhMap(
|
|
448
|
+
"opname", "create", "client", liveClient, "utility", liveUtility), null);
|
|
449
|
+
String url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01";
|
|
450
|
+
StringBuilder out = new StringBuilder();
|
|
451
|
+
for (String method : new String[] {"POST", "GET"}) {
|
|
452
|
+
try {
|
|
453
|
+
liveUtility.fetcher.fetch(ctx, url, fhMap("method", method, "headers", new LinkedHashMap<>()));
|
|
454
|
+
out.append("answered\n");
|
|
455
|
+
}
|
|
456
|
+
catch (SdkError e) {
|
|
457
|
+
out.append(e.code).append(' ').append(e.msg).append('\n');
|
|
458
|
+
}
|
|
459
|
+
catch (RuntimeException e) {
|
|
460
|
+
out.append("sent\n");
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return out.toString();
|
|
464
|
+
}
|
|
465
|
+
|
|
417
466
|
@Test
|
|
418
467
|
public void makeContextBasic() {
|
|
419
468
|
runsection("makeContext", (args) -> {
|
|
@@ -15,6 +15,7 @@ import java.util.function.BiFunction;
|
|
|
15
15
|
import java.util.function.Supplier;
|
|
16
16
|
|
|
17
17
|
import JAVAPACKAGE.core.Context;
|
|
18
|
+
import JAVAPACKAGE.core.SdkError;
|
|
18
19
|
import JAVAPACKAGE.utility.struct.Struct;
|
|
19
20
|
|
|
20
21
|
@SuppressWarnings({"unchecked"})
|
|
@@ -56,12 +57,35 @@ final class Fetcher {
|
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
static final String GETONLY_ENV = "VOXGIG_GETONLY_GUARD";
|
|
61
|
+
|
|
62
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
63
|
+
// names the path alone: the query can carry a credential.
|
|
64
|
+
static SdkError getOnlyRefusal(String fullurl, String method) {
|
|
65
|
+
method = method.toUpperCase(java.util.Locale.ROOT);
|
|
66
|
+
if (!"TRUE".equals(System.getenv(GETONLY_ENV)) || "GET".equals(method)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
String rest = fullurl;
|
|
70
|
+
int scheme = rest.indexOf("://");
|
|
71
|
+
if (scheme >= 0) {
|
|
72
|
+
rest = rest.substring(scheme + 3).replaceFirst("^[^/?#]*", "");
|
|
73
|
+
}
|
|
74
|
+
String path = rest.split("[?#]", 2)[0];
|
|
75
|
+
return new SdkError("fetch_getonly_block",
|
|
76
|
+
"[GET-ONLY GUARD] blocked " + method + " " + ("".equals(path) ? "/" : path), null);
|
|
77
|
+
}
|
|
78
|
+
|
|
59
79
|
static Map<String, Object> defaultHttpFetch(String fullurl, Map<String, Object> fetchdef) {
|
|
60
80
|
String method = fetchdef.get("method") instanceof String
|
|
61
81
|
? (String) fetchdef.get("method") : "";
|
|
62
82
|
if ("".equals(method)) {
|
|
63
83
|
method = "GET";
|
|
64
84
|
}
|
|
85
|
+
SdkError refused = getOnlyRefusal(fullurl, method);
|
|
86
|
+
if (refused != null) {
|
|
87
|
+
throw refused;
|
|
88
|
+
}
|
|
65
89
|
|
|
66
90
|
HttpRequest.BodyPublisher bodyPublisher = HttpRequest.BodyPublishers.noBody();
|
|
67
91
|
Object body = fetchdef.get("body");
|
|
@@ -37,13 +37,17 @@ final class MakeUrl {
|
|
|
37
37
|
joinParts.add(spec.suffix);
|
|
38
38
|
String url = Struct.join(joinParts, "/", true);
|
|
39
39
|
|
|
40
|
-
// A route the definition ends with a slash keeps it
|
|
41
|
-
//
|
|
40
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
41
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
42
42
|
Object orig = ctx.point == null ? null : Struct.getprop(ctx.point, "orig", null);
|
|
43
43
|
if (orig instanceof String && ((String) orig).endsWith("/") &&
|
|
44
44
|
(spec.suffix == null || spec.suffix.isEmpty()) && !url.endsWith("/")) {
|
|
45
45
|
url = url + "/";
|
|
46
46
|
}
|
|
47
|
+
int authority = url.indexOf("://");
|
|
48
|
+
if (0 < authority && url.substring(authority + 3).chars().noneMatch(c -> 0 <= "/?#".indexOf(c))) {
|
|
49
|
+
url = url + "/";
|
|
50
|
+
}
|
|
47
51
|
|
|
48
52
|
Map<String, Object> resmatch = new LinkedHashMap<>();
|
|
49
53
|
|
|
@@ -18,6 +18,23 @@ function defaultUserAgent(fetchdef) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
const GETONLY_ENV = 'VOXGIG_GETONLY_GUARD'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
25
|
+
// names the path alone: the query can carry a credential.
|
|
26
|
+
function getOnlyRefusal(ctx, fullurl, fetchdef) {
|
|
27
|
+
const method = String(fetchdef.method || 'GET').toUpperCase()
|
|
28
|
+
if ('TRUE' !== globalThis.process?.env?.[GETONLY_ENV] || 'GET' === method) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
const scheme = fullurl.indexOf('://')
|
|
32
|
+
const rest = scheme < 0 ? fullurl : fullurl.slice(scheme + 3).replace(/^[^/?#]*/, '')
|
|
33
|
+
const path = rest.split(/[?#]/)[0] || '/'
|
|
34
|
+
return ctx.error('fetch_getonly_block', '[GET-ONLY GUARD] blocked ' + method + ' ' + path)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
21
38
|
// Make HTTP call using library. Replace this utility for mocking etc.
|
|
22
39
|
async function fetcher(ctx, fullurl, fetchdef) {
|
|
23
40
|
|
|
@@ -37,6 +54,13 @@ async function fetcher(ctx, fullurl, fetchdef) {
|
|
|
37
54
|
|
|
38
55
|
const fetch = options.system.fetch
|
|
39
56
|
|
|
57
|
+
// The platform's fetch is the SDK's own transport; a supplied one is the
|
|
58
|
+
// caller's, and a mock sends nothing.
|
|
59
|
+
const refused = fetch === globalThis.fetch ? getOnlyRefusal(ctx, fullurl, fetchdef) : undefined
|
|
60
|
+
if (refused) {
|
|
61
|
+
return refused
|
|
62
|
+
}
|
|
63
|
+
|
|
40
64
|
defaultUserAgent(fetchdef)
|
|
41
65
|
|
|
42
66
|
const response = await fetch(fullurl, fetchdef)
|
|
@@ -20,12 +20,16 @@ function makeUrl(ctx) {
|
|
|
20
20
|
|
|
21
21
|
let url = join([spec.base, spec.prefix, spec.path, spec.suffix], '/', true)
|
|
22
22
|
|
|
23
|
-
// A route the definition ends with a slash keeps it
|
|
24
|
-
//
|
|
23
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
24
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
25
25
|
const orig = ctx.point && ctx.point.orig
|
|
26
26
|
if ('string' === typeof orig && orig.endsWith('/') && !spec.suffix && !url.endsWith('/')) {
|
|
27
27
|
url += '/'
|
|
28
28
|
}
|
|
29
|
+
const authority = url.indexOf('://')
|
|
30
|
+
if (0 < authority && !/[/?#]/.test(url.slice(authority + 3))) {
|
|
31
|
+
url += '/'
|
|
32
|
+
}
|
|
29
33
|
let resmatch = {}
|
|
30
34
|
|
|
31
35
|
// Sent with the request, never recorded as the entity's match.
|
|
@@ -244,12 +244,13 @@ describe('FeatureCorpus', () => {
|
|
|
244
244
|
})
|
|
245
245
|
|
|
246
246
|
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
test('this SDK has an operation the corpus can drive', () => {
|
|
250
|
-
|
|
251
|
-
'no declared operation
|
|
252
|
-
|
|
247
|
+
// With every operation needing an argument there is nothing to drive:
|
|
248
|
+
// skip and say so, as the clean test does, rather than fail.
|
|
249
|
+
test('this SDK has an operation the corpus can drive', (t) => {
|
|
250
|
+
if (0 === ops.length) {
|
|
251
|
+
return 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')
|
|
252
|
+
}
|
|
253
|
+
ok(0 < ops.length)
|
|
253
254
|
})
|
|
254
255
|
|
|
255
256
|
|
|
@@ -8,9 +8,12 @@ const strict_1 = __importDefault(require("node:assert/strict"));
|
|
|
8
8
|
const live_contract_1 = require("./live-contract");
|
|
9
9
|
const live_runner_1 = require("./live-runner");
|
|
10
10
|
const utility_1 = require("./utility");
|
|
11
|
+
const routeOf = (point) => String(point.m).toUpperCase() + ' ' + point.o;
|
|
12
|
+
const scalarOf = (value) => ['string', 'number', 'boolean'].includes(typeof value) ? value : undefined;
|
|
11
13
|
// The offline flow keeps its deterministic fixture assertions. Live flows
|
|
12
14
|
// resolve real prerequisites per operation and collect failures until done.
|
|
13
|
-
|
|
15
|
+
// `excluded` names, by step id, the steps this run leaves out, and why.
|
|
16
|
+
async function runLiveEntity(setup, entity, flow, accessor, facts = {}, settle = {}, excluded = {}) {
|
|
14
17
|
const { client, transport } = setup;
|
|
15
18
|
// A step switched off only because the offline call reaches no route of
|
|
16
19
|
// its operation still runs here, where each route's inputs are resolved.
|
|
@@ -28,11 +31,12 @@ async function runLiveEntity(setup, entity, flow, accessor, facts = {}, settle =
|
|
|
28
31
|
const report = await (0, live_runner_1.runLiveSteps)(steps.map((step, index) => {
|
|
29
32
|
const ref = step.i?.ref || entity.name + '_ref01';
|
|
30
33
|
const op = step.o;
|
|
31
|
-
const
|
|
34
|
+
const id = entity.name + '.' + op + '.' + index;
|
|
35
|
+
const control = (0, utility_1.isControlSkipped)('entityOp', entity.name + '.' + op, 'live');
|
|
32
36
|
return {
|
|
33
|
-
id
|
|
37
|
+
id,
|
|
34
38
|
cleanup: op === 'remove' || (step.v || []).some((v) => v.apply === 'ItemNotExists'),
|
|
35
|
-
excluded:
|
|
39
|
+
excluded: control.skip ? control.reason || 'Excluded by test control' : excluded[id],
|
|
36
40
|
run: async (context) => {
|
|
37
41
|
transport.enter(context);
|
|
38
42
|
const points = (entity.op?.[op]?.points || []).filter((point) => false !== point.a);
|
|
@@ -65,6 +69,14 @@ async function runLiveEntity(setup, entity, flow, accessor, facts = {}, settle =
|
|
|
65
69
|
if (undefined !== id)
|
|
66
70
|
input.id = id;
|
|
67
71
|
}
|
|
72
|
+
// A load of a known record takes the route the offline flow takes,
|
|
73
|
+
// and the parameters that flow reads from the record.
|
|
74
|
+
for (const [name, field] of Object.entries(step.record || {})) {
|
|
75
|
+
const value = scalarOf(loaded?.[field]);
|
|
76
|
+
if (undefined !== value)
|
|
77
|
+
input[name] = value;
|
|
78
|
+
}
|
|
79
|
+
const ordered = null == step.route ? points : [...points].sort((a, b) => Number(step.route !== routeOf(a)) - Number(step.route !== routeOf(b)));
|
|
68
80
|
// A nested route needing a parent id must not hide an available
|
|
69
81
|
// parameter-free route for the same operation. Use the first viable
|
|
70
82
|
// candidate. An action route is taken only when the step names its
|
|
@@ -73,7 +85,7 @@ async function runLiveEntity(setup, entity, flow, accessor, facts = {}, settle =
|
|
|
73
85
|
let selected;
|
|
74
86
|
const unusable = [];
|
|
75
87
|
const actionOnly = points.every((point) => null != point.q?.$action);
|
|
76
|
-
for (const point of
|
|
88
|
+
for (const point of ordered) {
|
|
77
89
|
const action = point.q?.$action;
|
|
78
90
|
if (null == input.$action ? null != action && !actionOnly : action !== input.$action)
|
|
79
91
|
continue;
|
|
@@ -85,7 +97,7 @@ async function runLiveEntity(setup, entity, flow, accessor, facts = {}, settle =
|
|
|
85
97
|
if (undefined !== candidate[arg.n] && null !== candidate[arg.n])
|
|
86
98
|
continue;
|
|
87
99
|
const key = arg.n === 'id' ? entity.name + '01' : arg.n.replace(/_id$/, '') + '01';
|
|
88
|
-
const value = setup.idmap[key] ?? setup.idmap[arg.n] ?? loaded?.[arg.n] ?? arg.ex;
|
|
100
|
+
const value = setup.idmap[key] ?? setup.idmap[arg.n] ?? scalarOf(loaded?.[arg.n]) ?? arg.ex;
|
|
89
101
|
if (undefined !== value && null !== value)
|
|
90
102
|
candidate[arg.n] = value;
|
|
91
103
|
else if (arg.r !== false)
|
|
@@ -11,6 +11,8 @@ exports.createLiveTransport = createLiveTransport;
|
|
|
11
11
|
class LiveBlocked extends Error {
|
|
12
12
|
}
|
|
13
13
|
exports.LiveBlocked = LiveBlocked;
|
|
14
|
+
// The SDK fetcher's code for a write a GET-only run refused unsent.
|
|
15
|
+
const GETONLY_CODE = 'fetch_getonly_block';
|
|
14
16
|
// The account answered, but holds no record the step could act on.
|
|
15
17
|
class LiveEmpty extends Error {
|
|
16
18
|
}
|
|
@@ -73,10 +75,12 @@ async function runLiveSteps(steps, options = {}) {
|
|
|
73
75
|
record({ id: step.id, state: 'passed', attempted, requests });
|
|
74
76
|
}
|
|
75
77
|
catch (error) {
|
|
78
|
+
const refused = GETONLY_CODE === error?.code;
|
|
76
79
|
const state = error instanceof LiveEmpty ? 'empty'
|
|
77
|
-
: error instanceof LiveBlocked ? 'blocked' : 'failed';
|
|
80
|
+
: error instanceof LiveBlocked || refused ? 'blocked' : 'failed';
|
|
78
81
|
record({ id: step.id, state, attempted, requests,
|
|
79
|
-
reason: '
|
|
82
|
+
reason: refused ? 'Refused by the GET-only guard' :
|
|
83
|
+
'failed' === state ? failureReason(error) : error.message });
|
|
80
84
|
}
|
|
81
85
|
if (attempted && (options.delayMs || 0) > 0) {
|
|
82
86
|
await new Promise(resolve => setTimeout(resolve, options.delayMs));
|
|
@@ -122,8 +126,12 @@ function assertLiveReport(report) {
|
|
|
122
126
|
throw new Error('Live coverage incomplete: ' + JSON.stringify(report));
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
|
-
// An account with no record for a step to read skips in either mode
|
|
129
|
+
// An account with no record for a step to read skips in either mode, as
|
|
130
|
+
// does a run that leaves out every step.
|
|
126
131
|
function settleLiveReport(report, settle = {}) {
|
|
132
|
+
if (0 < report.planned && report.excluded === report.planned && null != settle.t) {
|
|
133
|
+
return settle.t.skip('Live coverage incomplete: ' + liveSummary(report));
|
|
134
|
+
}
|
|
127
135
|
if (liveIncomplete(report)) {
|
|
128
136
|
if (false !== settle.strict || null == settle.t)
|
|
129
137
|
return assertLiveReport(report);
|
|
@@ -148,6 +156,10 @@ function createLiveTransport(timeoutMs = 30000) {
|
|
|
148
156
|
enter(next) { context = next; },
|
|
149
157
|
fetch: async (input, init) => {
|
|
150
158
|
const url = new URL(String(input));
|
|
159
|
+
const method = String(init?.method || 'GET').toUpperCase();
|
|
160
|
+
if ('TRUE' === process.env.VOXGIG_GETONLY_GUARD && 'GET' !== method) {
|
|
161
|
+
throw Object.assign(new Error('[GET-ONLY GUARD] blocked ' + method + ' ' + url.pathname), { code: GETONLY_CODE });
|
|
162
|
+
}
|
|
151
163
|
// A credential can travel as the agent (auth.name), so only whether
|
|
152
164
|
// the request carried one is recorded, never its value.
|
|
153
165
|
const request = {
|
|
@@ -502,6 +502,31 @@ describe('PrimaryUtility', async () => {
|
|
|
502
502
|
})
|
|
503
503
|
|
|
504
504
|
|
|
505
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
506
|
+
test('fetcher-getonly-guard', async () => {
|
|
507
|
+
const liveClient = new SDK({ base: 'http://127.0.0.1:9' })
|
|
508
|
+
const liveUtility = liveClient.utility()
|
|
509
|
+
const ctx = liveUtility.makeContext({ opname: 'create' }, liveClient._rootctx)
|
|
510
|
+
ctx.client = liveClient
|
|
511
|
+
const url = 'http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01'
|
|
512
|
+
|
|
513
|
+
const prior = process.env.VOXGIG_GETONLY_GUARD
|
|
514
|
+
process.env.VOXGIG_GETONLY_GUARD = 'TRUE'
|
|
515
|
+
try {
|
|
516
|
+
const refused = await liveUtility.fetcher(ctx, url, { method: 'POST', headers: {} })
|
|
517
|
+
equal(refused?.code, 'fetch_getonly_block')
|
|
518
|
+
ok(refused.message.includes('[GET-ONLY GUARD] blocked POST /planet/p1'), refused.message)
|
|
519
|
+
ok(!refused.message.includes('GUARDKEY01'))
|
|
520
|
+
|
|
521
|
+
await assert.rejects(liveUtility.fetcher(ctx, url, { method: 'GET', headers: {} }))
|
|
522
|
+
}
|
|
523
|
+
finally {
|
|
524
|
+
if (undefined === prior) delete process.env.VOXGIG_GETONLY_GUARD
|
|
525
|
+
else process.env.VOXGIG_GETONLY_GUARD = prior
|
|
526
|
+
}
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
|
|
505
530
|
test('makeError-no-throw', () => {
|
|
506
531
|
const ctx = makeFullCtx()
|
|
507
532
|
ctx.ctrl.throw = false
|
|
@@ -74,6 +74,31 @@ class PrimaryUtilityTest {
|
|
|
74
74
|
run()
|
|
75
75
|
return UTILITY!!
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
@JvmStatic
|
|
79
|
+
fun main(args: Array<String>) {
|
|
80
|
+
print(getOnlyProbe())
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fun getOnlyProbe(): String {
|
|
84
|
+
val liveClient = ProjectNameSDK(fhMap("base", "http://127.0.0.1:9"))
|
|
85
|
+
val liveUtility = liveClient.getUtility()
|
|
86
|
+
val ctx = liveUtility.makeContext(
|
|
87
|
+
fhMap("opname", "create", "client", liveClient, "utility", liveUtility), null)
|
|
88
|
+
val url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01"
|
|
89
|
+
val out = StringBuilder()
|
|
90
|
+
for (method in listOf("POST", "GET")) {
|
|
91
|
+
try {
|
|
92
|
+
liveUtility.fetcher(ctx, url, fhMap("method", method, "headers", linkedMapOf<String, Any?>()))
|
|
93
|
+
out.append("answered\n")
|
|
94
|
+
} catch (e: SdkError) {
|
|
95
|
+
out.append(e.code).append(' ').append(e.msg).append('\n')
|
|
96
|
+
} catch (e: RuntimeException) {
|
|
97
|
+
out.append("sent\n")
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out.toString()
|
|
101
|
+
}
|
|
77
102
|
}
|
|
78
103
|
|
|
79
104
|
// Run one corpus section, failing loudly when it would run ZERO cases.
|
|
@@ -382,6 +407,29 @@ class PrimaryUtilityTest {
|
|
|
382
407
|
}
|
|
383
408
|
}
|
|
384
409
|
|
|
410
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
411
|
+
// A JVM cannot set its own environment, so the probe runs in a child JVM.
|
|
412
|
+
@Test
|
|
413
|
+
fun fetcherGetOnlyGuard() {
|
|
414
|
+
val out = if ("TRUE" == System.getenv("VOXGIG_GETONLY_GUARD")) {
|
|
415
|
+
getOnlyProbe()
|
|
416
|
+
} else {
|
|
417
|
+
val pb = ProcessBuilder(
|
|
418
|
+
ProcessHandle.current().info().command().orElse("java"),
|
|
419
|
+
"-cp", System.getProperty("java.class.path"), PrimaryUtilityTest::class.java.name,
|
|
420
|
+
)
|
|
421
|
+
pb.environment()["VOXGIG_GETONLY_GUARD"] = "TRUE"
|
|
422
|
+
pb.redirectErrorStream(true)
|
|
423
|
+
val proc = pb.start()
|
|
424
|
+
val text = proc.inputStream.readAllBytes().toString(Charsets.UTF_8)
|
|
425
|
+
assertEquals(0, proc.waitFor(), text)
|
|
426
|
+
text
|
|
427
|
+
}
|
|
428
|
+
assertTrue(out.startsWith("fetch_getonly_block [GET-ONLY GUARD] blocked POST /planet/p1\n"), out)
|
|
429
|
+
assertTrue(out.trim().endsWith("\nsent"), out)
|
|
430
|
+
assertFalse(out.contains("GUARDKEY01"), out)
|
|
431
|
+
}
|
|
432
|
+
|
|
385
433
|
@Test
|
|
386
434
|
fun makeContextBasic() {
|
|
387
435
|
runsection("makeContext") { args ->
|
|
@@ -12,6 +12,7 @@ import java.util.function.BiFunction
|
|
|
12
12
|
import java.util.function.Supplier
|
|
13
13
|
|
|
14
14
|
import KOTLINPACKAGE.core.Context
|
|
15
|
+
import KOTLINPACKAGE.core.SdkError
|
|
15
16
|
import KOTLINPACKAGE.utility.struct.Struct
|
|
16
17
|
|
|
17
18
|
// Clients keyed by redirect policy and proxy. Each HttpClient owns a
|
|
@@ -45,12 +46,31 @@ private fun clientFor(fetchdef: MutableMap<String, Any?>): HttpClient {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
internal const val GETONLY_ENV = "VOXGIG_GETONLY_GUARD"
|
|
50
|
+
|
|
51
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
52
|
+
// names the path alone: the query can carry a credential.
|
|
53
|
+
internal fun getOnlyRefusal(fullurl: String, method: String): SdkError? {
|
|
54
|
+
val upper = method.uppercase()
|
|
55
|
+
if ("TRUE" != System.getenv(GETONLY_ENV) || "GET" == upper) {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
var rest = fullurl
|
|
59
|
+
val scheme = rest.indexOf("://")
|
|
60
|
+
if (scheme >= 0) {
|
|
61
|
+
rest = rest.substring(scheme + 3).replaceFirst(Regex("^[^/?#]*"), "")
|
|
62
|
+
}
|
|
63
|
+
val path = rest.split(Regex("[?#]"), 2)[0].ifEmpty { "/" }
|
|
64
|
+
return SdkError("fetch_getonly_block", "[GET-ONLY GUARD] blocked $upper $path", null)
|
|
65
|
+
}
|
|
66
|
+
|
|
48
67
|
@Suppress("UNCHECKED_CAST")
|
|
49
68
|
fun defaultHttpFetch(fullurl: String, fetchdef: MutableMap<String, Any?>): MutableMap<String, Any?> {
|
|
50
69
|
var method = if (fetchdef["method"] is String) fetchdef["method"] as String else ""
|
|
51
70
|
if ("" == method) {
|
|
52
71
|
method = "GET"
|
|
53
72
|
}
|
|
73
|
+
getOnlyRefusal(fullurl, method)?.let { throw it }
|
|
54
74
|
|
|
55
75
|
var bodyPublisher: HttpRequest.BodyPublisher = HttpRequest.BodyPublishers.noBody()
|
|
56
76
|
val body = fetchdef["body"]
|
|
@@ -114,13 +114,17 @@ fun makeUrl(ctx: Context): String {
|
|
|
114
114
|
joinParts.add(spec.suffix)
|
|
115
115
|
var url = Struct.join(joinParts, "/", true)
|
|
116
116
|
|
|
117
|
-
// A route the definition ends with a slash keeps it
|
|
118
|
-
//
|
|
117
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
118
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
119
119
|
val point = ctx.point
|
|
120
120
|
val orig = if (point == null) null else Struct.getprop(point, "orig", null)
|
|
121
121
|
if (orig is String && orig.endsWith("/") && spec.suffix.isEmpty() && !url.endsWith("/")) {
|
|
122
122
|
url += "/"
|
|
123
123
|
}
|
|
124
|
+
val authority = url.indexOf("://")
|
|
125
|
+
if (0 < authority && url.substring(authority + 3).none { it in "/?#" }) {
|
|
126
|
+
url += "/"
|
|
127
|
+
}
|
|
124
128
|
|
|
125
129
|
val resmatch = linkedMapOf<String, Any?>()
|
|
126
130
|
|
|
@@ -407,6 +407,33 @@ describe("pipeline", function()
|
|
|
407
407
|
end)
|
|
408
408
|
|
|
409
409
|
|
|
410
|
+
describe("makeUrl", function()
|
|
411
|
+
|
|
412
|
+
-- luasocket takes everything up to the first / as the host. The mock
|
|
413
|
+
-- fetcher never parses the URL, so the built string is what is checked.
|
|
414
|
+
local function url_for(base, path, query)
|
|
415
|
+
local ctx = base_ctx({})
|
|
416
|
+
ctx.spec = Spec.new({ base = base, path = path, query = query })
|
|
417
|
+
ctx.result = Result.new({})
|
|
418
|
+
local url, err = ctx.utility.make_url(ctx)
|
|
419
|
+
assert.is_nil(err)
|
|
420
|
+
return url
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
it("gives a route at the server root the path /", function()
|
|
424
|
+
assert.are.equal("https://api.test/?name=michael", url_for("https://api.test", "", { name = "michael" }))
|
|
425
|
+
assert.are.equal("https://api.test/", url_for("https://api.test", ""))
|
|
426
|
+
assert.are.equal("https://api.test/", url_for("https://api.test/", "/"))
|
|
427
|
+
end)
|
|
428
|
+
|
|
429
|
+
it("leaves a URL with a path, or with no authority, as it is", function()
|
|
430
|
+
assert.are.equal("https://api.test/v1?name=michael", url_for("https://api.test/v1", "", { name = "michael" }))
|
|
431
|
+
assert.are.equal("https://api.test/pets", url_for("https://api.test", "pets"))
|
|
432
|
+
assert.are.equal("base-/p", url_for("base-", "p"))
|
|
433
|
+
end)
|
|
434
|
+
end)
|
|
435
|
+
|
|
436
|
+
|
|
410
437
|
describe("makeError + done", function()
|
|
411
438
|
|
|
412
439
|
it("done returns resdata on success", function()
|
|
@@ -504,6 +504,42 @@ describe("PrimaryUtility", function()
|
|
|
504
504
|
end)
|
|
505
505
|
|
|
506
506
|
|
|
507
|
+
-- Nothing listens on port 9: a request the guard let through fails there.
|
|
508
|
+
-- Lua cannot set its own environment, so the test answers for os.getenv.
|
|
509
|
+
it("fetcher-getonly-guard", function()
|
|
510
|
+
local live_client = sdk.new({ base = "http://127.0.0.1:9" })
|
|
511
|
+
local live_utility = live_client:get_utility()
|
|
512
|
+
local ctx = live_utility.make_context({
|
|
513
|
+
opname = "create",
|
|
514
|
+
client = live_client,
|
|
515
|
+
utility = live_utility,
|
|
516
|
+
}, nil)
|
|
517
|
+
local url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01"
|
|
518
|
+
|
|
519
|
+
local getenv = os.getenv
|
|
520
|
+
os.getenv = function(name)
|
|
521
|
+
if name == "VOXGIG_GETONLY_GUARD" then
|
|
522
|
+
return "TRUE"
|
|
523
|
+
end
|
|
524
|
+
return getenv(name)
|
|
525
|
+
end
|
|
526
|
+
local passed, failure = pcall(function()
|
|
527
|
+
local _, err = live_utility.fetcher(ctx, url, { method = "POST", headers = {} })
|
|
528
|
+
assert.are.equal("fetch_getonly_block", type(err) == "table" and err.code or tostring(err))
|
|
529
|
+
assert.is_truthy(string.find(err.msg, "[GET-ONLY GUARD] blocked POST /planet/p1", 1, true))
|
|
530
|
+
assert.is_falsy(string.find(err.msg, "GUARDKEY01", 1, true))
|
|
531
|
+
|
|
532
|
+
local _, geterr = live_utility.fetcher(ctx, url, { method = "GET", headers = {} })
|
|
533
|
+
assert.is_not_nil(geterr)
|
|
534
|
+
assert.are_not.equal("fetch_getonly_block", type(geterr) == "table" and geterr.code or geterr)
|
|
535
|
+
end)
|
|
536
|
+
os.getenv = getenv
|
|
537
|
+
if not passed then
|
|
538
|
+
error(failure, 0)
|
|
539
|
+
end
|
|
540
|
+
end)
|
|
541
|
+
|
|
542
|
+
|
|
507
543
|
it("makeContext-basic", function()
|
|
508
544
|
runsection("makeContext", function(vin)
|
|
509
545
|
if type(vin) ~= "table" then
|