@voxgig/sdkgen 4.48.1 → 4.49.1
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/package.json +1 -1
- package/project/.sdk/model/feature/secrets.aontu +3 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
- package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
- package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
- package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
- package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
- package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
- package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
- package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
- package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
- package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
- package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
- package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
- package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
- package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
- package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
- package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
- package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
- package/project/.sdk/tm/c/feature/cache.c +16 -1
- package/project/.sdk/tm/c/feature/secrets.c +149 -18
- package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
- package/project/.sdk/tm/c/tests/feature_test.c +31 -0
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
- package/project/.sdk/tm/clojure/src/sdk/core.clj +55 -6
- package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
- package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
- package/project/.sdk/tm/cpp/core/types.hpp +1 -11
- package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
- package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
- package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
- package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
- package/project/.sdk/tm/csharp/core/Control.cs +0 -5
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
- package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
- package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
- package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
- package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
- package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
- package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
- package/project/.sdk/tm/go/test/feature_test.go +32 -0
- package/project/.sdk/tm/go/utility/media.go +2 -2
- package/project/.sdk/tm/java/core/Control.java +0 -5
- package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
- package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
- package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
- package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
- package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
- package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
- package/project/.sdk/tm/java/utility/Media.java +2 -2
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
- package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
- package/project/.sdk/tm/js/test/feature.test.js +17 -0
- package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
- package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
- package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
- package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
- package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
- package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
- package/project/.sdk/tm/lua/utility/clean.lua +1 -0
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
- package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
- package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
- package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
- package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
- package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
- package/project/.sdk/tm/perl/t/feature.t +24 -0
- package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
- package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
- package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
- package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
- package/project/.sdk/tm/py/test/test_feature.py +18 -0
- package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
- package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
- package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
- package/project/.sdk/tm/rust/feature/cache.rs +15 -1
- package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
- package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
- package/project/.sdk/tm/scala/core/Control.scala +0 -5
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
- package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
- package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
- package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
- package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
- package/project/.sdk/tm/zig/feature/cache.zig +15 -1
- package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
- package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
- package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
- package/project/sdkgen-package.json +1 -1
|
@@ -8,6 +8,8 @@ import java.net.http.HttpResponse;
|
|
|
8
8
|
import java.nio.charset.StandardCharsets;
|
|
9
9
|
import java.time.Duration;
|
|
10
10
|
import java.util.ArrayList;
|
|
11
|
+
import java.util.Base64;
|
|
12
|
+
import java.util.Locale;
|
|
11
13
|
import java.util.LinkedHashMap;
|
|
12
14
|
import java.util.List;
|
|
13
15
|
import java.util.Map;
|
|
@@ -19,6 +21,7 @@ import JAVAPACKAGE.core.Config;
|
|
|
19
21
|
import JAVAPACKAGE.core.Context;
|
|
20
22
|
import JAVAPACKAGE.core.SdkClient;
|
|
21
23
|
import JAVAPACKAGE.core.Utility;
|
|
24
|
+
import JAVAPACKAGE.utility.Fetcher;
|
|
22
25
|
import JAVAPACKAGE.feature.secrets.plugin.Definition;
|
|
23
26
|
import JAVAPACKAGE.feature.secrets.sekreto.Json;
|
|
24
27
|
import JAVAPACKAGE.feature.secrets.sekreto.Sekreto;
|
|
@@ -84,6 +87,11 @@ public class SecretsFeature extends BaseFeature {
|
|
|
84
87
|
// client clones for optionsMap). READ ONLY: this feature never writes it.
|
|
85
88
|
private Map<String, Object> liveopts;
|
|
86
89
|
|
|
90
|
+
// What prepareAuth was generated from: the config declares auth only
|
|
91
|
+
// where it places a credential, and Basic only where it composes one.
|
|
92
|
+
private boolean declared;
|
|
93
|
+
private boolean basic;
|
|
94
|
+
|
|
87
95
|
private String secretname = "apikey";
|
|
88
96
|
private boolean cache = true;
|
|
89
97
|
private Sekreto sek;
|
|
@@ -128,8 +136,11 @@ public class SecretsFeature extends BaseFeature {
|
|
|
128
136
|
String response;
|
|
129
137
|
List<Integer> statuses;
|
|
130
138
|
int retries;
|
|
139
|
+
String redirect;
|
|
131
140
|
}
|
|
132
141
|
|
|
142
|
+
private static final int REDIRECT_MAX = 5;
|
|
143
|
+
|
|
133
144
|
// One shared in-flight resolution: late arrivals await the latch and
|
|
134
145
|
// read the outcome.
|
|
135
146
|
private static final class SecretsCall {
|
|
@@ -153,6 +164,11 @@ public class SecretsFeature extends BaseFeature {
|
|
|
153
164
|
this.liveopts = ctx.options == null ? new LinkedHashMap<>() : ctx.options;
|
|
154
165
|
this.active = true;
|
|
155
166
|
|
|
167
|
+
Object configopts = ctx.config == null ? null : ctx.config.get("options");
|
|
168
|
+
Object authdecl = configopts instanceof Map ? ((Map<?, ?>) configopts).get("auth") : null;
|
|
169
|
+
this.declared = authdecl instanceof Map;
|
|
170
|
+
this.basic = this.declared && Boolean.TRUE.equals(((Map<?, ?>) authdecl).get("basic"));
|
|
171
|
+
|
|
156
172
|
this.secretname = FeatureOptions.foptStr(options, "name", "apikey");
|
|
157
173
|
this.cache = FeatureOptions.foptBool(options, "cache", true);
|
|
158
174
|
|
|
@@ -164,6 +180,8 @@ public class SecretsFeature extends BaseFeature {
|
|
|
164
180
|
x.request = FeatureOptions.foptStr(xopts, "request", "refresh_token");
|
|
165
181
|
x.response = FeatureOptions.foptStr(xopts, "response", "access_token");
|
|
166
182
|
x.retries = FeatureOptions.foptInt(xopts, "retries", 1);
|
|
183
|
+
x.redirect = "same-origin".equals(FeatureOptions.foptStr(xopts, "redirect", "refuse"))
|
|
184
|
+
? "same-origin" : "refuse";
|
|
167
185
|
x.statuses = new ArrayList<>();
|
|
168
186
|
List<Object> rawstatuses = FeatureOptions.foptList(xopts, "statuses");
|
|
169
187
|
if (rawstatuses != null) {
|
|
@@ -388,11 +406,17 @@ public class SecretsFeature extends BaseFeature {
|
|
|
388
406
|
}
|
|
389
407
|
}
|
|
390
408
|
|
|
409
|
+
// prepareAuth's decision: auth the config declares, not suppressed by
|
|
410
|
+
// `auth: null`.
|
|
411
|
+
private boolean authon() {
|
|
412
|
+
return this.declared && this.liveopts.get("auth") != null;
|
|
413
|
+
}
|
|
414
|
+
|
|
391
415
|
// resolveonce resolves once, reporting whether a credential came out of
|
|
392
416
|
// it. That boolean is the whole of what resolve() needs to tell a
|
|
393
417
|
// cacheable HIT from a miss it must not keep.
|
|
394
418
|
private boolean resolveonce() {
|
|
395
|
-
if (this.sek == null) {
|
|
419
|
+
if (this.sek == null || !authon()) {
|
|
396
420
|
return false;
|
|
397
421
|
}
|
|
398
422
|
|
|
@@ -438,17 +462,6 @@ public class SecretsFeature extends BaseFeature {
|
|
|
438
462
|
return true;
|
|
439
463
|
}
|
|
440
464
|
|
|
441
|
-
// `auth: null` is the documented way to send NO credential, and a
|
|
442
|
-
// purchase is a credential-bearing call: the refresh token goes to the
|
|
443
|
-
// token endpoint in the request body. withrefresh honours suppression
|
|
444
|
-
// for the RETRY, but it runs after this - by then the refresh token has
|
|
445
|
-
// already left the process, and no later check can call it back. The
|
|
446
|
-
// suppression has to be honoured here, before the first purchase, or it
|
|
447
|
-
// only ever half-held.
|
|
448
|
-
if (this.liveopts.get("auth") == null) {
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
465
|
buy();
|
|
453
466
|
|
|
454
467
|
return true;
|
|
@@ -465,12 +478,9 @@ public class SecretsFeature extends BaseFeature {
|
|
|
465
478
|
private Object withrefresh(Context ctx, String url, Map<String, Object> fetchdef,
|
|
466
479
|
Utility.FetcherFn inner) {
|
|
467
480
|
|
|
468
|
-
//
|
|
469
|
-
//
|
|
470
|
-
|
|
471
|
-
// cannot be fixed by buying one - retrying would transmit exactly the
|
|
472
|
-
// credential the caller suppressed.
|
|
473
|
-
if (this.liveopts.get("auth") == null) {
|
|
481
|
+
// A refusal of an unauthenticated request is not an expired token, and
|
|
482
|
+
// retrying would transmit the credential that auth off withholds.
|
|
483
|
+
if (!authon()) {
|
|
474
484
|
return inner.fetch(ctx, url, fetchdef);
|
|
475
485
|
}
|
|
476
486
|
|
|
@@ -549,7 +559,7 @@ public class SecretsFeature extends BaseFeature {
|
|
|
549
559
|
// The options map is FROZEN after construction (this feature never
|
|
550
560
|
// writes it), so the raw read is safe on any thread.
|
|
551
561
|
Object rawauth = this.liveopts.get("auth");
|
|
552
|
-
if (!(rawauth instanceof Map)) {
|
|
562
|
+
if (!authon() || !(rawauth instanceof Map)) {
|
|
553
563
|
headers.remove("authorization");
|
|
554
564
|
return;
|
|
555
565
|
}
|
|
@@ -559,17 +569,30 @@ public class SecretsFeature extends BaseFeature {
|
|
|
559
569
|
String name = nameRaw instanceof String && !"".equals(nameRaw)
|
|
560
570
|
? ((String) nameRaw).toLowerCase(java.util.Locale.ROOT) : "authorization";
|
|
561
571
|
|
|
572
|
+
String value = this.basic && Boolean.TRUE.equals(((Map<String, Object>) rawauth).get("basic"))
|
|
573
|
+
? pair(token) : token;
|
|
574
|
+
|
|
562
575
|
Object prefixRaw = ((Map<String, Object>) rawauth).get("prefix");
|
|
563
576
|
String prefix = prefixRaw instanceof String ? (String) prefixRaw : "";
|
|
564
577
|
|
|
565
578
|
if ("".equals(prefix)) {
|
|
566
|
-
headers.put(name,
|
|
579
|
+
headers.put(name, value);
|
|
567
580
|
}
|
|
568
581
|
else {
|
|
569
|
-
headers.put(name, prefix + " " +
|
|
582
|
+
headers.put(name, prefix + " " + value);
|
|
570
583
|
}
|
|
571
584
|
}
|
|
572
585
|
|
|
586
|
+
// Under Basic the token is the key half, as apikey is: prepareAuth's pair.
|
|
587
|
+
private String pair(String token) {
|
|
588
|
+
Object secret = this.liveopts.get("secret");
|
|
589
|
+
String pair = Base64.getEncoder().encodeToString(
|
|
590
|
+
(token + ":" + (secret instanceof String ? (String) secret : ""))
|
|
591
|
+
.getBytes(StandardCharsets.UTF_8));
|
|
592
|
+
register(pair);
|
|
593
|
+
return pair;
|
|
594
|
+
}
|
|
595
|
+
|
|
573
596
|
// buy an access token with the refresh token. Concurrent callers share
|
|
574
597
|
// the ONE in-flight purchase; the slot is cleared once settled, so the
|
|
575
598
|
// next expiry buys a fresh token rather than replaying this result.
|
|
@@ -689,24 +712,24 @@ public class SecretsFeature extends BaseFeature {
|
|
|
689
712
|
fetchdef.put("method", x.method);
|
|
690
713
|
fetchdef.put("headers", headers);
|
|
691
714
|
fetchdef.put("body", Json.stringify(payload));
|
|
692
|
-
// Never followed: a redirect would carry the refresh token on.
|
|
715
|
+
// Never followed by the client: a redirect would carry the refresh token on.
|
|
693
716
|
fetchdef.put("redirect", "manual");
|
|
694
717
|
|
|
695
718
|
// Deliberately NOT the SDK transport. The transport is what this
|
|
696
719
|
// feature wraps, and sending the token request back through it would
|
|
697
720
|
// recurse on the first expiry - and would route the exchange through
|
|
698
721
|
// the test mock, which knows nothing about it.
|
|
699
|
-
Object res;
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
res =
|
|
722
|
+
Object res = exchangeFetch(fetchRaw, url, fetchdef);
|
|
723
|
+
|
|
724
|
+
// By option alone, and only while the exchange stays on its own origin.
|
|
725
|
+
String at = url;
|
|
726
|
+
for (int hops = 0; "same-origin".equals(x.redirect) && hops < REDIRECT_MAX; hops++) {
|
|
727
|
+
String next = moved(url, at, res);
|
|
728
|
+
if (next == null) {
|
|
729
|
+
break;
|
|
730
|
+
}
|
|
731
|
+
at = next;
|
|
732
|
+
res = exchangeFetch(fetchRaw, at, fetchdef);
|
|
710
733
|
}
|
|
711
734
|
|
|
712
735
|
int status = FeatureOptions.fresStatus(res);
|
|
@@ -741,6 +764,51 @@ public class SecretsFeature extends BaseFeature {
|
|
|
741
764
|
return token;
|
|
742
765
|
}
|
|
743
766
|
|
|
767
|
+
private static Object exchangeFetch(Object fetchRaw, String url,
|
|
768
|
+
Map<String, Object> fetchdef) {
|
|
769
|
+
if (fetchRaw instanceof BiFunction) {
|
|
770
|
+
return ((BiFunction<String, Map<String, Object>, Object>) fetchRaw)
|
|
771
|
+
.apply(url, fetchdef);
|
|
772
|
+
}
|
|
773
|
+
// No custom transport supplied - the ordinary case. makeOptions
|
|
774
|
+
// leaves system.fetch unset, so the exchange gets its own raw HTTP
|
|
775
|
+
// path: requiring a custom transport for the COMMON case would
|
|
776
|
+
// reject every live token purchase before a request was made.
|
|
777
|
+
return rawExchangeFetch(url, fetchdef);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
// Where a 307 or 308 points, when that is on the exchange's own origin. Any
|
|
781
|
+
// other redirect would drop the body or leave the origin.
|
|
782
|
+
private static String moved(String url, String at, Object res) {
|
|
783
|
+
int status = FeatureOptions.fresStatus(res);
|
|
784
|
+
if (307 != status && 308 != status) {
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
String location = FeatureOptions.fresHeader(res, "location");
|
|
788
|
+
if ("".equals(location)) {
|
|
789
|
+
return null;
|
|
790
|
+
}
|
|
791
|
+
try {
|
|
792
|
+
URI next = Fetcher.resolveLocation(URI.create(at), location);
|
|
793
|
+
String origin = originOf(next);
|
|
794
|
+
return origin != null && origin.equals(originOf(URI.create(url))) ? next.toString() : null;
|
|
795
|
+
}
|
|
796
|
+
catch (RuntimeException e) {
|
|
797
|
+
return null;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
private static String originOf(URI uri) {
|
|
802
|
+
String scheme = uri.getScheme();
|
|
803
|
+
String host = uri.getHost();
|
|
804
|
+
if (scheme == null || host == null) {
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
scheme = scheme.toLowerCase(Locale.ROOT);
|
|
808
|
+
int port = uri.getPort() < 0 ? ("https".equals(scheme) ? 443 : 80) : uri.getPort();
|
|
809
|
+
return scheme + "://" + host.toLowerCase(Locale.ROOT) + ":" + port;
|
|
810
|
+
}
|
|
811
|
+
|
|
744
812
|
// rawExchangeFetch is the token-exchange transport of last resort: plain
|
|
745
813
|
// java.net.http, in the same result shape the system.fetch seam promises
|
|
746
814
|
// ("status" + "json"). utility/Fetcher.defaultHttpFetch is
|
|
@@ -799,7 +867,9 @@ public class SecretsFeature extends BaseFeature {
|
|
|
799
867
|
|
|
800
868
|
Map<String, Object> out = new LinkedHashMap<>();
|
|
801
869
|
out.put("status", resp.statusCode());
|
|
802
|
-
|
|
870
|
+
Map<String, Object> rheaders = new LinkedHashMap<>();
|
|
871
|
+
resp.headers().firstValue("location").ifPresent((v) -> rheaders.put("location", v));
|
|
872
|
+
out.put("headers", rheaders);
|
|
803
873
|
out.put("json", (Supplier<Object>) () -> jsonBody);
|
|
804
874
|
out.put("body", text);
|
|
805
875
|
return out;
|
|
@@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
11
11
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
12
12
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
13
13
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
14
|
+
import static org.junit.jupiter.api.Assertions.assertSame;
|
|
14
15
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
15
16
|
|
|
16
17
|
import static JAVAPACKAGE.sdktest.FeatureHarness.FhClock;
|
|
@@ -437,6 +438,30 @@ public class FeatureTest {
|
|
|
437
438
|
assertEquals(2, f.bypass, "expected 2 bypasses");
|
|
438
439
|
}
|
|
439
440
|
|
|
441
|
+
@Test
|
|
442
|
+
public void cache_aBodyThatDeclaresAnotherTypeThanJsonPassesByUnread() {
|
|
443
|
+
assumeFeatures("cache");
|
|
444
|
+
List<Map<String, Object>> sent = new ArrayList<>();
|
|
445
|
+
FhRecorder rec = new FhRecorder();
|
|
446
|
+
rec.reply = (n, fetchdef) -> {
|
|
447
|
+
Map<String, Object> res = fhResponse(200, null, fhMap("content-type", "audio/wav"));
|
|
448
|
+
res.put("body", new byte[] {'R', 'I', 'F', 'F'});
|
|
449
|
+
sent.add(res);
|
|
450
|
+
return res;
|
|
451
|
+
};
|
|
452
|
+
CacheFeature f = new CacheFeature();
|
|
453
|
+
FhHarness h = fhMake(rec::fetch, fhF(f, fhMap("ttl", 10000)));
|
|
454
|
+
FhOpResult a = h.op(fhOp("load").path("/w/1/audio"));
|
|
455
|
+
FhOpResult b = h.op(fhOp("load").path("/w/1/audio"));
|
|
456
|
+
assertEquals(2, rec.calls.size(), "the body was stored");
|
|
457
|
+
assertSame(sent.get(0).get("body"), a.ctx.response.body,
|
|
458
|
+
"the cache handed on a copy it had read");
|
|
459
|
+
assertSame(sent.get(0).get("headers"), a.ctx.response.headers);
|
|
460
|
+
assertSame(sent.get(1).get("body"), b.ctx.response.body);
|
|
461
|
+
assertSame(sent.get(1).get("headers"), b.ctx.response.headers);
|
|
462
|
+
assertEquals(2, f.bypass, "expected 2 bypasses");
|
|
463
|
+
}
|
|
464
|
+
|
|
440
465
|
@Test
|
|
441
466
|
public void cache_refetchesAfterTtl() {
|
|
442
467
|
assumeFeatures("cache");
|
|
@@ -463,6 +463,45 @@ public class PrimaryUtilityTest {
|
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
|
|
466
|
+
// A Location of a query alone keeps the path that answered.
|
|
467
|
+
@Test
|
|
468
|
+
@SuppressWarnings("unchecked")
|
|
469
|
+
public void fetcherRedirectToAQueryKeepsThePath() throws Exception {
|
|
470
|
+
List<String> seen = java.util.Collections.synchronizedList(new ArrayList<>());
|
|
471
|
+
com.sun.net.httpserver.HttpServer server = com.sun.net.httpserver.HttpServer.create(
|
|
472
|
+
new java.net.InetSocketAddress("127.0.0.1", 0), 0);
|
|
473
|
+
server.createContext("/", (exchange) -> {
|
|
474
|
+
String query = exchange.getRequestURI().getRawQuery();
|
|
475
|
+
seen.add(exchange.getRequestURI().getRawPath() + (query == null ? "" : "?" + query));
|
|
476
|
+
if (query == null) {
|
|
477
|
+
exchange.getResponseHeaders().set("Location", "?step=2");
|
|
478
|
+
exchange.sendResponseHeaders(302, -1);
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
byte[] body = "{\"id\":\"q1\"}".getBytes();
|
|
482
|
+
exchange.getResponseHeaders().set("Content-Type", "application/json");
|
|
483
|
+
exchange.sendResponseHeaders(200, body.length);
|
|
484
|
+
exchange.getResponseBody().write(body);
|
|
485
|
+
}
|
|
486
|
+
exchange.close();
|
|
487
|
+
});
|
|
488
|
+
server.start();
|
|
489
|
+
String base = "http://127.0.0.1:" + server.getAddress().getPort();
|
|
490
|
+
try {
|
|
491
|
+
ProjectNameSDK liveClient = new ProjectNameSDK(fhMap("base", base));
|
|
492
|
+
Utility liveUtility = liveClient.getUtility();
|
|
493
|
+
Context ctx = liveUtility.makeContext.apply(fhMap(
|
|
494
|
+
"opname", "load", "client", liveClient, "utility", liveUtility), null);
|
|
495
|
+
Map<String, Object> res = (Map<String, Object>) liveUtility.fetcher.fetch(ctx, base + "/redirect/q1",
|
|
496
|
+
fhMap("method", "GET", "headers", new LinkedHashMap<>()));
|
|
497
|
+
assertEquals(200, res.get("status"));
|
|
498
|
+
assertEquals(List.of("/redirect/q1", "/redirect/q1?step=2"), seen);
|
|
499
|
+
}
|
|
500
|
+
finally {
|
|
501
|
+
server.stop(0);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
466
505
|
// The API's origin, which redirects, and another origin, which records
|
|
467
506
|
// what reaches it: another port on the same host is another origin.
|
|
468
507
|
static final class RedirectOrigins implements AutoCloseable {
|