-
Notifications
You must be signed in to change notification settings - Fork 76
feat(auth): expose OAuth scope contract #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+157
−2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| # Changelog | ||
|
|
||
| ## Next release | ||
|
|
||
| - Add `pup auth scopes --output=json` to expose the default `pup auth login` | ||
| OAuth scope set without requiring authentication. The first compatible | ||
| version for Bits feature-probing will be the next release after `0.58.5`. | ||
|
|
||
| See the [GitHub Releases](https://github.com/DataDog/pup/releases) page for | ||
| the authoritative list of changes per release. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| use serde_json::Value; | ||
| use std::process::Command; | ||
|
|
||
| fn run_auth_scopes(output: &str) -> std::process::Output { | ||
| let config_dir = | ||
| std::env::temp_dir().join(format!("pup-auth-scopes-json-{}", std::process::id())); | ||
| std::fs::create_dir_all(&config_dir).expect("create isolated config dir"); | ||
|
|
||
| Command::new(env!("CARGO_BIN_EXE_pup")) | ||
| .args(["auth", "scopes", &format!("--output={output}")]) | ||
| .env("PUP_CONFIG_DIR", config_dir) | ||
| .env_remove("DD_ACCESS_TOKEN") | ||
| .env_remove("DD_API_KEY") | ||
| .env_remove("DD_APP_KEY") | ||
| .env_remove("DD_SITE") | ||
| .env_remove("DD_ORG") | ||
| .output() | ||
| .expect("run pup auth scopes") | ||
| } | ||
|
|
||
| #[test] | ||
| fn auth_scopes_json_emits_default_oauth_scope_contract_without_auth() { | ||
| let output = run_auth_scopes("json"); | ||
|
|
||
| assert!( | ||
| output.status.success(), | ||
| "expected pup auth scopes to succeed without auth; status: {:?}, stderr: {}", | ||
| output.status.code(), | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
| assert!( | ||
| output.stderr.is_empty(), | ||
| "scope discovery should not start OAuth or print auth diagnostics: {}", | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
|
|
||
| let value: Value = serde_json::from_slice(&output.stdout).expect("valid JSON scope contract"); | ||
| assert_eq!(value["schema_version"], 1); | ||
| assert_eq!(value["source"], "pup auth login"); | ||
|
|
||
| let scopes = value["scopes"] | ||
| .as_array() | ||
| .expect("scopes should be a JSON array"); | ||
| assert!(!scopes.is_empty(), "scopes should not be empty"); | ||
| assert!( | ||
| scopes.iter().all(|scope| scope.as_str().is_some()), | ||
| "all scopes should be strings: {scopes:?}" | ||
| ); | ||
|
|
||
| let scope_strings: Vec<&str> = scopes.iter().filter_map(Value::as_str).collect(); | ||
| assert!(scope_strings.contains(&"metrics_read")); | ||
| assert!(scope_strings.contains(&"timeseries_query")); | ||
| assert!(scope_strings.contains(&"dashboards_write")); | ||
| assert!(scope_strings.contains(&"org_management")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn auth_scopes_json_rejects_non_json_output() { | ||
| let output = run_auth_scopes("table"); | ||
|
|
||
| assert!( | ||
| !output.status.success(), | ||
| "expected pup auth scopes --output=table to fail" | ||
| ); | ||
| assert!( | ||
| output.stdout.is_empty(), | ||
| "scope discovery should not emit table output: {}", | ||
| String::from_utf8_lossy(&output.stdout) | ||
| ); | ||
|
|
||
| let stderr = String::from_utf8_lossy(&output.stderr); | ||
| assert!( | ||
| stderr.contains("pup auth scopes only supports --output=json"), | ||
| "expected non-json diagnostic, got: {stderr}" | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the mention of bits here