tensor-wasm-api 0.3.8

HTTP serverless API gateway (axum).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 Craton Software Company

//! Per-tenant scoped bearer tokens.
//!
//! Implements PATH-TO-V1 v0.4 exit-criterion *Scoped tokens*: each accepted
//! bearer token carries a [`TokenScope`] describing which tenants it may
//! address. Routes that bind to a tenant call
//! [`crate::rate_limit::AuthContext::authorize_tenant`] before doing any
//! per-tenant work and return `403 Forbidden { kind: "tenant_scope_denied" }`
//! when the caller's token does not cover the requested tenant.
//!
//! ## Wire format for `TENSOR_WASM_API_TOKENS`
//!
//! Two entry shapes are accepted in the comma-separated allowlist:
//!
//! 1. `token1:tenant=1,2,3` — scoped: the token grants access to tenants
//!    `1`, `2`, and `3` only.
//! 2. `token1:tenant=*` — wildcard: the token grants access to every tenant.
//! 3. `token1` — bare (legacy): treated as the wildcard form with a one-time
//!    deprecation warning emitted at startup. Scheduled for removal in v1.0.
//!
//! Forms can be mixed in the same env var; the parser splits on commas at
//! the *top level only*. Because tenant lists are themselves comma-separated
//! and live inside an entry, the parser groups all comma-separated values
//! that follow a `:tenant=` clause back into a single entry.
//!
//! ## Parser strategy
//!
//! The grammar is small enough that hand-rolling a one-pass scanner is the
//! lowest-overhead choice. We split the input on commas to obtain *raw
//! pieces*, then walk them left-to-right, joining pieces back together when
//! we observe a piece that is itself a continuation of a `:tenant=` clause
//! (i.e. it starts with neither a token name nor a colon — a numeric or `*`
//! continuation list). The walker accepts the same trailing whitespace the
//! pre-existing parser does (`split(',').map(str::trim)`).

use std::collections::{HashMap, HashSet};
use std::fmt;

use tensor_wasm_core::types::TenantId;

/// Tenant scope attached to a single bearer token.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TenantScope {
    /// Wildcard — the token grants access to every tenant. Produced by
    /// `token:tenant=*` and by the legacy bare-token shape (with deprecation
    /// warning).
    All,
    /// Explicit allowlist — the token grants access only to the listed
    /// tenant ids.
    Set(HashSet<TenantId>),
}

impl TenantScope {
    /// `true` if `tenant` is covered by this scope.
    pub fn allows(&self, tenant: TenantId) -> bool {
        match self {
            TenantScope::All => true,
            TenantScope::Set(s) => s.contains(&tenant),
        }
    }

    /// `true` if this scope is the wildcard form. Used by callers (and
    /// integration tests) that want to assert legacy semantics held.
    pub fn is_all(&self) -> bool {
        matches!(self, TenantScope::All)
    }
}

/// Authorization metadata derived from a single bearer-token entry.
///
/// Stored as a value in [`ParsedTokens::token_scopes`]; the bearer string
/// itself is the map key.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TokenScope {
    /// Tenants this token may address.
    pub tenants: TenantScope,
}

impl TokenScope {
    /// Wildcard scope — covers every tenant.
    pub fn all() -> Self {
        Self {
            tenants: TenantScope::All,
        }
    }

    /// Construct a scope from an explicit set of tenants.
    pub fn from_tenants<I>(iter: I) -> Self
    where
        I: IntoIterator<Item = TenantId>,
    {
        Self {
            tenants: TenantScope::Set(iter.into_iter().collect()),
        }
    }

    /// Convenience accessor: `true` if the scope admits `tenant`.
    pub fn allows(&self, tenant: TenantId) -> bool {
        self.tenants.allows(tenant)
    }
}

/// Alias for the raw bearer-token string used as the map key in
/// [`ParsedTokens`]. Kept as a type alias rather than a newtype because the
/// existing [`crate::middleware::AuthConfig`] also stores the raw string.
pub type BearerString = String;

/// Output of [`parse_tokens_env`].
#[derive(Debug, Default, Clone)]
pub struct ParsedTokens {
    /// All accepted bearer tokens with their scopes.
    pub token_scopes: HashMap<BearerString, TokenScope>,
    /// Count of entries that used the legacy bare-token shape and were
    /// silently coerced to the wildcard scope. The server emits a single
    /// `tracing::warn!` at startup if this is nonzero.
    pub deprecated_count: usize,
}

