diff --git a/README.md b/README.md index bbcaaf7..f1313fd 100644 --- a/README.md +++ b/README.md @@ -69,15 +69,9 @@ WebIdentityToken is not yet implemented. TODO List: -* Implement all demos as tests in src/aws.zig. This has been done for - all AWS protocols except rest XML. Due to the similarity of EC2 Query - protocol and rest XML it is likely that things are fully functional (with - a proxy). * Json parsing is based on a fork of the 0.9.0 (maybe earlier?) json parser. - Upgrading to 0.11 caused some commenting of things that probably broke some - stuff. JSON parsing in general needs a re-visit. Note also that a json.zig - file is embedded/copied from the codegen project, so that also needs a second - look. + This needs a re-visit. Note also that a json.zig file is embedded/copied + from the codegen project, so that also needs a second look. * Take a look to see about compilation speed. With codegen caching this is reasonable, but still takes longer than needed. * Upgrade the model files. This is a simple tasks, but I'd like the first diff --git a/src/aws.zig b/src/aws.zig index 78cdd34..a719ad0 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -1845,3 +1845,98 @@ test "ec2_query_with_input: EC2 describe instances" { try std.testing.expectEqualStrings("i-0212d7d1f62b96676", call.response.reservations.?[1].instances.?[0].instance_id.?); try std.testing.expectEqualStrings("123456789012:found-me", call.response.reservations.?[1].instances.?[0].tags.?[0].value.?); } +test "rest_xml_no_input: S3 list buckets" { + const allocator = std.testing.allocator; + var test_harness = TestSetup.init(allocator, .{ + .allocator = allocator, + .server_response = + \\3367189aa775bd98da38e55093705f2051443c1e775fc0971d6d77387a47c8d0emilerch+sub1550620852718-backup2020-06-17T16:26:51.000Zamplify-letmework-staging-185741-deployment2023-03-10T18:57:49.000Zaws-cloudtrail-logs-550620852718-224022a72021-06-21T18:32:44.000Zaws-sam-cli-managed-default-samclisourcebucket-1gy0z00mj47xe2021-10-05T16:38:07.000Zawsomeprojectstack-pipelineartifactsbucketaea9a05-1uzwo6c86ecr2021-10-05T22:55:09.000Zcdk-hnb659fds-assets-550620852718-us-west-22023-02-28T21:49:36.000Zcf-templates-12iy6putgdxtk-us-west-22020-06-26T02:31:59.000Zcodepipeline-us-west-2-467140836372021-09-14T18:43:07.000Zelasticbeanstalk-us-west-2-5506208527182022-04-15T16:22:42.000Zlobo-west2021-06-21T17:17:22.000Zlobo-west-22021-11-19T20:12:31.000Zlogging-backup-550620852718-us-east-22022-05-29T21:55:16.000Zmysfitszj3t6webstack-hostingbucketa91a61fe-1ep3ezkgwpxr02023-03-01T04:53:55.000Z + , + .server_response_headers = @constCast(&[_][2][]const u8{ + .{ "Content-Type", "application/xml" }, + .{ "x-amzn-RequestId", "9PEYBAZ9J7TPRX43" }, + }), + }); + defer test_harness.deinit(); + const options = try test_harness.start(); + const s3 = (Services(.{.s3}){}).s3; + const call = try test_harness.client.call(s3.list_buckets.Request{}, options); + defer call.deinit(); + test_harness.stop(); + // Request expectations + try std.testing.expectEqual(std.http.Method.GET, test_harness.request_options.request_method); + try std.testing.expectEqualStrings("/", test_harness.request_options.request_target); + try std.testing.expectEqualStrings("", test_harness.request_options.request_body); + // Response expectations + try std.testing.expectEqualStrings("9PEYBAZ9J7TPRX43", call.response_metadata.request_id); + try std.testing.expectEqual(@as(usize, 13), call.response.buckets.?.len); +} +test "rest_xml_anything_but_s3: CloudFront list key groups" { + const allocator = std.testing.allocator; + var test_harness = TestSetup.init(allocator, .{ + .allocator = allocator, + .server_response = + \\{"Items":null,"MaxItems":100,"NextMarker":null,"Quantity":0} + , + .server_response_headers = @constCast(&[_][2][]const u8{ + .{ "Content-Type", "application/json" }, + .{ "x-amzn-RequestId", "d3382082-5291-47a9-876b-8df3accbb7ea" }, + }), + }); + defer test_harness.deinit(); + const options = try test_harness.start(); + const cloudfront = (Services(.{.cloudfront}){}).cloudfront; + const call = try test_harness.client.call(cloudfront.list_key_groups.Request{}, options); + defer call.deinit(); + test_harness.stop(); + // Request expectations + try std.testing.expectEqual(std.http.Method.GET, test_harness.request_options.request_method); + try std.testing.expectEqualStrings("/2020-05-31/key-group", test_harness.request_options.request_target); + try std.testing.expectEqualStrings("", test_harness.request_options.request_body); + // Response expectations + try std.testing.expectEqualStrings("d3382082-5291-47a9-876b-8df3accbb7ea", call.response_metadata.request_id); + try std.testing.expectEqual(@as(i64, 100), call.response.key_group_list.?.max_items); +} +test "rest_xml_with_input: S3 put object" { + const allocator = std.testing.allocator; + var test_harness = TestSetup.init(allocator, .{ + .allocator = allocator, + .server_response = "", + .server_response_headers = @constCast(&[_][2][]const u8{ + // .{ "Content-Type", "application/xml" }, + .{ "x-amzn-RequestId", "9PEYBAZ9J7TPRX43" }, + .{ "x-amz-id-2", "jdRDo30t7Ge9lf6F+4WYpg+YKui8z0mz2+rwinL38xDZzvloJqrmpCAiKG375OSvHA9OBykJS44=" }, + .{ "x-amz-server-side-encryption", "AES256" }, + .{ "ETag", "37b51d194a7513e45b56f6524f2d51f2" }, + }), + }); + defer test_harness.deinit(); + const options = try test_harness.start(); + const s3opts = Options{ + .region = "us-west-2", + .client = options.client, + }; + const result = try Request(services.s3.put_object).call(.{ + .bucket = "mysfitszj3t6webstack-hostingbucketa91a61fe-1ep3ezkgwpxr0", + .key = "i/am/a/teapot/foo", + .content_type = "text/plain", + .body = "bar", + .storage_class = "STANDARD", + }, s3opts); + std.log.info("PutObject Request id: {any}", .{result.response_metadata.request_id}); + std.log.info("PutObject etag: {any}", .{result.response.e_tag.?}); + //mysfitszj3t6webstack-hostingbucketa91a61fe-1ep3ezkgwpxr0.s3.us-west-2.amazonaws.com + defer result.deinit(); + test_harness.stop(); + // Request expectations + try std.testing.expectEqual(std.http.Method.PUT, test_harness.request_options.request_method); + // I don't think this will work since we're overriding the url + // try test_harness.request_options.expectHeader("Host", "mysfitszj3t6webstack-hostingbucketa91a61fe-1ep3ezkgwpxr0.s3.us-west-2.amazonaws.com"); + try test_harness.request_options.expectHeader("x-amz-storage-class", "STANDARD"); + try std.testing.expectEqualStrings("/mysfitszj3t6webstack-hostingbucketa91a61fe-1ep3ezkgwpxr0/i/am/a/teapot/foo?x-id=PutObject", test_harness.request_options.request_target); + try std.testing.expectEqualStrings("bar", test_harness.request_options.request_body); + // Response expectations + try std.testing.expectEqualStrings("9PEYBAZ9J7TPRX43, host_id: jdRDo30t7Ge9lf6F+4WYpg+YKui8z0mz2+rwinL38xDZzvloJqrmpCAiKG375OSvHA9OBykJS44=", result.response_metadata.request_id); + try std.testing.expectEqualStrings("AES256", result.response.server_side_encryption.?); + try std.testing.expectEqualStrings("37b51d194a7513e45b56f6524f2d51f2", result.response.e_tag.?); +}