@voxgig/sdkgen 4.48.0 → 4.49.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 (174) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/dist/utility.js +9 -1
  4. package/dist/utility.js.map +1 -1
  5. package/package.json +1 -1
  6. package/project/.sdk/model/feature/secrets.aontu +3 -0
  7. package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
  8. package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
  9. package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
  10. package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
  11. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
  12. package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
  13. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
  14. package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
  15. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
  16. package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
  17. package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
  18. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
  19. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
  20. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
  21. package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
  22. package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
  23. package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
  24. package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
  25. package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
  26. package/project/.sdk/tm/c/feature/cache.c +16 -1
  27. package/project/.sdk/tm/c/feature/secrets.c +149 -18
  28. package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
  29. package/project/.sdk/tm/c/tests/feature_test.c +31 -0
  30. package/project/.sdk/tm/c/utility/make_spec.c +1 -1
  31. package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
  32. package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
  33. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
  34. package/project/.sdk/tm/clojure/src/sdk/core.clj +48 -10
  35. package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
  36. package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
  37. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
  38. package/project/.sdk/tm/cpp/core/types.hpp +1 -11
  39. package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
  40. package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
  41. package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
  42. package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
  43. package/project/.sdk/tm/cpp/utility/pipeline.hpp +52 -4
  44. package/project/.sdk/tm/csharp/core/Control.cs +0 -5
  45. package/project/.sdk/tm/csharp/core/Point.cs +6 -0
  46. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
  47. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
  48. package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
  49. package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
  50. package/project/.sdk/tm/csharp/utility/MakeSpec.cs +2 -2
  51. package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
  52. package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
  53. package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
  54. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
  55. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
  56. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +62 -6
  57. package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
  58. package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
  59. package/project/.sdk/tm/go/core/target.go +8 -0
  60. package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
  61. package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
  62. package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
  63. package/project/.sdk/tm/go/test/feature_test.go +32 -0
  64. package/project/.sdk/tm/go/utility/media.go +2 -2
  65. package/project/.sdk/tm/go/utility/prepare_body.go +37 -1
  66. package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
  67. package/project/.sdk/tm/java/core/Control.java +0 -5
  68. package/project/.sdk/tm/java/core/Point.java +7 -0
  69. package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
  70. package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
  71. package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
  72. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
  73. package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
  74. package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
  75. package/project/.sdk/tm/java/utility/MakeSpec.java +1 -1
  76. package/project/.sdk/tm/java/utility/Media.java +2 -2
  77. package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
  78. package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
  79. package/project/.sdk/tm/js/src/Point.js +2 -0
  80. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
  81. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
  82. package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +1 -1
  83. package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
  84. package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
  85. package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
  86. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  87. package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
  88. package/project/.sdk/tm/kotlin/core/Point.kt +7 -0
  89. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
  90. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
  91. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
  92. package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
  93. package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
  94. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
  95. package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +1 -1
  96. package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
  97. package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
  98. package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
  99. package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
  100. package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
  101. package/project/.sdk/tm/lua/utility/clean.lua +1 -0
  102. package/project/.sdk/tm/lua/utility/make_spec.lua +1 -1
  103. package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
  104. package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
  105. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
  106. package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
  107. package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -5
  108. package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
  109. package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
  110. package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
  111. package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
  112. package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
  113. package/project/.sdk/tm/perl/t/feature.t +24 -0
  114. package/project/.sdk/tm/perl/utility/make_spec.pm +1 -1
  115. package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
  116. package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
  117. package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
  118. package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
  119. package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
  120. package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
  121. package/project/.sdk/tm/php/utility/MakeSpec.php +2 -2
  122. package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
  123. package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
  124. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
  125. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
  126. package/project/.sdk/tm/py/pkg/utility/make_spec.py +1 -1
  127. package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
  128. package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
  129. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
  130. package/project/.sdk/tm/py/test/test_feature.py +18 -0
  131. package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
  132. package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
  133. package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
  134. package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
  135. package/project/.sdk/tm/rb/utility/make_spec.rb +1 -1
  136. package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
  137. package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
  138. package/project/.sdk/tm/rust/feature/cache.rs +15 -1
  139. package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
  140. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
  141. package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
  142. package/project/.sdk/tm/rust/utility/prepare_body.rs +51 -0
  143. package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
  144. package/project/.sdk/tm/scala/core/Control.scala +0 -5
  145. package/project/.sdk/tm/scala/core/Point.scala +3 -0
  146. package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
  147. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
  148. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
  149. package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
  150. package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
  151. package/project/.sdk/tm/scala/utility/MakeSpec.scala +1 -1
  152. package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
  153. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
  154. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
  155. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
  156. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
  157. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +1 -1
  158. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
  159. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
  160. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
  161. package/project/.sdk/tm/ts/src/Point.ts +3 -0
  162. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
  163. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
  164. package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +29 -0
  165. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
  166. package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
  167. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  168. package/project/.sdk/tm/zig/core/utility.zig +47 -4
  169. package/project/.sdk/tm/zig/feature/cache.zig +15 -1
  170. package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
  171. package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
  172. package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
  173. package/project/sdkgen-package.json +1 -1
  174. package/src/utility.ts +12 -1
