Skip to content
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

Fix broken code behind client_certificate feature #1706

Merged
merged 8 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions sdk/core/src/error/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ mod tests {
}
}

#[derive(thiserror::Error, Debug)]
enum IntermediateError {
#[error("second error")]
Io(#[from] std::io::Error),
}

#[test]
fn ensure_works() {
fn test_ensure(predicate: bool) -> crate::Result<()> {
Expand Down
1 change: 0 additions & 1 deletion sdk/identity/examples/azureauth_cli_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use azure_core::auth::TokenCredential;
use azure_identity::AzureauthCliCredential;
use clap::Parser;
use std::error::Error;
use url::Url;

#[derive(Debug, Parser)]
struct Args {
Expand Down
6 changes: 2 additions & 4 deletions sdk/identity/examples/client_certificate_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
/// please make sure to set the `send_certificate_chain` option to true otherwise
/// the authentication will fail.
use azure_core::auth::{Secret, TokenCredential};
use azure_identity::{
ClientCertificateCredential, ClientCertificateCredentialOptions, DefaultAzureCredential,
};
use azure_identity::{ClientCertificateCredential, ClientCertificateCredentialOptions};
use azure_security_keyvault::KeyvaultClient;
use std::env::var;
use url::Url;
Expand Down Expand Up @@ -44,7 +42,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let creds =
ClientCertificateCredential::new(tenant_id, client_id, cert, String::new(), options);

let res = creds
let res = creds?
.get_token(&["https://management.azure.com/.default"])
.await?;
// Let's enumerate the Azure SQL Databases instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use crate::token_credentials::cache::TokenCache;
use async_process::Command;
use azure_core::{
auth::{AccessToken, Secret, TokenCredential},
error::{Error, ErrorKind, ResultExt},
error::{Error, ErrorKind},
from_json,
};
use oauth2::ClientId;
use serde::Deserialize;
use std::str;
use time::OffsetDateTime;
Expand Down Expand Up @@ -40,7 +39,9 @@ mod unix_date_string {

#[derive(Debug, Clone, Deserialize)]
struct CliTokenResponse {
#[allow(dead_code)]
pub user: String,
#[allow(dead_code)]
pub display_name: String,
#[serde(rename = "token")]
pub access_token: Secret,
Expand Down Expand Up @@ -211,6 +212,8 @@ mod tests {

let response: CliTokenResponse = from_json(src)?;
assert_eq!(response.access_token.secret(), "security token here");
assert_eq!(response.user, "[email protected]");
assert_eq!(response.display_name, "Example User");
assert_eq!(
response.expires_on,
OffsetDateTime::from_unix_timestamp(1700166595).expect("known valid date")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,22 @@ impl ClientCertificateCredential {
client_certificate: C,
client_certificate_pass: P,
options: impl Into<ClientCertificateCredentialOptions>,
) -> ClientCertificateCredential
) -> azure_core::Result<ClientCertificateCredential>
where
C: Into<Secret>,
P: Into<Secret>,
{
let options = options.into();
ClientCertificateCredential {
Ok(ClientCertificateCredential {
tenant_id,
client_id,
client_certificate: client_certificate.into(),
client_certificate_pass: client_certificate_pass.into(),
http_client: options.options().http_client().clone(),
authority_host: options.options().authority_host().clone(),
authority_host: options.options().authority_host()?.clone(),
send_certificate_chain: options.send_certificate_chain(),
cache: TokenCache::new(),
}
})
}

fn sign(jwt: &str, pkey: &PKey<Private>) -> Result<Vec<u8>, ErrorStack> {
Expand Down Expand Up @@ -258,8 +258,12 @@ impl ClientCertificateCredential {
let rsp_status = rsp.status();

if !rsp_status.is_success() {
let rsp_body = rsp.into_body().collect().await?;
return Err(ErrorKind::http_response_from_body(rsp_status, &rsp_body).into_error());
let (rsp_status, rsp_headers, rsp_body) = rsp.deconstruct();
let rsp_body = rsp_body.collect().await?;
return Err(
ErrorKind::http_response_from_parts(rsp_status, &rsp_headers, &rsp_body)
.into_error(),
);
}

let response: AadTokenResponse = rsp.json().await?;
Expand Down Expand Up @@ -315,13 +319,13 @@ impl ClientCertificateCredential {
)
})?;

Ok(ClientCertificateCredential::new(
ClientCertificateCredential::new(
tenant_id,
client_id,
client_certificate,
client_certificate_password,
options,
))
)
}
}

Expand Down
4 changes: 1 addition & 3 deletions sdk/storage_blobs/tests/blob.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#![cfg(all(test, feature = "test_e2e", feature = "md5"))]
#[macro_use]
extern crate log;

use azure_core::{date, Url};
use azure_storage::prelude::*;
use azure_storage_blobs::container::operations::ListBlobsResponse;
Expand All @@ -11,6 +8,7 @@ use futures::StreamExt;
use std::ops::{Add, Deref};
use std::time::Duration;
use time::OffsetDateTime;
use tracing::trace;
use uuid::Uuid;

#[tokio::test]
Expand Down