@voxgig/sdkgen 4.35.0 → 4.35.2
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/src/cmp/py/EntityTypes_py.ts +33 -16
- package/project/.sdk/tm/c/feature/secrets.c +21 -6
- package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +24 -9
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +16 -10
- package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +16 -7
- package/project/.sdk/tm/cpp/feature/secrets.hpp +9 -4
- package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +20 -7
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +10 -6
- package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +21 -9
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +7 -3
- package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +15 -5
- package/project/.sdk/tm/go/feature/secrets_feature.go +9 -2
- package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +21 -10
- package/project/.sdk/tm/java/feature/SecretsFeature.java +10 -5
- package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +21 -9
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +8 -4
- package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +35 -24
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +11 -6
- package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +17 -8
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +11 -4
- package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +22 -9
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +8 -4
- package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +19 -10
- package/project/.sdk/tm/php/feature/SecretsFeature.php +10 -5
- package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +33 -11
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +8 -3
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +27 -13
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -5
- package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +20 -11
- package/project/.sdk/tm/rust/feature/secrets.rs +8 -7
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +17 -2
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +10 -5
- package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +19 -7
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -5
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +15 -7
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +5 -1
- package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +31 -20
- package/project/.sdk/tm/zig/feature/secrets.zig +12 -6
- package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +21 -5
- package/project/sdkgen-package.json +1 -1
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
-- `graphql()` run no hooks at all. The transport wrapper installed in init
|
|
22
22
|
-- is the one seam every wire path crosses: entity ops (make_request), the
|
|
23
23
|
-- raw paths (_raw_request) and the exchange retries all come through it. It
|
|
24
|
-
-- resolves there, rewrites the
|
|
24
|
+
-- resolves there, rewrites the credential header prepare_auth built from
|
|
25
25
|
-- the options apikey, and - this is the point - REFUSES TO SEND while the
|
|
26
26
|
-- chain is broken.
|
|
27
27
|
--
|
|
@@ -445,7 +445,7 @@ end
|
|
|
445
445
|
|
|
446
446
|
|
|
447
447
|
-- Buy a token and try the request again when the API says the current one
|
|
448
|
-
-- is spent. The retry rewrites the
|
|
448
|
+
-- is spent. The retry rewrites the credential header IN PLACE on the
|
|
449
449
|
-- fetchdef, because the header was built before this request left and it
|
|
450
450
|
-- carries the token that just failed.
|
|
451
451
|
function SecretsFeature:_with_refresh(ctx, fullurl, fetchdef, inner)
|
|
@@ -532,15 +532,22 @@ function SecretsFeature:_reauth(fetchdef, token)
|
|
|
532
532
|
return
|
|
533
533
|
end
|
|
534
534
|
|
|
535
|
+
-- The header prepare_auth writes: auth.name, lower-cased.
|
|
536
|
+
local name = auth["name"]
|
|
537
|
+
if type(name) ~= "string" or name == "" then
|
|
538
|
+
name = "authorization"
|
|
539
|
+
end
|
|
540
|
+
name = string.lower(name)
|
|
541
|
+
|
|
535
542
|
local prefix = auth["prefix"]
|
|
536
543
|
if type(prefix) ~= "string" then
|
|
537
544
|
prefix = ""
|
|
538
545
|
end
|
|
539
546
|
|
|
540
547
|
if prefix == "" then
|
|
541
|
-
headers[
|
|
548
|
+
headers[name] = token
|
|
542
549
|
else
|
|
543
|
-
headers[
|
|
550
|
+
headers[name] = prefix .. " " .. token
|
|
544
551
|
end
|
|
545
552
|
end
|
|
546
553
|
|
|
@@ -40,6 +40,19 @@ local SecretsFeature = require("feature.secrets_feature")
|
|
|
40
40
|
local sekreto = require("feature.secrets.sekreto")
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
-- The header the credential travels in: the DEFAULT client's auth.name,
|
|
44
|
+
-- lower-cased as prepare_auth sends it. Read from a default client because
|
|
45
|
+
-- a test that clears `auth` leaves no name to read.
|
|
46
|
+
local CREDHEADER = (function()
|
|
47
|
+
local auth = sdk.test(nil, nil):options_map().auth
|
|
48
|
+
local name = type(auth) == "table" and auth.name or nil
|
|
49
|
+
if type(name) == "string" and name ~= "" then
|
|
50
|
+
return string.lower(name)
|
|
51
|
+
end
|
|
52
|
+
return "authorization"
|
|
53
|
+
end)()
|
|
54
|
+
|
|
55
|
+
|
|
43
56
|
-- ---------------------------------------------------------------------
|
|
44
57
|
-- The recording transport: system.fetch for a LIVE client, scripting one
|
|
45
58
|
-- status per API call (the last repeating) and a token endpoint for the
|
|
@@ -64,7 +77,7 @@ local function make_wire(script)
|
|
|
64
77
|
|
|
65
78
|
w.fetch = function(url, fetchdef)
|
|
66
79
|
local headers = type(fetchdef) == "table" and fetchdef.headers or {}
|
|
67
|
-
local auth = headers[
|
|
80
|
+
local auth = headers[CREDHEADER]
|
|
68
81
|
w.calls[#w.calls + 1] = {
|
|
69
82
|
url = url, auth = auth, has = auth ~= nil,
|
|
70
83
|
body = fetchdef.body, method = fetchdef.method,
|
|
@@ -113,14 +126,14 @@ end
|
|
|
113
126
|
-- ---------------------------------------------------------------------
|
|
114
127
|
-- Support.
|
|
115
128
|
|
|
116
|
-
-- The
|
|
117
|
-
-- TEMPLATE cannot know - so assert on the CREDENTIAL and let the
|
|
118
|
-
-- whatever this SDK's API declares.
|
|
129
|
+
-- The credential header carries the SPEC's credential prefix (if any),
|
|
130
|
+
-- which a TEMPLATE cannot know - so assert on the CREDENTIAL and let the
|
|
131
|
+
-- prefix be whatever this SDK's API declares.
|
|
119
132
|
local function assert_credential(header, token)
|
|
120
133
|
local ok = header == token
|
|
121
134
|
or (type(header) == "string" and header:sub(-(#token + 1)) == " " .. token)
|
|
122
|
-
assert.is_true(ok, "expected the
|
|
123
|
-
", got: " .. tostring(header))
|
|
135
|
+
assert.is_true(ok, "expected the " .. CREDHEADER .. " header to carry " ..
|
|
136
|
+
token .. ", got: " .. tostring(header))
|
|
124
137
|
end
|
|
125
138
|
|
|
126
139
|
|
|
@@ -257,16 +270,16 @@ describe("secrets", function()
|
|
|
257
270
|
local client = sdk.test(nil, { apikey = "OPTKEY01" })
|
|
258
271
|
local fetchdef, err = client:prepare({ path = "/" })
|
|
259
272
|
assert.is_nil(err)
|
|
260
|
-
assert_credential(fetchdef.headers[
|
|
273
|
+
assert_credential(fetchdef.headers[CREDHEADER], "OPTKEY01")
|
|
261
274
|
assert.is_nil(secrets_feature_of(client),
|
|
262
275
|
"no model activation, no extend: the feature must not be installed")
|
|
263
276
|
end)
|
|
264
277
|
|
|
265
|
-
it("no apikey means no
|
|
278
|
+
it("no apikey means no credential header", function()
|
|
266
279
|
local client = sdk.test(nil, nil)
|
|
267
280
|
local fetchdef, err = client:prepare({ path = "/" })
|
|
268
281
|
assert.is_nil(err)
|
|
269
|
-
assert.is_nil(fetchdef.headers[
|
|
282
|
+
assert.is_nil(fetchdef.headers[CREDHEADER])
|
|
270
283
|
end)
|
|
271
284
|
|
|
272
285
|
it("an inactive feature wraps nothing and resolves nothing", function()
|
|
@@ -185,7 +185,7 @@ let make ?(plugins : Defs.definition list = [])
|
|
|
185
185
|
jo [("resolves", Num 0.); ("refusals", Num 0.); ("buys", Num 0.); ("retries", Num 0.)])
|
|
186
186
|
| None -> empty_map () in
|
|
187
187
|
|
|
188
|
-
(* Rewrite the
|
|
188
|
+
(* Rewrite the credential header on THIS request from the resolved
|
|
189
189
|
* credential, the way prepare_auth builds it: `auth: null` (Noval or a
|
|
190
190
|
* stored Null - the documented way to send NO credential) means no
|
|
191
191
|
* header, else options.auth.prefix + the token. *)
|
|
@@ -193,11 +193,15 @@ let make ?(plugins : Defs.definition list = [])
|
|
|
193
193
|
match getp fetchdef "headers" with
|
|
194
194
|
| Map _ as headers ->
|
|
195
195
|
let opts = live_options () in
|
|
196
|
+
(* The header prepare_auth writes: auth.name, lower-cased. *)
|
|
197
|
+
let name = match getpath_s opts "auth.name" with
|
|
198
|
+
| Str s when s <> "" -> String.lowercase_ascii s
|
|
199
|
+
| _ -> "authorization" in
|
|
196
200
|
(match getp opts "auth" with
|
|
197
201
|
| Map _ ->
|
|
198
202
|
let prefix = match getpath_s opts "auth.prefix" with Str s -> s | _ -> "" in
|
|
199
|
-
setp headers
|
|
200
|
-
| _ -> ignore (delprop headers (Str
|
|
203
|
+
setp headers name (Str (if prefix <> "" then prefix ^ " " ^ token else token))
|
|
204
|
+
| _ -> ignore (delprop headers (Str name)))
|
|
201
205
|
| _ -> () in
|
|
202
206
|
|
|
203
207
|
let spent (x : xchg) (res : value) : bool =
|
|
@@ -316,7 +320,7 @@ let make ?(plugins : Defs.definition list = [])
|
|
|
316
320
|
else (match buy x with Ok _ -> Ok () | Error m -> Error m))) in
|
|
317
321
|
|
|
318
322
|
(* Buy a token and try the request again when the API says the current
|
|
319
|
-
* one is spent. The retry rewrites the
|
|
323
|
+
* one is spent. The retry rewrites the credential header IN PLACE on
|
|
320
324
|
* the fetchdef, because the header carries the token that just failed. *)
|
|
321
325
|
let withrefresh (x : xchg) fctx url fetchdef inner : (value * sdk_error option) =
|
|
322
326
|
(* `auth: null` is the documented way to send NO credential, and
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* test-mode mock, which replaces the fetcher and hides the seam;
|
|
15
15
|
* - every assertion reads what the RECORDER received, never the options
|
|
16
16
|
* map, which this feature never writes. The FEATURE writes the
|
|
17
|
-
*
|
|
17
|
+
* credential header (see the header-only note on placed_cred_of
|
|
18
18
|
* below), so its cases read that; the three cases where the feature is
|
|
19
19
|
* inactive or missed read whatever the generated prepare_auth placed;
|
|
20
20
|
* - a refusal must carry the PROVIDER'S OWN message (sekreto's wording),
|
|
@@ -102,10 +102,11 @@ let token_calls (r : recorder) : value list =
|
|
|
102
102
|
* perfectly well.
|
|
103
103
|
*
|
|
104
104
|
* KNOWN GAP, DELIBERATELY NOT PAPERED OVER HERE: the FEATURE'S own rewrite
|
|
105
|
-
* (secrets_feature.ml)
|
|
106
|
-
* says, so a
|
|
107
|
-
*
|
|
108
|
-
* feature
|
|
105
|
+
* (secrets_feature.ml) always writes a HEADER - the one auth.name names -
|
|
106
|
+
* whatever the scheme's placement says, so on a query or cookie scheme a
|
|
107
|
+
* chain-resolved secret does NOT follow the placement. Every target's
|
|
108
|
+
* secrets feature does the same. The cases below that exercise the feature
|
|
109
|
+
* therefore keep reading the credential header - which is what the code
|
|
109
110
|
* actually does - and only the three cases where the feature is inactive or
|
|
110
111
|
* missed read the placed bag. Making the feature placement-aware is a
|
|
111
112
|
* separate change, across every target at once. *)
|
|
@@ -176,12 +177,20 @@ let placed_cred_of (fd : value) : value =
|
|
|
176
177
|
| Map _ -> Sdk_features.header_ci headers Sdk_prepare_auth.cred_name
|
|
177
178
|
| _ -> Noval)
|
|
178
179
|
|
|
179
|
-
(* The
|
|
180
|
+
(* The header the credential travels in: the DEFAULT client's auth.name,
|
|
181
|
+
* lower-cased as prepare_auth sends it. Read from a default client because
|
|
182
|
+
* a test's `auth: null` leaves no name to read. *)
|
|
183
|
+
let credheader : string =
|
|
184
|
+
match getpath_s (Sdk_client.test ()).cl_options "auth.name" with
|
|
185
|
+
| Str s when s <> "" -> String.lowercase_ascii s
|
|
186
|
+
| _ -> "authorization"
|
|
187
|
+
|
|
188
|
+
(* The CREDENTIAL HEADER the i-th API call carried, or Noval - what the
|
|
180
189
|
* feature's own rewrite writes (see the note above). *)
|
|
181
190
|
let auth_of (r : recorder) (i : int) : value =
|
|
182
191
|
match List.nth_opt (api_calls r) i with
|
|
183
192
|
| Some c -> (match getp (getp c "fetchdef") "headers" with
|
|
184
|
-
| Map _ as h -> Sdk_features.header_ci h
|
|
193
|
+
| Map _ as h -> Sdk_features.header_ci h credheader
|
|
185
194
|
| _ -> Noval)
|
|
186
195
|
| None -> Noval
|
|
187
196
|
|
|
@@ -205,7 +214,7 @@ let credential_is (header : value) (token : string) : bool =
|
|
|
205
214
|
let absent (header : value) : bool = is_nullish header
|
|
206
215
|
|
|
207
216
|
(* SUPPRESSION IS ABOUT EVERY BAG, not just the header. `auth: null` must
|
|
208
|
-
* leave nothing anywhere, so a suppression case asserts the
|
|
217
|
+
* leave nothing anywhere, so a suppression case asserts the credential
|
|
209
218
|
* header AND the bag this API's scheme places its credential in - otherwise
|
|
210
219
|
* a query-placement SDK could leak `?token=...` and still read green,
|
|
211
220
|
* because the header it never uses was empty. *)
|
|
@@ -645,7 +654,7 @@ let () =
|
|
|
645
654
|
ok200 (jo [("access_token", Str ("ACCESS" ^ string_of_int (List.length (token_calls r))))])
|
|
646
655
|
else
|
|
647
656
|
let token = match getp fd "headers" with
|
|
648
|
-
| Map _ as h -> (match Sdk_features.header_ci h
|
|
657
|
+
| Map _ as h -> (match Sdk_features.header_ci h credheader with Str s -> s | _ -> "")
|
|
649
658
|
| _ -> "" in
|
|
650
659
|
status_res (api token) (jo [("id", Str "r01")])) in
|
|
651
660
|
|
|
@@ -774,7 +783,7 @@ let () =
|
|
|
774
783
|
(entity_names ());
|
|
775
784
|
check "an entity op recorded its fetchdef" !seen;
|
|
776
785
|
let header = match getpath_s explain "fetchdef.headers" with
|
|
777
|
-
| Map _ as h -> Sdk_features.header_ci h
|
|
786
|
+
| Map _ as h -> Sdk_features.header_ci h credheader
|
|
778
787
|
| _ -> Noval in
|
|
779
788
|
check ("carries the deterministic test token: " ^ stringify header)
|
|
780
789
|
(credential_is header "test-access_token");
|
|
@@ -74,7 +74,7 @@ class ProjectNameSecretsMapProvider implements \Voxgig\Sekreto\Provider
|
|
|
74
74
|
// no way to refuse them when the chain is broken. The transport is the ONE
|
|
75
75
|
// seam every wire path crosses (utility/MakeRequest.php and Main's
|
|
76
76
|
// raw_request both call `$utility->fetcher`), so the wrapper installed in
|
|
77
|
-
// init() resolves there, rewrites the
|
|
77
|
+
// init() resolves there, rewrites the credential header prepare_auth
|
|
78
78
|
// built, and refuses the request outright when a provider errors.
|
|
79
79
|
//
|
|
80
80
|
// MISS vs ERROR (sekreto's invariant): a provider MISS falls through - the
|
|
@@ -427,7 +427,7 @@ class ProjectNameSecretsFeature extends ProjectNameBaseFeature
|
|
|
427
427
|
// Buy a token and try the request again when the API says the current
|
|
428
428
|
// one is spent.
|
|
429
429
|
//
|
|
430
|
-
// The retry rewrites the
|
|
430
|
+
// The retry rewrites the credential header IN PLACE on the fetchdef,
|
|
431
431
|
// because the header was built by the synchronous prepare_auth before
|
|
432
432
|
// this request left, and it carries the token that just failed.
|
|
433
433
|
private function with_refresh(ProjectNameContext $ctx, string $url, array $fetchdef, mixed $inner): array
|
|
@@ -610,7 +610,7 @@ class ProjectNameSecretsFeature extends ProjectNameBaseFeature
|
|
|
610
610
|
$this->cred = is_string($value) ? $value : '';
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
-
// Rebuild the
|
|
613
|
+
// Rebuild the credential header from the credential, exactly as
|
|
614
614
|
// prepare_auth builds it.
|
|
615
615
|
private function inject(array &$fetchdef, string $token): void
|
|
616
616
|
{
|
|
@@ -618,10 +618,15 @@ class ProjectNameSecretsFeature extends ProjectNameBaseFeature
|
|
|
618
618
|
return;
|
|
619
619
|
}
|
|
620
620
|
|
|
621
|
+
// The header prepare_auth writes: auth.name, lower-cased.
|
|
622
|
+
$name = \Voxgig\Struct\Struct::getpath($this->liveopts, 'auth.name');
|
|
623
|
+
$name = is_string($name) && '' !== $name
|
|
624
|
+
? strtolower($name) : 'authorization';
|
|
625
|
+
|
|
621
626
|
// Suppressed auth means NO header, the same answer prepare_auth
|
|
622
627
|
// gives - and so does an empty credential.
|
|
623
628
|
if (null === ($this->liveopts['auth'] ?? null) || '' === $token) {
|
|
624
|
-
unset($fetchdef['headers'][
|
|
629
|
+
unset($fetchdef['headers'][$name]);
|
|
625
630
|
return;
|
|
626
631
|
}
|
|
627
632
|
|
|
@@ -631,7 +636,7 @@ class ProjectNameSecretsFeature extends ProjectNameBaseFeature
|
|
|
631
636
|
}
|
|
632
637
|
|
|
633
638
|
// Empty prefix (raw apiKey credential) must not add a leading space.
|
|
634
|
-
$fetchdef['headers'][
|
|
639
|
+
$fetchdef['headers'][$name] = '' === $prefix
|
|
635
640
|
? $token : $prefix . ' ' . $token;
|
|
636
641
|
}
|
|
637
642
|
|
|
@@ -38,6 +38,22 @@ use PHPUnit\Framework\TestCase;
|
|
|
38
38
|
// exchange tests.
|
|
39
39
|
class ProjectNameSecretsWire
|
|
40
40
|
{
|
|
41
|
+
private static ?string $credheader = null;
|
|
42
|
+
|
|
43
|
+
// The header the credential travels in: the DEFAULT client's auth.name,
|
|
44
|
+
// lower-cased as prepare_auth sends it. Read from a default client
|
|
45
|
+
// because a test's `auth: null` leaves no name to read.
|
|
46
|
+
public static function credheader(): string
|
|
47
|
+
{
|
|
48
|
+
if (null === self::$credheader) {
|
|
49
|
+
$client = ProjectNameSDK::test(null, null);
|
|
50
|
+
$name = $client->options_map()['auth']['name'] ?? null;
|
|
51
|
+
self::$credheader = is_string($name) && '' !== $name
|
|
52
|
+
? strtolower($name) : 'authorization';
|
|
53
|
+
}
|
|
54
|
+
return self::$credheader;
|
|
55
|
+
}
|
|
56
|
+
|
|
41
57
|
/** @var array<int,array<string,mixed>> */
|
|
42
58
|
public array $calls = [];
|
|
43
59
|
/** @var array<int,int> */
|
|
@@ -63,8 +79,8 @@ class ProjectNameSecretsWire
|
|
|
63
79
|
$headers = is_array($fetchdef['headers'] ?? null) ? $fetchdef['headers'] : [];
|
|
64
80
|
$this->calls[] = [
|
|
65
81
|
'url' => $fullurl,
|
|
66
|
-
'auth' => $headers[
|
|
67
|
-
'has' => array_key_exists(
|
|
82
|
+
'auth' => $headers[self::credheader()] ?? null,
|
|
83
|
+
'has' => array_key_exists(self::credheader(), $headers),
|
|
68
84
|
'body' => $fetchdef['body'] ?? null,
|
|
69
85
|
];
|
|
70
86
|
|
|
@@ -138,15 +154,16 @@ class ProjectNameSecretsTest extends TestCase
|
|
|
138
154
|
// -----------------------------------------------------------------
|
|
139
155
|
// Support.
|
|
140
156
|
|
|
141
|
-
// The
|
|
142
|
-
// a TEMPLATE cannot know - so assert on the CREDENTIAL and let
|
|
143
|
-
// prefix be whatever this SDK's API declares.
|
|
157
|
+
// The credential header carries the SPEC's credential prefix (if any),
|
|
158
|
+
// which a TEMPLATE cannot know - so assert on the CREDENTIAL and let
|
|
159
|
+
// the prefix be whatever this SDK's API declares.
|
|
144
160
|
private function assertCredential(mixed $header, string $token): void
|
|
145
161
|
{
|
|
146
162
|
$ok = $header === $token
|
|
147
163
|
|| (is_string($header) && str_ends_with($header, ' ' . $token));
|
|
148
164
|
$this->assertTrue($ok,
|
|
149
|
-
'expected the
|
|
165
|
+
'expected the ' . ProjectNameSecretsWire::credheader() .
|
|
166
|
+
' header to carry ' . $token .
|
|
150
167
|
', got: ' . var_export($header, true));
|
|
151
168
|
}
|
|
152
169
|
|
|
@@ -299,17 +316,18 @@ class ProjectNameSecretsTest extends TestCase
|
|
|
299
316
|
{
|
|
300
317
|
$client = ProjectNameSDK::test(null, ['apikey' => 'OPTKEY01']);
|
|
301
318
|
$fetchdef = $client->prepare(['path' => '/']);
|
|
302
|
-
$this->assertCredential($fetchdef['headers'][
|
|
319
|
+
$this->assertCredential($fetchdef['headers'][ProjectNameSecretsWire::credheader()] ?? null, 'OPTKEY01');
|
|
303
320
|
|
|
304
321
|
$this->assertNull($this->secretsFeatureOf($client),
|
|
305
322
|
'no activation and no extend: the feature must not be installed');
|
|
306
323
|
}
|
|
307
324
|
|
|
308
|
-
public function
|
|
325
|
+
public function testInactiveNoApikeyMeansNoCredentialHeader(): void
|
|
309
326
|
{
|
|
310
327
|
$client = ProjectNameSDK::test(null, null);
|
|
311
328
|
$fetchdef = $client->prepare(['path' => '/']);
|
|
312
|
-
$this->assertArrayNotHasKey(
|
|
329
|
+
$this->assertArrayNotHasKey(ProjectNameSecretsWire::credheader(),
|
|
330
|
+
$fetchdef['headers']);
|
|
313
331
|
}
|
|
314
332
|
|
|
315
333
|
// -----------------------------------------------------------------
|
|
@@ -389,7 +407,8 @@ class ProjectNameSecretsTest extends TestCase
|
|
|
389
407
|
|
|
390
408
|
// Nor may it surface through the fetchdef prepare() builds.
|
|
391
409
|
$fetchdef = $client->prepare(['path' => '/']);
|
|
392
|
-
$this->assertArrayNotHasKey(
|
|
410
|
+
$this->assertArrayNotHasKey(ProjectNameSecretsWire::credheader(),
|
|
411
|
+
$fetchdef['headers']);
|
|
393
412
|
}
|
|
394
413
|
|
|
395
414
|
public function testCustomProvidersAreAcceptedVerbatim(): void
|
|
@@ -1029,12 +1048,15 @@ if (str_ends_with($path, '/auth/token')) {
|
|
|
1029
1048
|
}
|
|
1030
1049
|
$auth = '';
|
|
1031
1050
|
foreach ($_SERVER as $k => $v) {
|
|
1032
|
-
if ('
|
|
1051
|
+
if ('CREDKEY' === $k) { $auth = (string)$v; }
|
|
1033
1052
|
}
|
|
1034
1053
|
file_put_contents($dir . '/auth.txt', $auth);
|
|
1035
1054
|
header('content-type: application/json');
|
|
1036
1055
|
echo '{}';
|
|
1037
1056
|
ROUTER;
|
|
1057
|
+
// The server sees the credential header under its CGI name.
|
|
1058
|
+
$router = str_replace('CREDKEY', 'HTTP_' . strtoupper(
|
|
1059
|
+
str_replace('-', '_', ProjectNameSecretsWire::credheader())), $router);
|
|
1038
1060
|
file_put_contents($this->dir . '/router.php', $router);
|
|
1039
1061
|
|
|
1040
1062
|
// A free port: bind, read it, release it. The window between release
|
|
@@ -384,11 +384,11 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
|
|
|
384
384
|
# Buy a token and try the request again when the API says the current
|
|
385
385
|
# one is spent. Wraps the transport; installed only when exchanging.
|
|
386
386
|
#
|
|
387
|
-
# The retry rewrites the
|
|
387
|
+
# The retry rewrites the credential header IN PLACE on the
|
|
388
388
|
# fetchdef, because the header was built by the synchronous
|
|
389
389
|
# prepare_auth before this request left, and it carries the token that
|
|
390
390
|
# just failed. Rebuilt the way prepare_auth builds it, from the same
|
|
391
|
-
# options.auth
|
|
391
|
+
# options.auth name and prefix, so the two cannot drift.
|
|
392
392
|
def _with_refresh(self, ctx, url, fetchdef, inner):
|
|
393
393
|
x = self._exchange
|
|
394
394
|
max_retries = 0 if x is None else x["retries"]
|
|
@@ -459,8 +459,13 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
|
|
|
459
459
|
fetchdef["headers"].pop("authorization", None)
|
|
460
460
|
return
|
|
461
461
|
|
|
462
|
+
# The header prepare_auth wrote: auth.name, lower-cased.
|
|
463
|
+
name = auth.get("name") if isinstance(auth, dict) else None
|
|
464
|
+
name = name.lower() if isinstance(name, str) and "" != name \
|
|
465
|
+
else "authorization"
|
|
466
|
+
|
|
462
467
|
prefix = auth.get("prefix") if isinstance(auth, dict) else None
|
|
463
|
-
fetchdef["headers"][
|
|
468
|
+
fetchdef["headers"][name] = \
|
|
464
469
|
prefix + " " + token if prefix else token
|
|
465
470
|
|
|
466
471
|
|
|
@@ -37,6 +37,20 @@ from projectname_sdk.feature.secrets_feature import ProjectNameSecretsFeature
|
|
|
37
37
|
ENVPREFIX = "PROJECTENV_TEST_SECRETS_"
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
def cred_header():
|
|
41
|
+
"""The header the credential travels in: the DEFAULT client's
|
|
42
|
+
auth.name, lower-cased as prepare_auth sends it. Read from a default
|
|
43
|
+
client because a test's `auth: None` leaves no name to read."""
|
|
44
|
+
sdk = ProjectNameSDK({"base": "http://localhost:8080"})
|
|
45
|
+
name = (sdk.options_map().get("auth") or {}).get("name")
|
|
46
|
+
if isinstance(name, str) and "" != name:
|
|
47
|
+
return name.lower()
|
|
48
|
+
return "authorization"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
CREDHEADER = cred_header()
|
|
52
|
+
|
|
53
|
+
|
|
40
54
|
def secrets_sdk(sdkopts):
|
|
41
55
|
"""An SDK with the secrets feature ACTIVE.
|
|
42
56
|
|
|
@@ -120,14 +134,14 @@ class TestSecrets(unittest.TestCase):
|
|
|
120
134
|
return transport.calls[-1]["fetchdef"].get("headers") or {}
|
|
121
135
|
|
|
122
136
|
def assert_credential(self, headers, token):
|
|
123
|
-
# The
|
|
124
|
-
# which a TEMPLATE cannot know - assert on the CREDENTIAL and
|
|
125
|
-
# the prefix be whatever this SDK's API declares.
|
|
126
|
-
got = str(headers.get(
|
|
137
|
+
# The credential header carries the SPEC's credential prefix (if
|
|
138
|
+
# any), which a TEMPLATE cannot know - assert on the CREDENTIAL and
|
|
139
|
+
# let the prefix be whatever this SDK's API declares.
|
|
140
|
+
got = str(headers.get(CREDHEADER) or "")
|
|
127
141
|
self.assertTrue(
|
|
128
142
|
got == token or got.endswith(" " + token),
|
|
129
|
-
"expected the
|
|
130
|
-
% (token, got))
|
|
143
|
+
"expected the %s header to carry %s, got: %r"
|
|
144
|
+
% (CREDHEADER, token, got))
|
|
131
145
|
|
|
132
146
|
# --- the chain ---
|
|
133
147
|
|
|
@@ -184,7 +198,7 @@ class TestSecrets(unittest.TestCase):
|
|
|
184
198
|
sdk, transport = self._sdk(envchain())
|
|
185
199
|
|
|
186
200
|
headers = self._send(sdk, transport)
|
|
187
|
-
self.assertNotIn(
|
|
201
|
+
self.assertNotIn(CREDHEADER, headers)
|
|
188
202
|
|
|
189
203
|
def test_a_provider_error_fails_the_op(self):
|
|
190
204
|
# A broken store is NOT a miss: resolution must raise (failing the
|
|
@@ -233,7 +247,7 @@ class TestSecrets(unittest.TestCase):
|
|
|
233
247
|
})
|
|
234
248
|
|
|
235
249
|
headers = self._lastwire(sdk, transport)
|
|
236
|
-
self.assertNotIn(
|
|
250
|
+
self.assertNotIn(CREDHEADER, headers,
|
|
237
251
|
"the chain has nothing yet, so no credential "
|
|
238
252
|
"should go out")
|
|
239
253
|
|
|
@@ -290,7 +304,7 @@ class TestSecrets(unittest.TestCase):
|
|
|
290
304
|
sdk, transport = self._sdk(opts)
|
|
291
305
|
|
|
292
306
|
headers = self._send(sdk, transport)
|
|
293
|
-
self.assertNotIn(
|
|
307
|
+
self.assertNotIn(CREDHEADER, headers)
|
|
294
308
|
|
|
295
309
|
|
|
296
310
|
if __name__ == "__main__":
|
|
@@ -419,7 +433,7 @@ class TestSecretsReviewPins(unittest.TestCase):
|
|
|
419
433
|
|
|
420
434
|
state["have"] = False
|
|
421
435
|
headers = self._wire(sdk, transport)
|
|
422
|
-
self.assertEqual("", str(headers.get(
|
|
436
|
+
self.assertEqual("", str(headers.get(CREDHEADER) or ""),
|
|
423
437
|
"after the chain reports a miss, the retracted "
|
|
424
438
|
"credential must not go out")
|
|
425
439
|
|
|
@@ -444,8 +458,8 @@ class TestSecretsReviewPins(unittest.TestCase):
|
|
|
444
458
|
return transport.calls[-1]["fetchdef"].get("headers") or {}
|
|
445
459
|
|
|
446
460
|
def assert_credential(self, headers, token):
|
|
447
|
-
got = str(headers.get(
|
|
461
|
+
got = str(headers.get(CREDHEADER) or "")
|
|
448
462
|
self.assertTrue(
|
|
449
463
|
got == token or got.endswith(" " + token),
|
|
450
|
-
"expected the
|
|
451
|
-
% (token, got))
|
|
464
|
+
"expected the %s header to carry %s, got: %r"
|
|
465
|
+
% (CREDHEADER, token, got))
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
# the chain is broken. The transport is the ONE seam every wire path
|
|
24
24
|
# crosses (utility/make_request.rb and Main's raw_request both call
|
|
25
25
|
# `utility.fetcher`), so the wrapper installed in `init` resolves there,
|
|
26
|
-
# rewrites the
|
|
26
|
+
# rewrites the credential header prepare_auth built, and refuses the
|
|
27
27
|
# request outright when a provider errors.
|
|
28
28
|
#
|
|
29
29
|
# MISS vs ERROR (sekreto's invariant): a provider MISS falls through - the
|
|
@@ -328,7 +328,7 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
328
328
|
# Buy a token and try the request again when the API says the current one
|
|
329
329
|
# is spent.
|
|
330
330
|
#
|
|
331
|
-
# The retry rewrites the
|
|
331
|
+
# The retry rewrites the credential header IN PLACE on the fetchdef,
|
|
332
332
|
# because the header was built by the synchronous prepare_auth before
|
|
333
333
|
# this request left, and it carries the token that just failed.
|
|
334
334
|
def _with_refresh(ctx, url, fetchdef, inner)
|
|
@@ -511,16 +511,20 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
511
511
|
end
|
|
512
512
|
end
|
|
513
513
|
|
|
514
|
-
# Rebuild the
|
|
514
|
+
# Rebuild the credential header from the credential, exactly as
|
|
515
515
|
# prepare_auth builds it.
|
|
516
516
|
def _inject(fetchdef, token)
|
|
517
517
|
return unless fetchdef.is_a?(Hash)
|
|
518
518
|
headers = fetchdef["headers"]
|
|
519
519
|
return unless headers.is_a?(Hash)
|
|
520
520
|
|
|
521
|
+
# The header prepare_auth writes: auth.name, lower-cased.
|
|
522
|
+
name = VoxgigStruct.getpath(@liveopts, "auth.name")
|
|
523
|
+
name = name.is_a?(String) && !name.empty? ? name.downcase : "authorization"
|
|
524
|
+
|
|
521
525
|
# Suppressed auth means NO header, the same answer prepare_auth gives.
|
|
522
526
|
if @liveopts["auth"].nil? || token.nil? || token.empty?
|
|
523
|
-
headers.delete(
|
|
527
|
+
headers.delete(name)
|
|
524
528
|
return
|
|
525
529
|
end
|
|
526
530
|
|
|
@@ -528,7 +532,7 @@ class ProjectNameSecretsFeature < ProjectNameBaseFeature
|
|
|
528
532
|
prefix = "" unless prefix.is_a?(String)
|
|
529
533
|
|
|
530
534
|
# Empty prefix (raw apiKey credential) must not add a leading space.
|
|
531
|
-
headers[
|
|
535
|
+
headers[name] = prefix.empty? ? token : "#{prefix} #{token}"
|
|
532
536
|
end
|
|
533
537
|
|
|
534
538
|
# The plugin DEFINITIONS the model selected for this feature, emitted by
|
|
@@ -34,6 +34,15 @@ class SecretsFeatureTest < Minitest::Test
|
|
|
34
34
|
# changes.
|
|
35
35
|
ENVPREFIX = "PROJECTENV_TEST_SECRETS_"
|
|
36
36
|
|
|
37
|
+
# The header the credential travels in: the DEFAULT client's auth.name,
|
|
38
|
+
# lower-cased as prepare_auth sends it. Read from a default client because
|
|
39
|
+
# a test's `auth: nil` leaves no name to read.
|
|
40
|
+
CREDHEADER = begin
|
|
41
|
+
auth = ProjectNameSDK.test(nil, nil).options_map["auth"]
|
|
42
|
+
name = auth.is_a?(Hash) ? auth["name"] : nil
|
|
43
|
+
name.is_a?(String) && !name.empty? ? name.downcase : "authorization"
|
|
44
|
+
end
|
|
45
|
+
|
|
37
46
|
# ---------------------------------------------------------------------
|
|
38
47
|
# The recording transport: system.fetch for a LIVE client, scripting one
|
|
39
48
|
# status per API call (the last repeating) and a token endpoint for the
|
|
@@ -64,8 +73,8 @@ class SecretsFeatureTest < Minitest::Test
|
|
|
64
73
|
headers = fetchdef["headers"].is_a?(Hash) ? fetchdef["headers"] : {}
|
|
65
74
|
@calls << {
|
|
66
75
|
"url" => fullurl,
|
|
67
|
-
"auth" => headers[
|
|
68
|
-
"has" => headers.key?(
|
|
76
|
+
"auth" => headers[CREDHEADER],
|
|
77
|
+
"has" => headers.key?(CREDHEADER),
|
|
69
78
|
"body" => fetchdef["body"],
|
|
70
79
|
}
|
|
71
80
|
|
|
@@ -193,7 +202,7 @@ class SecretsFeatureTest < Minitest::Test
|
|
|
193
202
|
@lock.synchronize { @refresh = parsed["refresh_token"] }
|
|
194
203
|
payload = '{"access_token": "RAWTOK01"}'
|
|
195
204
|
else
|
|
196
|
-
@lock.synchronize { @auth = headers[
|
|
205
|
+
@lock.synchronize { @auth = headers[CREDHEADER] }
|
|
197
206
|
payload = "{}"
|
|
198
207
|
end
|
|
199
208
|
|
|
@@ -207,12 +216,12 @@ class SecretsFeatureTest < Minitest::Test
|
|
|
207
216
|
# -------------------------------------------------------------------
|
|
208
217
|
# Support.
|
|
209
218
|
|
|
210
|
-
# The
|
|
211
|
-
# TEMPLATE cannot know - so assert on the CREDENTIAL and let the
|
|
212
|
-
# whatever this SDK's API declares.
|
|
219
|
+
# The credential header carries the SPEC's credential prefix (if any),
|
|
220
|
+
# which a TEMPLATE cannot know - so assert on the CREDENTIAL and let the
|
|
221
|
+
# prefix be whatever this SDK's API declares.
|
|
213
222
|
def assert_credential(header, token)
|
|
214
223
|
ok = header == token || header.to_s.end_with?(" " + token)
|
|
215
|
-
assert ok, "expected the
|
|
224
|
+
assert ok, "expected the #{CREDHEADER} header to carry #{token}, got: #{header.inspect}"
|
|
216
225
|
end
|
|
217
226
|
|
|
218
227
|
def secrets_feature_of(client)
|
|
@@ -345,17 +354,17 @@ class SecretsFeatureTest < Minitest::Test
|
|
|
345
354
|
def test_inactive_apikey_option_behaves_exactly_as_before
|
|
346
355
|
client = ProjectNameSDK.test(nil, { "apikey" => "OPTKEY01" })
|
|
347
356
|
fetchdef = client.prepare({ "path" => "/" })
|
|
348
|
-
assert_credential(fetchdef["headers"][
|
|
357
|
+
assert_credential(fetchdef["headers"][CREDHEADER], "OPTKEY01")
|
|
349
358
|
|
|
350
359
|
assert_nil secrets_feature_of(client),
|
|
351
360
|
"no activation and no extend: the feature must not be installed"
|
|
352
361
|
end
|
|
353
362
|
|
|
354
|
-
def
|
|
363
|
+
def test_inactive_no_apikey_means_no_credential_header
|
|
355
364
|
client = ProjectNameSDK.test(nil, nil)
|
|
356
365
|
fetchdef = client.prepare({ "path" => "/" })
|
|
357
|
-
refute fetchdef["headers"].key?(
|
|
358
|
-
"unexpected
|
|
366
|
+
refute fetchdef["headers"].key?(CREDHEADER),
|
|
367
|
+
"unexpected #{CREDHEADER} header: #{fetchdef['headers'][CREDHEADER].inspect}"
|
|
359
368
|
end
|
|
360
369
|
|
|
361
370
|
# -------------------------------------------------------------------
|
|
@@ -607,12 +607,17 @@ fn reauth(state: &Rc<RefCell<SecretsState>>, fetchdef: &Value, token: &str) {
|
|
|
607
607
|
|
|
608
608
|
let options = state.borrow().options.clone();
|
|
609
609
|
|
|
610
|
+
let name = match getpath(&["auth", "name"], &options) {
|
|
611
|
+
Value::Str(s) if !s.is_empty() => s.to_ascii_lowercase(),
|
|
612
|
+
_ => "authorization".to_string(),
|
|
613
|
+
};
|
|
614
|
+
|
|
610
615
|
// Suppressed auth means NO header, the same answer prepare_auth gives.
|
|
611
616
|
// Reached defensively - with_refresh does not retry at all when auth
|
|
612
617
|
// is suppressed - but this is the function that writes the credential,
|
|
613
618
|
// so it is where the rule has to hold.
|
|
614
619
|
if !authactive(&options) {
|
|
615
|
-
vs::del_prop(headers, &Value::str(
|
|
620
|
+
vs::del_prop(headers, &Value::str(name.as_str()));
|
|
616
621
|
return;
|
|
617
622
|
}
|
|
618
623
|
|
|
@@ -623,13 +628,9 @@ fn reauth(state: &Rc<RefCell<SecretsState>>, fetchdef: &Value, token: &str) {
|
|
|
623
628
|
|
|
624
629
|
// Empty prefix (a raw apiKey credential) must not add a leading space.
|
|
625
630
|
if prefix.is_empty() {
|
|
626
|
-
setp(&headers,
|
|
631
|
+
setp(&headers, &name, Value::str(token));
|
|
627
632
|
} else {
|
|
628
|
-
setp(
|
|
629
|
-
&headers,
|
|
630
|
-
"authorization",
|
|
631
|
-
Value::str(format!("{} {}", prefix, token)),
|
|
632
|
-
);
|
|
633
|
+
setp(&headers, &name, Value::str(format!("{} {}", prefix, token)));
|
|
633
634
|
}
|
|
634
635
|
}
|
|
635
636
|
|