@@ -28,7 +28,8 @@
28
28
  // This file lives in the `feature/` container on purpose: it is per-feature
29
29
  // source, and travels with the feature.
30
30
 
31
- import java.util.{ArrayList, LinkedHashMap, List => JList, Map => JMap}
31
+ import java.nio.charset.StandardCharsets
32
+ import java.util.{ArrayList, Base64, LinkedHashMap, List => JList, Map => JMap}
32
33
  import java.util.function.{BiFunction, Supplier}
33
34
 
34
35
  import scala.collection.mutable.ListBuffer
@@ -68,23 +69,29 @@ object SecretsTestMain {
68
69
  private def eqi(name: String, exp: Int, act: Int): Unit =
69
70
  check(name, exp == act, "expected " + exp + ", got " + act)
70
71
 
71
- // The credential header carries the SPEC's credential prefix, which a
72
- // TEMPLATE cannot know: an OpenAPI `http`/`bearer` scheme gives `Bearer
73
- // <token>`, an apiKey scheme the raw token. So assert on the CREDENTIAL and
74
- // let the prefix be whatever this SDK's API declares - pinning the whole
75
- // header value passes only for a prefix-less API, and this file ships to
76
- // every project that selects the feature.
77
- // HTTP Basic carries base64(key:secret) instead, and scala ships this suite
78
- // untrimmed, so it also runs for a Basic API.
79
- private def credentialIs(name: String, header: String, token: String): Unit = {
80
- val got = if (header == null) "" else header
81
- val basic = got.startsWith("Basic ") && (try {
82
- new String(java.util.Base64.getDecoder.decode(got.substring(6)), "UTF-8").startsWith(token + ":")
83
- } catch { case _: IllegalArgumentException => false })
84
- check(name, got == token || got.endsWith(" " + token) || basic,
85
- "expected the " + CREDHEADER + " header to carry " + token + ", got \"" + got + "\"")
72
+ // The form prepareAuth writes, from the DEFAULT client's auth: under Basic
73
+ // the token is the key half of the encoded pair, and a prefix is
74
+ // space-joined.
75
+ private lazy val CREDFORM: (String, Boolean) =
76
+ ProjectNameSDK.testSDK(null, null).optionsMap().get("auth") match {
77
+ case auth: JMap[_, _] =>
78
+ (auth.get("prefix") match { case s: String => s; case _ => "" },
79
+ java.lang.Boolean.TRUE == auth.get("basic"))
80
+ case _ => ("", false)
81
+ }
82
+
83
+ // The header value prepareAuth writes for a token.
84
+ private def credential(token: String, secret: String): String = {
85
+ val value =
86
+ if (CREDFORM._2) Base64.getEncoder.encodeToString((token + ":" + secret).getBytes(StandardCharsets.UTF_8))
87
+ else token
88
+ if ("" == CREDFORM._1) value else CREDFORM._1 + " " + value
86
89
  }
87
90
 
91
+ private def credentialIs(name: String, header: String, token: String, secret: String = ""): Unit =
92
+ eqs(name, credential(token, secret), if (header == null) "" else header,
93
+ "the " + CREDHEADER + " header carries " + token)
94
+
88
95
  // ---- the recording transport --------------------------------------------
89
96
  //
90
97
  // system.fetch for a LIVE client: one status per API call (the last
@@ -115,6 +122,7 @@ object SecretsTestMain {
115
122
  case s: String => s
116
123
  case _ => ""
117
124
  })
125
+ call.put("values", headers.values().toArray.map(v => String.valueOf(v)).mkString("\n"))
118
126
  call.put("body", fetchdef.get("body") match { case s: String => s; case _ => "" })
119
127
  call.put("redirect", fetchdef.get("redirect"))
120
128
  calls.add(call)
@@ -396,6 +404,16 @@ object SecretsTestMain {
396
404
  client.optionsMap().get("apikey") match { case s: String => s; case _ => "" })
397
405
  }
398
406
 
