AWSLambda: publish_layer_version() should always set the code_sha_256 attr (#6920)
This commit is contained in:
		
							parent
							
								
									2021e564fa
								
							
						
					
					
						commit
						1f51c2f766
					
				| @ -371,6 +371,11 @@ class LayerVersion(CloudFormationModel): | |||||||
|                     self.code_sha_256, |                     self.code_sha_256, | ||||||
|                     self.code_digest, |                     self.code_digest, | ||||||
|                 ) = _s3_content(key) |                 ) = _s3_content(key) | ||||||
|  |             else: | ||||||
|  |                 self.code_bytes = b"" | ||||||
|  |                 self.code_size = 0 | ||||||
|  |                 self.code_sha_256 = "" | ||||||
|  |                 self.code_digest = "" | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def arn(self) -> str: |     def arn(self) -> str: | ||||||
|  | |||||||
| @ -1,10 +1,12 @@ | |||||||
| import boto3 | import boto3 | ||||||
|  | import os | ||||||
| import pytest | import pytest | ||||||
| 
 | 
 | ||||||
| from botocore.exceptions import ClientError | from botocore.exceptions import ClientError | ||||||
| from freezegun import freeze_time | from freezegun import freeze_time | ||||||
| from moto import mock_lambda, mock_s3 | from moto import mock_lambda, mock_s3, settings | ||||||
| from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID | from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID | ||||||
|  | from unittest import mock, SkipTest | ||||||
| from uuid import uuid4 | from uuid import uuid4 | ||||||
| 
 | 
 | ||||||
| from .utilities import get_role_name, get_test_zip_file1 | from .utilities import get_role_name, get_test_zip_file1 | ||||||
| @ -31,6 +33,20 @@ def test_publish_lambda_layers__without_content(): | |||||||
|     assert err["Message"] == "Missing Content" |     assert err["Message"] == "Missing Content" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @mock_lambda | ||||||
|  | @mock.patch.dict(os.environ, {"VALIDATE_LAMBDA_S3": "false"}) | ||||||
|  | def test_publish_layer_with_unknown_s3_file(): | ||||||
|  |     if not settings.TEST_DECORATOR_MODE: | ||||||
|  |         raise SkipTest("Can only set env var in DecoratorMode") | ||||||
|  |     conn = boto3.client("lambda", _lambda_region) | ||||||
|  |     content = conn.publish_layer_version( | ||||||
|  |         LayerName=str(uuid4())[0:6], | ||||||
|  |         Content=dict(S3Bucket="my-bucket", S3Key="my-key.zip"), | ||||||
|  |     )["Content"] | ||||||
|  |     assert content["CodeSha256"] == "" | ||||||
|  |     assert content["CodeSize"] == 0 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| @mock_lambda | @mock_lambda | ||||||
| @mock_s3 | @mock_s3 | ||||||
| @freeze_time("2015-01-01 00:00:00") | @freeze_time("2015-01-01 00:00:00") | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user