/// Errors produced when parsing a single token entry. The wrapper around
/// [`parse_tokens_env`] turns each into a startup-time `tracing::warn!`
/// rather than aborting the process — the gateway prefers to keep the
/// remaining valid entries.
#[derive(Debug, PartialEq, Eq)]
pub enum ScopeParseError {
    /// The entry was empty after trimming.
    EmptyEntry,
    /// The entry was `:tenant=...` with no bearer token before the colon.
    MissingBearer,
    /// The entry contained a `:tenant=` clause with no value after `=`.
    EmptyTenantList,
    /// The tenant list contained a token that was neither `*` nor a valid
    /// `u64`. Carries the offending fragment for diagnostics.
    InvalidTenant(String),
    /// The entry mixed `*` with explicit tenant ids in the same clause.
    /// Either use `tenant=*` exactly or list ids; we refuse to silently
    /// promote `tenant=1,*` to wildcard because the user's intent is
    /// ambiguous.
    WildcardMixedWithIds,
    /// The entry used an unrecognised key after the colon (only `tenant=` is
    /// supported in v0.4). Carries the offending key.
    UnknownKey(String),
}

impl fmt::Display for ScopeParseError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ScopeParseError::EmptyEntry => f.write_str("empty token entry"),
            ScopeParseError::MissingBearer => {
                f.write_str("token entry has scope clause but no bearer token")
            }
            ScopeParseError::EmptyTenantList => f.write_str("tenant= clause has no value"),
            ScopeParseError::InvalidTenant(s) => {
                write!(f, "tenant id {s:?} is neither '*' nor a u64")
            }
            ScopeParseError::WildcardMixedWithIds => {
                f.write_str("tenant=* cannot be mixed with explicit tenant ids")
            }
            ScopeParseError::UnknownKey(k) => {
                write!(f, "unknown scope key {k:?} (only 'tenant=' is supported)")
            }
        }
    }
}

impl std::error::Error for ScopeParseError {}

/// Parse a single entry of the `TENSOR_WASM_API_TOKENS` allowlist.
///
/// Accepted shapes (after trimming surrounding whitespace):
///
/// * `token` — legacy bare bearer. Returns [`TokenScope::all`].
/// * `token:tenant=*` — explicit wildcard.
/// * `token:tenant=1,2,3` — explicit allowlist.
///
/// The parser is intentionally strict on the scoped form: an empty tenant
/// list, an unknown key, or a tenant id that does not parse as a `u64`
/// returns an [`Err`]. The caller decides whether to ignore (skip the
/// entry) or surface the error — see [`parse_tokens_env`] for the policy
/// applied at startup.
pub fn parse_token_entry(s: &str) -> Result<(BearerString, TokenScope), ScopeParseError> {
    let trimmed = s.trim();
    if trimmed.is_empty() {
        return Err(ScopeParseError::EmptyEntry);
    }
    match trimmed.split_once(':') {
        None => {
            // Bare-token form. Coerce to wildcard; the caller stamps the
            // deprecation warning.
            Ok((trimmed.to_owned(), TokenScope::all()))
        }
        Some((bearer, rest)) => {
            let bearer = bearer.trim();
            if bearer.is_empty() {
                return Err(ScopeParseError::MissingBearer);
            }
            let rest = rest.trim();
            // The v0.4 grammar only knows the `tenant=` key. Future keys
            // (e.g. `qps=`) can extend this match without breaking the
            // existing wire format.
            let value = match rest.split_once('=') {
                Some(("tenant", v)) => v.trim(),
                Some((other, _)) => {
                    return Err(ScopeParseError::UnknownKey(other.to_owned()));
                }
                None => {
                    return Err(ScopeParseError::UnknownKey(rest.to_owned()));
                }
            };
            if value.is_empty() {
                return Err(ScopeParseError::EmptyTenantList);
            }
            // Split the comma-separated tenant list, sniffing for wildcard.
            let mut saw_wildcard = false;
            let mut ids: HashSet<TenantId> = HashSet::new();
            for raw in value.split(',') {
                let frag = raw.trim();
                if frag.is_empty() {
                    return Err(ScopeParseError::InvalidTenant(frag.to_owned()));
                }
                if frag == "*" {
                    saw_wildcard = true;
                } else {
                    match frag.parse::<u64>() {
                        Ok(v) => {
                            ids.insert(TenantId(v));
                        }
                        Err(_) => return Err(ScopeParseError::InvalidTenant(frag.to_owned())),
                    }
                }
            }
            if saw_wildcard && !ids.is_empty() {
                return Err(ScopeParseError::WildcardMixedWithIds);
            }
            let scope = if saw_wildcard {
                TokenScope::all()
            } else {
                TokenScope {
                    tenants: TenantScope::Set(ids),
                }
            };
            Ok((bearer.to_owned(), scope))
        }
    }
}