407
+ private def testResolvedKeyPaired(): Unit = {
408
+ val w = new Wire()
409
+ val client = secretsClient(w,
410
+ "secret" -> "PASS01",
411
+ "feature" -> secretsOpts(memchain("APIKEY" -> "CHAINKEY05")))
412
+
413
+ check("chain.paired.drive", driveOneCall(client, w), "no entity op reached the transport")
414
+ if (w.api().nonEmpty) credentialIs("chain.paired", w.authof(w.api().head), "CHAINKEY05", "PASS01")
415
+ }
416
+
399
417
  private def testCustomProvider(): Unit = {
400
418
  val w = new Wire()
401
419
  val prov = working("CUSTOM01")
@@ -907,6 +925,21 @@ object SecretsTestMain {
907
925
  "the caller sees the successful retry, got " + res)
908
926
  }
909
927
 
928
+ private def testExchangeRetryPaired(): Unit = {
929
+ val w = new Wire()
930
+ w.apistatus = List(401, 200)
931
+
932
+ val client = secretsClient(w, "secret" -> "PASS01",
933
+ "allow" -> jmap("op" -> "direct"), "feature" -> exchangeOpts())
934
+ client.direct(jmap("path" -> "/thing"))
935
+
936
+ eqi("exchange.paired.retried", 2, w.api().length)
937
+ if (2 <= w.api().length) {
938
+ credentialIs("exchange.paired.first", w.authof(w.api()(0)), "ACCESS01", "PASS01")
939
+ credentialIs("exchange.paired.retry", w.authof(w.api()(1)), "ACCESS02", "PASS01")
940
+ }
941
+ }
942
+
910
943
  private def testExchangeOnePurchaseManyRequests(): Unit = {
911
944
  val w = new Wire()
912
945
  val client = secretsClient(w, "allow" -> jmap("op" -> "direct"), "feature" -> exchangeOpts())
@@ -1010,17 +1043,27 @@ object SecretsTestMain {
1010
1043
  "an empty chain must refuse rather than send unauthenticated, got " + res)
1011
1044
  }
1012
1045
 
