Skip to content

Commit 00f7a4c

Browse files
committed
authn-mappings: fix stale no-auth test, add OAuth bearer test
- src/client.rs: the make_api_no_auth! macro-contract test used AuthNMappingsAPI as its vehicle type, which is no longer accurate now that authn_mappings.rs uses make_api!. Swapped to ApplicationSecurityAPI (ASM WAF custom rules), which is still genuinely no-auth today. - Added test_authn_mappings_list_accepts_oauth_bearer_token, which configures access_token only (no API/APP keys) and asserts the Authorization: Bearer header is sent -- the prior tests all used test_config's defaults (access_token: None), so the make_api_no_auth! -> make_api! change wasn't actually exercised by any test.
1 parent a25aad1 commit 00f7a4c

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

src/client.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,11 @@ mod tests {
697697
/// Same coverage for the no-auth variant. Asserts the UA is overridden
698698
/// AND that no `Authorization` header leaks through, even when a bearer
699699
/// token exists in the config — that's the contract of `make_api_no_auth!`.
700+
/// Uses `ApplicationSecurityAPI` (ASM WAF custom rules), which is still a
701+
/// genuinely no-auth production call site as of this test.
700702
#[tokio::test]
701703
async fn test_make_api_no_auth_sends_pup_user_agent() {
702-
use datadog_api_client::datadogV2::api_authn_mappings::{
703-
AuthNMappingsAPI, ListAuthNMappingsOptionalParams,
704-
};
704+
use datadog_api_client::datadogV2::api_application_security::ApplicationSecurityAPI;
705705
let _lock = lock_env().await;
706706
let mut server = mockito::Server::new_async().await;
707707
let mock = server
@@ -719,10 +719,8 @@ mod tests {
719719
// Set a token so the Authorization-absent assertion meaningfully
720720
// exercises that `make_api_no_auth!` actively suppresses bearer.
721721
cfg.access_token = Some("test-bearer-token".into());
722-
let api: AuthNMappingsAPI = crate::make_api_no_auth!(AuthNMappingsAPI, &cfg);
723-
let resp = api
724-
.list_authn_mappings(ListAuthNMappingsOptionalParams::default())
725-
.await;
722+
let api: ApplicationSecurityAPI = crate::make_api_no_auth!(ApplicationSecurityAPI, &cfg);
723+
let resp = api.list_application_security_waf_custom_rules().await;
726724
assert!(
727725
resp.is_ok(),
728726
"make_api_no_auth! request leaked Authorization or wrong UA: {:?}",

src/commands/authn_mappings.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,38 @@ mod tests {
115115
std::env::remove_var("DD_TOKEN_STORAGE");
116116
}
117117

118+
#[tokio::test]
119+
async fn test_authn_mappings_list_accepts_oauth_bearer_token() {
120+
let _lock = lock_env().await;
121+
std::env::set_var("DD_TOKEN_STORAGE", "file");
122+
let mut server = mockito::Server::new_async().await;
123+
let mut cfg = test_config(&server.url());
124+
// Simulate OAuth-only auth: bearer token configured, no API/APP keys.
125+
cfg.api_key = None;
126+
cfg.app_key = None;
127+
cfg.access_token = Some("oauth-bearer-token".into());
128+
std::env::remove_var("DD_API_KEY");
129+
std::env::remove_var("DD_APP_KEY");
130+
131+
let _mock = server
132+
.mock("GET", mockito::Matcher::Any)
133+
.match_header("Authorization", "Bearer oauth-bearer-token")
134+
.with_status(200)
135+
.with_header("content-type", "application/json")
136+
.with_body(r#"{"data":[]}"#)
137+
.create_async()
138+
.await;
139+
140+
let result = super::list(&cfg).await;
141+
assert!(
142+
result.is_ok(),
143+
"authn mappings list with OAuth bearer failed: {:?}",
144+
result.err()
145+
);
146+
cleanup_env();
147+
std::env::remove_var("DD_TOKEN_STORAGE");
148+
}
149+
118150
#[tokio::test]
119151
async fn test_authn_mappings_list_error() {
120152
let _lock = lock_env().await;

0 commit comments

Comments
 (0)