/// Parse the `TENSOR_WASM_API_TOKENS` env-var value into a map of bearer →
/// scope, plus a count of legacy (bare) entries that were coerced to the
/// wildcard scope.
///
/// The input may mix the two entry shapes freely. Splitting is two-pass:
///
/// 1. Split on commas to obtain *raw fragments*.
/// 2. Walk fragments left to right, re-joining any fragment that does not
///    contain a `:` and follows an entry whose scope clause was `tenant=`
///    (a continuation of the tenant list).
///
/// Entries that fail [`parse_token_entry`] are dropped with a
/// `tracing::warn!` so a malformed entry never causes the gateway to refuse
/// to start. The remaining valid entries are returned in [`ParsedTokens`].
pub fn parse_tokens_env(env_value: &str) -> ParsedTokens {
    let mut out = ParsedTokens::default();
    if env_value.trim().is_empty() {
        return out;
    }

    // Re-glue fragments that belong to a single `tenant=...` list which was
    // itself comma-separated. We accumulate fragments into `current`; a
    // fragment that starts a new entry is one that either looks like
    // `token` or `token:tenant=...`. A continuation fragment is one that
    // does not contain `:` AND we are currently mid-tenant-list.
    let raw_fragments: Vec<&str> = env_value.split(',').collect();
    let mut entries: Vec<String> = Vec::with_capacity(raw_fragments.len());
    let mut current = String::new();
    let mut in_tenant_list = false;

    for frag in raw_fragments {
        let trimmed = frag.trim();
        if trimmed.is_empty() {
            // Empty fragments (`",,"`) flush whatever we have so the
            // subsequent fragment starts a fresh entry. Without this,
            // `foo:tenant=,1` would be silently glued into `foo:tenant=1`.
            if !current.is_empty() {
                entries.push(std::mem::take(&mut current));
            }
            in_tenant_list = false;
            continue;
        }
        let has_colon = trimmed.contains(':');
        // A continuation fragment must be a *tenant-list-shaped* token: the
        // wildcard `*` or a `u64`. Anything else (e.g. a bare bearer named
        // `foo`) is treated as a new entry — otherwise `a:tenant=*,foo` would
        // silently glue `foo` onto the wildcard list and fail with
        // `WildcardMixedWithIds`, rather than parsing as two entries.
        let looks_like_tenant_continuation = trimmed == "*" || trimmed.parse::<u64>().is_ok();
        if in_tenant_list && !has_colon && looks_like_tenant_continuation {
            // Continuation of the previous entry's tenant list.
            current.push(',');
            current.push_str(trimmed);
        } else {
            // Start a new entry.
            if !current.is_empty() {
                entries.push(std::mem::take(&mut current));
            }
            current.push_str(trimmed);
            in_tenant_list = has_colon
                && trimmed
                    .split_once(':')
                    .is_some_and(|(_, rest)| rest.trim().starts_with("tenant="));
        }
    }
    if !current.is_empty() {
        entries.push(current);
    }

    for entry in entries {
        let is_bare = !entry.contains(':');
        match parse_token_entry(&entry) {
            Ok((bearer, scope)) => {
                if is_bare {
                    out.deprecated_count += 1;
                }
                out.token_scopes.insert(bearer, scope);
            }
            Err(e) => {
                // We deliberately do not fail startup on a malformed entry —
                // the operator can fix it without losing all the other
                // tokens in the allowlist. The warning carries enough
                // context to find it.
                tracing::warn!(
                    target: "tensor_wasm_api::token_scope",
                    error = %e,
                    entry = %entry,
                    "ignoring malformed TENSOR_WASM_API_TOKENS entry",
                );
            }
        }
    }
    out
}

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

#[cfg(test)]
mod tests {
    use super::*;

    fn ids(it: impl IntoIterator<Item = u64>) -> HashSet<TenantId> {
        it.into_iter().map(TenantId).collect()
    }

    #[test]
    fn parse_bare_entry_yields_wildcard() {
        let (bearer, scope) = parse_token_entry("alpha").expect("parses");
        assert_eq!(bearer, "alpha");
        assert!(scope.tenants.is_all());
    }

