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