import canonicalization test from aws-c-auth
This commit is contained in:
parent
c7544b930b
commit
b753c4e441
|
@ -665,11 +665,6 @@ test "canonical headers" {
|
||||||
\\x-amz-date:20150830T123600Z
|
\\x-amz-date:20150830T123600Z
|
||||||
\\
|
\\
|
||||||
;
|
;
|
||||||
// {
|
|
||||||
// // TODO: Remove block
|
|
||||||
// std.testing.log_level = .debug;
|
|
||||||
// _ = try std.io.getStdErr().write("\n");
|
|
||||||
// }
|
|
||||||
const actual = try canonicalHeaders(allocator, headers.items);
|
const actual = try canonicalHeaders(allocator, headers.items);
|
||||||
defer allocator.free(actual.str);
|
defer allocator.free(actual.str);
|
||||||
defer allocator.free(actual.signed_headers);
|
defer allocator.free(actual.signed_headers);
|
||||||
|
@ -681,17 +676,14 @@ test "canonical request" {
|
||||||
const allocator = std.testing.allocator;
|
const allocator = std.testing.allocator;
|
||||||
var headers = try std.ArrayList(base.Header).initCapacity(allocator, 5);
|
var headers = try std.ArrayList(base.Header).initCapacity(allocator, 5);
|
||||||
defer headers.deinit();
|
defer headers.deinit();
|
||||||
try headers.append(.{ .name = "Content-Type", .value = "application/x-www-form-urlencoded" });
|
try headers.append(.{ .name = "User-agent", .value = "c sdk v1.0" });
|
||||||
try headers.append(.{ .name = "Content-Length", .value = "43" });
|
// In contrast to AWS CRT (aws-c-auth), we add the date as part of the
|
||||||
try headers.append(.{ .name = "User-Agent", .value = "zig-aws 1.0, Powered by the AWS Common Runtime." });
|
// signing operation. They add it as part of the canonicalization
|
||||||
try headers.append(.{ .name = "Host", .value = "sts.us-west-2.amazonaws.com" });
|
try headers.append(.{ .name = "X-Amz-Date", .value = "20150830T123600Z" });
|
||||||
try headers.append(.{ .name = "Accept", .value = "application/json" });
|
try headers.append(.{ .name = "Host", .value = "example.amazonaws.com" });
|
||||||
const req = base.Request{
|
const req = base.Request{
|
||||||
.path = "/",
|
.path = "/",
|
||||||
.query = "",
|
.method = "GET",
|
||||||
.body = "Action=GetCallerIdentity&Version=2011-06-15",
|
|
||||||
.method = "POST",
|
|
||||||
.content_type = "application/json",
|
|
||||||
.headers = headers.items,
|
.headers = headers.items,
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
|
@ -715,8 +707,18 @@ test "canonical request" {
|
||||||
defer allocator.free(request.headers.signed_headers);
|
defer allocator.free(request.headers.signed_headers);
|
||||||
log.debug("canonical request:\n{s}", .{request.arr});
|
log.debug("canonical request:\n{s}", .{request.arr});
|
||||||
log.debug("canonical request hash: {s}", .{request.hash});
|
log.debug("canonical request hash: {s}", .{request.hash});
|
||||||
try std.testing.expect(request.arr.len > 0); // TODO: improvify this
|
|
||||||
|
|
||||||
|
const expected =
|
||||||
|
\\GET
|
||||||
|
\\/
|
||||||
|
\\
|
||||||
|
\\host:example.amazonaws.com
|
||||||
|
\\x-amz-date:20150830T123600Z
|
||||||
|
\\
|
||||||
|
\\host;x-amz-date
|
||||||
|
\\e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
;
|
||||||
|
try std.testing.expectEqualStrings(expected, request.arr);
|
||||||
}
|
}
|
||||||
test "can sign" {
|
test "can sign" {
|
||||||
// [debug] (aws): call: prefix sts, sigv4 sts, version 2011-06-15, action GetCallerIdentity
|
// [debug] (aws): call: prefix sts, sigv4 sts, version 2011-06-15, action GetCallerIdentity
|
||||||
|
|
Loading…
Reference in New Issue
Block a user