diff --git a/.github/workflows/tests_sdk_dotnet.yml b/.github/workflows/tests_sdk_dotnet.yml index b82fe65d1..4bf92e76f 100644 --- a/.github/workflows/tests_sdk_dotnet.yml +++ b/.github/workflows/tests_sdk_dotnet.yml @@ -28,8 +28,8 @@ jobs: restore-keys: | ${{ runner.os }}-nuget - name: Install dependencies - run: cd other_langs/tests_dotnet && dotnet restore ExampleTestProject/ + run: cd other_langs/tests_dotnet && dotnet restore ExampleTestProject/ && dotnet restore ebs - name: Run tests run: | mkdir ~/.aws && touch ~/.aws/credentials && echo -e "[default]\naws_access_key_id = test\naws_secret_access_key = test" > ~/.aws/credentials - cd other_langs/tests_dotnet && dotnet test ExampleTestProject/ + cd other_langs/tests_dotnet && dotnet test ExampleTestProject/ && dotnet restore ebs diff --git a/moto/ebs/responses.py b/moto/ebs/responses.py index 75d1549f9..0e9b2ad99 100644 --- a/moto/ebs/responses.py +++ b/moto/ebs/responses.py @@ -24,7 +24,7 @@ class EBSResponse(BaseResponse): return self.start_snapshot() def snapshot_block(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return] - self.setup_class(request, full_url, headers) + self.setup_class(request, full_url, headers, use_raw_body=True) if request.method == "PUT": return self.put_snapshot_block(full_url, headers) if request.method == "GET": @@ -59,7 +59,7 @@ class EBSResponse(BaseResponse): self.setup_class(request, full_url, headers) snapshot_id = full_url.split("/")[-1] status = self.ebs_backend.complete_snapshot(snapshot_id=snapshot_id) - return 200, {}, json.dumps(status) + return 202, {}, json.dumps(status) def put_snapshot_block(self, full_url: str, headers: Any) -> TYPE_RESPONSE: """ @@ -82,7 +82,7 @@ class EBSResponse(BaseResponse): data_length=data_length, ) return ( - 200, + 201, { "x-amz-Checksum": checksum, "x-amz-Checksum-Algorithm": checksum_algorithm, diff --git a/other_langs/tests_dotnet/ebs/ElasticBlockStore.csproj b/other_langs/tests_dotnet/ebs/ElasticBlockStore.csproj new file mode 100644 index 000000000..a58828d3f --- /dev/null +++ b/other_langs/tests_dotnet/ebs/ElasticBlockStore.csproj @@ -0,0 +1,26 @@ + + + + net7.0 + enable + enable + + true + true + + 45a910a7-aba2-43ee-ad3c-ccad57f044d9 + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/other_langs/tests_dotnet/ebs/UnitTest.cs b/other_langs/tests_dotnet/ebs/UnitTest.cs new file mode 100644 index 000000000..50d8ce402 --- /dev/null +++ b/other_langs/tests_dotnet/ebs/UnitTest.cs @@ -0,0 +1,56 @@ +using FluentAssertions; + +// To interact with Amazon EBS +using Amazon.EBS; +using Amazon.EBS.Model; + +using System.Security.Cryptography; + + +public class EbsSnashotTest +{ + [Fact] + public async Task TestSnapshotCreation() + { + + AmazonEBSConfig config = new AmazonEBSConfig() + { + ServiceURL = "http://localhost:5000", + }; + + AmazonEBSClient ebsClient = new AmazonEBSClient(config); + + // https://docs.aws.amazon.com/ebs/latest/APIReference/API_StartSnapshot.html + var startSnapshotRequest = new StartSnapshotRequest { VolumeSize = 1 }; + var startSnapshotResponse = await ebsClient.StartSnapshotAsync(startSnapshotRequest); + startSnapshotResponse.Status.Should().Be("pending"); + + // https://docs.aws.amazon.com/ebs/latest/APIReference/API_PutSnapshotBlock.html + var blockData = new byte[] { 0x01, 0x02, 0x03, 0x04 }; + Stream blockDataStream = new MemoryStream(blockData); + SHA256Managed sha256hasher = new SHA256Managed(); + byte[] sha256Hash = sha256hasher.ComputeHash(blockDataStream); + var sha256checksum = Convert.ToBase64String(sha256Hash); + var putSnapshotBlockRequest = new PutSnapshotBlockRequest + { + BlockIndex = 0, + Checksum = sha256checksum, + ChecksumAlgorithm = "SHA256", + DataLength = blockData.Length, + SnapshotId = startSnapshotResponse.SnapshotId, + BlockData = blockDataStream + }; + var putSnapshotBlockResponse = await ebsClient.PutSnapshotBlockAsync(putSnapshotBlockRequest); + putSnapshotBlockResponse.Checksum.Should().Be(sha256checksum); + putSnapshotBlockResponse.ChecksumAlgorithm.Should().Be("SHA256"); + + https://docs.aws.amazon.com/ebs/latest/APIReference/API_CompleteSnapshot.html + var completeSnapshotRequest = new CompleteSnapshotRequest + { + ChangedBlocksCount = 1, + SnapshotId = startSnapshotResponse.SnapshotId + }; + var completeSnapshotResponse = await ebsClient.CompleteSnapshotAsync(completeSnapshotRequest); + completeSnapshotResponse.Status.Should().Be("completed"); + } +} diff --git a/other_langs/tests_dotnet/ebs/Usings.cs b/other_langs/tests_dotnet/ebs/Usings.cs new file mode 100644 index 000000000..8c927eb74 --- /dev/null +++ b/other_langs/tests_dotnet/ebs/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/tests/test_ebs/test_ebs.py b/tests/test_ebs/test_ebs.py index 561811a77..06cc49dfc 100644 --- a/tests/test_ebs/test_ebs.py +++ b/tests/test_ebs/test_ebs.py @@ -51,7 +51,7 @@ def test_complete_snapshot(): @mock_ebs def test_put_snapshot_block(): - data = b"data for this specific block" + data = b"data for this specific block\xbf" checksum = hashlib.sha256(data).hexdigest() client = boto3.client("ebs", region_name="eu-west-1") snapshot_id = client.start_snapshot(VolumeSize=720)["SnapshotId"]