@voxgig/sdkgen 4.35.3 → 4.36.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 +4 -3
- package/project/.sdk/src/cmp/go/Main_go.ts +2 -2
- 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/ReadmeQuick_go.ts +4 -4
- package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +3 -3
- 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/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/ReadmeEntity_rust.ts +2 -2
- package/project/.sdk/src/cmp/rust/ReadmeHowto_rust.ts +2 -2
- package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +4 -4
- package/project/.sdk/src/cmp/rust/ReadmeRef_rust.ts +3 -3
- package/project/.sdk/src/cmp/rust/ReadmeTopQuick_rust.ts +2 -2
- package/project/.sdk/src/cmp/rust/ReadmeTopTest_rust.ts +2 -2
- package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +40 -12
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +108 -25
- 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/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/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/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
|
@@ -81,7 +81,7 @@ class PrimaryUtilityTest < Minitest::Test
|
|
|
81
81
|
return nil unless m.is_a?(Hash)
|
|
82
82
|
msg = m["message"]
|
|
83
83
|
return nil unless msg.is_a?(String) && !msg.empty?
|
|
84
|
-
ProjectNameError.new(m["code"] || ""
|
|
84
|
+
ProjectNameError.new(msg, code: m["code"] || "")
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
|
|
@@ -278,6 +278,33 @@ class PrimaryUtilityTest < Minitest::Test
|
|
|
278
278
|
assert_includes err.to_s.downcase, "blocked"
|
|
279
279
|
end
|
|
280
280
|
|
|
281
|
+
# Nothing listens on port 9: a request the guard let through fails there.
|
|
282
|
+
def test_fetcher_getonly_guard
|
|
283
|
+
live_client = ProjectNameSDK.new({ "base" => "http://127.0.0.1:9" })
|
|
284
|
+
live_utility = live_client.get_utility
|
|
285
|
+
ctx = live_utility.make_context.call({
|
|
286
|
+
"opname" => "create",
|
|
287
|
+
"client" => live_client,
|
|
288
|
+
"utility" => live_utility,
|
|
289
|
+
}, nil)
|
|
290
|
+
url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01"
|
|
291
|
+
prior = ENV["VOXGIG_GETONLY_GUARD"]
|
|
292
|
+
ENV["VOXGIG_GETONLY_GUARD"] = "TRUE"
|
|
293
|
+
begin
|
|
294
|
+
_, err = live_utility.fetcher.call(ctx, url, { "method" => "POST", "headers" => {} })
|
|
295
|
+
assert_kind_of ProjectNameError, err
|
|
296
|
+
assert_equal "fetch_getonly_block", err.code
|
|
297
|
+
assert_includes err.msg, "[GET-ONLY GUARD] blocked POST /planet/p1"
|
|
298
|
+
refute_includes err.msg, "GUARDKEY01"
|
|
299
|
+
|
|
300
|
+
_, geterr = live_utility.fetcher.call(ctx, url, { "method" => "GET", "headers" => {} })
|
|
301
|
+
assert geterr, "expected the GET to reach the closed port"
|
|
302
|
+
refute_kind_of ProjectNameError, geterr
|
|
303
|
+
ensure
|
|
304
|
+
ENV["VOXGIG_GETONLY_GUARD"] = prior
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
281
308
|
|
|
282
309
|
# === makeContext ===
|
|
283
310
|
|
|
@@ -41,6 +41,21 @@ module ProjectNameUtilities
|
|
|
41
41
|
nil
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
GETONLY_ENV = "VOXGIG_GETONLY_GUARD"
|
|
45
|
+
|
|
46
|
+
# A GET-only live run refuses any other method before it is sent. The error
|
|
47
|
+
# names the path alone: the query can carry a credential.
|
|
48
|
+
def self.getonly_refusal(ctx, fullurl, method)
|
|
49
|
+
method = method.to_s.upcase
|
|
50
|
+
method = "GET" if method.empty?
|
|
51
|
+
return nil if ENV[GETONLY_ENV] != "TRUE" || method == "GET"
|
|
52
|
+
rest = fullurl.to_s
|
|
53
|
+
rest = rest.split("://", 2)[1].sub(%r{\A[^/?#]*}, "") if rest.include?("://")
|
|
54
|
+
path = rest[/\A[^?#]*/]
|
|
55
|
+
path = "/" if path.empty?
|
|
56
|
+
ctx.make_error("fetch_getonly_block", "[GET-ONLY GUARD] blocked #{method} #{path}")
|
|
57
|
+
end
|
|
58
|
+
|
|
44
59
|
DefaultHttpFetch = ->(fullurl, fetchdef) {
|
|
45
60
|
method_str = fetchdef["method"] || "GET"
|
|
46
61
|
body_str = fetchdef["body"]
|
|
@@ -134,7 +149,11 @@ module ProjectNameUtilities
|
|
|
134
149
|
|
|
135
150
|
sys_fetch = VoxgigStruct.getpath(options, "system.fetch")
|
|
136
151
|
|
|
137
|
-
|
|
152
|
+
if sys_fetch.nil?
|
|
153
|
+
refused = ProjectNameUtilities.getonly_refusal(ctx, fullurl, fetchdef["method"])
|
|
154
|
+
return nil, refused if refused
|
|
155
|
+
return DefaultHttpFetch.call(fullurl, fetchdef)
|
|
156
|
+
end
|
|
138
157
|
return sys_fetch.call(fullurl, fetchdef) if sys_fetch.is_a?(Proc)
|
|
139
158
|
|
|
140
159
|
return nil, ctx.make_error("fetch_invalid", "system.fetch is not a valid function")
|
|
@@ -36,7 +36,7 @@ module ProjectNameUtilities
|
|
|
36
36
|
# The context stays reachable for a debugger (`err.ctx`) and is left out
|
|
37
37
|
# of every serialiser the error defines; result and spec are cleaned
|
|
38
38
|
# COPIES, so masking them never masks the pipeline's own objects.
|
|
39
|
-
sdk_err = ProjectNameError.new(
|
|
39
|
+
sdk_err = ProjectNameError.new(msg, ctx: ctx)
|
|
40
40
|
sdk_err.result = clean.call(ctx, result)
|
|
41
41
|
sdk_err.spec = clean.call(ctx, spec)
|
|
42
42
|
|
|
@@ -14,12 +14,14 @@ module ProjectNameUtilities
|
|
|
14
14
|
# Sent with the request, never recorded as the entity's match.
|
|
15
15
|
authquery = (spec.respond_to?(:authquery) ? spec.authquery : nil) || []
|
|
16
16
|
|
|
17
|
-
# A route the definition ends with a slash keeps it
|
|
18
|
-
#
|
|
17
|
+
# A route the definition ends with a slash keeps it, for a Django REST server,
|
|
18
|
+
# and a host with no path takes /, or luasocket reads a query as the host.
|
|
19
19
|
orig = ctx.point ? VoxgigStruct.getprop(ctx.point, "orig") : nil
|
|
20
20
|
if orig.is_a?(String) && orig.end_with?("/") && spec.suffix.to_s.empty? && !url.end_with?("/")
|
|
21
21
|
url += "/"
|
|
22
22
|
end
|
|
23
|
+
authority = url.index("://")
|
|
24
|
+
url += "/" if authority && 0 < authority && url[(authority + 3)..] !~ %r{[/?#]}
|
|
23
25
|
|
|
24
26
|
param_items = VoxgigStruct.items(spec.params)
|
|
25
27
|
if param_items
|
|
@@ -376,6 +376,40 @@ fn primary_fetcher_blocked_test_mode() {
|
|
|
376
376
|
);
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
380
|
+
#[test]
|
|
381
|
+
fn primary_fetcher_getonly_guard() {
|
|
382
|
+
let live_client = ProjectNameSDK::new(jo(vec![("base", Value::str("http://127.0.0.1:9"))]));
|
|
383
|
+
let live_utility = live_client.get_utility();
|
|
384
|
+
let ctx = live_utility.make_context(
|
|
385
|
+
CtxSpec {
|
|
386
|
+
opname: Some("create".to_string()),
|
|
387
|
+
client: Some(live_client.clone()),
|
|
388
|
+
utility: Some(live_utility.clone()),
|
|
389
|
+
..Default::default()
|
|
390
|
+
},
|
|
391
|
+
None,
|
|
392
|
+
);
|
|
393
|
+
let url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01";
|
|
394
|
+
let def = |method: &str| jo(vec![("method", Value::str(method)), ("headers", Value::empty_map())]);
|
|
395
|
+
|
|
396
|
+
let prior = std::env::var("VOXGIG_GETONLY_GUARD").ok();
|
|
397
|
+
std::env::set_var("VOXGIG_GETONLY_GUARD", "TRUE");
|
|
398
|
+
let refused = live_utility.fetch(&ctx, url, &def("POST")).err();
|
|
399
|
+
let sent = live_utility.fetch(&ctx, url, &def("GET")).err();
|
|
400
|
+
match prior {
|
|
401
|
+
Some(v) => std::env::set_var("VOXGIG_GETONLY_GUARD", v),
|
|
402
|
+
None => std::env::remove_var("VOXGIG_GETONLY_GUARD"),
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
let refused = refused.expect("expected the POST to be refused");
|
|
406
|
+
assert_eq!(refused.code, "fetch_getonly_block");
|
|
407
|
+
assert!(refused.msg.contains("[GET-ONLY GUARD] blocked POST /planet/p1"), "{}", refused.msg);
|
|
408
|
+
assert!(!refused.msg.contains("GUARDKEY01"), "{}", refused.msg);
|
|
409
|
+
let sent = sent.expect("expected the GET to reach the closed port");
|
|
410
|
+
assert_ne!(sent.code, "fetch_getonly_block", "{}", sent.msg);
|
|
411
|
+
}
|
|
412
|
+
|
|
379
413
|
#[test]
|
|
380
414
|
fn primary_make_context_basic() {
|
|
381
415
|
let (client, utility) = base_client();
|
|
@@ -44,11 +44,38 @@ fn agent_for(fetchdef: &Value) -> ureq::Agent {
|
|
|
44
44
|
.clone()
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
const GETONLY_ENV: &str = "VOXGIG_GETONLY_GUARD";
|
|
48
|
+
|
|
49
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
50
|
+
// names the path alone: the query can carry a credential.
|
|
51
|
+
fn getonly_refusal(fullurl: &str, method: &str) -> Option<ProjectNameError> {
|
|
52
|
+
let method = method.to_uppercase();
|
|
53
|
+
if std::env::var(GETONLY_ENV).ok().as_deref() != Some("TRUE") || method == "GET" {
|
|
54
|
+
return None;
|
|
55
|
+
}
|
|
56
|
+
let rest = match fullurl.find("://") {
|
|
57
|
+
Some(i) => {
|
|
58
|
+
let auth = &fullurl[i + 3..];
|
|
59
|
+
&auth[auth.find(|c| matches!(c, '/' | '?' | '#')).unwrap_or(auth.len())..]
|
|
60
|
+
}
|
|
61
|
+
None => fullurl,
|
|
62
|
+
};
|
|
63
|
+
let path = &rest[..rest.find(|c| matches!(c, '?' | '#')).unwrap_or(rest.len())];
|
|
64
|
+
let path = if path.is_empty() { "/" } else { path };
|
|
65
|
+
Some(ProjectNameError::new(
|
|
66
|
+
"fetch_getonly_block",
|
|
67
|
+
&format!("[GET-ONLY GUARD] blocked {} {}", method, path),
|
|
68
|
+
))
|
|
69
|
+
}
|
|
70
|
+
|
|
47
71
|
// Default live transport: ureq (blocking, minimal).
|
|
48
72
|
fn default_http_fetch(fullurl: &str, fetchdef: &Value) -> Result<Value, ProjectNameError> {
|
|
49
73
|
let method = get_str(fetchdef, "method")
|
|
50
74
|
.filter(|m| !m.is_empty())
|
|
51
75
|
.unwrap_or_else(|| "GET".to_string());
|
|
76
|
+
if let Some(refused) = getonly_refusal(fullurl, &method) {
|
|
77
|
+
return Err(refused);
|
|
78
|
+
}
|
|
52
79
|
|
|
53
80
|
let agent = agent_for(fetchdef);
|
|
54
81
|
let mut req = agent.request(&method, fullurl);
|
|
@@ -60,13 +60,18 @@ pub fn make_url_util(ctx: &Rc<Context>) -> Result<String, ProjectNameError> {
|
|
|
60
60
|
true,
|
|
61
61
|
);
|
|
62
62
|
|
|
63
|
-
// A route the definition ends with a slash keeps it
|
|
64
|
-
//
|
|
63
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
64
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
65
65
|
if let Value::Str(orig) = getp(&ctx.point.borrow().clone(), "orig") {
|
|
66
66
|
if orig.ends_with('/') && suffixless && !url.ends_with('/') {
|
|
67
67
|
url.push('/');
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
+
if let Some(authority) = url.find("://") {
|
|
71
|
+
if 0 < authority && !url[authority + 3..].contains(|c| matches!(c, '/' | '?' | '#')) {
|
|
72
|
+
url.push('/');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
70
75
|
|
|
71
76
|
let resmatch = Value::empty_map();
|
|
72
77
|
|
|
@@ -706,6 +706,27 @@ object SdkTestMain {
|
|
|
706
706
|
// Small identity wrapper so IntConsumer/LongSupplier land in the map as-is.
|
|
707
707
|
private def f0(o: Object): Object = o
|
|
708
708
|
|
|
709
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
710
|
+
// A JVM cannot set its own environment, so the probe runs in a child JVM.
|
|
711
|
+
private def testGetOnlyGuard(): Unit = {
|
|
712
|
+
val out =
|
|
713
|
+
if ("TRUE" == System.getenv("VOXGIG_GETONLY_GUARD")) SdkGetOnlyProbe.probe()
|
|
714
|
+
else {
|
|
715
|
+
val pb = new ProcessBuilder(ProcessHandle.current().info().command().orElse("java"),
|
|
716
|
+
"-cp", System.getProperty("java.class.path"), "SdkGetOnlyProbe")
|
|
717
|
+
pb.environment().put("VOXGIG_GETONLY_GUARD", "TRUE")
|
|
718
|
+
pb.redirectErrorStream(true)
|
|
719
|
+
val proc = pb.start()
|
|
720
|
+
val text = new String(proc.getInputStream.readAllBytes(), "UTF-8")
|
|
721
|
+
eqI("getonly.exit", 0, proc.waitFor())
|
|
722
|
+
text
|
|
723
|
+
}
|
|
724
|
+
check("getonly.refused",
|
|
725
|
+
out.startsWith("fetch_getonly_block [GET-ONLY GUARD] blocked POST /planet/p1\n"), out)
|
|
726
|
+
check("getonly.get", out.trim.endsWith("\nsent"), out)
|
|
727
|
+
check("getonly.query", !out.contains("GUARDKEY01"), out)
|
|
728
|
+
}
|
|
729
|
+
|
|
709
730
|
def main(args: Array[String]): Unit = {
|
|
710
731
|
val suites: Seq[(String, () => Unit)] = Seq(
|
|
711
732
|
"netsim" -> testNetsim, "retry" -> testRetry, "timeout" -> testTimeout,
|
|
@@ -715,7 +736,7 @@ object SdkTestMain {
|
|
|
715
736
|
"paging" -> testPaging, "streaming" -> testStreaming, "proxy" -> testProxy,
|
|
716
737
|
"composition" -> testComposition, "featureAdd" -> testFeatureAdd,
|
|
717
738
|
"featureOrder" -> testFeatureOrder, "entityCrud" -> testEntityCrud,
|
|
718
|
-
"entityStream" -> testEntityStream)
|
|
739
|
+
"entityStream" -> testEntityStream, "getOnlyGuard" -> testGetOnlyGuard)
|
|
719
740
|
|
|
720
741
|
suites.foreach { case (name, fn) =>
|
|
721
742
|
try fn()
|
|
@@ -728,3 +749,32 @@ object SdkTestMain {
|
|
|
728
749
|
if (failures.size() > 0) System.exit(1)
|
|
729
750
|
}
|
|
730
751
|
}
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
// The GET-only guard test's child: a POST, then a GET, to a closed port.
|
|
755
|
+
object SdkGetOnlyProbe {
|
|
756
|
+
def probe(): String = {
|
|
757
|
+
val opts = new LinkedHashMap[String, Object]()
|
|
758
|
+
opts.put("base", "http://127.0.0.1:9")
|
|
759
|
+
val client = new ProjectNameSDK(opts)
|
|
760
|
+
val utility = client.getUtility()
|
|
761
|
+
val cm = new LinkedHashMap[String, Object]()
|
|
762
|
+
cm.put("opname", "create")
|
|
763
|
+
val ctx = utility.makeContext(cm, client.getRootCtx())
|
|
764
|
+
val url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01"
|
|
765
|
+
val out = new StringBuilder()
|
|
766
|
+
for (method <- Seq("POST", "GET")) {
|
|
767
|
+
val fetchdef = new LinkedHashMap[String, Object]()
|
|
768
|
+
fetchdef.put("method", method)
|
|
769
|
+
fetchdef.put("headers", new LinkedHashMap[String, Object]())
|
|
770
|
+
try { utility.fetcher(ctx, url, fetchdef); out.append("answered\n") }
|
|
771
|
+
catch {
|
|
772
|
+
case e: SdkError => out.append(e.code).append(' ').append(e.msg).append('\n')
|
|
773
|
+
case _: RuntimeException => out.append("sent\n")
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
out.toString
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
def main(args: Array[String]): Unit = print(probe())
|
|
780
|
+
}
|
|
@@ -41,9 +41,25 @@ object Fetcher {
|
|
|
41
41
|
})
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
val GETONLY_ENV = "VOXGIG_GETONLY_GUARD"
|
|
45
|
+
|
|
46
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
47
|
+
// names the path alone: the query can carry a credential.
|
|
48
|
+
def getOnlyRefusal(fullurl: String, method: String): SdkError = {
|
|
49
|
+
val upper = method.toUpperCase(java.util.Locale.ROOT)
|
|
50
|
+
if ("TRUE" != System.getenv(GETONLY_ENV) || "GET" == upper) return null
|
|
51
|
+
val scheme = fullurl.indexOf("://")
|
|
52
|
+
val rest = if (scheme < 0) fullurl else fullurl.substring(scheme + 3).replaceFirst("^[^/?#]*", "")
|
|
53
|
+
val path = rest.split("[?#]", 2)(0)
|
|
54
|
+
new SdkError("fetch_getonly_block",
|
|
55
|
+
"[GET-ONLY GUARD] blocked " + upper + " " + (if (path.isEmpty) "/" else path), null)
|
|
56
|
+
}
|
|
57
|
+
|
|
44
58
|
def defaultHttpFetch(fullurl: String, fetchdef: JMap[String, Object]): JMap[String, Object] = {
|
|
45
59
|
var method = fetchdef.get("method") match { case s: String => s; case _ => "" }
|
|
46
60
|
if ("" == method) method = "GET"
|
|
61
|
+
val refused = getOnlyRefusal(fullurl, method)
|
|
62
|
+
if (refused != null) throw refused
|
|
47
63
|
|
|
48
64
|
var bodyPublisher = HttpRequest.BodyPublishers.noBody()
|
|
49
65
|
fetchdef.get("body") match {
|
|
@@ -678,14 +678,18 @@ object MakeUrl {
|
|
|
678
678
|
joinParts.add(spec.suffix)
|
|
679
679
|
var url = Struct.join(joinParts, "/", true)
|
|
680
680
|
|
|
681
|
-
// A route the definition ends with a slash keeps it
|
|
682
|
-
//
|
|
681
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
682
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
683
683
|
val orig = if (ctx.point == null) null else Struct.getprop(ctx.point, "orig", null)
|
|
684
684
|
orig match {
|
|
685
685
|
case o: String if o.endsWith("/") && (spec.suffix == null || spec.suffix.isEmpty) && !url.endsWith("/") =>
|
|
686
686
|
url = url + "/"
|
|
687
687
|
case _ =>
|
|
688
688
|
}
|
|
689
|
+
val authority = url.indexOf("://")
|
|
690
|
+
if (0 < authority && !url.substring(authority + 3).exists(c => 0 <= "/?#".indexOf(c))) {
|
|
691
|
+
url = url + "/"
|
|
692
|
+
}
|
|
689
693
|
|
|
690
694
|
val resmatch = new LinkedHashMap[String, Object]()
|
|
691
695
|
|
|
@@ -42,7 +42,31 @@ private let manualRedirectSession = URLSession(
|
|
|
42
42
|
configuration: cookielessConfiguration(),
|
|
43
43
|
delegate: ManualRedirectDelegate(), delegateQueue: nil)
|
|
44
44
|
|
|
45
|
+
let getOnlyEnv = "VOXGIG_GETONLY_GUARD"
|
|
46
|
+
|
|
47
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
48
|
+
// names the path alone: the query can carry a credential.
|
|
49
|
+
func getOnlyRefusal(_ fullurl: String, _ method: String) -> ProjectNameError? {
|
|
50
|
+
let upper = method.uppercased()
|
|
51
|
+
if ProcessInfo.processInfo.environment[getOnlyEnv] != "TRUE" || upper == "GET" {
|
|
52
|
+
return nil
|
|
53
|
+
}
|
|
54
|
+
var rest = Substring(fullurl)
|
|
55
|
+
if let scheme = rest.range(of: "://") {
|
|
56
|
+
rest = rest[scheme.upperBound...]
|
|
57
|
+
rest = rest[(rest.firstIndex(where: { "/?#".contains($0) }) ?? rest.endIndex)...]
|
|
58
|
+
}
|
|
59
|
+
let path = rest[..<(rest.firstIndex(where: { "?#".contains($0) }) ?? rest.endIndex)]
|
|
60
|
+
return ProjectNameError("fetch_getonly_block",
|
|
61
|
+
"[GET-ONLY GUARD] blocked \(upper) \(path.isEmpty ? "/" : String(path))", nil)
|
|
62
|
+
}
|
|
63
|
+
|
|
45
64
|
func defaultHttpFetch(_ fullurl: String, _ fetchdef: VMap) throws -> Value {
|
|
65
|
+
let method = gp(fetchdef, "method").asString ?? "GET"
|
|
66
|
+
if let refused = getOnlyRefusal(fullurl, method.isEmpty ? "GET" : method) {
|
|
67
|
+
throw refused
|
|
68
|
+
}
|
|
69
|
+
|
|
46
70
|
// A request that cannot be sent fails the operation.
|
|
47
71
|
guard let url = URL(string: fullurl) else {
|
|
48
72
|
throw ProjectNameError("fetch_transport", "the URL could not be parsed", nil)
|
|
@@ -266,12 +266,16 @@ func makeUrlUtil(_ ctx: Context) throws -> String {
|
|
|
266
266
|
// Sent with the request, never recorded as the entity's match.
|
|
267
267
|
let authquery = spec.authquery
|
|
268
268
|
|
|
269
|
-
// A route the definition ends with a slash keeps it
|
|
270
|
-
//
|
|
269
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
270
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
271
271
|
if let orig = gp(ctx.point, "orig").asString, orig.hasSuffix("/"), spec.suffix.isEmpty,
|
|
272
272
|
!url.hasSuffix("/") {
|
|
273
273
|
url += "/"
|
|
274
274
|
}
|
|
275
|
+
if let authority = url.range(of: "://"), url.startIndex < authority.lowerBound,
|
|
276
|
+
!url[authority.upperBound...].contains(where: { "/?#".contains($0) }) {
|
|
277
|
+
url += "/"
|
|
278
|
+
}
|
|
275
279
|
|
|
276
280
|
for item in items(.map(spec.params)) {
|
|
277
281
|
let key = item[0].asString ?? ""
|
|
@@ -425,6 +425,40 @@ final class PrimaryUtilityTest: XCTestCase {
|
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
429
|
+
func testFetcherGetOnlyGuard() {
|
|
430
|
+
let opts = VMap()
|
|
431
|
+
opts.entries["base"] = .string("http://127.0.0.1:9")
|
|
432
|
+
let liveClient = ProjectNameSDK(opts)
|
|
433
|
+
let liveUtility = liveClient.getUtility()
|
|
434
|
+
let ctx = liveUtility.makeContext(
|
|
435
|
+
["opname": "create", "client": liveClient, "utility": liveUtility], nil)
|
|
436
|
+
let url = "http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01"
|
|
437
|
+
func def(_ method: String) -> VMap {
|
|
438
|
+
let fetchdef = VMap()
|
|
439
|
+
fetchdef.entries["method"] = .string(method)
|
|
440
|
+
fetchdef.entries["headers"] = .map(VMap())
|
|
441
|
+
return fetchdef
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
let prior = ProcessInfo.processInfo.environment["VOXGIG_GETONLY_GUARD"]
|
|
445
|
+
setenv("VOXGIG_GETONLY_GUARD", "TRUE", 1)
|
|
446
|
+
defer {
|
|
447
|
+
if let prior = prior { setenv("VOXGIG_GETONLY_GUARD", prior, 1) }
|
|
448
|
+
else { unsetenv("VOXGIG_GETONLY_GUARD") }
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
XCTAssertThrowsError(try liveUtility.fetcher(ctx, url, def("POST"))) { error in
|
|
452
|
+
let refused = error as? ProjectNameError
|
|
453
|
+
XCTAssertEqual(refused?.code, "fetch_getonly_block")
|
|
454
|
+
XCTAssertTrue(errMessage(error).contains("[GET-ONLY GUARD] blocked POST /planet/p1"), errMessage(error))
|
|
455
|
+
XCTAssertFalse(errMessage(error).contains("GUARDKEY01"))
|
|
456
|
+
}
|
|
457
|
+
XCTAssertThrowsError(try liveUtility.fetcher(ctx, url, def("GET"))) { error in
|
|
458
|
+
XCTAssertNotEqual((error as? ProjectNameError)?.code, "fetch_getonly_block")
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
428
462
|
func testMakeContextBasic() {
|
|
429
463
|
runsection("makeContext") { args in
|
|
430
464
|
guard let inMap = args.first?.asMap else { return .noval }
|
|
@@ -21,6 +21,23 @@ function defaultUserAgent(fetchdef: Record<string, any>) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
const GETONLY_ENV = 'VOXGIG_GETONLY_GUARD'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// A GET-only live run refuses any other method before it is sent. The error
|
|
28
|
+
// names the path alone: the query can carry a credential.
|
|
29
|
+
function getOnlyRefusal(ctx: Context, fullurl: string, fetchdef: Record<string, any>) {
|
|
30
|
+
const method = String(fetchdef.method || 'GET').toUpperCase()
|
|
31
|
+
if ('TRUE' !== (globalThis as any).process?.env?.[GETONLY_ENV] || 'GET' === method) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
const scheme = fullurl.indexOf('://')
|
|
35
|
+
const rest = scheme < 0 ? fullurl : fullurl.slice(scheme + 3).replace(/^[^/?#]*/, '')
|
|
36
|
+
const path = rest.split(/[?#]/)[0] || '/'
|
|
37
|
+
return ctx.error('fetch_getonly_block', '[GET-ONLY GUARD] blocked ' + method + ' ' + path)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
24
41
|
// Make HTTP call using library. Replace this utility for mocking etc.
|
|
25
42
|
async function fetcher(
|
|
26
43
|
ctx: Context,
|
|
@@ -44,6 +61,13 @@ async function fetcher(
|
|
|
44
61
|
|
|
45
62
|
const fetch = options.system.fetch
|
|
46
63
|
|
|
64
|
+
// The platform's fetch is the SDK's own transport; a supplied one is the
|
|
65
|
+
// caller's, and a mock sends nothing.
|
|
66
|
+
const refused = fetch === globalThis.fetch ? getOnlyRefusal(ctx, fullurl, fetchdef) : undefined
|
|
67
|
+
if (refused) {
|
|
68
|
+
return refused
|
|
69
|
+
}
|
|
70
|
+
|
|
47
71
|
defaultUserAgent(fetchdef)
|
|
48
72
|
|
|
49
73
|
const response = await fetch(fullurl, fetchdef)
|
|
@@ -29,12 +29,16 @@ function makeUrl(ctx: Context): Error | string {
|
|
|
29
29
|
// Sent with the request, never recorded as the entity's match.
|
|
30
30
|
const authquery: string[] = spec.authquery || []
|
|
31
31
|
|
|
32
|
-
// A route the definition ends with a slash keeps it
|
|
33
|
-
//
|
|
32
|
+
// A route the definition ends with a slash keeps it, for a Django REST server,
|
|
33
|
+
// and a host with no path takes /, or luasocket reads a query as the host.
|
|
34
34
|
const orig = ctx.point?.orig
|
|
35
35
|
if ('string' === typeof orig && orig.endsWith('/') && !spec.suffix && !url.endsWith('/')) {
|
|
36
36
|
url += '/'
|
|
37
37
|
}
|
|
38
|
+
const authority = url.indexOf('://')
|
|
39
|
+
if (0 < authority && !/[/?#]/.test(url.slice(authority + 3))) {
|
|
40
|
+
url += '/'
|
|
41
|
+
}
|
|
38
42
|
|
|
39
43
|
const params = spec.params
|
|
40
44
|
|
|
@@ -196,12 +196,13 @@ describe('FeatureCorpus', () => {
|
|
|
196
196
|
})
|
|
197
197
|
|
|
198
198
|
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
test('this SDK has an operation the corpus can drive', () => {
|
|
202
|
-
|
|
203
|
-
'no declared operation
|
|
204
|
-
|
|
199
|
+
// With every operation needing an argument there is nothing to drive:
|
|
200
|
+
// skip and say so, as the clean test does, rather than fail.
|
|
201
|
+
test('this SDK has an operation the corpus can drive', (t) => {
|
|
202
|
+
if (0 === ops.length) {
|
|
203
|
+
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')
|
|
204
|
+
}
|
|
205
|
+
ok(0 < ops.length)
|
|
205
206
|
})
|
|
206
207
|
|
|
207
208
|
|
|
@@ -4,10 +4,16 @@ import { runLiveSteps, settleLiveReport, LiveBlocked, LiveEmpty } from './live-r
|
|
|
4
4
|
import type { LiveSettle } from './live-runner'
|
|
5
5
|
import { isControlSkipped, liveDelayMs } from './utility'
|
|
6
6
|
|
|
7
|
+
const routeOf = (point: any) => String(point.m).toUpperCase() + ' ' + point.o
|
|
8
|
+
|
|
9
|
+
const scalarOf = (value: any) => ['string', 'number', 'boolean'].includes(typeof value) ? value : undefined
|
|
10
|
+
|
|
7
11
|
// The offline flow keeps its deterministic fixture assertions. Live flows
|
|
8
12
|
// resolve real prerequisites per operation and collect failures until done.
|
|
13
|
+
// `excluded` names, by step id, the steps this run leaves out, and why.
|
|
9
14
|
async function runLiveEntity(
|
|
10
15
|
setup: any, entity: any, flow: any, accessor: string, facts: any = {}, settle: LiveSettle = {},
|
|
16
|
+
excluded: Record<string, string> = {},
|
|
11
17
|
) {
|
|
12
18
|
const { client, transport } = setup
|
|
13
19
|
// A step switched off only because the offline call reaches no route of
|
|
@@ -26,11 +32,12 @@ async function runLiveEntity(
|
|
|
26
32
|
const report = await runLiveSteps(steps.map((step, index) => {
|
|
27
33
|
const ref = step.i?.ref || entity.name + '_ref01'
|
|
28
34
|
const op = step.o
|
|
29
|
-
const
|
|
35
|
+
const id = entity.name + '.' + op + '.' + index
|
|
36
|
+
const control = isControlSkipped('entityOp', entity.name + '.' + op, 'live')
|
|
30
37
|
return {
|
|
31
|
-
id
|
|
38
|
+
id,
|
|
32
39
|
cleanup: op === 'remove' || (step.v || []).some((v: any) => v.apply === 'ItemNotExists'),
|
|
33
|
-
excluded:
|
|
40
|
+
excluded: control.skip ? control.reason || 'Excluded by test control' : excluded[id],
|
|
34
41
|
run: async (context: any) => {
|
|
35
42
|
transport.enter(context)
|
|
36
43
|
const points = (entity.op?.[op]?.points || []).filter((point: any) => false !== point.a)
|
|
@@ -59,6 +66,14 @@ async function runLiveEntity(
|
|
|
59
66
|
const id = loaded[idField] ?? loaded.id
|
|
60
67
|
if (undefined !== id) input.id = id
|
|
61
68
|
}
|
|
69
|
+
// A load of a known record takes the route the offline flow takes,
|
|
70
|
+
// and the parameters that flow reads from the record.
|
|
71
|
+
for (const [name, field] of Object.entries(step.record || {})) {
|
|
72
|
+
const value = scalarOf(loaded?.[field as string])
|
|
73
|
+
if (undefined !== value) input[name] = value
|
|
74
|
+
}
|
|
75
|
+
const ordered = null == step.route ? points : [...points].sort((a: any, b: any) =>
|
|
76
|
+
Number(step.route !== routeOf(a)) - Number(step.route !== routeOf(b)))
|
|
62
77
|
// A nested route needing a parent id must not hide an available
|
|
63
78
|
// parameter-free route for the same operation. Use the first viable
|
|
64
79
|
// candidate. An action route is taken only when the step names its
|
|
@@ -67,7 +82,7 @@ async function runLiveEntity(
|
|
|
67
82
|
let selected: any
|
|
68
83
|
const unusable: { route: string, missing: string[] }[] = []
|
|
69
84
|
const actionOnly = points.every((point: any) => null != point.q?.$action)
|
|
70
|
-
for (const point of
|
|
85
|
+
for (const point of ordered) {
|
|
71
86
|
const action = point.q?.$action
|
|
72
87
|
if (null == input.$action ? null != action && !actionOnly : action !== input.$action) continue
|
|
73
88
|
const candidate = null == action ? { ...input } : { ...input, $action: action }
|
|
@@ -77,7 +92,7 @@ async function runLiveEntity(
|
|
|
77
92
|
for (const arg of [...params, ...query]) {
|
|
78
93
|
if (undefined !== candidate[arg.n] && null !== candidate[arg.n]) continue
|
|
79
94
|
const key = arg.n === 'id' ? entity.name + '01' : arg.n.replace(/_id$/, '') + '01'
|
|
80
|
-
const value = setup.idmap[key] ?? setup.idmap[arg.n] ?? loaded?.[arg.n] ?? arg.ex
|
|
95
|
+
const value = setup.idmap[key] ?? setup.idmap[arg.n] ?? scalarOf(loaded?.[arg.n]) ?? arg.ex
|
|
81
96
|
if (undefined !== value && null !== value) candidate[arg.n] = value
|
|
82
97
|
else if (arg.r !== false) missing.push(arg.n)
|
|
83
98
|
}
|
|
@@ -40,6 +40,9 @@ type LiveStep = {
|
|
|
40
40
|
|
|
41
41
|
class LiveBlocked extends Error {}
|
|
42
42
|
|
|
43
|
+
// The SDK fetcher's code for a write a GET-only run refused unsent.
|
|
44
|
+
const GETONLY_CODE = 'fetch_getonly_block'
|
|
45
|
+
|
|
43
46
|
// The account answered, but holds no record the step could act on.
|
|
44
47
|
class LiveEmpty extends Error {}
|
|
45
48
|
|
|
@@ -119,10 +122,12 @@ async function runLiveSteps(
|
|
|
119
122
|
record({ id: step.id, state: 'passed', attempted, requests })
|
|
120
123
|
}
|
|
121
124
|
catch (error) {
|
|
125
|
+
const refused = GETONLY_CODE === (error as any)?.code
|
|
122
126
|
const state: LiveState = error instanceof LiveEmpty ? 'empty'
|
|
123
|
-
: error instanceof LiveBlocked ? 'blocked' : 'failed'
|
|
127
|
+
: error instanceof LiveBlocked || refused ? 'blocked' : 'failed'
|
|
124
128
|
record({ id: step.id, state, attempted, requests,
|
|
125
|
-
reason:
|
|
129
|
+
reason: refused ? 'Refused by the GET-only guard' :
|
|
130
|
+
'failed' === state ? failureReason(error) : (error as Error).message })
|
|
126
131
|
}
|
|
127
132
|
if (attempted && (options.delayMs || 0) > 0) {
|
|
128
133
|
await new Promise(resolve => setTimeout(resolve, options.delayMs))
|
|
@@ -173,8 +178,12 @@ function assertLiveReport(report: LiveReport): void {
|
|
|
173
178
|
}
|
|
174
179
|
}
|
|
175
180
|
|
|
176
|
-
// An account with no record for a step to read skips in either mode
|
|
181
|
+
// An account with no record for a step to read skips in either mode, as
|
|
182
|
+
// does a run that leaves out every step.
|
|
177
183
|
function settleLiveReport(report: LiveReport, settle: LiveSettle = {}): void {
|
|
184
|
+
if (0 < report.planned && report.excluded === report.planned && null != settle.t) {
|
|
185
|
+
return settle.t.skip('Live coverage incomplete: ' + liveSummary(report))
|
|
186
|
+
}
|
|
178
187
|
if (liveIncomplete(report)) {
|
|
179
188
|
if (false !== settle.strict || null == settle.t) return assertLiveReport(report)
|
|
180
189
|
return settle.t.skip('Live coverage incomplete (main.kit.test.live.strict is false): ' +
|
|
@@ -199,6 +208,11 @@ function createLiveTransport(timeoutMs = 30000) {
|
|
|
199
208
|
enter(next: LiveContext) { context = next },
|
|
200
209
|
fetch: async (input: any, init?: any) => {
|
|
201
210
|
const url = new URL(String(input))
|
|
211
|
+
const method = String(init?.method || 'GET').toUpperCase()
|
|
212
|
+
if ('TRUE' === process.env.VOXGIG_GETONLY_GUARD && 'GET' !== method) {
|
|
213
|
+
throw Object.assign(new Error('[GET-ONLY GUARD] blocked ' + method + ' ' + url.pathname),
|
|
214
|
+
{ code: GETONLY_CODE })
|
|
215
|
+
}
|
|
202
216
|
// A credential can travel as the agent (auth.name), so only whether
|
|
203
217
|
// the request carried one is recorded, never its value.
|
|
204
218
|
const request: LiveRequest = {
|
|
@@ -499,6 +499,31 @@ describe('PrimaryUtility', async () => {
|
|
|
499
499
|
})
|
|
500
500
|
|
|
501
501
|
|
|
502
|
+
// Nothing listens on port 9: a request the guard let through fails there.
|
|
503
|
+
test('fetcher-getonly-guard', async () => {
|
|
504
|
+
const liveClient = new (SDK as any)({ base: 'http://127.0.0.1:9' })
|
|
505
|
+
const liveUtility = liveClient.utility()
|
|
506
|
+
const ctx = liveUtility.makeContext({ opname: 'create' }, liveClient._rootctx)
|
|
507
|
+
ctx.client = liveClient
|
|
508
|
+
const url = 'http://127.0.0.1:9/planet/p1?apikey=GUARDKEY01'
|
|
509
|
+
|
|
510
|
+
const prior = process.env.VOXGIG_GETONLY_GUARD
|
|
511
|
+
process.env.VOXGIG_GETONLY_GUARD = 'TRUE'
|
|
512
|
+
try {
|
|
513
|
+
const refused = await liveUtility.fetcher(ctx, url, { method: 'POST', headers: {} })
|
|
514
|
+
equal(refused?.code, 'fetch_getonly_block')
|
|
515
|
+
ok(refused.message.includes('[GET-ONLY GUARD] blocked POST /planet/p1'), refused.message)
|
|
516
|
+
ok(!refused.message.includes('GUARDKEY01'))
|
|
517
|
+
|
|
518
|
+
await assert.rejects(liveUtility.fetcher(ctx, url, { method: 'GET', headers: {} }))
|
|
519
|
+
}
|
|
520
|
+
finally {
|
|
521
|
+
if (undefined === prior) delete process.env.VOXGIG_GETONLY_GUARD
|
|
522
|
+
else process.env.VOXGIG_GETONLY_GUARD = prior
|
|
523
|
+
}
|
|
524
|
+
})
|
|
525
|
+
|
|
526
|
+
|
|
502
527
|
test('makeError-no-throw', () => {
|
|
503
528
|
const ctx = makeFullCtx()
|
|
504
529
|
ctx.ctrl.throw = false
|