    #[test]
    fn parse_bare_entry_trims_whitespace() {
        let (bearer, _) = parse_token_entry("  alpha  ").expect("parses");
        assert_eq!(bearer, "alpha");
    }

    #[test]
    fn parse_wildcard_entry_yields_wildcard() {
        let (bearer, scope) = parse_token_entry("alpha:tenant=*").expect("parses");
        assert_eq!(bearer, "alpha");
        assert!(scope.tenants.is_all());
    }

    #[test]
    fn parse_single_tenant_entry() {
        let (bearer, scope) = parse_token_entry("alpha:tenant=7").expect("parses");
        assert_eq!(bearer, "alpha");
        assert_eq!(scope.tenants, TenantScope::Set(ids([7])));
    }

    #[test]
    fn parse_multi_tenant_entry() {
        let (bearer, scope) = parse_token_entry("alpha:tenant=1,2,3").expect("parses");
        assert_eq!(bearer, "alpha");
        assert_eq!(scope.tenants, TenantScope::Set(ids([1, 2, 3])));
        assert!(scope.allows(TenantId(2)));
        assert!(!scope.allows(TenantId(4)));
    }

    #[test]
    fn parse_multi_tenant_entry_with_whitespace() {
        let (bearer, scope) = parse_token_entry("alpha:tenant= 1 , 2 , 3 ").expect("parses");
        assert_eq!(bearer, "alpha");
        assert_eq!(scope.tenants, TenantScope::Set(ids([1, 2, 3])));
    }

    #[test]
    fn parse_empty_entry_errors() {
        assert_eq!(
            parse_token_entry("").unwrap_err(),
            ScopeParseError::EmptyEntry
        );
        assert_eq!(
            parse_token_entry("   ").unwrap_err(),
            ScopeParseError::EmptyEntry
        );
    }

    #[test]
    fn parse_missing_bearer_errors() {
        assert_eq!(
            parse_token_entry(":tenant=1").unwrap_err(),
            ScopeParseError::MissingBearer
        );
    }

    #[test]
    fn parse_empty_tenant_list_errors() {
        assert_eq!(
            parse_token_entry("alpha:tenant=").unwrap_err(),
            ScopeParseError::EmptyTenantList
        );
    }

    #[test]
    fn parse_invalid_tenant_errors() {
        let err = parse_token_entry("alpha:tenant=not-a-number").unwrap_err();
        assert_eq!(err, ScopeParseError::InvalidTenant("not-a-number".into()));
    }

    #[test]
    fn parse_unknown_key_errors() {
        // We accept only `tenant=` in v0.4.
        let err = parse_token_entry("alpha:qps=100").unwrap_err();
        assert_eq!(err, ScopeParseError::UnknownKey("qps".into()));
    }

    #[test]
    fn parse_missing_eq_errors() {
        let err = parse_token_entry("alpha:tenant").unwrap_err();
        assert_eq!(err, ScopeParseError::UnknownKey("tenant".into()));
    }

    #[test]
    fn parse_wildcard_mixed_with_ids_errors() {
        let err = parse_token_entry("alpha:tenant=1,*,2").unwrap_err();
        assert_eq!(err, ScopeParseError::WildcardMixedWithIds);
    }

    #[test]
    fn parse_tenant_list_with_trailing_comma_is_invalid() {
        // `alpha:tenant=1,` → the second fragment is empty, which we treat
        // as an invalid tenant rather than silently accepting it.
        let err = parse_token_entry("alpha:tenant=1,").unwrap_err();
        assert_eq!(err, ScopeParseError::InvalidTenant(String::new()));
    }

    #[test]
    fn parse_env_empty_returns_default() {
        let parsed = parse_tokens_env("");
        assert!(parsed.token_scopes.is_empty());
        assert_eq!(parsed.deprecated_count, 0);

        let parsed = parse_tokens_env("   ");
        assert!(parsed.token_scopes.is_empty());
        assert_eq!(parsed.deprecated_count, 0);
    }

    #[test]
    fn parse_env_single_bare_token() {
        let parsed = parse_tokens_env("alpha");
        assert_eq!(parsed.deprecated_count, 1);
        assert_eq!(parsed.token_scopes.len(), 1);
        assert!(parsed.token_scopes.get("alpha").unwrap().tenants.is_all());
    }

    #[test]
    fn parse_env_three_bare_tokens() {
        let parsed = parse_tokens_env("alpha,beta,gamma");
        assert_eq!(parsed.deprecated_count, 3);
        assert_eq!(parsed.token_scopes.len(), 3);
        for name in ["alpha", "beta", "gamma"] {
            assert!(
                parsed.token_scopes.get(name).unwrap().tenants.is_all(),
                "{name} not wildcard",
            );
        }
    }

