Skip to content

Commit 0c612e9

Browse files
committed
fix(auth): loosen brittle scope-command test, add default-flag drift test
- auth_scopes_lists_every_scope_with_live_commands asserted the domains.domain:create scope's command list equals exactly ["domain purchase"], which would break if a future command legitimately requires the same scope. Assert containment instead. - Add scope_registry_default_flag_matches_default_oauth_scopes: closes the gap SCOPE_REGISTRY's own doc comment flagged (no automated check that its `default` flag matches environments::DEFAULT_OAUTH_SCOPES), so a drift here can no longer silently make `gddy auth scopes --defaults-only` misleading.
1 parent 9977cfa commit 0c612e9

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

rust/src/scopes.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ pub struct ScopeInfo {
132132

133133
/// Every requestable scope, described for `gddy auth scopes`. Keep in sync
134134
/// with the constants above (`scope_registry_covers_every_declared_scope`
135-
/// enforces the constant side of this; there's no automated check for the
136-
/// `default` flag — cross-check
137-
/// [`crate::environments::DEFAULT_OAUTH_SCOPES`] when adding a scope here).
135+
/// enforces the constant side of this; `scope_registry_default_flag_matches_default_oauth_scopes`
136+
/// enforces that the `default` flag exactly matches
137+
/// [`crate::environments::DEFAULT_OAUTH_SCOPES`]).
138138
pub const SCOPE_REGISTRY: &[ScopeInfo] = &[
139139
ScopeInfo {
140140
scope: APP_REGISTRY_READ,
@@ -313,4 +313,28 @@ mod tests {
313313
);
314314
}
315315
}
316+
317+
/// [`SCOPE_REGISTRY`]'s `default` flag must exactly match
318+
/// [`crate::environments::DEFAULT_OAUTH_SCOPES`] — the module doc on
319+
/// [`SCOPE_REGISTRY`] used to call this out as an unenforced invariant;
320+
/// this is that check. If they drift, `gddy auth scopes --defaults-only`
321+
/// would misdescribe which scopes actually get requested at login.
322+
#[test]
323+
fn scope_registry_default_flag_matches_default_oauth_scopes() {
324+
let default_in_registry: std::collections::HashSet<&str> = SCOPE_REGISTRY
325+
.iter()
326+
.filter(|info| info.default)
327+
.map(|info| info.scope)
328+
.collect();
329+
let default_oauth_scopes: std::collections::HashSet<&str> =
330+
crate::environments::DEFAULT_OAUTH_SCOPES
331+
.iter()
332+
.copied()
333+
.collect();
334+
assert_eq!(
335+
default_in_registry, default_oauth_scopes,
336+
"SCOPE_REGISTRY's `default` flags must match \
337+
crate::environments::DEFAULT_OAUTH_SCOPES exactly"
338+
);
339+
}
316340
}

rust/src/scopes_cmd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ mod tests {
199199
.iter()
200200
.map(|c| c.as_str().expect("command is a string"))
201201
.collect();
202-
assert_eq!(commands, vec!["domain purchase"]);
202+
assert!(commands.contains(&"domain purchase"));
203203
}
204204

205205
/// `--command` is a reverse lookup: given a command path, return exactly

0 commit comments

Comments
 (0)