@@ -114,6 +114,40 @@ def s3_client(boto3_session: Session, localstack: URL) -> BaseClient:
114114def firehose_client (boto3_session : Session , localstack : URL ) -> BaseClient :
115115 return boto3_session .client ("firehose" , endpoint_url = str (localstack ))
116116
117+ @pytest .fixture (scope = "session" )
118+ def secretsmanager_client (boto3_session : Session , localstack : URL ) -> BaseClient :
119+ """
120+ Provides a boto3 Secrets Manager client bound to LocalStack.
121+ Seeds a test secret for use in integration tests.
122+ """
123+ client :BaseClient = boto3_session .client (
124+ service_name = "secretsmanager" ,
125+ endpoint_url = str (localstack ),
126+ region_name = "eu-west-1"
127+ )
128+
129+ secret_name = "test_secret"
130+ secret_value = "test_value_old"
131+
132+ try :
133+ client .create_secret (
134+ Name = secret_name ,
135+ SecretString = secret_value ,
136+ )
137+ except client .exceptions .ResourceExistsException :
138+ client .put_secret_value (
139+ SecretId = secret_name ,
140+ SecretString = secret_value ,
141+ )
142+
143+ secret_name = "test_secret"
144+ secret_value = "test_value"
145+
146+ client .put_secret_value (
147+ SecretId = secret_name ,
148+ SecretString = secret_value ,
149+ )
150+ return client
117151
118152@pytest .fixture (scope = "session" )
119153def iam_role (iam_client : BaseClient ) -> Generator [str ]:
@@ -209,6 +243,7 @@ def flask_function(lambda_client: BaseClient, iam_role: str, lambda_zip: Path) -
209243 "DYNAMODB_ENDPOINT" : os .getenv ("LOCALSTACK_INTERNAL_ENDPOINT" , "http://localstack:4566/" ),
210244 "S3_ENDPOINT" : os .getenv ("LOCALSTACK_INTERNAL_ENDPOINT" , "http://localstack:4566/" ),
211245 "FIREHOSE_ENDPOINT" : os .getenv ("LOCALSTACK_INTERNAL_ENDPOINT" , "http://localstack:4566/" ),
246+ "SECRET_MANAGER_ENDPOINT" : os .getenv ("LOCALSTACK_INTERNAL_ENDPOINT" , "http://localstack:4566/" ),
212247 "AWS_REGION" : AWS_REGION ,
213248 "LOG_LEVEL" : "DEBUG" ,
214249 }
0 commit comments