@voxgig/sdkgen 4.49.1 → 4.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/cache.aontu +6 -4
- package/project/.sdk/model/target/lua.aontu +6 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
- package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
- package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
- package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
- package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
- package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
- package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
- package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
- package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
- package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
- package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
- package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
- package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
- package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
- package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
- package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
- package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
- package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
- package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
- package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
- package/project/.sdk/tm/c/core/context.c +1 -0
- package/project/.sdk/tm/c/core/sdk.h +7 -4
- package/project/.sdk/tm/c/feature/cache.c +243 -13
- package/project/.sdk/tm/c/feature/debug.c +1 -0
- package/project/.sdk/tm/c/feature/secrets.c +27 -38
- package/project/.sdk/tm/c/feature/telemetry.c +1 -0
- package/project/.sdk/tm/c/tests/feature_test.c +142 -0
- package/project/.sdk/tm/c/utility/clean.c +26 -33
- package/project/.sdk/tm/c/utility/make_options.c +9 -8
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
- package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
- package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
- package/project/.sdk/tm/clojure/src/sdk/features.clj +83 -10
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +47 -0
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
- package/project/.sdk/tm/cpp/Makefile +5 -0
- package/project/.sdk/tm/cpp/core/types.hpp +11 -4
- package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
- package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
- package/project/.sdk/tm/cpp/feature/debug.hpp +1 -0
- package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
- package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
- package/project/.sdk/tm/cpp/test/feature_test.cpp +128 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
- package/project/.sdk/tm/csharp/core/Context.cs +4 -0
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
- package/project/.sdk/tm/csharp/feature/DebugFeature.cs +1 -0
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
- package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +101 -0
- package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
- package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
- package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
- package/project/.sdk/tm/elixir/lib/projectname/feature/debug.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
- package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
- package/project/.sdk/tm/elixir/test/feature_test.exs +84 -0
- package/project/.sdk/tm/go/core/context.go +6 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
- package/project/.sdk/tm/go/feature/debug_feature.go +3 -2
- package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
- package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
- package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
- package/project/.sdk/tm/go/test/feature_test.go +101 -0
- package/project/.sdk/tm/go/utility/clean.go +5 -7
- package/project/.sdk/tm/go/utility/fetcher.go +11 -0
- package/project/.sdk/tm/go/utility/make_options.go +5 -7
- package/project/.sdk/tm/java/core/Context.java +9 -0
- package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
- package/project/.sdk/tm/java/feature/DebugFeature.java +1 -0
- package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
- package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
- package/project/.sdk/tm/java/test/FeatureTest.java +88 -0
- package/project/.sdk/tm/java/utility/Clean.java +6 -10
- package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
- package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
- package/project/.sdk/tm/js/src/Context.js +4 -0
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
- package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
- package/project/.sdk/tm/js/src/feature/debug/DebugFeature.js +1 -0
- package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
- package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
- package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +1 -0
- package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
- package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
- package/project/.sdk/tm/js/test/feature/harness.js +3 -3
- package/project/.sdk/tm/js/test/feature.test.js +17 -0
- package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
- package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
- package/project/.sdk/tm/kotlin/feature/DebugFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
- package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +79 -0
- package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
- package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
- package/project/.sdk/tm/lua/core/context.lua +6 -0
- package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
- package/project/.sdk/tm/lua/feature/debug_feature.lua +1 -0
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
- package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
- package/project/.sdk/tm/lua/test/feature_test.lua +108 -0
- package/project/.sdk/tm/lua/utility/clean.lua +6 -9
- package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
- package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
- package/project/.sdk/tm/ocaml/sdk_features.ml +108 -8
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
- package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
- package/project/.sdk/tm/ocaml/test/t_feature.ml +51 -1
- package/project/.sdk/tm/perl/core/context.pm +3 -0
- package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
- package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
- package/project/.sdk/tm/perl/feature/debug_feature.pm +1 -0
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
- package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
- package/project/.sdk/tm/perl/t/feature.t +86 -0
- package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
- package/project/.sdk/tm/perl/utility/clean.pm +6 -8
- package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
- package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
- package/project/.sdk/tm/php/core/Context.php +4 -0
- package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
- package/project/.sdk/tm/php/feature/DebugFeature.php +1 -0
- package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
- package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
- package/project/.sdk/tm/php/test/FeatureTest.php +90 -0
- package/project/.sdk/tm/php/utility/Clean.php +3 -10
- package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
- package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
- package/project/.sdk/tm/py/pkg/core/context.py +4 -0
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
- package/project/.sdk/tm/py/pkg/feature/debug_feature.py +1 -0
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
- package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
- package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
- package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
- package/project/.sdk/tm/py/test/test_feature.py +73 -0
- package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
- package/project/.sdk/tm/rb/core/context.rb +4 -1
- package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
- package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
- package/project/.sdk/tm/rb/feature/debug_feature.rb +1 -0
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
- package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
- package/project/.sdk/tm/rb/test/feature_test.rb +93 -0
- package/project/.sdk/tm/rb/utility/clean.rb +6 -7
- package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
- package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
- package/project/.sdk/tm/rust/core/context.rs +8 -0
- package/project/.sdk/tm/rust/feature/cache.rs +120 -3
- package/project/.sdk/tm/rust/feature/debug.rs +1 -0
- package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
- package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
- package/project/.sdk/tm/rust/tests/feature_test.rs +141 -0
- package/project/.sdk/tm/rust/utility/clean.rs +35 -43
- package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
- package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
- package/project/.sdk/tm/scala/core/Context.scala +4 -0
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
- package/project/.sdk/tm/scala/feature/DebugFeature.scala +1 -0
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
- package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +52 -1
- package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
- package/project/.sdk/tm/scala/utility/Make.scala +3 -1
- package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/DebugFeature.swift +1 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +79 -0
- package/project/.sdk/tm/ts/src/Context.ts +4 -0
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
- package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
- package/project/.sdk/tm/ts/src/feature/debug/DebugFeature.ts +1 -0
- package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
- package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +1 -0
- package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
- package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
- package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
- package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
- package/project/.sdk/tm/zig/core/context.zig +5 -0
- package/project/.sdk/tm/zig/core/utility.zig +11 -9
- package/project/.sdk/tm/zig/feature/cache.zig +144 -13
- package/project/.sdk/tm/zig/feature/debug.zig +1 -0
- package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
- package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
- package/project/.sdk/tm/zig/test/feature_test.zig +100 -0
- package/project/sdkgen-package.json +1 -1
|
@@ -425,6 +425,9 @@ private:
|
|
|
425
425
|
|
|
426
426
|
std::shared_ptr<Exchange> exchange_;
|
|
427
427
|
std::string refresh_;
|
|
428
|
+
// The transport's refusal of the last purchase, which the gate throws in
|
|
429
|
+
// place of a resolution error.
|
|
430
|
+
SdkErrorPtr refused_;
|
|
428
431
|
|
|
429
432
|
// The custom-provider slot table: the Injector each `custom` spec's slot
|
|
430
433
|
// ticket names.
|
|
@@ -567,6 +570,7 @@ private:
|
|
|
567
570
|
// message, or "" for success with the token in cred_. Called under mu_.
|
|
568
571
|
std::string buy() {
|
|
569
572
|
const Exchange& x = *exchange_;
|
|
573
|
+
refused_ = nullptr;
|
|
570
574
|
|
|
571
575
|
// TEST MODE BUYS NOTHING. The test feature replaces the transport so no
|
|
572
576
|
// request leaves the process; an exchange here would be the one HTTP
|
|
@@ -629,6 +633,10 @@ private:
|
|
|
629
633
|
}
|
|
630
634
|
return "";
|
|
631
635
|
}
|
|
636
|
+
// Not util::fetcher, as every other target does: the cpp core has no
|
|
637
|
+
// client of its own, so only the guard is applied before sekreto's.
|
|
638
|
+
refused_ = util::getOnlyRefusal(client->rootctx, at, fetchdef);
|
|
639
|
+
if (refused_) return refused_->msg;
|
|
632
640
|
std::vector<std::pair<std::string, std::string>> hdrs{{"content-type", "application/json"}};
|
|
633
641
|
SecretsRawResponse raw = secrets_rawfetch(x.method, at, hdrs, bodytext);
|
|
634
642
|
if (!raw.ok) return raw.err;
|
|
@@ -824,6 +832,9 @@ private:
|
|
|
824
832
|
std::string rerr = resolve();
|
|
825
833
|
if (!rerr.empty()) {
|
|
826
834
|
track_.refused++;
|
|
835
|
+
SdkErrorPtr refused = refused_;
|
|
836
|
+
refused_ = nullptr;
|
|
837
|
+
if (refused) throw refused;
|
|
827
838
|
throw ctx->makeError("secrets_resolve", rerr);
|
|
828
839
|
}
|
|
829
840
|
|
|
@@ -865,6 +876,7 @@ private:
|
|
|
865
876
|
// The purchase failed: answer with the API's own refusal rather
|
|
866
877
|
// than this one. The caller asked for data, and the refusal is
|
|
867
878
|
// the more useful of the two - the exchange error is a symptom.
|
|
879
|
+
refused_ = nullptr;
|
|
868
880
|
return out;
|
|
869
881
|
}
|
|
870
882
|
}
|
|
@@ -52,6 +52,7 @@ public:
|
|
|
52
52
|
Value span = vmap();
|
|
53
53
|
map_put(span, "traceId", Value(id("trace")));
|
|
54
54
|
map_put(span, "spanId", Value(id("span")));
|
|
55
|
+
map_put(span, "correlationId", Value(ctx->id));
|
|
55
56
|
map_put(span, "name", Value(entity + "." + opname));
|
|
56
57
|
map_put(span, "start", Value((long long) fopt::foptNow(options)()));
|
|
57
58
|
pending[ctx->id] = span;
|
|
@@ -430,6 +430,79 @@ static void cache_inactiveDoesNotWrap() {
|
|
|
430
430
|
ASSERT_EQ((int)rec->calls.size(), 2, "expected 2 calls");
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
+
// The reference vectors of the SipHash paper: key 00..0f, message 00..len-1.
|
|
434
|
+
static void cache_siphashMatchesTheReferenceVectors() {
|
|
435
|
+
if (!have({"cache"})) return;
|
|
436
|
+
const std::vector<std::pair<size_t, uint64_t>> vectors = {{0, 0x726fdb47dd0e0e31ULL}, {1, 0x74f839c593dc67fdULL}, {2, 0x0d6c8009d9a94f5aULL}, {3, 0x85676696d7fb7e2dULL}, {4, 0xcf2794e0277187b7ULL}, {5, 0x18765564cd99a68dULL}, {6, 0xcbc9466e58fee3ceULL}, {7, 0xab0200f58b01d137ULL}, {8, 0x93f5f5799a932462ULL}, {15, 0xa129ca6149be45e5ULL}, {16, 0x3f2acc7f57c29bdbULL}, {63, 0x958a324ceb064572ULL}};
|
|
437
|
+
uint8_t key[16];
|
|
438
|
+
for (int i = 0; i < 16; i++) key[i] = static_cast<uint8_t>(i);
|
|
439
|
+
std::string msg;
|
|
440
|
+
for (int i = 0; i < 64; i++) msg.push_back(static_cast<char>(i));
|
|
441
|
+
for (const auto& v : vectors) {
|
|
442
|
+
ASSERT_TRUE(CacheFeature::siphash24(key, msg.substr(0, v.first)) == v.second,
|
|
443
|
+
"siphash reference vector " + std::to_string(v.first));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
static void cache_keysOnRequestHeaders() {
|
|
448
|
+
if (!have({"cache"})) return;
|
|
449
|
+
auto rec = std::make_shared<FhRecorder>();
|
|
450
|
+
FetcherFn server = [rec](CtxPtr c, const std::string& u, const Value& fd) { return rec->fetch(c, u, fd); };
|
|
451
|
+
auto h = fhMake(server, {FF(std::make_shared<CacheFeature>(), fhMap({{"ttl", Value(10000)}}))});
|
|
452
|
+
h->op(fhOp("load").setPath("/w/1").setHeaders(fhMap({{"x-tenant", Value("tenant-a")}})));
|
|
453
|
+
h->op(fhOp("load").setPath("/w/1").setHeaders(fhMap({{"X-Tenant", Value("tenant-b")}})));
|
|
454
|
+
ASSERT_EQ((int)rec->calls.size(), 2, "a second tenant was served the first tenant's entry");
|
|
455
|
+
h->op(fhOp("load").setPath("/w/1").setHeaders(fhMap({{"x-tenant", Value("tenant-b")}})));
|
|
456
|
+
ASSERT_EQ((int)rec->calls.size(), 2, "the same headers did not share an entry");
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
static void cache_aWriteDropsItsCollection() {
|
|
460
|
+
if (!have({"cache"})) return;
|
|
461
|
+
auto rec = std::make_shared<FhRecorder>();
|
|
462
|
+
FetcherFn server = [rec](CtxPtr c, const std::string& u, const Value& fd) { return rec->fetch(c, u, fd); };
|
|
463
|
+
auto f = std::make_shared<CacheFeature>();
|
|
464
|
+
auto h = fhMake(server, {FF(f, fhMap({{"ttl", Value(10000)}}))});
|
|
465
|
+
const char* paths[] = {"/w/1", "/w", "/w/1/part", "/other/1", "/w/2"};
|
|
466
|
+
for (const char* p : paths) h->op(fhOp("load").setPath(p));
|
|
467
|
+
h->op(fhOp("update").setMethod("PUT").setPath("/w/1"));
|
|
468
|
+
for (const char* p : paths) h->op(fhOp("load").setPath(p));
|
|
469
|
+
ASSERT_EQ((int)rec->calls.size(), 9, "expected the collection refetched and /other cached");
|
|
470
|
+
ASSERT_EQ(f->hit, 2, "expected /other served from cache");
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
static void cache_cacheControlPreventsStoring() {
|
|
474
|
+
if (!have({"cache"})) return;
|
|
475
|
+
for (std::string control : {"no-store", "private", "No-Cache", "max-age=60, private"}) {
|
|
476
|
+
auto rec = std::make_shared<FhRecorder>();
|
|
477
|
+
rec->reply = [control](int, const Value&) {
|
|
478
|
+
return fhResponse(200, fhMap({{"ok", Value(true)}}), fhMap({{"Cache-Control", Value(control)}}));
|
|
479
|
+
};
|
|
480
|
+
FetcherFn server = [rec](CtxPtr c, const std::string& u, const Value& fd) { return rec->fetch(c, u, fd); };
|
|
481
|
+
auto h = fhMake(server, {FF(std::make_shared<CacheFeature>(), fhMap({{"ttl", Value(10000)}}))});
|
|
482
|
+
h->op(fhOp("load").setPath("/w"));
|
|
483
|
+
h->op(fhOp("load").setPath("/w"));
|
|
484
|
+
ASSERT_EQ((int)rec->calls.size(), 2, control + " was stored");
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
static void cache_maxAgeCapsTheTtl() {
|
|
489
|
+
if (!have({"cache"})) return;
|
|
490
|
+
FhClock clock;
|
|
491
|
+
auto rec = std::make_shared<FhRecorder>();
|
|
492
|
+
rec->reply = [](int, const Value&) {
|
|
493
|
+
return fhResponse(200, fhMap({{"ok", Value(true)}}), fhMap({{"cache-control", Value("max-age=1")}}));
|
|
494
|
+
};
|
|
495
|
+
FetcherFn server = [rec](CtxPtr c, const std::string& u, const Value& fd) { return rec->fetch(c, u, fd); };
|
|
496
|
+
auto h = fhMake(server, {FF(std::make_shared<CacheFeature>(), fhMap({{"ttl", Value(10000)}, {"now", clock.nowFn()}}))});
|
|
497
|
+
h->op(fhOp("load").setPath("/w"));
|
|
498
|
+
clock.advance(500);
|
|
499
|
+
h->op(fhOp("load").setPath("/w"));
|
|
500
|
+
ASSERT_EQ((int)rec->calls.size(), 1, "expected a hit inside max-age");
|
|
501
|
+
clock.advance(600);
|
|
502
|
+
h->op(fhOp("load").setPath("/w"));
|
|
503
|
+
ASSERT_EQ((int)rec->calls.size(), 2, "expected max-age=1 to expire the entry before the ttl");
|
|
504
|
+
}
|
|
505
|
+
|
|
433
506
|
// ============================ idempotency ==============================
|
|
434
507
|
|
|
435
508
|
static void idempotency_addsKeyToMutatingOps() {
|
|
@@ -700,6 +773,53 @@ static void audit_inactiveRecordsNothing() {
|
|
|
700
773
|
ASSERT_EQ((int)f->records.as_list()->size(), 0, "expected no records");
|
|
701
774
|
}
|
|
702
775
|
|
|
776
|
+
static void audit_perCallMarkerEndsWithTheCall() {
|
|
777
|
+
if (!have({"audit", "netsim"})) return;
|
|
778
|
+
auto f = std::make_shared<AuditFeature>();
|
|
779
|
+
auto h = fhMake(nullptr, {
|
|
780
|
+
FF(std::make_shared<NetsimFeature>(), fhMap({{"failEvery", Value(2)}, {"failStatus", Value(500)}})),
|
|
781
|
+
FF(f, Value::undef())});
|
|
782
|
+
std::vector<std::weak_ptr<Context>> held;
|
|
783
|
+
for (int i = 0; i < 20; i++) {
|
|
784
|
+
auto res = h->op(fhOp("load").setPath("/w/" + std::to_string(i)));
|
|
785
|
+
ASSERT_TRUE(nullptr != res.ctx, "expected the call's context");
|
|
786
|
+
if (nullptr == res.ctx) return;
|
|
787
|
+
ASSERT_TRUE(res.ctx->out.extra.count("audit_seen") == 1, "expected the marker on the call's context");
|
|
788
|
+
held.push_back(res.ctx);
|
|
789
|
+
}
|
|
790
|
+
ASSERT_EQ((int)f->records.as_list()->size(), 20, "expected one record per call");
|
|
791
|
+
int alive = 0;
|
|
792
|
+
for (auto& w : held) if (!w.expired()) alive++;
|
|
793
|
+
ASSERT_EQ(alive, 0, "expected no context kept alive past its call");
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// ============================ one call, one id =========================
|
|
797
|
+
|
|
798
|
+
static void telemetryDebugAudit_carryOneCallsContextId() {
|
|
799
|
+
if (!have({"telemetry", "debug", "audit"})) return;
|
|
800
|
+
auto tf = std::make_shared<TelemetryFeature>();
|
|
801
|
+
auto df = std::make_shared<DebugFeature>();
|
|
802
|
+
auto af = std::make_shared<AuditFeature>();
|
|
803
|
+
auto h = fhMake(nullptr, {FF(tf, Value::undef()), FF(df, Value::undef()), FF(af, Value::undef())});
|
|
804
|
+
h->op(fhOp("load"));
|
|
805
|
+
h->op(fhOp("list"));
|
|
806
|
+
auto ids = [](const Value& recs) {
|
|
807
|
+
Value out = vlist();
|
|
808
|
+
for (const auto& rec : *recs.as_list()) out.as_list()->push_back(getp(rec, "correlationId"));
|
|
809
|
+
return out;
|
|
810
|
+
};
|
|
811
|
+
Value calls = ids(af->records);
|
|
812
|
+
ASSERT_EQ((int)calls.as_list()->size(), 2, "expected 2 audit records");
|
|
813
|
+
for (const auto& id : *calls.as_list()) {
|
|
814
|
+
ASSERT_TRUE(id.is_string() && !id.as_string().empty(),
|
|
815
|
+
"expected a non-empty string id, got " + sdktest::vstr(calls));
|
|
816
|
+
}
|
|
817
|
+
ASSERT_TRUE(vs::getelem(calls, Value(int64_t(0))) != vs::getelem(calls, Value(int64_t(1))),
|
|
818
|
+
"expected one id per call");
|
|
819
|
+
ASSERT_EQ_VAL(ids(tf->spans), calls, "expected the spans' ids");
|
|
820
|
+
ASSERT_EQ_VAL(ids(df->entries), calls, "expected the debug entries' ids");
|
|
821
|
+
}
|
|
822
|
+
|
|
703
823
|
// ============================ clienttrack ==============================
|
|
704
824
|
|
|
705
825
|
static void clienttrack_stableClientIdUniqueRequestIdsUa() {
|
|
@@ -935,6 +1055,11 @@ int main() {
|
|
|
935
1055
|
T_RUN(cache_refetchesAfterTtl);
|
|
936
1056
|
T_RUN(cache_evictsOldestPastMax);
|
|
937
1057
|
T_RUN(cache_inactiveDoesNotWrap);
|
|
1058
|
+
T_RUN(cache_keysOnRequestHeaders);
|
|
1059
|
+
T_RUN(cache_aWriteDropsItsCollection);
|
|
1060
|
+
T_RUN(cache_cacheControlPreventsStoring);
|
|
1061
|
+
T_RUN(cache_maxAgeCapsTheTtl);
|
|
1062
|
+
T_RUN(cache_siphashMatchesTheReferenceVectors);
|
|
938
1063
|
|
|
939
1064
|
T_RUN(idempotency_addsKeyToMutatingOps);
|
|
940
1065
|
T_RUN(idempotency_addsKeyByHttpMethod);
|
|
@@ -967,6 +1092,9 @@ int main() {
|
|
|
967
1092
|
T_RUN(audit_defaultActorAnonymous);
|
|
968
1093
|
T_RUN(audit_injectedClock);
|
|
969
1094
|
T_RUN(audit_inactiveRecordsNothing);
|
|
1095
|
+
T_RUN(audit_perCallMarkerEndsWithTheCall);
|
|
1096
|
+
|
|
1097
|
+
T_RUN(telemetryDebugAudit_carryOneCallsContextId);
|
|
970
1098
|
|
|
971
1099
|
T_RUN(clienttrack_stableClientIdUniqueRequestIdsUa);
|
|
972
1100
|
T_RUN(clienttrack_doesNotClobberCallerUa);
|
|
@@ -67,9 +67,10 @@ inline CtxPtr makeContext(const CtxSpec& cs, CtxPtr basectx) {
|
|
|
67
67
|
// sensitive KEY name is masked whatever it holds. Inside the pipeline data
|
|
68
68
|
// stays raw, so a hook can still read the header it must add to.
|
|
69
69
|
//
|
|
70
|
-
// The configuration is the
|
|
71
|
-
// (`
|
|
72
|
-
// it can be replaced after construction - features
|
|
70
|
+
// The configuration is the clean registry makeOptions builds and holds on
|
|
71
|
+
// the context beside the options (`ctx->cleancfg`): a plain map, so the
|
|
72
|
+
// registry list inside it can be replaced after construction - features
|
|
73
|
+
// register later.
|
|
73
74
|
|
|
74
75
|
constexpr int CLEAN_MAXDEPTH = 32;
|
|
75
76
|
|
|
@@ -159,12 +160,11 @@ inline Value makeCleanConfig(const Value& cleanopts) {
|
|
|
159
160
|
return cfg;
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
// A context without
|
|
163
|
+
// A context without a registry (makeError is reached with a bare one) falls
|
|
163
164
|
// back to the schema defaults, so nothing leaves raw for want of a
|
|
164
165
|
// constructor.
|
|
165
166
|
inline Value cleanConfig(CtxPtr ctx) {
|
|
166
|
-
|
|
167
|
-
if (derived.is_map()) return derived;
|
|
167
|
+
if (ctx && ctx->cleancfg.is_map()) return ctx->cleancfg;
|
|
168
168
|
return makeCleanConfig(getp(sharedOptspec(), "clean"));
|
|
169
169
|
}
|
|
170
170
|
|
|
@@ -2260,10 +2260,12 @@ inline Value makeOptions(CtxPtr ctx) {
|
|
|
2260
2260
|
for (const auto& n : featureOrder) orderList.as_list()->push_back(Value(n));
|
|
2261
2261
|
|
|
2262
2262
|
Value derived = vmap();
|
|
2263
|
-
map_put(derived, "clean", derivedClean);
|
|
2264
2263
|
map_put(derived, "featureorder", orderList);
|
|
2265
2264
|
map_put(opts, "__derived__", derived);
|
|
2266
2265
|
|
|
2266
|
+
// Beside the options, not in them: optionsMap hands them to callers.
|
|
2267
|
+
ctx->cleancfg = derivedClean;
|
|
2268
|
+
|
|
2267
2269
|
// Again over the merged result: the config's own defaults can carry one.
|
|
2268
2270
|
cleanAddSensitiveCfg(derivedClean, optsWithout(opts, {"clean", "__derived__"}));
|
|
2269
2271
|
|
|
@@ -19,6 +19,8 @@ public class Context
|
|
|
19
19
|
public Dictionary<string, object?>? Config;
|
|
20
20
|
public Dictionary<string, object?>? Entopts;
|
|
21
21
|
public Dictionary<string, object?>? Options;
|
|
22
|
+
// The clean registry, beside the options rather than in them.
|
|
23
|
+
public ProjectNameSdk.Util.CleanConfig? CleanCfg;
|
|
22
24
|
public ConcurrentDictionary<string, Operation> Opmap = new();
|
|
23
25
|
public Response? Response;
|
|
24
26
|
public Result? Result;
|
|
@@ -125,6 +127,8 @@ public class Context
|
|
|
125
127
|
{
|
|
126
128
|
Options = basectx.Options;
|
|
127
129
|
}
|
|
130
|
+
CleanCfg = Helpers.GetCtxProp(ctxmap, "cleancfg") as ProjectNameSdk.Util.CleanConfig
|
|
131
|
+
?? basectx?.CleanCfg;
|
|
128
132
|
|
|
129
133
|
// Entity
|
|
130
134
|
if (Helpers.GetCtxProp(ctxmap, "entity") is IEntity ent)
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
// Response caching for safe (read) requests
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// are snapshotted on capture so both the current caller and later hits can
|
|
8
|
-
// re-read the JSON body repeatedly.
|
|
1
|
+
// Response caching for safe (read) requests, per client: see the features
|
|
2
|
+
// reference for the key, the write invalidation and the Cache-Control rules.
|
|
3
|
+
|
|
4
|
+
using System.Security.Cryptography;
|
|
5
|
+
using System.Text;
|
|
6
|
+
using System.Text.RegularExpressions;
|
|
9
7
|
|
|
10
8
|
using ProjectNameSdk.Util;
|
|
11
9
|
|
|
@@ -19,6 +17,11 @@ public class CacheFeature : BaseFeature
|
|
|
19
17
|
private Dictionary<string, object?>? _options;
|
|
20
18
|
private Dictionary<string, CacheEntry> _store = new();
|
|
21
19
|
private List<string> _order = new();
|
|
20
|
+
private byte[] _secret = Array.Empty<byte>();
|
|
21
|
+
|
|
22
|
+
private static readonly string[] SafeMethods = { "GET", "HEAD" };
|
|
23
|
+
private static readonly string[] Unstored = { "no-store", "private", "no-cache" };
|
|
24
|
+
private static readonly Regex MaxAge = new("^max-age\\s*=\\s*\"?(\\d+)\"?$");
|
|
22
25
|
|
|
23
26
|
// Activity tracking (mirrors the ts client._cache record).
|
|
24
27
|
public int Hit;
|
|
@@ -28,6 +31,7 @@ public class CacheFeature : BaseFeature
|
|
|
28
31
|
private class CacheEntry
|
|
29
32
|
{
|
|
30
33
|
public long Expiry;
|
|
34
|
+
public string Scope = "";
|
|
31
35
|
public CacheSnapshot Snapshot = new();
|
|
32
36
|
}
|
|
33
37
|
|
|
@@ -59,6 +63,7 @@ public class CacheFeature : BaseFeature
|
|
|
59
63
|
|
|
60
64
|
_store = new Dictionary<string, CacheEntry>();
|
|
61
65
|
_order = new List<string>();
|
|
66
|
+
_secret = RandomNumberGenerator.GetBytes(32);
|
|
62
67
|
|
|
63
68
|
var inner = ctx.Utility!.Fetcher;
|
|
64
69
|
|
|
@@ -78,10 +83,22 @@ public class CacheFeature : BaseFeature
|
|
|
78
83
|
var cacheable = methods.Any(x => x.ToUpperInvariant() == method);
|
|
79
84
|
if (!cacheable)
|
|
80
85
|
{
|
|
81
|
-
|
|
86
|
+
if (SafeMethods.Contains(method))
|
|
87
|
+
{
|
|
88
|
+
return inner(ctx, url, fetchdef);
|
|
89
|
+
}
|
|
90
|
+
try
|
|
91
|
+
{
|
|
92
|
+
return inner(ctx, url, fetchdef);
|
|
93
|
+
}
|
|
94
|
+
finally
|
|
95
|
+
{
|
|
96
|
+
Invalidate(url);
|
|
97
|
+
}
|
|
82
98
|
}
|
|
83
99
|
|
|
84
|
-
|
|
100
|
+
fetchdef.TryGetValue("headers", out var headers);
|
|
101
|
+
var key = method + " " + url + " " + Digest(headers);
|
|
85
102
|
var now = FoptNow(_options)();
|
|
86
103
|
|
|
87
104
|
if (_store.TryGetValue(key, out var hit) && hit.Expiry > now)
|
|
@@ -111,9 +128,15 @@ public class CacheFeature : BaseFeature
|
|
|
111
128
|
if (err == null && Storable(res))
|
|
112
129
|
{
|
|
113
130
|
var snapshot = Snapshot(res);
|
|
114
|
-
var ttl = FoptInt(_options, "ttl", 5000);
|
|
131
|
+
var ttl = Lifetime(snapshot.Headers, FoptInt(_options, "ttl", 5000));
|
|
132
|
+
if (ttl <= 0)
|
|
133
|
+
{
|
|
134
|
+
Bypass++;
|
|
135
|
+
return Replay(snapshot);
|
|
136
|
+
}
|
|
137
|
+
Drop(key);
|
|
115
138
|
Evict();
|
|
116
|
-
_store[key] = new CacheEntry { Expiry = now + ttl, Snapshot = snapshot };
|
|
139
|
+
_store[key] = new CacheEntry { Expiry = now + ttl, Scope = UrlScope(url), Snapshot = snapshot };
|
|
117
140
|
_order.Add(key);
|
|
118
141
|
Miss++;
|
|
119
142
|
return Replay(snapshot);
|
|
@@ -127,6 +150,97 @@ public class CacheFeature : BaseFeature
|
|
|
127
150
|
return res;
|
|
128
151
|
}
|
|
129
152
|
|
|
153
|
+
private string Digest(object? headers)
|
|
154
|
+
{
|
|
155
|
+
var pairs = new List<(string Name, string Value)>();
|
|
156
|
+
if (headers is IDictionary<string, object?> hm)
|
|
157
|
+
{
|
|
158
|
+
foreach (var kv in hm)
|
|
159
|
+
{
|
|
160
|
+
if (kv.Value != null)
|
|
161
|
+
{
|
|
162
|
+
pairs.Add((kv.Key.ToLowerInvariant(), Convert.ToString(kv.Value, System.Globalization.CultureInfo.InvariantCulture) ?? ""));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
var text = new StringBuilder();
|
|
167
|
+
foreach (var (name, value) in pairs.OrderBy(p => p.Name, StringComparer.Ordinal).ThenBy(p => p.Value, StringComparer.Ordinal))
|
|
168
|
+
{
|
|
169
|
+
text.Append(name).Append(':').Append(value).Append('\n');
|
|
170
|
+
}
|
|
171
|
+
return Convert.ToHexString(HMACSHA256.HashData(_secret, Encoding.UTF8.GetBytes(text.ToString()))).ToLowerInvariant();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private void Invalidate(string url)
|
|
175
|
+
{
|
|
176
|
+
var path = UrlScope(url);
|
|
177
|
+
var collection = UrlParent(path);
|
|
178
|
+
foreach (var key in _store.Where(kv => Under(kv.Value.Scope, path) || kv.Value.Scope == collection)
|
|
179
|
+
.Select(kv => kv.Key).ToList())
|
|
180
|
+
{
|
|
181
|
+
Drop(key);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private void Drop(string key)
|
|
186
|
+
{
|
|
187
|
+
if (_store.Remove(key))
|
|
188
|
+
{
|
|
189
|
+
_order.Remove(key);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// The configured ttl capped by the response's Cache-Control; zero when the
|
|
194
|
+
// response may not be stored.
|
|
195
|
+
private static long Lifetime(Dictionary<string, object?> headers, long ttl)
|
|
196
|
+
{
|
|
197
|
+
var control = "";
|
|
198
|
+
foreach (var kv in headers)
|
|
199
|
+
{
|
|
200
|
+
if (kv.Key.ToLowerInvariant() == "cache-control")
|
|
201
|
+
{
|
|
202
|
+
control = (Convert.ToString(kv.Value) ?? "").ToLowerInvariant();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
var life = ttl;
|
|
206
|
+
foreach (var part in control.Split(','))
|
|
207
|
+
{
|
|
208
|
+
var directive = part.Trim();
|
|
209
|
+
if (Unstored.Contains(directive))
|
|
210
|
+
{
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
var age = MaxAge.Match(directive);
|
|
214
|
+
if (age.Success && long.TryParse(age.Groups[1].Value, out var secs))
|
|
215
|
+
{
|
|
216
|
+
life = Math.Min(life, secs * 1000);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return life;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private static string UrlScope(string url)
|
|
223
|
+
{
|
|
224
|
+
var cut = url.IndexOfAny(new[] { '?', '#' });
|
|
225
|
+
return (cut < 0 ? url : url[..cut]).TrimEnd('/');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private static string UrlParent(string scope)
|
|
229
|
+
{
|
|
230
|
+
var scheme = scope.IndexOf("://", StringComparison.Ordinal);
|
|
231
|
+
var root = scheme < 0 ? 0 : scope.IndexOf('/', scheme + 3);
|
|
232
|
+
if (root < 0)
|
|
233
|
+
{
|
|
234
|
+
return scope;
|
|
235
|
+
}
|
|
236
|
+
return scope[..Math.Max(scope.LastIndexOf('/'), root)];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private static bool Under(string scope, string prefix)
|
|
240
|
+
{
|
|
241
|
+
return scope == prefix || scope.StartsWith(prefix + "/", StringComparison.Ordinal);
|
|
242
|
+
}
|
|
243
|
+
|
|
130
244
|
// A body the transport could not read as JSON passes through, for the operation to report.
|
|
131
245
|
private static bool Storable(object? res)
|
|
132
246
|
{
|
|
@@ -87,6 +87,7 @@ namespace ProjectNameSdk.Feature;
|
|
|
87
87
|
public class SecretsFeature : BaseFeature
|
|
88
88
|
{
|
|
89
89
|
private ProjectNameSDK? _client;
|
|
90
|
+
private Context? _rootctx;
|
|
90
91
|
|
|
91
92
|
// The LIVE options map (root ctx options). READ ONLY: this feature
|
|
92
93
|
// never writes it (see the header).
|
|
@@ -135,6 +136,7 @@ public class SecretsFeature : BaseFeature
|
|
|
135
136
|
public override void Init(Context ctx, Dictionary<string, object?> options)
|
|
136
137
|
{
|
|
137
138
|
_client = ctx.Client;
|
|
139
|
+
_rootctx = ctx;
|
|
138
140
|
_liveopts = ctx.Options;
|
|
139
141
|
Active = FoptBool(options, "active", false);
|
|
140
142
|
|
|
@@ -785,35 +787,15 @@ public class SecretsFeature : BaseFeature
|
|
|
785
787
|
["body"] = body,
|
|
786
788
|
// Never followed by the client: a redirect would carry the refresh token on.
|
|
787
789
|
["redirect"] = "manual",
|
|
790
|
+
// Its own bound, in milliseconds: the timeout feature's wrapper is above it.
|
|
791
|
+
["timeout"] = 30000,
|
|
788
792
|
};
|
|
789
793
|
|
|
790
|
-
//
|
|
791
|
-
// feature
|
|
792
|
-
// would recurse on the first expiry
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
// system.fetch when the caller supplied one, else SdkUtility's own
|
|
796
|
-
// raw HttpClient fetch. The fallback matters: MakeOptions leaves
|
|
797
|
-
// system.fetch unset in the ORDINARY case, and requiring a custom
|
|
798
|
-
// transport there would reject every live token purchase before a
|
|
799
|
-
// request was made. DefaultHttpFetch is `internal` in this
|
|
800
|
-
// assembly, is not the SDK transport (no feature wrapping, no
|
|
801
|
-
// mode/test block) and returns the same { status, json } shape the
|
|
802
|
-
// system.fetch seam promises.
|
|
803
|
-
var sysfetch = StructUtils.GetPath(options, StructUtils.Jt("system", "fetch"));
|
|
804
|
-
|
|
805
|
-
object? Fetch(string at)
|
|
806
|
-
{
|
|
807
|
-
if (sysfetch is Func<string, Dictionary<string, object?>, Dictionary<string, object?>> ff)
|
|
808
|
-
{
|
|
809
|
-
return ff(at, fetchdef);
|
|
810
|
-
}
|
|
811
|
-
if (sysfetch is Func<string, Dictionary<string, object?>, object?> ffa)
|
|
812
|
-
{
|
|
813
|
-
return ffa(at, fetchdef);
|
|
814
|
-
}
|
|
815
|
-
return SdkUtility.DefaultHttpFetch(at, fetchdef);
|
|
816
|
-
}
|
|
794
|
+
// The SDK's own transport, beneath every feature's wrapper: it holds
|
|
795
|
+
// the test feature's block and the GET-only guard, and the wrapped
|
|
796
|
+
// one would recurse on the first expiry.
|
|
797
|
+
var rootctx = _rootctx!;
|
|
798
|
+
object? Fetch(string at) => SdkUtility.FetcherUtil(rootctx, at, fetchdef);
|
|
817
799
|
|
|
818
800
|
var res = Fetch(url);
|
|
819
801
|
|
|
@@ -572,6 +572,82 @@ public class FeatureCacheTest
|
|
|
572
572
|
Assert.Equal(2, f.Bypass);
|
|
573
573
|
}
|
|
574
574
|
|
|
575
|
+
[Fact]
|
|
576
|
+
public void KeysOnRequestHeaders()
|
|
577
|
+
{
|
|
578
|
+
if (Fh.SkipWithout("cache")) return;
|
|
579
|
+
var rec = new FhRecorder();
|
|
580
|
+
var h = Fh.Make(rec.Fetch, (new CacheFeature(), new Dictionary<string, object?> { ["ttl"] = 10000 }));
|
|
581
|
+
h.Op(new FhOpSpec { Op = "load", Path = "/w/1", Headers = new() { ["x-tenant"] = "tenant-a" } });
|
|
582
|
+
h.Op(new FhOpSpec { Op = "load", Path = "/w/1", Headers = new() { ["X-Tenant"] = "tenant-b" } });
|
|
583
|
+
Assert.Equal(2, rec.Calls.Count);
|
|
584
|
+
h.Op(new FhOpSpec { Op = "load", Path = "/w/1", Headers = new() { ["x-tenant"] = "tenant-b" } });
|
|
585
|
+
Assert.Equal(2, rec.Calls.Count);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
[Fact]
|
|
589
|
+
public void AWriteDropsItsCollection()
|
|
590
|
+
{
|
|
591
|
+
if (Fh.SkipWithout("cache")) return;
|
|
592
|
+
var rec = new FhRecorder();
|
|
593
|
+
var f = new CacheFeature();
|
|
594
|
+
var h = Fh.Make(rec.Fetch, (f, new Dictionary<string, object?> { ["ttl"] = 10000 }));
|
|
595
|
+
var paths = new[] { "/w/1", "/w", "/w/1/part", "/other/1", "/w/2" };
|
|
596
|
+
foreach (var p in paths)
|
|
597
|
+
{
|
|
598
|
+
h.Op(new FhOpSpec { Op = "load", Path = p });
|
|
599
|
+
}
|
|
600
|
+
h.Op(new FhOpSpec { Op = "update", Method = "PUT", Path = "/w/1" });
|
|
601
|
+
foreach (var p in paths)
|
|
602
|
+
{
|
|
603
|
+
h.Op(new FhOpSpec { Op = "load", Path = p });
|
|
604
|
+
}
|
|
605
|
+
Assert.Equal(9, rec.Calls.Count);
|
|
606
|
+
Assert.Equal(2, f.Hit);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
[Fact]
|
|
610
|
+
public void CacheControlPreventsStoring()
|
|
611
|
+
{
|
|
612
|
+
if (Fh.SkipWithout("cache")) return;
|
|
613
|
+
foreach (var control in new[] { "no-store", "private", "No-Cache", "max-age=60, private" })
|
|
614
|
+
{
|
|
615
|
+
var rec = new FhRecorder
|
|
616
|
+
{
|
|
617
|
+
Reply = (_, _) => Fh.Response(200, new Dictionary<string, object?> { ["ok"] = true },
|
|
618
|
+
new Dictionary<string, object?> { ["Cache-Control"] = control }),
|
|
619
|
+
};
|
|
620
|
+
var h = Fh.Make(rec.Fetch, (new CacheFeature(), new Dictionary<string, object?> { ["ttl"] = 10000 }));
|
|
621
|
+
h.Op(new FhOpSpec { Op = "load", Path = "/w" });
|
|
622
|
+
h.Op(new FhOpSpec { Op = "load", Path = "/w" });
|
|
623
|
+
Assert.True(2 == rec.Calls.Count, control + " was stored");
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
[Fact]
|
|
628
|
+
public void MaxAgeCapsTheTtl()
|
|
629
|
+
{
|
|
630
|
+
if (Fh.SkipWithout("cache")) return;
|
|
631
|
+
var clock = new FhClock();
|
|
632
|
+
var rec = new FhRecorder
|
|
633
|
+
{
|
|
634
|
+
Reply = (_, _) => Fh.Response(200, new Dictionary<string, object?> { ["ok"] = true },
|
|
635
|
+
new Dictionary<string, object?> { ["cache-control"] = "max-age=1" }),
|
|
636
|
+
};
|
|
637
|
+
var h = Fh.Make(rec.Fetch, (new CacheFeature(), new Dictionary<string, object?>
|
|
638
|
+
{
|
|
639
|
+
["ttl"] = 10000,
|
|
640
|
+
["now"] = (Func<long>)clock.Now,
|
|
641
|
+
}));
|
|
642
|
+
h.Op(new FhOpSpec { Op = "load", Path = "/w" });
|
|
643
|
+
clock.Advance(500);
|
|
644
|
+
h.Op(new FhOpSpec { Op = "load", Path = "/w" });
|
|
645
|
+
Assert.Single(rec.Calls);
|
|
646
|
+
clock.Advance(600);
|
|
647
|
+
h.Op(new FhOpSpec { Op = "load", Path = "/w" });
|
|
648
|
+
Assert.Equal(2, rec.Calls.Count);
|
|
649
|
+
}
|
|
650
|
+
|
|
575
651
|
[Fact]
|
|
576
652
|
public void InactiveDoesNotWrap()
|
|
577
653
|
{
|
|
@@ -1020,6 +1096,31 @@ public class FeatureAuditTest
|
|
|
1020
1096
|
}
|
|
1021
1097
|
}
|
|
1022
1098
|
|
|
1099
|
+
// --- one call, one id -----------------------------------------------------------
|
|
1100
|
+
|
|
1101
|
+
public class FeatureCorrelationTest
|
|
1102
|
+
{
|
|
1103
|
+
[Fact]
|
|
1104
|
+
public void TelemetryDebugAndAuditCarryOneCallsContextId()
|
|
1105
|
+
{
|
|
1106
|
+
if (Fh.SkipWithout("telemetry", "debug", "audit")) return;
|
|
1107
|
+
var telemetry = new TelemetryFeature();
|
|
1108
|
+
var debug = new DebugFeature();
|
|
1109
|
+
var audit = new AuditFeature();
|
|
1110
|
+
var h = Fh.Make(null, (telemetry, null), (debug, null), (audit, null));
|
|
1111
|
+
h.Op(new FhOpSpec { Op = "load" });
|
|
1112
|
+
h.Op(new FhOpSpec { Op = "list" });
|
|
1113
|
+
static List<object?> Ids(List<Dictionary<string, object?>> recs) =>
|
|
1114
|
+
recs.Select(rec => rec.GetValueOrDefault("correlationId")).ToList();
|
|
1115
|
+
var calls = Ids(audit.Records);
|
|
1116
|
+
Assert.Equal(2, calls.Count);
|
|
1117
|
+
Assert.All(calls, id => Assert.True(id is string s && s != "", $"context id: {id}"));
|
|
1118
|
+
Assert.NotEqual(calls[0], calls[1]);
|
|
1119
|
+
Assert.Equal(calls, Ids(telemetry.Spans));
|
|
1120
|
+
Assert.Equal(calls, Ids(debug.Entries));
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1023
1124
|
// --- clienttrack ----------------------------------------------------------------
|
|
1024
1125
|
|
|
1025
1126
|
public class FeatureClienttrackTest
|