Skip to content

Commit

Permalink
chore: remove unreproducible test cases
Browse files Browse the repository at this point in the history
This may obviate some of the status reason analysis, but we won't change
the source until we upgrade the AWS SDK.
  • Loading branch information
connec committed Apr 12, 2024
1 parent f6f947d commit f946857
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 92 deletions.
22 changes: 1 addition & 21 deletions tests/it/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,7 @@ pub const NON_EMPTY_TEMPLATE: &str = r#"{
}
}"#;

pub const MISSING_PERMISSION_1_TEMPLATE: &str = r#"{
"Resources": {
"Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {}
}
}
}"#;

pub const MISSING_PERMISSION_2_TEMPLATE: &str = r#"{
pub const MISSING_PERMISSION_TEMPLATE: &str = r#"{
"Resources": {
"Fs": {
"Type": "AWS::EFS::FileSystem",
Expand All @@ -70,17 +61,6 @@ pub const MISSING_PERMISSION_2_TEMPLATE: &str = r#"{
}
}"#;

pub const AUTHORIZATION_FAILURE_TEMPLATE: &str = r#"{
"Resources": {
"Vpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "0.0.0.0/16"
}
}
}
}"#;

pub const SECRETS_MANAGER_SECRET: &str = r#"{
"Parameters": {
"TagValue": {
Expand Down
73 changes: 2 additions & 71 deletions tests/it/status_reasons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,9 @@ use cloudformatious::{
};

use crate::common::{
clean_up, generated_name, get_client, get_sdk_config, AUTHORIZATION_FAILURE_TEMPLATE,
MISSING_PERMISSION_1_TEMPLATE, MISSING_PERMISSION_2_TEMPLATE,
clean_up, generated_name, get_client, get_sdk_config, MISSING_PERMISSION_TEMPLATE,
};

#[tokio::test]
async fn status_reason_missing_permission_no_principal() -> Result<(), Box<dyn std::error::Error>> {
let client = get_client().await;

let stack_name = generated_name();
let input = ApplyStackInput::new(
&stack_name,
TemplateSource::inline(MISSING_PERMISSION_1_TEMPLATE),
);
let error = client.apply_stack(input).await.unwrap_err();

let failure = assert_matches!(error, ApplyStackError::Failure(failure) => failure);
assert_eq!(failure.stack_status, StackStatus::RollbackComplete);

let status_reason = assert_matches!(
&failure.resource_events[..],
[(ResourceStatus::CreateFailed, status)] if status.logical_resource_id() == "Bucket" => {
status.resource_status_reason()
}
);
let missing_permission = assert_matches!(
status_reason.detail(),
Some(StatusReasonDetail::MissingPermission(missing_permission)) => missing_permission
);

assert_eq!(missing_permission.permission, "s3:CreateBucket");
assert_eq!(missing_permission.principal, None);
assert!(missing_permission.encoded_authorization_message.is_none());

clean_up(stack_name).await?;

Ok(())
}

#[tokio::test]
async fn status_reason_missing_permission_with_principal() -> Result<(), Box<dyn std::error::Error>>
{
Expand All @@ -56,7 +21,7 @@ async fn status_reason_missing_permission_with_principal() -> Result<(), Box<dyn
let stack_name = generated_name();
let input = ApplyStackInput::new(
&stack_name,
TemplateSource::inline(MISSING_PERMISSION_2_TEMPLATE),
TemplateSource::inline(MISSING_PERMISSION_TEMPLATE),
);
let error = client.apply_stack(input).await.unwrap_err();

Expand Down Expand Up @@ -85,37 +50,3 @@ async fn status_reason_missing_permission_with_principal() -> Result<(), Box<dyn

Ok(())
}

#[tokio::test]
async fn status_reason_authorization_failure() -> Result<(), Box<dyn std::error::Error>> {
let client = get_client().await;

let stack_name = generated_name();
let input = ApplyStackInput::new(
&stack_name,
TemplateSource::inline(AUTHORIZATION_FAILURE_TEMPLATE),
);
let error = client.apply_stack(input).await.unwrap_err();

let failure = assert_matches!(error, ApplyStackError::Failure(failure) => failure);
assert_eq!(failure.stack_status, StackStatus::RollbackComplete);

let status_reason = assert_matches!(
&failure.resource_events[..],
[(ResourceStatus::CreateFailed, status)] if status.logical_resource_id() == "Vpc" => {
status.resource_status_reason()
}
);
let encoded_message = assert_matches!(
status_reason.detail(),
Some(StatusReasonDetail::AuthorizationFailure(m)) => m
);

let sdk_config = get_sdk_config().await;
let decoded_message = encoded_message.decode(&sdk_config).await?;
assert_eq!(decoded_message["context"]["action"], "ec2:CreateVpc");

clean_up(stack_name).await?;

Ok(())
}

0 comments on commit f946857

Please sign in to comment.