@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.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +9 -1
- package/dist/utility.js.map +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/c/utility/make_spec.c +1 -1
- package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
- package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
- package/project/.sdk/tm/clojure/src/sdk/core.clj +48 -10
- 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/cpp/utility/pipeline.hpp +52 -4
- package/project/.sdk/tm/csharp/core/Control.cs +0 -5
- package/project/.sdk/tm/csharp/core/Point.cs +6 -0
- 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/csharp/utility/MakeSpec.cs +2 -2
- package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
- package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
- 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/lib/projectname/utility.ex +62 -6
- 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/core/target.go +8 -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/go/utility/prepare_body.go +37 -1
- package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
- package/project/.sdk/tm/java/core/Control.java +0 -5
- package/project/.sdk/tm/java/core/Point.java +7 -0
- 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/MakeSpec.java +1 -1
- package/project/.sdk/tm/java/utility/Media.java +2 -2
- package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
- package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
- package/project/.sdk/tm/js/src/Point.js +2 -0
- 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/src/utility/MakeSpecUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
- package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
- 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/core/Point.kt +7 -0
- 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/kotlin/utility/MakeSpecUrl.kt +1 -1
- package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
- 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/lua/utility/make_spec.lua +1 -1
- package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
- package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
- 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/sdk_runtime.ml +40 -5
- 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/perl/utility/make_spec.pm +1 -1
- package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
- package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
- 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/php/utility/MakeSpec.php +2 -2
- package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
- package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
- 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/pkg/utility/make_spec.py +1 -1
- package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
- package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
- 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/rb/utility/make_spec.rb +1 -1
- package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
- package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
- 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/rust/utility/prepare_body.rs +51 -0
- package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
- package/project/.sdk/tm/scala/core/Control.scala +0 -5
- package/project/.sdk/tm/scala/core/Point.scala +3 -0
- 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/scala/utility/MakeSpec.scala +1 -1
- package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
- 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/Sources/ProjectNameSDK/utility/Make.swift +1 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
- 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/Point.ts +3 -0
- 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/src/utility/PrepareBodyUtility.ts +29 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
- 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/core/utility.zig +47 -4
- 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
- package/src/utility.ts +12 -1
|
@@ -78,6 +78,7 @@ internal class WireCall
|
|
|
78
78
|
public string Url = "";
|
|
79
79
|
public string Auth = "";
|
|
80
80
|
public bool HasAuth;
|
|
81
|
+
public string Values = "";
|
|
81
82
|
public string Body = "";
|
|
82
83
|
public object? Redirect;
|
|
83
84
|
}
|
|
@@ -106,11 +107,14 @@ internal class Wire
|
|
|
106
107
|
var call = new WireCall { Url = url };
|
|
107
108
|
|
|
108
109
|
if (fetchdef.TryGetValue("headers", out var hraw) &&
|
|
109
|
-
hraw is Dictionary<string, object?> headers
|
|
110
|
-
headers.TryGetValue(SecretsFeatureTest.CredHeader, out var auth))
|
|
110
|
+
hraw is Dictionary<string, object?> headers)
|
|
111
111
|
{
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
if (headers.TryGetValue(SecretsFeatureTest.CredHeader, out var auth))
|
|
113
|
+
{
|
|
114
|
+
call.HasAuth = true;
|
|
115
|
+
call.Auth = auth as string ?? "";
|
|
116
|
+
}
|
|
117
|
+
call.Values = string.Join("\n", headers.Values);
|
|
114
118
|
}
|
|
115
119
|
if (fetchdef.TryGetValue("body", out var braw) && braw is string body)
|
|
116
120
|
{
|
|
@@ -197,8 +201,7 @@ public class SecretsFeatureTest
|
|
|
197
201
|
private static bool SkippedWithoutAuth(
|
|
198
202
|
[System.Runtime.CompilerServices.CallerMemberName] string test = "")
|
|
199
203
|
{
|
|
200
|
-
if (
|
|
201
|
-
options.ContainsKey("auth"))
|
|
204
|
+
if (DeclaresAuth())
|
|
202
205
|
{
|
|
203
206
|
return false;
|
|
204
207
|
}
|
|
@@ -206,17 +209,25 @@ public class SecretsFeatureTest
|
|
|
206
209
|
return true;
|
|
207
210
|
}
|
|
208
211
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
|
|
212
|
+
private static bool DeclaresAuth() =>
|
|
213
|
+
SdkConfig.SharedConfig()["options"] is Dictionary<string, object?> options &&
|
|
214
|
+
options.ContainsKey("auth");
|
|
215
|
+
|
|
216
|
+
// The header value PrepareAuth writes for a token, in the form the
|
|
217
|
+
// DEFAULT client's auth gives: under Basic the token is the key half of
|
|
218
|
+
// the encoded pair, and a prefix is space-joined.
|
|
219
|
+
private static string Credential(string token, string secret)
|
|
220
|
+
{
|
|
221
|
+
var auth = StructUtils.GetProp(ProjectNameSDK.TestSDK(null, null).OptionsMap(), "auth");
|
|
222
|
+
var prefix = StructUtils.GetProp(auth, "prefix") as string ?? "";
|
|
223
|
+
var value = true.Equals(StructUtils.GetProp(auth, "basic"))
|
|
224
|
+
? Convert.ToBase64String(Encoding.UTF8.GetBytes(token + ":" + secret)) : token;
|
|
225
|
+
return "" == prefix ? value : prefix + " " + value;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private static void CredentialIs(string header, string token, string secret = "")
|
|
216
229
|
{
|
|
217
|
-
|
|
218
|
-
Assert.True(got == token || got.EndsWith(" " + token),
|
|
219
|
-
"expected the " + CredHeader + " header to carry " + token + ", got: " + got);
|
|
230
|
+
Assert.Equal(Credential(token, secret), header);
|
|
220
231
|
}
|
|
221
232
|
|
|
222
233
|
// Construct the client and ADOPT the feature via `extend` ONLY when the
|
|
@@ -516,6 +527,30 @@ public class SecretsFeatureTest
|
|
|
516
527
|
}
|
|
517
528
|
}
|
|
518
529
|
|
|
530
|
+
[Fact]
|
|
531
|
+
public void AResolvedKeyIsPlacedAsPrepareAuthPlacesItTheSecretKept()
|
|
532
|
+
{
|
|
533
|
+
if (SkippedWithoutAuth()) return;
|
|
534
|
+
|
|
535
|
+
Environment.SetEnvironmentVariable(EnvPrefix + "APIKEY", "ENVKEY04");
|
|
536
|
+
try
|
|
537
|
+
{
|
|
538
|
+
var w = new Wire();
|
|
539
|
+
var client = SecretsClient(w, new Dictionary<string, object?>
|
|
540
|
+
{
|
|
541
|
+
["secret"] = "PASS01",
|
|
542
|
+
["feature"] = SecretsOpts(null),
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
DriveEntityOp(client, w);
|
|
546
|
+
CredentialIs(w.Api()[0].Auth, "ENVKEY04", "PASS01");
|
|
547
|
+
}
|
|
548
|
+
finally
|
|
549
|
+
{
|
|
550
|
+
Environment.SetEnvironmentVariable(EnvPrefix + "APIKEY", null);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
519
554
|
[Fact]
|
|
520
555
|
public void CustomProviderObjectsAreAcceptedVerbatim()
|
|
521
556
|
{
|
|
@@ -1408,6 +1443,34 @@ public class SecretsFeatureTest
|
|
|
1408
1443
|
}
|
|
1409
1444
|
}
|
|
1410
1445
|
|
|
1446
|
+
[Fact]
|
|
1447
|
+
public void ATokenBoughtOnARefusalIsPlacedAsPrepareAuthPlacesIt()
|
|
1448
|
+
{
|
|
1449
|
+
if (SkippedWithoutAuth()) return;
|
|
1450
|
+
|
|
1451
|
+
Environment.SetEnvironmentVariable(EnvPrefix + "REFRESH_TOKEN", "REFRESH01");
|
|
1452
|
+
try
|
|
1453
|
+
{
|
|
1454
|
+
var w = new Wire { ApiStatus = new List<int> { 401, 200 } };
|
|
1455
|
+
var client = SecretsClient(w, new Dictionary<string, object?>
|
|
1456
|
+
{
|
|
1457
|
+
["secret"] = "PASS01",
|
|
1458
|
+
["feature"] = ExchangeOpts(null),
|
|
1459
|
+
});
|
|
1460
|
+
|
|
1461
|
+
client.Direct(new Dictionary<string, object?> { ["path"] = "/thing" });
|
|
1462
|
+
|
|
1463
|
+
Assert.True(2 == w.Api().Count,
|
|
1464
|
+
"expected the request to be retried exactly once, got " + w.Api().Count);
|
|
1465
|
+
CredentialIs(w.Api()[0].Auth, "ACCESS01", "PASS01");
|
|
1466
|
+
CredentialIs(w.Api()[1].Auth, "ACCESS02", "PASS01");
|
|
1467
|
+
}
|
|
1468
|
+
finally
|
|
1469
|
+
{
|
|
1470
|
+
Environment.SetEnvironmentVariable(EnvPrefix + "REFRESH_TOKEN", null);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1411
1474
|
[Fact]
|
|
1412
1475
|
public void AnExplicitExchangeRefreshWinsOverTheChain()
|
|
1413
1476
|
{
|
|
@@ -1899,39 +1962,102 @@ public class SecretsFeatureTest
|
|
|
1899
1962
|
}
|
|
1900
1963
|
}
|
|
1901
1964
|
|
|
1902
|
-
// Real
|
|
1903
|
-
|
|
1904
|
-
|
|
1965
|
+
// Real origins: this one answers the exchange as Answer says and
|
|
1966
|
+
// records whatever else it gets; the other records everything.
|
|
1967
|
+
private sealed class RedirectOrigins : IDisposable
|
|
1905
1968
|
{
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1969
|
+
public readonly List<string> Elsewhere = new();
|
|
1970
|
+
public readonly List<string> Followed = new();
|
|
1971
|
+
public int Exchanged;
|
|
1972
|
+
public (int Status, string Location) Answer = (307, "");
|
|
1973
|
+
public readonly ExchangeOrigin Origin;
|
|
1974
|
+
public readonly ExchangeOrigin Other;
|
|
1911
1975
|
|
|
1912
|
-
|
|
1976
|
+
public RedirectOrigins()
|
|
1913
1977
|
{
|
|
1914
|
-
|
|
1978
|
+
Other = new ExchangeOrigin((method, path, body) =>
|
|
1915
1979
|
{
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1980
|
+
lock (Elsewhere)
|
|
1981
|
+
{
|
|
1982
|
+
Elsewhere.Add(method + " " + path + " " + body);
|
|
1983
|
+
}
|
|
1984
|
+
return ("200 OK", null, "{\"access_token\":\"ELSEWHERE01\"}");
|
|
1985
|
+
});
|
|
1986
|
+
Origin = new ExchangeOrigin((method, path, body) =>
|
|
1987
|
+
{
|
|
1988
|
+
lock (Followed)
|
|
1989
|
+
{
|
|
1990
|
+
if ("/api/auth/token" == path)
|
|
1991
|
+
{
|
|
1992
|
+
Exchanged++;
|
|
1993
|
+
return (Answer.Status + " X", Answer.Location, "");
|
|
1994
|
+
}
|
|
1995
|
+
Followed.Add((method + " " + path + " " + body).Trim());
|
|
1996
|
+
}
|
|
1997
|
+
return ("200 OK", null, "{\"access_token\":\"MOVED01\"}");
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
public string Base => Origin.Base + "/api";
|
|
2002
|
+
public string Away => Other.Base + "/api/auth/token";
|
|
2003
|
+
|
|
2004
|
+
public void Dispose()
|
|
1921
2005
|
{
|
|
1922
|
-
|
|
2006
|
+
Origin.Dispose();
|
|
2007
|
+
Other.Dispose();
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
private static ProjectNameSDK RedirectClient(RedirectOrigins o, string? redirect = null)
|
|
2012
|
+
{
|
|
2013
|
+
return WithSecrets(extend =>
|
|
2014
|
+
{
|
|
2015
|
+
var exchange = new Dictionary<string, object?>
|
|
2016
|
+
{
|
|
2017
|
+
["active"] = true,
|
|
2018
|
+
["refresh"] = "REFRESH01",
|
|
2019
|
+
};
|
|
2020
|
+
if (null != redirect)
|
|
1923
2021
|
{
|
|
1924
|
-
|
|
2022
|
+
exchange["redirect"] = redirect;
|
|
1925
2023
|
}
|
|
1926
|
-
|
|
2024
|
+
var opts = new Dictionary<string, object?>
|
|
1927
2025
|
{
|
|
1928
|
-
|
|
2026
|
+
["base"] = o.Base,
|
|
2027
|
+
["allow"] = new Dictionary<string, object?>
|
|
2028
|
+
{
|
|
2029
|
+
["op"] = "create,update,load,list,remove,command,direct,graphql",
|
|
2030
|
+
},
|
|
2031
|
+
["feature"] = new Dictionary<string, object?>
|
|
2032
|
+
{
|
|
2033
|
+
["secrets"] = new Dictionary<string, object?>
|
|
2034
|
+
{
|
|
2035
|
+
["active"] = true,
|
|
2036
|
+
["name"] = "refresh_token",
|
|
2037
|
+
["exchange"] = exchange,
|
|
2038
|
+
},
|
|
2039
|
+
},
|
|
2040
|
+
};
|
|
2041
|
+
if (extend)
|
|
2042
|
+
{
|
|
2043
|
+
opts["extend"] = new List<object?> { new SecretsFeature() };
|
|
1929
2044
|
}
|
|
1930
|
-
return (
|
|
2045
|
+
return new ProjectNameSDK(opts);
|
|
1931
2046
|
});
|
|
2047
|
+
}
|
|
1932
2048
|
|
|
1933
|
-
|
|
1934
|
-
|
|
2049
|
+
// Real listeners and the SDK's own raw fetch: a stub follows nothing.
|
|
2050
|
+
[Fact]
|
|
2051
|
+
public void ARedirectAnsweringTheExchangeIsAFailureAndNothingFollowsIt()
|
|
2052
|
+
{
|
|
2053
|
+
if (SkippedWithoutAuth()) return;
|
|
2054
|
+
|
|
2055
|
+
using var o = new RedirectOrigins();
|
|
2056
|
+
var elsewhere = o.Elsewhere;
|
|
2057
|
+
var followed = o.Followed;
|
|
2058
|
+
|
|
2059
|
+
var basev = o.Base;
|
|
2060
|
+
var away = o.Away;
|
|
1935
2061
|
var answers = new[] { (307, away), (308, away), (302, away), (307, "/api/moved/token") };
|
|
1936
2062
|
|
|
1937
2063
|
var allowed = new List<string>();
|
|
@@ -1939,36 +2065,8 @@ public class SecretsFeatureTest
|
|
|
1939
2065
|
|
|
1940
2066
|
foreach (var next in answers)
|
|
1941
2067
|
{
|
|
1942
|
-
|
|
1943
|
-
var client =
|
|
1944
|
-
{
|
|
1945
|
-
var opts = new Dictionary<string, object?>
|
|
1946
|
-
{
|
|
1947
|
-
["base"] = basev,
|
|
1948
|
-
["allow"] = new Dictionary<string, object?>
|
|
1949
|
-
{
|
|
1950
|
-
["op"] = "create,update,load,list,remove,command,direct,graphql",
|
|
1951
|
-
},
|
|
1952
|
-
["feature"] = new Dictionary<string, object?>
|
|
1953
|
-
{
|
|
1954
|
-
["secrets"] = new Dictionary<string, object?>
|
|
1955
|
-
{
|
|
1956
|
-
["active"] = true,
|
|
1957
|
-
["name"] = "refresh_token",
|
|
1958
|
-
["exchange"] = new Dictionary<string, object?>
|
|
1959
|
-
{
|
|
1960
|
-
["active"] = true,
|
|
1961
|
-
["refresh"] = "REFRESH01",
|
|
1962
|
-
},
|
|
1963
|
-
},
|
|
1964
|
-
},
|
|
1965
|
-
};
|
|
1966
|
-
if (extend)
|
|
1967
|
-
{
|
|
1968
|
-
opts["extend"] = new List<object?> { new SecretsFeature() };
|
|
1969
|
-
}
|
|
1970
|
-
return new ProjectNameSDK(opts);
|
|
1971
|
-
});
|
|
2068
|
+
o.Answer = next;
|
|
2069
|
+
var client = RedirectClient(o);
|
|
1972
2070
|
|
|
1973
2071
|
var res = client.Direct(new Dictionary<string, object?> { ["path"] = "/thing" });
|
|
1974
2072
|
var message = ErrMessage(res);
|
|
@@ -1996,6 +2094,91 @@ public class SecretsFeatureTest
|
|
|
1996
2094
|
Assert.Equal(answers.Length, refused);
|
|
1997
2095
|
}
|
|
1998
2096
|
|
|
2097
|
+
[Fact]
|
|
2098
|
+
public void WithTheOptionARedirectOnTheExchangesOwnOriginIsFollowedAndNoOther()
|
|
2099
|
+
{
|
|
2100
|
+
if (SkippedWithoutAuth()) return;
|
|
2101
|
+
|
|
2102
|
+
using var o = new RedirectOrigins();
|
|
2103
|
+
var sent = " {\"refresh_token\":\"REFRESH01\"}";
|
|
2104
|
+
// Each case: the status, the Location, and the path the exchange is
|
|
2105
|
+
// asked again at, or null where the redirect is refused.
|
|
2106
|
+
var cases = new (int, string, string?)[]
|
|
2107
|
+
{
|
|
2108
|
+
(307, "/api/moved/token", "/api/moved/token"),
|
|
2109
|
+
(308, o.Origin.Base + "/api/moved/token", "/api/moved/token"),
|
|
2110
|
+
// A Location of a query alone keeps the path that answered.
|
|
2111
|
+
(307, "?step=2", "/api/auth/token?step=2"),
|
|
2112
|
+
(307, o.Away, null),
|
|
2113
|
+
(302, "/api/moved/token", null),
|
|
2114
|
+
(307, "/api/auth/token", null),
|
|
2115
|
+
};
|
|
2116
|
+
|
|
2117
|
+
var wrong = new List<string>();
|
|
2118
|
+
var followed = 0;
|
|
2119
|
+
var refused = 0;
|
|
2120
|
+
var looped = 0;
|
|
2121
|
+
|
|
2122
|
+
foreach (var (status, location, path) in cases)
|
|
2123
|
+
{
|
|
2124
|
+
lock (o.Followed)
|
|
2125
|
+
{
|
|
2126
|
+
o.Answer = (status, location);
|
|
2127
|
+
o.Followed.Clear();
|
|
2128
|
+
o.Exchanged = 0;
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
var res = RedirectClient(o, "same-origin")
|
|
2132
|
+
.Direct(new Dictionary<string, object?> { ["path"] = "/thing" });
|
|
2133
|
+
var message = ErrMessage(res);
|
|
2134
|
+
|
|
2135
|
+
List<string> seen;
|
|
2136
|
+
lock (o.Followed)
|
|
2137
|
+
{
|
|
2138
|
+
seen = new List<string>(o.Followed);
|
|
2139
|
+
if ("/api/auth/token" == location)
|
|
2140
|
+
{
|
|
2141
|
+
looped = o.Exchanged;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
var report = status + " to " + location + ": ok=" + res["ok"] + " " + message +
|
|
2145
|
+
" [" + string.Join(" | ", seen) + "]";
|
|
2146
|
+
|
|
2147
|
+
if (null != path)
|
|
2148
|
+
{
|
|
2149
|
+
if (Equals(res["ok"], true) && 2 == seen.Count && "POST " + path + sent == seen[0])
|
|
2150
|
+
{
|
|
2151
|
+
followed++;
|
|
2152
|
+
}
|
|
2153
|
+
else
|
|
2154
|
+
{
|
|
2155
|
+
wrong.Add(report);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
else if (0 == seen.Count && message.Contains(
|
|
2159
|
+
"token exchange failed: " + status + " from " + o.Base + "/auth/token"))
|
|
2160
|
+
{
|
|
2161
|
+
refused++;
|
|
2162
|
+
}
|
|
2163
|
+
else
|
|
2164
|
+
{
|
|
2165
|
+
wrong.Add(report);
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
Console.WriteLine("secrets: exchange opt-in followed " + followed +
|
|
2170
|
+
" redirect(s) on its own origin, refused " + refused + ", " +
|
|
2171
|
+
o.Elsewhere.Count + " elsewhere");
|
|
2172
|
+
|
|
2173
|
+
Assert.True(0 == o.Elsewhere.Count,
|
|
2174
|
+
"the exchange reached another origin: " + string.Join(" | ", o.Elsewhere));
|
|
2175
|
+
Assert.True(0 == wrong.Count, string.Join(" || ", wrong));
|
|
2176
|
+
Assert.Equal(3, followed);
|
|
2177
|
+
Assert.Equal(3, refused);
|
|
2178
|
+
// A redirect to itself stops at the hop limit.
|
|
2179
|
+
Assert.Equal(6, looped);
|
|
2180
|
+
}
|
|
2181
|
+
|
|
1999
2182
|
private static int FreePort()
|
|
2000
2183
|
{
|
|
2001
2184
|
var probe = new System.Net.Sockets.TcpListener(IPAddress.Loopback, 0);
|
|
@@ -2075,4 +2258,68 @@ public class SecretsFeatureTest
|
|
|
2075
2258
|
CredentialIs(call.Auth, "FRESH01");
|
|
2076
2259
|
}
|
|
2077
2260
|
}
|
|
2261
|
+
|
|
2262
|
+
// --- auth off -------------------------------------------------------
|
|
2263
|
+
//
|
|
2264
|
+
// Off by the config where it declares no auth, else by `auth: null`:
|
|
2265
|
+
// either way the feature places no credential, buys no token and
|
|
2266
|
+
// retries nothing.
|
|
2267
|
+
|
|
2268
|
+
[Fact]
|
|
2269
|
+
public void AuthOffPlacesNoCredentialAndBuysNoToken()
|
|
2270
|
+
{
|
|
2271
|
+
var declared = DeclaresAuth();
|
|
2272
|
+
var secrets = new[] { "OFFKEY01", "OFFKEY02", "OFFREFRESH01", "ACCESS01" };
|
|
2273
|
+
bool Carries(WireCall call) => call.HasAuth || secrets.Any(call.Values.Contains);
|
|
2274
|
+
var sent = new List<WireCall>();
|
|
2275
|
+
var bought = 0;
|
|
2276
|
+
|
|
2277
|
+
var scenarios = new (string What, string Env, string Value, Dictionary<string, object?> Opts, int Status)[]
|
|
2278
|
+
{
|
|
2279
|
+
("a key the chain resolves", "APIKEY", "OFFKEY01",
|
|
2280
|
+
new Dictionary<string, object?> { ["feature"] = SecretsOpts(null) }, 200),
|
|
2281
|
+
("an explicit apikey", "", "",
|
|
2282
|
+
new Dictionary<string, object?> { ["apikey"] = "OFFKEY02", ["feature"] = SecretsOpts(null) }, 200),
|
|
2283
|
+
("a refusal", "REFRESH_TOKEN", "OFFREFRESH01",
|
|
2284
|
+
new Dictionary<string, object?> { ["feature"] = ExchangeOpts(null) }, 401),
|
|
2285
|
+
};
|
|
2286
|
+
|
|
2287
|
+
foreach (var (what, env, value, opts, status) in scenarios)
|
|
2288
|
+
{
|
|
2289
|
+
if ("" != env)
|
|
2290
|
+
{
|
|
2291
|
+
Environment.SetEnvironmentVariable(EnvPrefix + env, value);
|
|
2292
|
+
}
|
|
2293
|
+
try
|
|
2294
|
+
{
|
|
2295
|
+
var w = new Wire { ApiStatus = new List<int> { status } };
|
|
2296
|
+
if (declared)
|
|
2297
|
+
{
|
|
2298
|
+
opts["auth"] = null;
|
|
2299
|
+
}
|
|
2300
|
+
var client = SecretsClient(w, opts);
|
|
2301
|
+
|
|
2302
|
+
client.Direct(new Dictionary<string, object?> { ["path"] = "/thing" });
|
|
2303
|
+
|
|
2304
|
+
Assert.True(1 == w.Api().Count, what + ": a request was retried with auth off");
|
|
2305
|
+
Assert.True(0 == w.Token().Count, what + ": a token was bought with auth off");
|
|
2306
|
+
Assert.False(Carries(w.Api()[0]), what + ": a credential was sent with auth off: " + w.Report());
|
|
2307
|
+
Assert.Equal("", SecretsOf(client)!.Credential());
|
|
2308
|
+
|
|
2309
|
+
sent.AddRange(w.Api());
|
|
2310
|
+
bought += w.Token().Count;
|
|
2311
|
+
}
|
|
2312
|
+
finally
|
|
2313
|
+
{
|
|
2314
|
+
if ("" != env)
|
|
2315
|
+
{
|
|
2316
|
+
Environment.SetEnvironmentVariable(EnvPrefix + env, null);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
Console.WriteLine("secrets: auth off by " + (declared ? "option" : "config") + ": " +
|
|
2322
|
+
sent.Count + " request(s), " + sent.Count(Carries) + " credential(s), " +
|
|
2323
|
+
bought + " token(s)");
|
|
2324
|
+
}
|
|
2078
2325
|
}
|
|
@@ -64,8 +64,8 @@ public static partial class SdkUtility
|
|
|
64
64
|
{
|
|
65
65
|
// GraphQL addresses one endpoint: no path parts, no query
|
|
66
66
|
// string, and the body carries the operation. PrepareBody is
|
|
67
|
-
// skipped deliberately — it only
|
|
68
|
-
//
|
|
67
|
+
// skipped deliberately — it builds only a REST body,
|
|
68
|
+
// whereas every GraphQL op posts one, including
|
|
69
69
|
// load/list/remove.
|
|
70
70
|
ctx.Spec.Body = utility.GraphqlBody(ctx);
|
|
71
71
|
ctx.Spec.Path = "";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// ProjectName SDK utility: prepareBody.
|
|
2
2
|
|
|
3
|
+
using Voxgig.Struct;
|
|
4
|
+
|
|
3
5
|
namespace ProjectNameSdk.Util;
|
|
4
6
|
|
|
5
7
|
public static partial class SdkUtility
|
|
@@ -18,6 +20,46 @@ public static partial class SdkUtility
|
|
|
18
20
|
return body;
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
if (StructUtils.GetProp(ctx.Point, "fields") is List<object?> fields && 0 < fields.Count)
|
|
24
|
+
{
|
|
25
|
+
return MatchBody(ctx, fields);
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
return null;
|
|
22
29
|
}
|
|
30
|
+
|
|
31
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
32
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
33
|
+
// cookie or query argument the body does not also declare as a field.
|
|
34
|
+
private static Dictionary<string, object?> MatchBody(Context ctx, List<object?> fields)
|
|
35
|
+
{
|
|
36
|
+
var routed = new List<object?>();
|
|
37
|
+
if (StructUtils.GetProp(ctx.Point, "params") is List<object?> pl)
|
|
38
|
+
{
|
|
39
|
+
routed.AddRange(pl);
|
|
40
|
+
}
|
|
41
|
+
if (StructUtils.GetPath(ctx.Point, StructUtils.Jt("args", "params")) is List<object?> apl)
|
|
42
|
+
{
|
|
43
|
+
routed.AddRange(apl.Select(pd => StructUtils.GetProp(pd, "name")));
|
|
44
|
+
}
|
|
45
|
+
foreach (var kind in new[] { "header", "cookie", "query" })
|
|
46
|
+
{
|
|
47
|
+
if (StructUtils.GetPath(ctx.Point, StructUtils.Jt("args", kind)) is List<object?> defs)
|
|
48
|
+
{
|
|
49
|
+
routed.AddRange(defs.Where(ad => StructUtils.GetProp(ad, "field") is not true)
|
|
50
|
+
.Select(ad => StructUtils.GetProp(ad, "name")));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var body = new Dictionary<string, object?>();
|
|
55
|
+
foreach (var field in fields)
|
|
56
|
+
{
|
|
57
|
+
if (field is string name && "$action" != name && !routed.Contains(name) &&
|
|
58
|
+
StructUtils.GetProp(ctx.Reqmatch, name) is { } val)
|
|
59
|
+
{
|
|
60
|
+
body[name] = val;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return body;
|
|
64
|
+
}
|
|
23
65
|
}
|
|
@@ -32,8 +32,9 @@ public static partial class SdkUtility
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// A header or cookie parameter travels in the headers, which
|
|
35
|
-
// PrepareHeaders fills,
|
|
36
|
-
//
|
|
35
|
+
// PrepareHeaders fills, and a field the point's body declares travels in
|
|
36
|
+
// the body, which PrepareBody fills, unless a query parameter shares its
|
|
37
|
+
// name: then both are sent.
|
|
37
38
|
var declared = new List<object?>();
|
|
38
39
|
if (point != null &&
|
|
39
40
|
StructUtils.GetPath(point, StructUtils.Jt("args", "query")) is List<object?> dql)
|
|
@@ -65,6 +66,16 @@ public static partial class SdkUtility
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
}
|
|
69
|
+
if (point != null && StructUtils.GetProp(point, "fields") is List<object?> afl)
|
|
70
|
+
{
|
|
71
|
+
foreach (var fd in afl)
|
|
72
|
+
{
|
|
73
|
+
if (fd is string fname && !declared.Contains(fname))
|
|
74
|
+
{
|
|
75
|
+
paramnames.Add(fname);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
68
79
|
|
|
69
80
|
// A query parameter travels under the name the definition gives it,
|
|
70
81
|
// its orig, which the model may have renamed for the caller.
|
|
@@ -110,8 +110,6 @@ defmodule ProjectName.EntityBase do
|
|
|
110
110
|
# entity is yielded as its record, the struct map its data_get/1 returns.
|
|
111
111
|
# `callopts` parameterises the call:
|
|
112
112
|
# - ctrl: per-call pipeline control (threaded onto the op ctx);
|
|
113
|
-
# - body: an enumerable/list payload for outbound (upload) streaming,
|
|
114
|
-
# attached to the request (reqdata.body$ + a stream_out marker);
|
|
115
113
|
# - signal: an optional 0-arity fn; when it returns true iteration stops.
|
|
116
114
|
def stream(ent, action, args \\ nil, callopts \\ nil) do
|
|
117
115
|
callopts = if S.ismap(callopts), do: callopts, else: S.jm([])
|
|
@@ -134,17 +132,6 @@ defmodule ProjectName.EntityBase do
|
|
|
134
132
|
|
|
135
133
|
ctx = Context.new(ctxmap, S.getprop(ent, "_entctx"))
|
|
136
134
|
|
|
137
|
-
# Outbound: expose an enumerable/list payload so the request builder /
|
|
138
|
-
# transport can stream it as the request body.
|
|
139
|
-
body = S.getprop(callopts, "body")
|
|
140
|
-
|
|
141
|
-
if body != nil do
|
|
142
|
-
reqdata = H.or_(H.to_map(S.getprop(ctx, "reqdata")), S.jm([]))
|
|
143
|
-
S.setprop(reqdata, "body$", body)
|
|
144
|
-
S.setprop(ctx, "reqdata", reqdata)
|
|
145
|
-
S.setprop(ctx, "stream_out", body)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
135
|
Pipeline.run_op(ctx, fn -> nil end)
|
|
149
136
|
|
|
150
137
|
result = S.getprop(ctx, "result")
|
|
@@ -60,16 +60,23 @@ defmodule ProjectName.Feature.Cache do
|
|
|
60
60
|
else
|
|
61
61
|
{res, err} = inner.(ctx, url, fetchdef)
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
cond do
|
|
64
|
+
# A body that declares another type than JSON passes by, unread.
|
|
65
|
+
err == nil and cacheable(res) and not json?(res) ->
|
|
66
|
+
track(f, "bypass")
|
|
67
|
+
{res, err}
|
|
68
|
+
|
|
69
|
+
err == nil and cacheable(res) ->
|
|
70
|
+
snap = snapshot(res)
|
|
71
|
+
ttl = case S.getprop(opts, "ttl") do nil -> 5000; v -> v end
|
|
72
|
+
evict(f)
|
|
73
|
+
S.setprop(store, key, S.jm(["expiry", now + ttl, "snapshot", snap]))
|
|
74
|
+
track(f, "miss")
|
|
75
|
+
{replay(snap), nil}
|
|
76
|
+
|
|
77
|
+
true ->
|
|
78
|
+
track(f, "bypass")
|
|
79
|
+
{res, err}
|
|
73
80
|
end
|
|
74
81
|
end
|
|
75
82
|
end
|
|
@@ -90,6 +97,21 @@ defmodule ProjectName.Feature.Cache do
|
|
|
90
97
|
end
|
|
91
98
|
end
|
|
92
99
|
|
|
100
|
+
defp json?(res) do
|
|
101
|
+
headers = S.getprop(res, "headers")
|
|
102
|
+
|
|
103
|
+
type =
|
|
104
|
+
if S.ismap(headers) do
|
|
105
|
+
Enum.find_value(H.entries(headers), "", fn {k, v} ->
|
|
106
|
+
if String.downcase(to_string(k)) == "content-type", do: to_string(v)
|
|
107
|
+
end)
|
|
108
|
+
else
|
|
109
|
+
""
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
type == "" or ProjectName.Utility.json_media?(type)
|
|
113
|
+
end
|
|
114
|
+
|
|
93
115
|
defp snapshot(res) do
|
|
94
116
|
jf = S.getprop(res, "json")
|
|
95
117
|
|