@@ -1363,3 +1363,54 @@ def test_validate_command_with_invalid_value(self, tmp_path):
13631363 result = runner .invoke (app , ["--file" , file_path , "validate" ])
13641364 assert result .exit_code == 1
13651365 assert "Value 'invalid_value' for variable 'MY_VAR' does not match validation regex" in result .stderr
1366+
1367+
1368+ def test_output_multiline_secret_dotenv (tmp_path ):
1369+ encrypted_string = base64 .b64encode (b"some_encrypted_bytes" ).decode ("utf-8" )
1370+ initial_content = f"""
1371+ configuration:
1372+ app: MyApp
1373+ kms_key: \" arn:aws:kms:us-east-1:123456789012:key/mrk-12345\"
1374+ environments:
1375+ - dev
1376+ locations:
1377+ - my_loc: \" loc123\"
1378+ environment_variables:
1379+ MY_MULTILINE_SECRET:
1380+ dev:
1381+ my_loc: !secret { encrypted_string }
1382+ """
1383+ file_path = create_envars_file (tmp_path , initial_content )
1384+
1385+ multiline_value = "line1\n line2\n line3"
1386+
1387+ kms_client = boto3 .client ("kms" , region_name = "us-east-1" )
1388+ with Stubber (kms_client ) as stubber :
1389+ stubber .add_response (
1390+ "decrypt" ,
1391+ {"Plaintext" : multiline_value .encode ("utf-8" )},
1392+ {
1393+ "CiphertextBlob" : b"some_encrypted_bytes" ,
1394+ "EncryptionContext" : {"app" : "MyApp" , "env" : "dev" , "location" : "my_loc" },
1395+ },
1396+ )
1397+ with patch ("boto3.client" , return_value = kms_client ):
1398+ result = runner .invoke (
1399+ app ,
1400+ [
1401+ "--file" ,
1402+ file_path ,
1403+ "output" ,
1404+ "--format" ,
1405+ "dotenv" ,
1406+ "--env" ,
1407+ "dev" ,
1408+ "--loc" ,
1409+ "my_loc" ,
1410+ ],
1411+ )
1412+ assert result .exit_code == 0 , result .stderr
1413+ escaped_multiline_value = multiline_value .replace ("\n " , "\\ n" )
1414+ expected_output = f'MY_MULTILINE_SECRET="{ escaped_multiline_value } "'
1415+ assert expected_output in result .stdout
1416+ stubber .assert_no_pending_responses ()
0 commit comments