    #[test]
    fn parse_env_mixed_bare_and_scoped() {
        let parsed = parse_tokens_env("alpha,beta:tenant=1,2,gamma:tenant=*");
        assert_eq!(parsed.deprecated_count, 1, "only `alpha` is bare");
        assert_eq!(parsed.token_scopes.len(), 3);
        assert!(parsed.token_scopes["alpha"].tenants.is_all());
        assert_eq!(
            parsed.token_scopes["beta"].tenants,
            TenantScope::Set(ids([1, 2]))
        );
        assert!(parsed.token_scopes["gamma"].tenants.is_all());
    }

    #[test]
    fn parse_env_scoped_token_with_long_tenant_list() {
        let parsed = parse_tokens_env("alpha:tenant=1,2,3,4,5,6,7");
        assert_eq!(parsed.deprecated_count, 0);
        assert_eq!(parsed.token_scopes.len(), 1);
        let scope = &parsed.token_scopes["alpha"];
        for t in 1..=7u64 {
            assert!(scope.allows(TenantId(t)));
        }
        assert!(!scope.allows(TenantId(8)));
    }

    #[test]
    fn parse_env_handles_whitespace_around_entries() {
        let parsed = parse_tokens_env("  alpha , beta:tenant=1 , gamma:tenant=*  ");
        assert_eq!(parsed.token_scopes.len(), 3);
        assert!(parsed.token_scopes.contains_key("alpha"));
        assert!(parsed.token_scopes.contains_key("beta"));
        assert!(parsed.token_scopes.contains_key("gamma"));
    }

    #[test]
    fn parse_env_drops_malformed_entry_but_keeps_others() {
        // The middle entry has no bearer prefix → dropped. The bookend
        // entries survive.
        let parsed = parse_tokens_env("alpha,:tenant=1,gamma:tenant=*");
        assert_eq!(parsed.token_scopes.len(), 2);
        assert!(parsed.token_scopes.contains_key("alpha"));
        assert!(parsed.token_scopes.contains_key("gamma"));
        assert_eq!(parsed.deprecated_count, 1, "only `alpha` was bare");
    }

    #[test]
    fn parse_env_two_scoped_tokens_with_continuation_lists() {
        // The tricky case: two scoped tokens, each with a comma-separated
        // tenant list. The continuation logic must group `5,6` back with
        // `beta:tenant=4` and `1,2,3` with `alpha:tenant=`.
        let parsed = parse_tokens_env("alpha:tenant=1,2,3,beta:tenant=4,5,6");
        assert_eq!(parsed.deprecated_count, 0);
        assert_eq!(parsed.token_scopes.len(), 2);
        assert_eq!(
            parsed.token_scopes["alpha"].tenants,
            TenantScope::Set(ids([1, 2, 3]))
        );
        assert_eq!(
            parsed.token_scopes["beta"].tenants,
            TenantScope::Set(ids([4, 5, 6]))
        );
    }

    #[test]
    fn parse_env_bare_token_after_scoped_token() {
        // Tricky-case the continuation logic: `a:tenant=*,bare` must parse
        // as two entries, not one. The naive "no colon → continuation"
        // rule would glue `bare` onto the wildcard list and produce
        // WildcardMixedWithIds; the continuation-must-be-numeric rule
        // correctly splits.
        let parsed = parse_tokens_env("a:tenant=*,bare,b:tenant=4,5");
        assert_eq!(parsed.token_scopes.len(), 3);
        assert!(parsed.token_scopes["a"].tenants.is_all());
        assert!(parsed.token_scopes["bare"].tenants.is_all());
        assert_eq!(parsed.deprecated_count, 1, "`bare` is bare");
        assert_eq!(
            parsed.token_scopes["b"].tenants,
            TenantScope::Set(ids([4, 5]))
        );
    }

    #[test]
    fn tenant_scope_allows_in_set() {
        let s = TokenScope::from_tenants([TenantId(1), TenantId(2)]);
        assert!(s.allows(TenantId(1)));
        assert!(s.allows(TenantId(2)));
        assert!(!s.allows(TenantId(3)));
    }

    #[test]
    fn tenant_scope_wildcard_admits_arbitrary() {
        let s = TokenScope::all();
        assert!(s.allows(TenantId(0)));
        assert!(s.allows(TenantId(u64::MAX)));
    }
}