Best Python code snippet using localstack_python
test_secretsmanager.py
Source:test_secretsmanager.py
...209 des = sm_client.describe_secret(SecretId=secret_name)210 assert des["RotationEnabled"]211 assert des["RotationRules"] == {"AutomaticallyAfterDays": 1}212 assert des["RotationLambdaARN"] == function_arn213 lst_res = sm_client.list_secret_version_ids(SecretId=secret_name)214 versions = lst_res["Versions"]215 assert len(versions) == 2216 get_res_v0 = sm_client.get_secret_value(SecretId=secret_name, VersionId=version_id_0)217 assert get_res_v0["VersionId"] == version_id_0218 assert get_res_v0["SecretString"] == "init"219 get_res_v1 = sm_client.get_secret_value(SecretId=secret_name, VersionId=version_id_1)220 assert get_res_v1["VersionId"] == version_id_1221 secret_string_1 = lambda_rotate_secret.secret_of_rotation_from_version_id(version_id_1)222 assert get_res_v1["SecretString"] == secret_string_1223 get_res = sm_client.get_secret_value(SecretId=secret_name)224 assert get_res["VersionId"] == version_id_1225 assert get_res["SecretString"] == secret_string_1226 rot_2_res = sm_client.rotate_secret(227 SecretId=secret_name,228 RotationLambdaARN=function_arn,229 RotationRules={230 "AutomaticallyAfterDays": 1,231 },232 RotateImmediately=True,233 )234 version_id_2 = rot_2_res["VersionId"]235 assert len({version_id_0, version_id_1, version_id_2}) == 3236 # Assert secretsmanager promoted the creation of the new secret version by reporting resource not found237 # exception on pending secret version.238 sig_rnfe_2 = lambda_rotate_secret.secret_signal_resource_not_found_exception_on_create(239 version_id_2240 )241 get_sig_rnfe_2 = sm_client.get_secret_value(SecretId=sig_rnfe_2)242 assert get_sig_rnfe_2["Name"] == sig_rnfe_2243 assert get_sig_rnfe_2["SecretString"] == sig_rnfe_2244 get_res = sm_client.get_secret_value(SecretId=secret_name)245 assert get_res["VersionId"] == version_id_2246 secret_string_2 = lambda_rotate_secret.secret_of_rotation_from_version_id(version_id_2)247 assert get_res["SecretString"] == secret_string_2248 # clean up249 sm_client.delete_secret(SecretId=secret_name, ForceDeleteWithoutRecovery=True)250 testutil.delete_lambda_function(function_name)251 def test_rotate_secret_invalid_lambda_arn(self, sm_client):252 secret_name = f"s-{short_uid()}"253 sm_client.create_secret(Name=secret_name, SecretString="init")254 invalid_arn = (255 "arn:aws:lambda:sa-east-1:000000000000:function:rotate_secret_invalid_lambda_arn"256 )257 with pytest.raises(Exception) as res_not_found_ex:258 sm_client.rotate_secret(259 SecretId=secret_name,260 RotationLambdaARN=invalid_arn,261 RotationRules={262 "AutomaticallyAfterDays": 1,263 },264 )265 assert res_not_found_ex.typename == "ResourceNotFoundException"266 assert (267 res_not_found_ex.value.response["Error"]["Message"]268 == "Lambda does not exist or could not be accessed"269 )270 des = sm_client.describe_secret(SecretId=secret_name)271 assert "RotationEnabled" not in des272 assert "RotationRules" not in des273 assert "RotationLambdaARN" not in des274 def test_put_secret_value_with_version_stages(self, sm_client):275 secret_name = f"s-{short_uid()}"276 secret_string_v0: str = "secret_string_v0"277 cr_v0_res = sm_client.create_secret(Name=secret_name, SecretString=secret_string_v0)278 pv_v0_vid: str = cr_v0_res["VersionId"]279 rs_get_curr = sm_client.get_secret_value(SecretId=secret_name)280 assert rs_get_curr["SecretString"] == secret_string_v0281 assert rs_get_curr["VersionStages"] == ["AWSCURRENT"]282 secret_string_v1: str = "secret_string_v1"283 version_stages_v1: ["str"] = ["SAMPLESTAGE1", "SAMPLESTAGE0"]284 pv_v1_vid: str = str(uuid.uuid4())285 pv_v1_res = sm_client.put_secret_value(286 SecretId=secret_name,287 SecretString=secret_string_v1,288 VersionStages=version_stages_v1,289 ClientRequestToken=pv_v1_vid,290 )291 assert pv_v1_res["VersionId"] == pv_v1_vid292 assert pv_v1_res["VersionStages"] == version_stages_v1293 rs_get_curr = sm_client.get_secret_value(SecretId=secret_name)294 assert rs_get_curr["VersionId"] == pv_v0_vid295 assert rs_get_curr["SecretString"] == secret_string_v0296 assert rs_get_curr["VersionStages"] == ["AWSCURRENT"]297 secret_string_v2: str = "secret_string_v2"298 version_stages_v2: ["str"] = version_stages_v1299 pv_v2_vid: str = str(uuid.uuid4())300 pv_v2_res = sm_client.put_secret_value(301 SecretId=secret_name,302 SecretString=secret_string_v2,303 VersionStages=version_stages_v2,304 ClientRequestToken=pv_v2_vid,305 )306 assert pv_v2_res["VersionId"] == pv_v2_vid307 assert pv_v2_res["VersionStages"] == version_stages_v2308 rs_get_curr = sm_client.get_secret_value(SecretId=secret_name)309 assert rs_get_curr["VersionId"] == pv_v0_vid310 assert rs_get_curr["SecretString"] == secret_string_v0311 assert rs_get_curr["VersionStages"] == ["AWSCURRENT"]312 secret_string_v3: str = "secret_string_v3"313 version_stages_v3: ["str"] = ["AWSPENDING"]314 pv_v3_vid: str = str(uuid.uuid4())315 pv_v3_res = sm_client.put_secret_value(316 SecretId=secret_name,317 SecretString=secret_string_v3,318 VersionStages=version_stages_v3,319 ClientRequestToken=pv_v3_vid,320 )321 assert pv_v3_res["VersionId"] == pv_v3_vid322 assert pv_v3_res["VersionStages"] == version_stages_v3323 rs_get_curr = sm_client.get_secret_value(SecretId=secret_name)324 assert rs_get_curr["VersionId"] == pv_v0_vid325 assert rs_get_curr["SecretString"] == secret_string_v0326 assert rs_get_curr["VersionStages"] == ["AWSCURRENT"]327 secret_string_v4: str = "secret_string_v4"328 pv_v4_vid: str = str(uuid.uuid4())329 pv_v4_res = sm_client.put_secret_value(330 SecretId=secret_name, SecretString=secret_string_v4, ClientRequestToken=pv_v4_vid331 )332 assert pv_v4_res["VersionId"] == pv_v4_vid333 assert pv_v4_res["VersionStages"] == ["AWSCURRENT"]334 rs_get_curr = sm_client.get_secret_value(SecretId=secret_name)335 assert rs_get_curr["VersionId"] == pv_v4_vid336 assert rs_get_curr["SecretString"] == secret_string_v4337 assert rs_get_curr["VersionStages"] == ["AWSCURRENT"]338 sm_client.delete_secret(SecretId=secret_name, ForceDeleteWithoutRecovery=True)339 @pytest.mark.parametrize(340 "secret_name", ["Inv Name", " Inv Name", " Inv*Name? ", " Inv *?!]Name\\-"]341 )342 def test_invalid_secret_name(self, sm_client, secret_name: str):343 def check_validation_exception(exc_info: ExceptionInfo):344 error = exc_info.value.response["Error"]345 error_code = error["Code"]346 error_msg = error["Message"]347 assert error_code == "ValidationException"348 assert (349 error_msg350 == "Invalid name. Must be a valid name containing alphanumeric characters, or any of the following: -/_+=.@!"351 )352 # The secret name can contain ASCII letters, numbers, and the following characters: /_+=.@-353 with pytest.raises(Exception) as validation_exception:354 sm_client.create_secret(Name=secret_name, SecretString="MySecretString")355 check_validation_exception(validation_exception)356 with pytest.raises(Exception) as validation_exception:357 sm_client.delete_secret(SecretId=secret_name, ForceDeleteWithoutRecovery=True)358 check_validation_exception(validation_exception)359 with pytest.raises(Exception) as validation_exception:360 sm_client.describe_secret(SecretId=secret_name)361 check_validation_exception(validation_exception)362 with pytest.raises(Exception) as validation_exception:363 sm_client.get_secret_value(SecretId=secret_name)364 check_validation_exception(validation_exception)365 with pytest.raises(Exception) as validation_exception:366 sm_client.list_secret_version_ids(SecretId=secret_name, IncludeDeprecated=True)367 check_validation_exception(validation_exception)368 with pytest.raises(Exception) as validation_exception:369 sm_client.put_secret_value(SecretId=secret_name, SecretString="MySecretString")370 check_validation_exception(validation_exception)371 with pytest.raises(Exception) as validation_exception:372 sm_client.tag_resource(373 SecretId=secret_name, Tags=[{"Key": "FirstTag", "Value": "SomeValue"}]374 )375 check_validation_exception(validation_exception)376 with pytest.raises(Exception) as validation_exception:377 sm_client.untag_resource(SecretId=secret_name, TagKeys=["FirstTag"])378 check_validation_exception(validation_exception)379 with pytest.raises(Exception) as validation_exception:380 sm_client.update_secret(SecretId=secret_name, Description="MyNewDescription")381 check_validation_exception(validation_exception)382 with pytest.raises(Exception) as validation_exception:383 sm_client.validate_resource_policy(384 SecretId=secret_name,385 ResourcePolicy='{\n"Version":"2012-10-17",\n"Statement":[{\n"Effect":"Allow",\n"Principal":{\n"AWS":"arn:aws:iam::123456789012:root"\n},\n"Action":"secretsmanager:GetSecretValue",\n"Resource":"*"\n}]\n}',386 )387 check_validation_exception(validation_exception)388 def test_last_accessed_date(self, sm_client):389 def last_accessed_scenario_1(fail_if_days_overlap: bool) -> bool:390 secret_name = f"s-{short_uid()}"391 sm_client.create_secret(Name=secret_name, SecretString="MySecretValue")392 des = sm_client.describe_secret(SecretId=secret_name)393 assert "LastAccessedDate" not in des394 t0 = today_no_time()395 sm_client.get_secret_value(SecretId=secret_name)396 des = sm_client.describe_secret(SecretId=secret_name)397 assert "LastAccessedDate" in des398 lad_v0 = des["LastAccessedDate"]399 assert isinstance(lad_v0, datetime)400 sm_client.get_secret_value(SecretId=secret_name)401 des = sm_client.describe_secret(SecretId=secret_name)402 assert "LastAccessedDate" in des403 lad_v1 = des["LastAccessedDate"]404 assert isinstance(lad_v1, datetime)405 if t0 == today_no_time() or fail_if_days_overlap:406 assert lad_v0 == lad_v1407 return True408 else:409 return False410 if not last_accessed_scenario_1(411 False412 ): # Test started yesterday and ended today (where relevant).413 last_accessed_scenario_1(414 True415 ) # Replay today or allow failure (this should never take longer than a day).416 def test_last_updated_date(self, sm_client):417 secret_name = f"s-{short_uid()}"418 sm_client.create_secret(Name=secret_name, SecretString="MySecretValue")419 res = sm_client.describe_secret(SecretId=secret_name)420 assert "LastChangedDate" in res421 create_date = res["LastChangedDate"]422 assert isinstance(create_date, datetime)423 res = sm_client.get_secret_value(SecretId=secret_name)424 assert create_date == res["CreatedDate"]425 res = sm_client.describe_secret(SecretId=secret_name)426 assert "LastChangedDate" in res427 assert create_date == res["LastChangedDate"]428 sm_client.update_secret(SecretId=secret_name, SecretString="MyNewSecretValue")429 res = sm_client.describe_secret(SecretId=secret_name)430 assert "LastChangedDate" in res431 assert create_date < res["LastChangedDate"]432 last_changed = res["LastChangedDate"]433 sm_client.update_secret(SecretId=secret_name, SecretString="MyNewSecretValue")434 res = sm_client.describe_secret(SecretId=secret_name)435 assert "LastChangedDate" in res436 assert last_changed < res["LastChangedDate"]437 sm_client.update_secret(SecretId=secret_name, SecretString="MyVeryNewSecretValue")438 res = sm_client.describe_secret(SecretId=secret_name)439 assert "LastChangedDate" in res440 assert create_date < res["LastChangedDate"]441 def test_update_secret_description(self, sm_client):442 secret_name = f"s-{short_uid()}"443 secret_string_v0 = "MySecretString"444 sm_client.create_secret(Name=secret_name, SecretString=secret_string_v0)445 des = sm_client.describe_secret(SecretId=secret_name)446 assert "Description" not in des447 description_v1 = "MyDescription"448 sm_client.update_secret(SecretId=secret_name, Description=description_v1)449 des = sm_client.describe_secret(SecretId=secret_name)450 assert des["Description"] == description_v1451 description_v2 = "MyNewDescription"452 secret_string_v1 = "MyNewSecretString"453 sm_client.update_secret(454 SecretId=secret_name, SecretString=secret_string_v1, Description=description_v2455 )456 des = sm_client.describe_secret(SecretId=secret_name)457 assert des["Description"] == description_v2458 sm_client.update_secret(SecretId=secret_name, SecretString=secret_string_v1 * 2)459 des = sm_client.describe_secret(SecretId=secret_name)460 assert des["Description"] == description_v2461 def test_update_secret_version_stages_return_type(self, sm_client):462 secret_name = f"s-{short_uid()}"463 create = sm_client.create_secret(Name=secret_name, SecretString="Something1")464 version_id_v0 = create["VersionId"]465 put_pending_res = sm_client.put_secret_value(466 SecretId=secret_name, SecretString="Something2", VersionStages=["AWSPENDING"]467 )468 version_id_v1 = put_pending_res["VersionId"]469 assert version_id_v1 != version_id_v0470 upd_res = sm_client.update_secret_version_stage(471 SecretId=secret_name,472 RemoveFromVersionId=version_id_v0,473 MoveToVersionId=version_id_v1,474 VersionStage="AWSCURRENT",475 )476 assert upd_res.keys() == {"Name", "ARN", "ResponseMetadata"}477 assert upd_res["Name"] == create["Name"]478 assert upd_res["ARN"] == create["ARN"]479 def test_update_secret_version_stages_current_previous(self, sm_client):480 secret_name = f"s-{short_uid()}"481 secret_string_v0 = "secret_string_v0"482 create = sm_client.create_secret(Name=secret_name, SecretString=secret_string_v0)483 version_id_v0 = create["VersionId"]484 lst_ids_v0 = sm_client.list_secret_version_ids(SecretId=secret_name)485 versions_v0 = lst_ids_v0["Versions"]486 assert len(versions_v0) == 1487 versions_v0_v0 = versions_v0[0]488 assert versions_v0_v0["VersionId"] == version_id_v0489 assert versions_v0_v0["VersionStages"] == ["AWSCURRENT"]490 secret_string_v1 = "secret_string_v1"491 update_v1 = sm_client.update_secret(SecretId=secret_name, SecretString=secret_string_v1)492 version_id_v1 = update_v1["VersionId"]493 assert version_id_v0 != version_id_v1494 lst_ids_v1 = sm_client.list_secret_version_ids(SecretId=secret_name)495 versions_v1 = lst_ids_v1["Versions"]496 assert len(versions_v1) == 2497 versions_v1_v0 = versions_v1[0]498 assert versions_v1_v0["VersionId"] == version_id_v0499 assert versions_v1_v0["VersionStages"] == ["AWSPREVIOUS"]500 versions_v1_v1 = versions_v1[1]501 assert versions_v1_v1["VersionId"] == version_id_v1502 assert versions_v1_v1["VersionStages"] == ["AWSCURRENT"]503 def test_update_secret_version_stages_current_pending(self, sm_client):504 secret_name = f"s-{short_uid()}"505 create = sm_client.create_secret(Name=secret_name, SecretString="Something1")506 version_id_v0 = create["VersionId"]507 put_pending_res = sm_client.put_secret_value(508 SecretId=secret_name, SecretString="Something2", VersionStages=["AWSPENDING"]509 )510 version_id_v1 = put_pending_res["VersionId"]511 assert version_id_v1 != version_id_v0512 list_ids_res = sm_client.list_secret_version_ids(SecretId=secret_name)513 assert len(list_ids_res["Versions"]) == 2514 list_ids_0 = list_ids_res["Versions"][0]515 assert list_ids_0["VersionId"] == version_id_v0516 assert list_ids_0["VersionStages"] == ["AWSCURRENT"]517 list_ids_1 = list_ids_res["Versions"][1]518 assert list_ids_1["VersionId"] == version_id_v1519 assert list_ids_1["VersionStages"] == ["AWSPENDING"]520 upd_res = sm_client.update_secret_version_stage(521 SecretId=secret_name,522 RemoveFromVersionId=version_id_v0,523 MoveToVersionId=version_id_v1,524 VersionStage="AWSCURRENT",525 )526 assert "VersionId" not in upd_res527 list_ids_2_res = sm_client.list_secret_version_ids(SecretId=secret_name)528 assert len(list_ids_2_res["Versions"]) == 2529 list_ids_2_0 = list_ids_2_res["Versions"][0]530 assert list_ids_2_0["VersionId"] == version_id_v0531 assert list_ids_2_0["VersionStages"] == ["AWSPREVIOUS"]532 list_ids_2_1 = list_ids_2_res["Versions"][1]533 assert list_ids_2_1["VersionId"] == version_id_v1534 assert list_ids_2_1["VersionStages"] == ["AWSPENDING", "AWSCURRENT"]535 upd_2_res = sm_client.put_secret_value(SecretId=secret_name, SecretString="SS3")536 version_id_v2 = upd_2_res["VersionId"]537 assert len({version_id_v0, version_id_v1, version_id_v2}) == 3538 list_ids_3_res = sm_client.list_secret_version_ids(SecretId=secret_name)539 assert len(list_ids_3_res["Versions"]) == 2540 list_ids_3_0 = list_ids_3_res["Versions"][0]541 assert list_ids_3_0["VersionId"] == version_id_v1542 assert list_ids_3_0["VersionStages"] == ["AWSPREVIOUS"]543 list_ids_3_1 = list_ids_3_res["Versions"][1]544 assert list_ids_3_1["VersionId"] == version_id_v2545 assert list_ids_3_1["VersionStages"] == ["AWSCURRENT"]546 def test_update_secret_version_stages_current_pending_cycle(self, sm_client):547 secret_name = f"s-{short_uid()}"548 create = sm_client.create_secret(Name=secret_name, SecretString="S1")549 vid_0 = create["VersionId"]550 put_1 = sm_client.put_secret_value(551 SecretId=secret_name, SecretString="S2", VersionStages=["AWSPENDING"]552 )553 vid_1 = put_1["VersionId"]554 assert vid_1 != vid_0555 lst_1 = sm_client.list_secret_version_ids(SecretId=secret_name)556 assert len(lst_1["Versions"]) == 2557 #558 lst_1_v_0 = lst_1["Versions"][0]559 assert lst_1_v_0["VersionId"] == vid_0560 assert lst_1_v_0["VersionStages"] == ["AWSCURRENT"]561 #562 lst_1_v_1 = lst_1["Versions"][1]563 assert lst_1_v_1["VersionId"] == vid_1564 assert lst_1_v_1["VersionStages"] == ["AWSPENDING"]565 get_1 = sm_client.get_secret_value(SecretId=secret_name)566 assert get_1["VersionId"] == vid_0567 assert get_1["SecretString"] == "S1"568 assert get_1["VersionStages"] == ["AWSCURRENT"]569 upd_1 = sm_client.update_secret_version_stage(570 SecretId=secret_name,571 RemoveFromVersionId=vid_0,572 MoveToVersionId=vid_1,573 VersionStage="AWSCURRENT",574 )575 assert "VersionId" not in upd_1576 lst_1_u = sm_client.list_secret_version_ids(SecretId=secret_name)577 assert len(lst_1_u["Versions"]) == 2578 #579 lst_1_u_v_0 = lst_1_u["Versions"][0]580 assert lst_1_u_v_0["VersionId"] == vid_0581 assert lst_1_u_v_0["VersionStages"] == ["AWSPREVIOUS"]582 #583 lst_1_u_v_1 = lst_1_u["Versions"][1]584 assert lst_1_u_v_1["VersionId"] == vid_1585 assert lst_1_u_v_1["VersionStages"] == ["AWSPENDING", "AWSCURRENT"]586 get_1_u = sm_client.get_secret_value(SecretId=secret_name)587 assert get_1_u["VersionId"] == vid_1588 assert get_1_u["SecretString"] == "S2"589 assert get_1_u["VersionStages"] == ["AWSPENDING", "AWSCURRENT"]590 put_2 = sm_client.put_secret_value(591 SecretId=secret_name, SecretString="S3", VersionStages=["AWSPENDING"]592 )593 vid_2 = put_2["VersionId"]594 assert len({vid_0, vid_1, vid_2}) == 3595 lst_2 = sm_client.list_secret_version_ids(SecretId=secret_name)596 assert len(lst_2["Versions"]) == 3597 #598 lst_2_v_0 = lst_2["Versions"][0]599 assert lst_2_v_0["VersionId"] == vid_0600 assert lst_2_v_0["VersionStages"] == ["AWSPREVIOUS"]601 #602 lst_2_v_1 = lst_2["Versions"][1]603 assert lst_2_v_1["VersionId"] == vid_1604 assert lst_2_v_1["VersionStages"] == ["AWSCURRENT"]605 #606 lst_2_v_2 = lst_2["Versions"][2]607 assert lst_2_v_2["VersionId"] == vid_2608 assert lst_2_v_2["VersionStages"] == ["AWSPENDING"]609 get_2 = sm_client.get_secret_value(SecretId=secret_name)610 assert get_2["VersionId"] == vid_1611 assert get_2["SecretString"] == "S2"612 assert get_2["VersionStages"] == ["AWSCURRENT"]613 upd_2 = sm_client.update_secret_version_stage(614 SecretId=secret_name,615 RemoveFromVersionId=vid_1,616 MoveToVersionId=vid_2,617 VersionStage="AWSCURRENT",618 )619 assert "VersionId" not in upd_2620 lst_2_u = sm_client.list_secret_version_ids(SecretId=secret_name)621 assert len(lst_2_u["Versions"]) == 2622 #623 lst_2_u_v_0 = lst_2_u["Versions"][0]624 assert lst_2_u_v_0["VersionId"] == vid_1625 assert lst_2_u_v_0["VersionStages"] == ["AWSPREVIOUS"]626 #627 lst_2_u_v_1 = lst_2_u["Versions"][1]628 assert lst_2_u_v_1["VersionId"] == vid_2629 assert lst_2_u_v_1["VersionStages"] == ["AWSPENDING", "AWSCURRENT"]630 get_1_u = sm_client.get_secret_value(SecretId=secret_name)631 assert get_1_u["VersionId"] == vid_2632 assert get_1_u["SecretString"] == "S3"633 assert get_1_u["VersionStages"] == ["AWSPENDING", "AWSCURRENT"]634 def test_update_secret_version_stages_current_pending_cycle_custom_stages_1(self, sm_client):635 secret_name = f"s-{short_uid()}"636 create = sm_client.create_secret(Name=secret_name, SecretString="S1")637 vid_0 = create["VersionId"]638 put_1 = sm_client.put_secret_value(639 SecretId=secret_name, SecretString="S2", VersionStages=["AWSPENDING", "PUT1"]640 )641 vid_1 = put_1["VersionId"]642 assert vid_1 != vid_0643 lst_1 = sm_client.list_secret_version_ids(SecretId=secret_name)644 assert len(lst_1["Versions"]) == 2645 #646 lst_1_v_0 = lst_1["Versions"][0]647 assert lst_1_v_0["VersionId"] == vid_0648 assert lst_1_v_0["VersionStages"] == ["AWSCURRENT"]649 #650 lst_1_v_1 = lst_1["Versions"][1]651 assert lst_1_v_1["VersionId"] == vid_1652 assert lst_1_v_1["VersionStages"] == ["AWSPENDING", "PUT1"]653 get_1 = sm_client.get_secret_value(SecretId=secret_name)654 assert get_1["VersionId"] == vid_0655 assert get_1["SecretString"] == "S1"656 assert get_1["VersionStages"] == ["AWSCURRENT"]657 upd_1 = sm_client.update_secret_version_stage(658 SecretId=secret_name,659 RemoveFromVersionId=vid_0,660 MoveToVersionId=vid_1,661 VersionStage="AWSCURRENT",662 )663 assert "VersionId" not in upd_1664 lst_1_u = sm_client.list_secret_version_ids(SecretId=secret_name)665 assert len(lst_1_u["Versions"]) == 2666 #667 lst_1_u_v_0 = lst_1_u["Versions"][0]668 assert lst_1_u_v_0["VersionId"] == vid_0669 assert lst_1_u_v_0["VersionStages"] == ["AWSPREVIOUS"]670 #671 lst_1_u_v_1 = lst_1_u["Versions"][1]672 assert lst_1_u_v_1["VersionId"] == vid_1673 assert lst_1_u_v_1["VersionStages"] == ["AWSPENDING", "PUT1", "AWSCURRENT"]674 get_1_u = sm_client.get_secret_value(SecretId=secret_name)675 assert get_1_u["VersionId"] == vid_1676 assert get_1_u["SecretString"] == "S2"677 assert get_1_u["VersionStages"] == ["AWSPENDING", "PUT1", "AWSCURRENT"]678 put_2 = sm_client.put_secret_value(679 SecretId=secret_name, SecretString="S3", VersionStages=["AWSPENDING", "PUT2"]680 )681 vid_2 = put_2["VersionId"]682 assert len({vid_0, vid_1, vid_2}) == 3683 lst_2 = sm_client.list_secret_version_ids(SecretId=secret_name)684 assert len(lst_2["Versions"]) == 3685 #686 lst_2_v_0 = lst_2["Versions"][0]687 assert lst_2_v_0["VersionId"] == vid_0688 assert lst_2_v_0["VersionStages"] == ["AWSPREVIOUS"]689 #690 lst_2_v_1 = lst_2["Versions"][1]691 assert lst_2_v_1["VersionId"] == vid_1692 assert lst_2_v_1["VersionStages"] == ["PUT1", "AWSCURRENT"]693 #694 lst_2_v_2 = lst_2["Versions"][2]695 assert lst_2_v_2["VersionId"] == vid_2696 assert lst_2_v_2["VersionStages"] == ["AWSPENDING", "PUT2"]697 get_2 = sm_client.get_secret_value(SecretId=secret_name)698 assert get_2["VersionId"] == vid_1699 assert get_2["SecretString"] == "S2"700 assert get_2["VersionStages"] == ["PUT1", "AWSCURRENT"]701 upd_2 = sm_client.update_secret_version_stage(702 SecretId=secret_name,703 RemoveFromVersionId=vid_1,704 MoveToVersionId=vid_2,705 VersionStage="AWSCURRENT",706 )707 assert "VersionId" not in upd_2708 lst_2_u = sm_client.list_secret_version_ids(SecretId=secret_name)709 assert len(lst_2_u["Versions"]) == 2710 #711 lst_2_u_v_0 = lst_2_u["Versions"][0]712 assert lst_2_u_v_0["VersionId"] == vid_1713 assert lst_2_u_v_0["VersionStages"] == ["PUT1", "AWSPREVIOUS"]714 #715 lst_2_u_v_1 = lst_2_u["Versions"][1]716 assert lst_2_u_v_1["VersionId"] == vid_2717 assert lst_2_u_v_1["VersionStages"] == ["AWSPENDING", "PUT2", "AWSCURRENT"]718 get_1_u = sm_client.get_secret_value(SecretId=secret_name)719 assert get_1_u["VersionId"] == vid_2720 assert get_1_u["SecretString"] == "S3"721 assert get_1_u["VersionStages"] == ["AWSPENDING", "PUT2", "AWSCURRENT"]722 def test_update_secret_version_stages_current_pending_cycle_custom_stages_2(self, sm_client):723 secret_name = f"s-{short_uid()}"724 create = sm_client.create_secret(Name=secret_name, SecretString="SS")725 vid_s = create["VersionId"]726 put_0 = sm_client.put_secret_value(727 SecretId=secret_name, SecretString="S1", VersionStages=["AWSCURRENT", "PUT0"]728 )729 vid_0 = put_0["VersionId"]730 assert vid_0 != vid_s731 lst_0 = sm_client.list_secret_version_ids(SecretId=secret_name)732 assert len(lst_0["Versions"]) == 2733 #734 lst_0_v_s = lst_0["Versions"][0]735 assert lst_0_v_s["VersionId"] == vid_s736 assert lst_0_v_s["VersionStages"] == ["AWSPREVIOUS"]737 #738 lst_0_v_0 = lst_0["Versions"][1]739 assert lst_0_v_0["VersionId"] == vid_0740 assert lst_0_v_0["VersionStages"] == ["AWSCURRENT", "PUT0"]741 put_1 = sm_client.put_secret_value(742 SecretId=secret_name, SecretString="S2", VersionStages=["AWSPENDING", "PUT1"]743 )744 vid_1 = put_1["VersionId"]745 assert len({vid_s, vid_0, vid_1}) == 3746 lst_1 = sm_client.list_secret_version_ids(SecretId=secret_name)747 assert len(lst_1["Versions"]) == 3748 #749 lst_1_v_s = lst_1["Versions"][0]750 assert lst_1_v_s["VersionId"] == vid_s751 assert lst_1_v_s["VersionStages"] == ["AWSPREVIOUS"]752 #753 lst_1_v_0 = lst_1["Versions"][1]754 assert lst_1_v_0["VersionId"] == vid_0755 assert lst_1_v_0["VersionStages"] == ["AWSCURRENT", "PUT0"]756 #757 lst_1_v_1 = lst_1["Versions"][2]758 assert lst_1_v_1["VersionId"] == vid_1759 assert lst_1_v_1["VersionStages"] == ["AWSPENDING", "PUT1"]760 get_1 = sm_client.get_secret_value(SecretId=secret_name)761 assert get_1["VersionId"] == vid_0762 assert get_1["SecretString"] == "S1"763 assert get_1["VersionStages"] == ["AWSCURRENT", "PUT0"]764 upd_1 = sm_client.update_secret_version_stage(765 SecretId=secret_name,766 RemoveFromVersionId=vid_0,767 MoveToVersionId=vid_1,768 VersionStage="AWSCURRENT",769 )770 assert "VersionId" not in upd_1771 lst_1_u = sm_client.list_secret_version_ids(SecretId=secret_name)772 assert len(lst_1_u["Versions"]) == 2773 #774 lst_1_u_v_0 = lst_1_u["Versions"][0]775 assert lst_1_u_v_0["VersionId"] == vid_0776 assert lst_1_u_v_0["VersionStages"] == ["PUT0", "AWSPREVIOUS"]777 #778 lst_1_u_v_1 = lst_1_u["Versions"][1]779 assert lst_1_u_v_1["VersionId"] == vid_1780 assert lst_1_u_v_1["VersionStages"] == ["AWSPENDING", "PUT1", "AWSCURRENT"]781 get_1_u = sm_client.get_secret_value(SecretId=secret_name)782 assert get_1_u["VersionId"] == vid_1783 assert get_1_u["SecretString"] == "S2"784 assert get_1_u["VersionStages"] == ["AWSPENDING", "PUT1", "AWSCURRENT"]785 put_2 = sm_client.put_secret_value(786 SecretId=secret_name, SecretString="S3", VersionStages=["AWSPENDING", "PUT2"]787 )788 vid_2 = put_2["VersionId"]789 assert len({vid_s, vid_0, vid_1, vid_2}) == 4790 lst_2 = sm_client.list_secret_version_ids(SecretId=secret_name)791 assert len(lst_2["Versions"]) == 3792 #793 lst_2_v_0 = lst_2["Versions"][0]794 assert lst_2_v_0["VersionId"] == vid_0795 assert lst_2_v_0["VersionStages"] == ["PUT0", "AWSPREVIOUS"]796 #797 lst_2_v_1 = lst_2["Versions"][1]798 assert lst_2_v_1["VersionId"] == vid_1799 assert lst_2_v_1["VersionStages"] == ["PUT1", "AWSCURRENT"]800 #801 lst_2_v_2 = lst_2["Versions"][2]802 assert lst_2_v_2["VersionId"] == vid_2803 assert lst_2_v_2["VersionStages"] == ["AWSPENDING", "PUT2"]804 get_2 = sm_client.get_secret_value(SecretId=secret_name)805 assert get_2["VersionId"] == vid_1806 assert get_2["SecretString"] == "S2"807 assert get_2["VersionStages"] == ["PUT1", "AWSCURRENT"]808 upd_2 = sm_client.update_secret_version_stage(809 SecretId=secret_name,810 RemoveFromVersionId=vid_1,811 MoveToVersionId=vid_2,812 VersionStage="AWSCURRENT",813 )814 assert "VersionId" not in upd_2815 lst_2_u = sm_client.list_secret_version_ids(SecretId=secret_name)816 assert len(lst_2_u["Versions"]) == 3817 #818 lst_2_u_v_0 = lst_2_u["Versions"][0]819 assert lst_2_u_v_0["VersionId"] == vid_0820 assert lst_2_u_v_0["VersionStages"] == ["PUT0"]821 #822 lst_2_u_v_1 = lst_2_u["Versions"][1]823 assert lst_2_u_v_1["VersionId"] == vid_1824 assert lst_2_u_v_1["VersionStages"] == ["PUT1", "AWSPREVIOUS"]825 #826 lst_2_u_v_2 = lst_2_u["Versions"][2]827 assert lst_2_u_v_2["VersionId"] == vid_2828 assert lst_2_u_v_2["VersionStages"] == ["AWSPENDING", "PUT2", "AWSCURRENT"]829 #830 get_1_u = sm_client.get_secret_value(SecretId=secret_name)831 assert get_1_u["VersionId"] == vid_2832 assert get_1_u["SecretString"] == "S3"833 assert get_1_u["VersionStages"] == ["AWSPENDING", "PUT2", "AWSCURRENT"]834 def test_non_versioning_version_stages_replacement(self, sm_client):835 secret_name = f"s-{short_uid()}"836 create = sm_client.create_secret(Name=secret_name, SecretString="S0")837 vid_s = create["VersionId"]838 put_0 = sm_client.put_secret_value(839 SecretId=secret_name, SecretString="S1", VersionStages=["one", "two", "three"]840 )841 vid_0 = put_0["VersionId"]842 assert vid_0 != vid_s843 lst_0 = sm_client.list_secret_version_ids(SecretId=secret_name)844 assert len(lst_0["Versions"]) == 2845 #846 lst_0_v_0 = lst_0["Versions"][0]847 assert lst_0_v_0["VersionId"] == vid_s848 assert lst_0_v_0["VersionStages"] == ["AWSCURRENT"]849 #850 lst_0_v_1 = lst_0["Versions"][1]851 assert lst_0_v_1["VersionId"] == vid_0852 assert lst_0_v_1["VersionStages"] == ["one", "two", "three"]853 put_1 = sm_client.put_secret_value(854 SecretId=secret_name, SecretString="S2", VersionStages=["one", "two", "three", "four"]855 )856 vid_1 = put_1["VersionId"]857 assert len({vid_s, vid_0, vid_1}) == 3858 lst_1 = sm_client.list_secret_version_ids(SecretId=secret_name)859 assert len(lst_1["Versions"]) == 2860 #861 lst_1_v_0 = lst_1["Versions"][0]862 assert lst_1_v_0["VersionId"] == vid_s863 assert lst_1_v_0["VersionStages"] == ["AWSCURRENT"]864 #865 lst_1_v_1 = lst_1["Versions"][1]866 assert lst_1_v_1["VersionId"] == vid_1867 assert lst_1_v_1["VersionStages"] == ["one", "two", "three", "four"]868 def test_non_versioning_version_stages_no_replacement(self, sm_client):869 secret_name = f"s-{short_uid()}"870 create = sm_client.create_secret(Name=secret_name, SecretString="S0")871 vid_s = create["VersionId"]872 put_0 = sm_client.put_secret_value(873 SecretId=secret_name, SecretString="S1", VersionStages=["one", "two", "three"]874 )875 vid_0 = put_0["VersionId"]876 assert vid_0 != vid_s877 lst_0 = sm_client.list_secret_version_ids(SecretId=secret_name)878 assert len(lst_0["Versions"]) == 2879 #880 lst_0_v_0 = lst_0["Versions"][0]881 assert lst_0_v_0["VersionId"] == vid_s882 assert lst_0_v_0["VersionStages"] == ["AWSCURRENT"]883 #884 lst_0_v_1 = lst_0["Versions"][1]885 assert lst_0_v_1["VersionId"] == vid_0886 assert lst_0_v_1["VersionStages"] == ["one", "two", "three"]887 put_1 = sm_client.put_secret_value(888 SecretId=secret_name, SecretString="S2", VersionStages=["one", "two", "four"]889 )890 vid_1 = put_1["VersionId"]891 assert len({vid_s, vid_0, vid_1}) == 3892 lst_1 = sm_client.list_secret_version_ids(SecretId=secret_name)893 assert len(lst_1["Versions"]) == 3894 #895 lst_1_v_0 = lst_1["Versions"][0]896 assert lst_1_v_0["VersionId"] == vid_s897 assert lst_1_v_0["VersionStages"] == ["AWSCURRENT"]898 #899 lst_1_v_1 = lst_1["Versions"][1]900 assert lst_1_v_1["VersionId"] == vid_0901 assert lst_1_v_1["VersionStages"] == ["three"]902 #903 lst_1_v_2 = lst_1["Versions"][2]904 assert lst_1_v_2["VersionId"] == vid_1905 assert lst_1_v_2["VersionStages"] == ["one", "two", "four"]906 @staticmethod907 def secretsmanager_http_json_headers(amz_target: str) -> Dict:908 headers = aws_stack.mock_aws_request_headers("secretsmanager")909 headers["X-Amz-Target"] = amz_target910 return headers911 def secretsmanager_http_json_post(self, amz_target: str, http_body: json) -> requests.Response:912 ep_url: str = aws_stack.get_local_service_url("secretsmanager")913 http_headers: Dict = self.secretsmanager_http_json_headers(amz_target)914 return requests.post(ep_url, headers=http_headers, data=json.dumps(http_body))915 def secretsmanager_http_create_secret_string(916 self, secret_name: str, secret_string: str917 ) -> requests.Response:918 http_body: json = {"Name": secret_name, "SecretString": secret_string}919 return self.secretsmanager_http_json_post("secretsmanager.CreateSecret", http_body)920 @staticmethod921 def secretsmanager_http_create_secret_string_val_res(922 res: requests.Response, secret_name: str923 ) -> json:924 assert res.status_code == 200925 res_json: json = res.json()926 assert res_json["Name"] == secret_name927 return res_json928 def secretsmanager_http_delete_secret(self, secret_id: str) -> requests.Response:929 http_body: json = {"SecretId": secret_id}930 return self.secretsmanager_http_json_post("secretsmanager.DeleteSecret", http_body)931 @staticmethod932 def secretsmanager_http_delete_secret_val_res(res: requests.Response, secret_id: str) -> json:933 assert res.status_code == 200934 res_json: json = res.json()935 assert res_json["Name"] == secret_id936 return res_json937 def secretsmanager_http_get_secret_value(self, secret_id: str) -> requests.Response:938 http_body: json = {"SecretId": secret_id}939 return self.secretsmanager_http_json_post("secretsmanager.GetSecretValue", http_body)940 @staticmethod941 def secretsmanager_http_get_secret_value_val_res(942 res: requests.Response, secret_name: str, secret_string: str, version_id: str943 ) -> json:944 assert res.status_code == 200945 res_json: json = res.json()946 assert res_json["Name"] == secret_name947 assert res_json["SecretString"] == secret_string948 assert res_json["VersionId"] == version_id949 return res_json950 def secretsmanager_http_get_secret_value_with(951 self, secret_id: str, version_stage: str952 ) -> requests.Response:953 http_body: json = {"SecretId": secret_id, "VersionStage": version_stage}954 return self.secretsmanager_http_json_post("secretsmanager.GetSecretValue", http_body)955 @staticmethod956 def secretsmanager_http_get_secret_value_with_val_res(957 res: requests.Response,958 secret_name: str,959 secret_string: str,960 version_id: str,961 version_stage: str,962 ) -> json:963 res_json = TestSecretsManager.secretsmanager_http_get_secret_value_val_res(964 res, secret_name, secret_string, version_id965 )966 assert res_json["VersionStages"] == [version_stage]967 return res_json968 def secretsmanager_http_list_secret_version_ids(self, secret_id: str) -> requests.Response:969 http_body: json = {"SecretId": secret_id}970 return self.secretsmanager_http_json_post("secretsmanager.ListSecretVersionIds", http_body)971 @staticmethod972 def secretsmanager_http_list_secret_version_ids_val_res(973 res: requests.Response, secret_name: str, versions: json974 ) -> json:975 assert res.status_code == 200976 res_json: json = res.json()977 assert res_json["Name"] == secret_name978 res_versions: [json] = res_json["Versions"]979 assert len(res_versions) == len(versions)980 assert len(set([rv["VersionId"] for rv in res_versions])) == len(res_versions)981 assert len(set([v["VersionId"] for v in versions])) == len(versions)982 for version in versions:983 vs_in_res: [json] = list(984 filter(lambda rv: rv["VersionId"] == version["VersionId"], res_versions)985 )986 assert len(vs_in_res) == 1987 v_in_res = vs_in_res[0]988 assert v_in_res["VersionStages"] == version["VersionStages"]989 return res_json990 def secretsmanager_http_put_secret_value(991 self, secret_id: str, secret_string: str992 ) -> requests.Response:993 http_body: json = {994 "SecretId": secret_id,995 "SecretString": secret_string,996 }997 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)998 @staticmethod999 def secretsmanager_http_put_secret_value_val_res(1000 res: requests.Response, secret_name: str1001 ) -> json:1002 assert res.status_code == 2001003 res_json: json = res.json()1004 assert res_json["Name"] == secret_name1005 return res_json1006 def secretsmanager_http_put_pending_secret_value(1007 self, secret_id: str, secret_string: str1008 ) -> requests.Response:1009 http_body: json = {1010 "SecretId": secret_id,1011 "SecretString": secret_string,1012 "VersionStages": ["AWSPENDING"],1013 }1014 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)1015 @staticmethod1016 def secretsmanager_http_put_pending_secret_value_val_res(1017 res: requests.Response, secret_name: str1018 ) -> json:1019 return TestSecretsManager.secretsmanager_http_put_secret_value_val_res(res, secret_name)1020 def secretsmanager_http_put_secret_value_with(1021 self, secret_id: str, secret_string: str, client_request_token: Optional[str]1022 ) -> requests.Response:1023 http_body: json = {1024 "SecretId": secret_id,1025 "SecretString": secret_string,1026 "ClientRequestToken": client_request_token,1027 }1028 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)1029 @staticmethod1030 def secretsmanager_http_put_secret_value_with_val_res(1031 res: requests.Response, secret_name: str, client_request_token: str1032 ) -> json:1033 assert res.status_code == 2001034 res_json: json = res.json()1035 assert res_json["Name"] == secret_name1036 assert res_json["VersionId"] == client_request_token1037 return res_json1038 def secretsmanager_http_update_secret(1039 self, secret_id: str, secret_string: str, client_request_token: Optional[str]1040 ):1041 http_body: json = {"SecretId": secret_id, "SecretString": secret_string}1042 if client_request_token:1043 http_body["ClientRequestToken"] = client_request_token1044 return self.secretsmanager_http_json_post("secretsmanager.UpdateSecret", http_body)1045 @staticmethod1046 def secretsmanager_http_update_secret_val_res(1047 res: requests.Response, secret_name: str, client_request_token: Optional[str]1048 ):1049 assert res.status_code == 2001050 res_json: json = res.json()1051 assert res_json["Name"] == secret_name1052 if client_request_token:1053 assert res_json["VersionId"] == client_request_token1054 return res_json1055 def secretsmanager_http_put_secret_value_with_version(1056 self,1057 secret_id: str,1058 secret_string: str,1059 client_request_token: Optional[str],1060 version_stages: List[str],1061 ) -> requests.Response:1062 http_body: json = {1063 "SecretId": secret_id,1064 "SecretString": secret_string,1065 "ClientRequestToken": client_request_token,1066 "VersionStages": version_stages,1067 }1068 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)1069 @staticmethod1070 def secretsmanager_http_put_secret_value_with_version_val_res(1071 res: requests.Response,1072 secret_name: str,1073 client_request_token: Optional[str],1074 version_stages: List[str],1075 ) -> json:1076 req_version_id: str1077 if client_request_token is None:1078 assert res.status_code == 2001079 req_version_id = res.json()["VersionId"]1080 else:1081 req_version_id = client_request_token1082 res_json = TestSecretsManager.secretsmanager_http_put_secret_value_with_val_res(1083 res, secret_name, req_version_id1084 )1085 assert res_json["VersionStages"] == version_stages1086 return res_json1087 def test_http_update_secret_with_missing_client_request_token(self):1088 secret_name = f"s-{short_uid()}"1089 # Create v0.1090 secret_string_v0: str = "secret_string_v0"1091 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(1092 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),1093 secret_name,1094 )1095 version_id_v0 = cr_v0_res_json["VersionId"]1096 # Update with client request token.1097 secret_string_v1: str = "secret_string_v1"1098 version_id_v1: str = str(uuid.uuid4())1099 self.secretsmanager_http_update_secret_val_res(1100 self.secretsmanager_http_update_secret(secret_name, secret_string_v1, version_id_v1),1101 secret_name,1102 version_id_v1,1103 )1104 # Get.1105 self.secretsmanager_http_get_secret_value_val_res(1106 self.secretsmanager_http_get_secret_value(secret_name),1107 secret_name,1108 secret_string_v1,1109 version_id_v1,1110 )1111 # Update without client request token.1112 secret_string_v2: str = "secret_string_v2"1113 res_update_json = self.secretsmanager_http_update_secret_val_res(1114 self.secretsmanager_http_update_secret(secret_name, secret_string_v2, None),1115 secret_name,1116 None,1117 )1118 version_id_v2 = res_update_json["VersionId"]1119 assert version_id_v2 != version_id_v11120 assert version_id_v2 != version_id_v01121 # Get.1122 self.secretsmanager_http_get_secret_value_val_res(1123 self.secretsmanager_http_get_secret_value(secret_name),1124 secret_name,1125 secret_string_v2,1126 version_id_v2,1127 )1128 def test_http_put_secret_value_with_new_custom_client_request_token(self):1129 secret_name = f"s-{short_uid()}"1130 # Create v0.1131 secret_string_v0: str = "MySecretString"1132 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(1133 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),1134 secret_name,1135 )1136 #1137 # Check v0 base consistency.1138 self.secretsmanager_http_get_secret_value_val_res(1139 self.secretsmanager_http_get_secret_value(secret_name),1140 secret_name,1141 secret_string_v0,1142 cr_v0_res_json["VersionId"],1143 )1144 # Update v0 with predefined ClientRequestToken.1145 secret_string_v1: str = "MyNewSecretString"1146 #1147 crt_v1: str = str(uuid.uuid4())1148 while crt_v1 == cr_v0_res_json["VersionId"]:1149 crt_v1 = str(uuid.uuid4())1150 #1151 self.secretsmanager_http_put_secret_value_val_res(1152 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, crt_v1),1153 secret_name,1154 )1155 #1156 # Check v1 base consistency.1157 self.secretsmanager_http_get_secret_value_val_res(1158 self.secretsmanager_http_get_secret_value(secret_name),1159 secret_name,1160 secret_string_v1,1161 crt_v1,1162 )1163 #1164 # Check versioning base consistency.1165 versions_v0_v1: json = [1166 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},1167 {"VersionId": crt_v1, "VersionStages": ["AWSCURRENT"]},1168 ]1169 self.secretsmanager_http_list_secret_version_ids_val_res(1170 self.secretsmanager_http_list_secret_version_ids(secret_name),1171 secret_name,1172 versions_v0_v1,1173 )1174 self.secretsmanager_http_delete_secret_val_res(1175 self.secretsmanager_http_delete_secret(secret_name), secret_name1176 )1177 def test_http_put_secret_value_with_duplicate_client_request_token(self):1178 secret_name = f"s-{short_uid()}"1179 # Create v0.1180 secret_string_v0: str = "MySecretString"1181 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(1182 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),1183 secret_name,1184 )1185 #1186 # Check v0 base consistency.1187 self.secretsmanager_http_get_secret_value_val_res(1188 self.secretsmanager_http_get_secret_value(secret_name),1189 secret_name,1190 secret_string_v0,1191 cr_v0_res_json["VersionId"],1192 )1193 # Update v0 with duplicate ClientRequestToken.1194 secret_string_v1: str = "MyNewSecretString"1195 #1196 crt_v1: str = cr_v0_res_json["VersionId"]1197 #1198 self.secretsmanager_http_put_secret_value_val_res(1199 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, crt_v1),1200 secret_name,1201 )1202 #1203 # Check v1 base consistency.1204 self.secretsmanager_http_get_secret_value_val_res(1205 self.secretsmanager_http_get_secret_value(secret_name),1206 secret_name,1207 secret_string_v1,1208 crt_v1,1209 )1210 #1211 # Check versioning base consistency.1212 versions_v0_v1: json = [{"VersionId": crt_v1, "VersionStages": ["AWSCURRENT"]}]1213 self.secretsmanager_http_list_secret_version_ids_val_res(1214 self.secretsmanager_http_list_secret_version_ids(secret_name),1215 secret_name,1216 versions_v0_v1,1217 )1218 self.secretsmanager_http_delete_secret_val_res(1219 self.secretsmanager_http_delete_secret(secret_name), secret_name1220 )1221 def test_http_put_secret_value_with_null_client_request_token(self):1222 secret_name = f"s-{short_uid()}"1223 # Create v0.1224 secret_string_v0: str = "MySecretString"1225 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(1226 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),1227 secret_name,1228 )1229 #1230 # Check v0 base consistency.1231 self.secretsmanager_http_get_secret_value_val_res(1232 self.secretsmanager_http_get_secret_value(secret_name),1233 secret_name,1234 secret_string_v0,1235 cr_v0_res_json["VersionId"],1236 )1237 # Update v0 with null ClientRequestToken.1238 secret_string_v1: str = "MyNewSecretString"1239 #1240 pv_v1_res_json = self.secretsmanager_http_put_secret_value_val_res(1241 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, None),1242 secret_name,1243 )1244 #1245 # Check v1 base consistency.1246 self.secretsmanager_http_get_secret_value_val_res(1247 self.secretsmanager_http_get_secret_value(secret_name),1248 secret_name,1249 secret_string_v1,1250 pv_v1_res_json["VersionId"],1251 )1252 #1253 # Check versioning base consistency.1254 versions_v0_v1: json = [1255 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},1256 {"VersionId": pv_v1_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},1257 ]1258 self.secretsmanager_http_list_secret_version_ids_val_res(1259 self.secretsmanager_http_list_secret_version_ids(secret_name),1260 secret_name,1261 versions_v0_v1,1262 )1263 self.secretsmanager_http_delete_secret_val_res(1264 self.secretsmanager_http_delete_secret(secret_name), secret_name1265 )1266 def test_http_put_secret_value_with_undefined_client_request_token(self):1267 secret_name = f"s-{short_uid()}"1268 # Create v0.1269 secret_string_v0: str = "MySecretString"1270 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(1271 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),1272 secret_name,1273 )1274 #1275 # Check v0 base consistency.1276 self.secretsmanager_http_get_secret_value_val_res(1277 self.secretsmanager_http_get_secret_value(secret_name),1278 secret_name,1279 secret_string_v0,1280 cr_v0_res_json["VersionId"],1281 )1282 # Update v0 with undefined ClientRequestToken.1283 secret_string_v1: str = "MyNewSecretString"1284 #1285 pv_v1_res_json = self.secretsmanager_http_put_secret_value_val_res(1286 self.secretsmanager_http_put_secret_value(secret_name, secret_string_v1), secret_name1287 )1288 #1289 # Check v1 base consistency.1290 self.secretsmanager_http_get_secret_value_val_res(1291 self.secretsmanager_http_get_secret_value(secret_name),1292 secret_name,1293 secret_string_v1,1294 pv_v1_res_json["VersionId"],1295 )1296 #1297 # Check versioning base consistency.1298 versions_v0_v1: json = [1299 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},1300 {"VersionId": pv_v1_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},1301 ]1302 self.secretsmanager_http_list_secret_version_ids_val_res(1303 self.secretsmanager_http_list_secret_version_ids(secret_name),1304 secret_name,1305 versions_v0_v1,1306 )1307 self.secretsmanager_http_delete_secret_val_res(1308 self.secretsmanager_http_delete_secret(secret_name), secret_name1309 )1310 def test_http_put_secret_value_duplicate_req(self):1311 secret_name = f"s-{short_uid()}"1312 # Create v0.1313 secret_string_v0: str = "MySecretString"1314 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(1315 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),1316 secret_name,1317 )1318 #1319 # Check v0 base consistency.1320 self.secretsmanager_http_get_secret_value_val_res(1321 self.secretsmanager_http_get_secret_value(secret_name),1322 secret_name,1323 secret_string_v0,1324 cr_v0_res_json["VersionId"],1325 )1326 # Duplicate update.1327 self.secretsmanager_http_put_secret_value_val_res(1328 self.secretsmanager_http_put_secret_value_with(1329 secret_name, secret_string_v0, cr_v0_res_json["VersionId"]1330 ),1331 secret_name,1332 )1333 #1334 # Check v1 base consistency.1335 self.secretsmanager_http_get_secret_value_val_res(1336 self.secretsmanager_http_get_secret_value(secret_name),1337 secret_name,1338 secret_string_v0,1339 cr_v0_res_json["VersionId"],1340 )1341 #1342 # Check versioning base consistency.1343 versions_v0_v1: json = [1344 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},1345 ]1346 self.secretsmanager_http_list_secret_version_ids_val_res(1347 self.secretsmanager_http_list_secret_version_ids(secret_name),1348 secret_name,1349 versions_v0_v1,1350 )1351 self.secretsmanager_http_delete_secret_val_res(1352 self.secretsmanager_http_delete_secret(secret_name), secret_name1353 )1354 def test_http_put_secret_value_null_client_request_token_new_version_stages(self):1355 secret_name = f"s-{short_uid()}"1356 # Create v0.1357 secret_string_v0: str = "MySecretString"1358 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(1359 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),1360 secret_name,1361 )1362 #1363 # Check v0 base consistency.1364 self.secretsmanager_http_get_secret_value_val_res(1365 self.secretsmanager_http_get_secret_value(secret_name),1366 secret_name,1367 secret_string_v0,1368 cr_v0_res_json["VersionId"],1369 )1370 # Update v0 with null ClientRequestToken.1371 secret_string_v1: str = "MyNewSecretString"1372 version_stages_v1: List[str] = ["AWSPENDING"]1373 #1374 pv_v1_res_json = self.secretsmanager_http_put_secret_value_with_version_val_res(1375 self.secretsmanager_http_put_secret_value_with_version(1376 secret_name, secret_string_v1, None, version_stages_v11377 ),1378 secret_name,1379 None,1380 version_stages_v1,1381 )1382 #1383 assert pv_v1_res_json["VersionId"] != cr_v0_res_json["VersionId"]1384 #1385 # Check v1 base consistency.1386 self.secretsmanager_http_get_secret_value_with_val_res(1387 self.secretsmanager_http_get_secret_value_with(secret_name, "AWSPENDING"),1388 secret_name,1389 secret_string_v1,1390 pv_v1_res_json["VersionId"],1391 "AWSPENDING",1392 )1393 #1394 # Check v0 base consistency.1395 self.secretsmanager_http_get_secret_value_val_res(1396 self.secretsmanager_http_get_secret_value(secret_name),1397 secret_name,1398 secret_string_v0,1399 cr_v0_res_json["VersionId"],1400 )1401 #1402 # Check versioning base consistency.1403 versions_v0_v1: json = [1404 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},1405 {"VersionId": pv_v1_res_json["VersionId"], "VersionStages": ["AWSPENDING"]},1406 ]1407 self.secretsmanager_http_list_secret_version_ids_val_res(1408 self.secretsmanager_http_list_secret_version_ids(secret_name),1409 secret_name,1410 versions_v0_v1,1411 )1412 self.secretsmanager_http_delete_secret_val_res(1413 self.secretsmanager_http_delete_secret(secret_name), secret_name1414 )1415 def test_http_put_secret_value_custom_client_request_token_new_version_stages(self):1416 secret_name = f"s-{short_uid()}"1417 # Create v0.1418 secret_string_v0: str = "MySecretString"1419 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(1420 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),1421 secret_name,1422 )1423 #1424 # Check v0 base consistency.1425 self.secretsmanager_http_get_secret_value_val_res(1426 self.secretsmanager_http_get_secret_value(secret_name),1427 secret_name,1428 secret_string_v0,1429 cr_v0_res_json["VersionId"],1430 )1431 # Update v0 with null ClientRequestToken.1432 secret_string_v1: str = "MyNewSecretString"1433 version_stages_v1: List[str] = ["AWSPENDING"]1434 crt_v1: str = str(uuid.uuid4())1435 while crt_v1 == cr_v0_res_json["VersionId"]:1436 crt_v1 = str(uuid.uuid4())1437 #1438 self.secretsmanager_http_put_secret_value_with_version_val_res(1439 self.secretsmanager_http_put_secret_value_with_version(1440 secret_name, secret_string_v1, crt_v1, version_stages_v11441 ),1442 secret_name,1443 crt_v1,1444 version_stages_v1,1445 )1446 #1447 # Check v1 base consistency.1448 self.secretsmanager_http_get_secret_value_with_val_res(1449 self.secretsmanager_http_get_secret_value_with(secret_name, "AWSPENDING"),1450 secret_name,1451 secret_string_v1,1452 crt_v1,1453 "AWSPENDING",1454 )1455 #1456 # Check v0 base consistency.1457 self.secretsmanager_http_get_secret_value_val_res(1458 self.secretsmanager_http_get_secret_value(secret_name),1459 secret_name,1460 secret_string_v0,1461 cr_v0_res_json["VersionId"],1462 )1463 #1464 # Check versioning base consistency.1465 versions_v0_v1: json = [1466 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},1467 {"VersionId": crt_v1, "VersionStages": ["AWSPENDING"]},1468 ]1469 self.secretsmanager_http_list_secret_version_ids_val_res(1470 self.secretsmanager_http_list_secret_version_ids(secret_name),1471 secret_name,1472 versions_v0_v1,1473 )1474 self.secretsmanager_http_delete_secret_val_res(1475 self.secretsmanager_http_delete_secret(secret_name), secret_name...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!