1013
- // Real listeners and the SDK's raw HTTP path: a stub follows nothing.
1014
- private def testExchangeRedirectRefused(): Unit = {
1046
+ // Two real listeners and the SDK's raw HTTP path: a stub follows nothing.
1047
+ // The origin answers the exchange as `answer` says and records what else
1048
+ // it gets.
1049
+ private final class Origins {
1015
1050
  val elsewhere = java.util.Collections.synchronizedList(new ArrayList[String]())
1016
1051
  val followed = java.util.Collections.synchronizedList(new ArrayList[String]())
1052
+ val exchanged = new java.util.concurrent.atomic.AtomicInteger()
1017
1053
  @volatile var answer: (Int, String) = (307, "")
1054
+ var origin = ""
1055
+ var base = ""
1056
+ var away = ""
1057
+ }
1058
+
1059
+ private def withOrigins(run: Origins => Unit): Unit = {
1060
+ val o = new Origins()
1018
1061
 
1019
1062
  val other = com.sun.net.httpserver.HttpServer.create(
1020
1063
  new java.net.InetSocketAddress("127.0.0.1", 0), 0)
1021
1064
  other.createContext("/", (ex: com.sun.net.httpserver.HttpExchange) => {
1022
1065
  val body = new String(ex.getRequestBody.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8)
1023
- elsewhere.add(ex.getRequestMethod + " " + ex.getRequestURI.getRawPath + " " + body)
1066
+ o.elsewhere.add(ex.getRequestMethod + " " + ex.getRequestURI.getRawPath + " " + body)
1024
1067
  val out = "{\"access_token\":\"ELSEWHERE01\"}".getBytes
1025
1068
  ex.getResponseHeaders.set("Content-Type", "application/json")
1026
1069
  ex.sendResponseHeaders(200, out.length.toLong)
@@ -1030,14 +1073,17 @@ object SecretsTestMain {
1030
1073
  val origin = com.sun.net.httpserver.HttpServer.create(
1031
1074
  new java.net.InetSocketAddress("127.0.0.1", 0), 0)
1032
1075
  origin.createContext("/", (ex: com.sun.net.httpserver.HttpExchange) => {
1033
- ex.getRequestBody.readAllBytes()
1034
- val path = ex.getRequestURI.getRawPath
1076
+ val body = new String(ex.getRequestBody.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8)
1077
+ val query = ex.getRequestURI.getRawQuery
1078
+ val path = ex.getRequestURI.getRawPath + (if (query == null) "" else "?" + query)
1035
1079
  if ("/api/auth/token" == path) {
1080
+ o.exchanged.incrementAndGet()
1081
+ val answer = o.answer
1036
1082
  ex.getResponseHeaders.set("Location", answer._2)
1037
1083
  ex.sendResponseHeaders(answer._1, -1)
1038
1084
  ex.close()
1039
1085
  } else {
1040
- followed.add(ex.getRequestMethod + " " + path)
1086
+ o.followed.add((ex.getRequestMethod + " " + path + " " + body).trim)
1041
1087
  val out = "{\"access_token\":\"MOVED01\"}".getBytes
1042
1088
  ex.getResponseHeaders.set("Content-Type", "application/json")
1043
1089
  ex.sendResponseHeaders(200, out.length.toLong)
@@ -1048,60 +1094,123 @@ object SecretsTestMain {
1048
1094
  other.start()
1049
1095
  origin.start()
1050
1096
 
1051
- val base = "http://127.0.0.1:" + origin.getAddress.getPort + "/api"
1052
- val away = "http://127.0.0.1:" + other.getAddress.getPort + "/api/auth/token"
1097
+ o.origin = "http://127.0.0.1:" + origin.getAddress.getPort
1098
+ o.base = o.origin + "/api"
1099
+ o.away = "http://127.0.0.1:" + other.getAddress.getPort + "/api/auth/token"
1053
1100
 
1054
- try {
1055
- val answers = List((307, away), (308, away), (302, away), (307, "/api/moved/token"))
1056
- val allowed = ListBuffer.empty[String]
1057
- var refused = 0
1058
-
1059
- for (a <- answers) {
1060
- answer = a
1061
- val client = withSecrets { extend =>
1062
- val opts = jmap(
1063
- "base" -> base,
1064
- "allow" -> jmap("op" -> "direct"),
1065
- "feature" -> jmap("secrets" -> jmap(
1066
- "active" -> java.lang.Boolean.TRUE,
1067
- "name" -> "refresh_token",
1068
- "exchange" -> jmap("active" -> java.lang.Boolean.TRUE, "refresh" -> "REFRESH01"))))
1069
- if (extend) opts.put("extend", jlist(new SecretsFeature()))
1070
- new ProjectNameSDK(opts)
1071
- }
1101
+ try run(o)
1102
+ finally {
1103
+ origin.stop(0)
1104
+ other.stop(0)
1105
+ }
1106
+ }
1072
1107
 
1073
- val message =
1074
- try {
1075
- val res = client.direct(jmap("path" -> "/thing"))
1076
- res.get("err") match {
1077
- case err: Throwable => errtext(err)
1078
- case _ => String.valueOf(res)
1079
- }
1080
- }
1081
- catch { case err: RuntimeException => errtext(err) }
1082
-
1083
- if (message.contains("token exchange failed: " + a._1 + " from " + base + "/auth/token")) {
1084
- refused += 1
1085
- } else {
1086
- allowed += (a._1.toString + " to " + a._2 + ": " + message)
1087
- }
1108
+ private def redirectClient(o: Origins, exchange: (String, Object)*): ProjectNameSDK =
1109
+ withSecrets { extend =>
1110
+ val x = jmap("active" -> java.lang.Boolean.TRUE, "refresh" -> "REFRESH01")
1111
+ for ((k, v) <- exchange) x.put(k, v)
1112
+ val opts = jmap(
1113
+ "base" -> o.base,
1114
+ "allow" -> jmap("op" -> "direct"),
1115
+ "feature" -> jmap("secrets" -> jmap(
1116
+ "active" -> java.lang.Boolean.TRUE,
1117
+ "name" -> "refresh_token",
1118
+ "exchange" -> x)))
1119
+ if (extend) opts.put("extend", jlist(new SecretsFeature()))
1120
+ new ProjectNameSDK(opts)
1121
+ }
1122
+
1123
+ // The direct call's result, and its error message (the result when none).
1124
+ private def directOutcome(client: ProjectNameSDK): (JMap[String, Object], String) =
1125
+ try {
1126
+ val res = client.direct(jmap("path" -> "/thing"))
1127
+ res.get("err") match {
1128
+ case err: Throwable => (res, errtext(err))
1129
+ case _ => (res, String.valueOf(res))
1088
1130
  }
1131
+ }
1132
+ catch { case err: RuntimeException => (null, errtext(err)) }
1133
+
1134
+ private def testExchangeRedirectRefused(): Unit = withOrigins { o =>
1135
+ val answers = List((307, o.away), (308, o.away), (302, o.away), (307, "/api/moved/token"))
1136
+ val allowed = ListBuffer.empty[String]
1137
+ var refused = 0
1089
1138
 
1090
- println("secrets: exchange refused " + refused + " redirect(s), " +
1091
- (elsewhere.size() + followed.size()) + " followed")
1139
+ for (a <- answers) {
1140
+ o.answer = a
1141
+ val message = directOutcome(redirectClient(o))._2
1092
1142
 
1093
- check("exchange.redirect.elsewhere", elsewhere.isEmpty,
1094
- "the exchange reached another origin: " + elsewhere)
1095
- check("exchange.redirect.followed", followed.isEmpty,
1096
- "a request followed a refused exchange: " + followed)
1097
- check("exchange.redirect.allowed", allowed.isEmpty,
1098
- "a redirect was not a failed exchange: " + allowed.mkString("; "))
1099
- eqi("exchange.redirect.refused", answers.length, refused)
1143
+ if (message.contains("token exchange failed: " + a._1 + " from " + o.base + "/auth/token")) {
1144
+ refused += 1
1145
+ } else {
1146
+ allowed += (a._1.toString + " to " + a._2 + ": " + message)
1147
+ }
1100
1148
  }
1101
- finally {
1102
- origin.stop(0)
1103
- other.stop(0)
1149
+
1150
+ println("secrets: exchange refused " + refused + " redirect(s), " +
1151
+ (o.elsewhere.size() + o.followed.size()) + " followed")
1152
+
1153
+ check("exchange.redirect.elsewhere", o.elsewhere.isEmpty,
1154
+ "the exchange reached another origin: " + o.elsewhere)
1155
+ check("exchange.redirect.followed", o.followed.isEmpty,
1156
+ "a request followed a refused exchange: " + o.followed)
1157
+ check("exchange.redirect.allowed", allowed.isEmpty,
1158
+ "a redirect was not a failed exchange: " + allowed.mkString("; "))
1159
+ eqi("exchange.redirect.refused", answers.length, refused)
1160
+ }
1161
+
1162
+ private def testExchangeRedirectSameOrigin(): Unit = withOrigins { o =>
1163
+ val sent = " {\"refresh_token\":\"REFRESH01\"}"
1164
+ // Each case: the status, the Location, and the path the exchange is
1165
+ // asked again at, or null where the redirect is refused.
1166
+ val cases: List[(Int, String, String)] = List(
1167
+ (307, "/api/moved/token", "/api/moved/token"),
1168
+ (308, o.origin + "/api/moved/token", "/api/moved/token"),
1169
+ // A Location of a query alone keeps the path that answered.
1170
+ (307, "?step=2", "/api/auth/token?step=2"),
1171
+ (307, o.away, null),
1172
+ (302, "/api/moved/token", null),
1173
+ (307, "/api/auth/token", null),
1174
+ )
1175
+
1176
+ val wrong = ListBuffer.empty[String]
1177
+ var followed = 0
1178
+ var refused = 0
1179
+ var looped = 0
1180
+
1181
+ for ((status, location, path) <- cases) {
1182
+ o.answer = (status, location)
1183
+ o.followed.clear()
1184
+ o.exchanged.set(0)
1185
+
1186
+ val (res, message) = directOutcome(redirectClient(o, "redirect" -> "same-origin"))
1187
+ val seen = status.toString + " to " + location + ": " + message + " " + o.followed
1188
+
1189
+ if (path != null) {
1190
+ if (res != null && java.lang.Boolean.TRUE == res.get("ok") &&
1191
+ 2 == o.followed.size() && ("POST " + path + sent) == o.followed.get(0)) followed += 1
1192
+ else wrong += seen
1193
+ } else if (o.followed.isEmpty && message.contains(
1194
+ "token exchange failed: " + status + " from " + o.base + "/auth/token")) {
1195
+ refused += 1
1196
+ } else {
1197
+ wrong += seen
1198
+ }
1199
+
1200
+ if ("/api/auth/token" == location) looped = o.exchanged.get()
1104
1201
  }
1202
+
1203
+ println("secrets: exchange opt-in followed " + followed +
1204
+ " redirect(s) on its own origin, refused " + refused + ", " +
1205
+ o.elsewhere.size() + " elsewhere")
1206
+
1207
+ check("exchange.sameorigin.elsewhere", o.elsewhere.isEmpty,
1208
+ "the exchange reached another origin: " + o.elsewhere)
1209
+ check("exchange.sameorigin.wrong", wrong.isEmpty, wrong.mkString("; "))
1210
+ eqi("exchange.sameorigin.followed", 3, followed)
1211
+ eqi("exchange.sameorigin.refused", 3, refused)
1212
+ // A redirect to itself stops at the hop limit.
1213
+ eqi("exchange.sameorigin.looped", 6, looped)
1105
1214
  }
1106
1215
 
1107
1216
  // TEST MODE BUYS NOTHING and needs no token endpoint.
@@ -1115,18 +1224,61 @@ object SecretsTestMain {
1115
1224
  eqs("exchange.testmode.token", "test-access_token", secretsFeatureOf(client).credential())
1116
1225
  }
1117
1226
 
1227
+ // Off by the config where it declares no auth, else by `auth: null`: either
1228
+ // way the feature places no credential, buys no token and retries nothing.
1229
+ private def testAuthOff(declared: Boolean): Unit = {
1230
+ val secrets = List("OFFKEY01", "OFFKEY02", "OFFREFRESH01", "ACCESS01")
1231
+ def carries(call: JMap[String, Object]): Boolean = {
1232
+ val values = String.valueOf(call.get("values"))
1233
+ java.lang.Boolean.TRUE == call.get("has") || secrets.exists(s => values.contains(s))
1234
+ }
1235
+ val sent = ListBuffer.empty[JMap[String, Object]]
1236
+ var bought = 0
1237
+
1238
+ val scenarios: List[(String, List[(String, Object)], List[Int])] = List(
1239
+ ("a key the chain resolves",
1240
+ List("feature" -> secretsOpts(memchain("APIKEY" -> "OFFKEY01"))), List(200)),
1241
+ ("an explicit apikey",
1242
+ List("apikey" -> "OFFKEY02", "feature" -> secretsOpts(jlist())), List(200)),
1243
+ ("a refusal", List("feature" -> secretsOpts(memchain("REFRESH_TOKEN" -> "OFFREFRESH01"),
1244
+ "name" -> "refresh_token", "exchange" -> jmap("active" -> java.lang.Boolean.TRUE))), List(401)),
1245
+ )
1246
+
1247
+ for ((what, opts, statuses) <- scenarios) {
1248
+ val w = new Wire()
1249
+ w.apistatus = statuses
1250
+ val off: List[(String, Object)] = if (declared) List("auth" -> null) else Nil
1251
+ val client = secretsClient(w, (("allow" -> jmap("op" -> "direct")) :: opts ++ off)*)
1252
+
1253
+ client.direct(jmap("path" -> "/thing"))
1254
+
1255
+ eqi("authoff.noretry: " + what, 1, w.api().length)
1256
+ eqi("authoff.nobuy: " + what, 0, w.token().length)
1257
+ check("authoff.nocred: " + what, w.api().nonEmpty && !carries(w.api().head),
1258
+ "a credential was sent with auth off: " + w.report())
1259
+ eqs("authoff.unresolved: " + what, "", secretsFeatureOf(client).credential())
1260
+
1261
+ sent ++= w.api()
1262
+ bought += w.token().length
1263
+ }
1264
+
1265
+ println("secrets: auth off by " + (if (declared) "option" else "config") + ": " +
1266
+ sent.length + " request(s), " + sent.count(carries) + " credential(s), " +
1267
+ bought + " token(s)")
1268
+ }
1269
+
1118
1270
  // =========================================================================
1119
1271
 
1120
1272
  def main(args: Array[String]): Unit = {
1121
1273
  // Read from the config, never from a probe: an SDK whose config declares
1122
1274
  // no auth places no credential, and these tests assert on the one it places.
1123
- if (!SCALAPACKAGE.core.Config.sharedConfig().get("options").asInstanceOf[JMap[String, Object]]
1124
- .containsKey("auth")) {
1275
+ val declared = SCALAPACKAGE.core.Config.sharedConfig().get("options").asInstanceOf[JMap[String, Object]]
1276
+ .containsKey("auth")
1277
+ if (!declared) {
1125
1278
  println("SKIP secrets: this SDK's config declares no auth, so it places no credential")
1126
- return
1127
1279
  }
1128
1280
 
1129
- val cases: List[(String, () => Unit)] = List(
1281
+ val placing: List[(String, () => Unit)] = List(
1130
1282
  "inactive" -> testInactive,
1131
1283
  "optionWins" -> testOptionWins,
1132
1284
  "omittedDefers" -> testOmittedDefers,
@@ -1152,8 +1304,13 @@ object SecretsTestMain {
1152
1304
  "exchangeAuthNullNotRetried" -> testExchangeAuthNullNotRetried,
1153
1305
  "exchangeNoRefresh" -> testExchangeNoRefresh,
1154
1306
  "exchangeRedirectRefused" -> testExchangeRedirectRefused,
1307
+ "exchangeRedirectSameOrigin" -> testExchangeRedirectSameOrigin,
1155
1308
  "exchangeTestMode" -> testExchangeTestMode,
1309
+ "resolvedKeyPaired" -> testResolvedKeyPaired,
1310
+ "exchangeRetryPaired" -> testExchangeRetryPaired,
1156
1311
  )
1312
+ val cases: List[(String, () => Unit)] =
1313
+ (if (declared) placing else Nil) :+ ("authOff" -> (() => testAuthOff(declared)))
1157
1314
 
1158
1315
  for ((name, body) <- cases) {
1159
1316
  try body()
@@ -96,7 +96,7 @@ object Fetcher {
96
96
  var next: URI = null
97
97
  try {
98
98
  from = URI.create(fullurl)
99
- next = from.resolve(URI.create(location.asInstanceOf[String].trim))
99
+ next = resolveLocation(from, location.asInstanceOf[String])
100
100
  }
101
101
  catch { case _: RuntimeException => return res }
102
102
 
@@ -140,6 +140,18 @@ object Fetcher {
140
140
  followRedirects(ctx, next.toString, nextdef, hops + 1)
141
141
  }
142
142
 
143
+ // A reference of a query alone keeps the path, as RFC 3986 resolves it;
144
+ // URI.resolve follows RFC 2396 there and drops the last segment.
145
+ def resolveLocation(from: URI, location: String): URI = {
146
+ val loc = location.trim
147
+ if (loc.startsWith("?")) {
148
+ val base = from.toString
149
+ val cut = base.indexWhere(c => c == '?' || c == '#')
150
+ URI.create((if (cut < 0) base else base.substring(0, cut)) + loc)
151
+ }
152
+ else from.resolve(URI.create(loc))
153
+ }
154
+
143
155
  // For a caller with no operation context, as the secrets exchange is: a
144
156
  // redirect follows the same rules, a credential told by the clean defaults.
145
157
  def defaultHttpFetch(fullurl: String, fetchdef: JMap[String, Object]): JMap[String, Object] =
@@ -54,7 +54,7 @@ object MakeSpec {
54
54
  if ("graphql" == pkind) {
55
55
  // GraphQL addresses one endpoint: no path parts, no query string, and
56
56
  // the body carries the operation. prepareBody is skipped deliberately
57
- // — it only emits a body for data-input ops, whereas every GraphQL op
57
+ // — it builds only a REST body, whereas every GraphQL op
58
58
  // posts one, including load/list/remove.
59
59
  ctx.spec.body = utility.graphqlBody(ctx)
60
60
  ctx.spec.path = ""
@@ -80,21 +80,20 @@ object PrepareQuery {
80
80
  }
81
81
  case _ =>
82
82
  }
83
- // A header or cookie name leaves the query unless a query parameter shares it: then both are sent.
83
+ // A header or cookie name leaves the query for the headers, and a field the point's body
84
+ // declares leaves it for the body, unless a query parameter shares it: then both are sent.
84
85
  val declared = new ArrayList[Object]()
85
86
  Struct.getpath(point, java.util.List.of("args", "query")) match {
86
87
  case l: JList[_] => val dit = l.iterator(); while (dit.hasNext) declared.add(Struct.getprop(dit.next(), "name"))
87
88
  case _ =>
88
89
  }
89
- for (located <- Seq(Struct.getpath(point, java.util.List.of("args", "header")),
90
- Struct.getpath(point, java.util.List.of("args", "cookie")))) located match {
91
- case l: JList[_] =>
92
- val hit = l.iterator()
93
- while (hit.hasNext) {
94
- Struct.getprop(hit.next(), "name") match { case s: String if !declared.contains(s) => params.add(s); case _ => }
95
- }
96
- case _ =>
90
+ val located = Seq(Struct.getpath(point, java.util.List.of("args", "header")),
91
+ Struct.getpath(point, java.util.List.of("args", "cookie"))).flatMap {
92
+ case l: JList[_] => l.toArray.toSeq.map(ad => Struct.getprop(ad, "name"))
93
+ case _ => Seq.empty
97
94
  }
95
+ val fields = Struct.getprop(point, "fields") match { case l: JList[_] => l.toArray.toSeq; case _ => Seq.empty }
96
+ (located ++ fields).foreach { case s: String if !declared.contains(s) => params.add(s); case _ => }
98
97
  }
99
98
 
100
99
  // A query parameter travels under the name the definition gives it, its
@@ -222,9 +221,51 @@ object PrepareHeaders {
222
221
 
223
222
  object PrepareBody {
224
223
  def prepareBody(ctx: Context): Object =
225
- if ("data" != ctx.op.input) null
226
- else if (Media.isRawRequest(ctx.point)) Media.rawBody(ctx.reqdata)
227
- else ctx.utility.transformRequest(ctx)
224
+ if ("data" == ctx.op.input) {
225
+ if (Media.isRawRequest(ctx.point)) Media.rawBody(ctx.reqdata)
226
+ else ctx.utility.transformRequest(ctx)
227
+ }
228
+ else Struct.getprop(ctx.point, "fields") match {
229
+ case fields: JList[_] if !fields.isEmpty => matchBody(ctx, fields)
230
+ case _ => null
231
+ }
232
+
233
+ // A list, load or remove routed to a method with a body sends the match
234
+ // fields that body declares, never a path parameter, and never a header,
235
+ // cookie or query argument the body does not also declare as a field.
236
+ private def matchBody(ctx: Context, fields: JList[_]): JMap[String, Object] = {
237
+ val routed = new ArrayList[Object]()
238
+ Struct.getprop(ctx.point, "params") match { case l: JList[_] => routed.addAll(l.asInstanceOf[JList[Object]]); case _ => }
239
+ Struct.getpath(ctx.point, java.util.List.of("args", "params")) match {
240
+ case l: JList[_] =>
241
+ val pit = l.iterator()
242
+ while (pit.hasNext) routed.add(Struct.getprop(pit.next(), "name"))
243
+ case _ =>
244
+ }
245
+ for (kind <- Seq("header", "cookie", "query")) {
246
+ Struct.getpath(ctx.point, java.util.List.of("args", kind)) match {
247
+ case l: JList[_] =>
248
+ val ait = l.iterator()
249
+ while (ait.hasNext) {
250
+ val ad = ait.next()
251
+ if (java.lang.Boolean.TRUE != Struct.getprop(ad, "field")) routed.add(Struct.getprop(ad, "name"))
252
+ }
253
+ case _ =>
254
+ }
255
+ }
256
+
257
+ val body = new LinkedHashMap[String, Object]()
258
+ val fit = fields.iterator()
259
+ while (fit.hasNext) {
260
+ fit.next() match {
261
+ case name: String =>
262
+ val v = Struct.getprop(ctx.reqmatch, name, null)
263
+ if (v != null && "$action" != name && !routed.contains(name)) body.put(name, v)
264
+ case _ =>
265
+ }
266
+ }
267
+ body
268
+ }
228
269
  }
229
270
 
230
271
  // NO `object PrepareAuth` HERE, and its absence is the point.
@@ -11,10 +11,5 @@ public final class Control {
11
11
  public var actor: String = ""
12
12
  public var paging: VMap? = nil
13
13
 
14
- // Outbound streaming marker: the entity `stream` method sets this to the
15
- // caller-supplied streamable payload so the request builder / transport can
16
- // stream it as the request body.
17
- public var streamOut: Value? = nil
18
-
19
14
  public init() {}
20
15
  }
@@ -16,6 +16,8 @@ public final class Point {
16
16
  public var relations: VList? = nil
17
17
  public var alias: VMap = VMap()
18
18
  public var transform: VMap = VMap()
19
+ // The fields a list, load or remove sends in a request body.
20
+ public var fields: VList? = nil
19
21
 
20
22
  public init(_ pointmap: VMap?) {
21
23
  args = VMap()
@@ -35,5 +37,6 @@ public final class Point {
35
37
  if let rl = getprop(pm, .string("relations")).asList { relations = rl }
36
38
  if let al = getprop(pm, .string("alias")).asMap { alias = al }
37
39
  if let tf = getprop(pm, .string("transform")).asMap { transform = tf }
40
+ if let fl = getprop(pm, .string("fields")).asList { fields = fl }
38
41
  }
39
42
  }
@@ -87,6 +87,12 @@ public final class CacheFeature: BaseFeature {
87
87
  err = error
88
88
  }
89
89
 
90
+ // A body that declares another type than JSON passes by, unread.
91
+ if err == nil && CacheFeature.storable(res) && !CacheFeature.json(res) {
92
+ bypass += 1
93
+ return res
94
+ }
95
+
90
96
  if err == nil && CacheFeature.storable(res) {
91
97
  let snap = CacheFeature.snapshot(res)
92
98
  let ttl = foptInt(options, "ttl", 5000)
@@ -113,6 +119,11 @@ public final class CacheFeature: BaseFeature {
113
119
  return has && status >= 200 && status < 300 && gp(res, "unreadable") != .bool(true)
114
120
  }
115
121
 
122
+ private static func json(_ res: Value) -> Bool {
123
+ let type = Response.headerValue(gp(res, "headers"), "content-type")
124
+ return type.isEmpty || isJsonMedia(.string(type))
125
+ }
126
+
116
127
  private static func snapshot(_ res: Value) -> CacheSnapshot {
117
128
  let snap = CacheSnapshot()
118
129