---
cases:
  - note: providers-aws-sign_req/success-simple-no body
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "http://example.com"}

        aws_config := {
        	"aws_access_key": "MYAWSACCESSKEYGOESHERE",
        	"aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE",
        	"aws_service": "s3",
        	"aws_region": "us-east-1",
        }

        expected := {
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=0047a7016c81e5c7f29cd522f97e911e04fc472fced0aee7916cbc287ad6c8e3",
        		"host": "example.com",
        		"x-amz-content-sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"url": "http://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-with headers no body
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "http://example.com", "headers": {"foo": "bar"}}

        aws_config := {
        	"aws_access_key": "MYAWSACCESSKEYGOESHERE",
        	"aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE",
        	"aws_service": "s3",
        	"aws_region": "us-east-1",
        }

        expected := {
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=foo;host;x-amz-content-sha256;x-amz-date,Signature=8f1dc7c9b9978356a0d0989fd26a95307f4f8a4aa264d8220647b7097d839952",
        		"host": "example.com",
        		"x-amz-content-sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
        		"x-amz-date": "20151228T140825Z",
        		"foo": "bar",
        	},
        	"method": "get",
        	"url": "http://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-no body-with session token
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "http://example.com"}

        aws_config := {
        	"aws_access_key": "MYAWSACCESSKEYGOESHERE",
        	"aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE",
        	"aws_session_token": "MYAWSSECURITYTOKENGOESHERE",
        	"aws_service": "s3",
        	"aws_region": "us-east-1",
        }

        expected := {
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token,Signature=23c31bda8a74630c0a94f6b82a3511e7e74728df98e6f54ed0840488dbbdc8d1",
        		"host": "example.com",
        		"x-amz-content-sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
        		"x-amz-date": "20151228T140825Z",
        		"x-amz-security-token": "MYAWSSECURITYTOKENGOESHERE",
        	},
        	"method": "get",
        	"url": "http://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-body
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "http://example.com", "body": {"example": {1, 2, 3, 4}}}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1"}

        expected := {
        	"body": {"example": {1, 2, 3, 4}},
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=5fb06ab1cfd74c8fcb3af95b8cce696708cf6155d971dac10f254d79799c6e88",
        		"host": "example.com",
        		"x-amz-content-sha256": "bacff6243c850423883052ac3c336fd645994442933408dfd3f9e858e69bda07",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"url": "http://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-raw_body
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "http://example.com", "raw_body": "{\"example\": {1, 2, 3, 4}}"}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1"}

        expected := {
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=5bf26e169cb8b02330dba39d53932532438fc856c2f10537689a09ed807c7195",
        		"host": "example.com",
        		"x-amz-content-sha256": "22906461e2a98a3e780d0fd260e341bed5e544661e97c5936fc7f3af11aaad8b",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"raw_body": "{\"example\": {1, 2, 3, 4}}",
        	"url": "http://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-body-and-raw_body
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "http://example.com", "body": {"example": {1, 2, 3, 4}}, "raw_body": "{\"example\": {1, 2, 3, 4}}"}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1"}

        expected := {
        	"body": {"example": {1, 2, 3, 4}},
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=5bf26e169cb8b02330dba39d53932532438fc856c2f10537689a09ed807c7195",
        		"host": "example.com",
        		"x-amz-content-sha256": "22906461e2a98a3e780d0fd260e341bed5e544661e97c5936fc7f3af11aaad8b",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"raw_body": "{\"example\": {1, 2, 3, 4}}",
        	"url": "http://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-with-headers-no-body-with-payload-signing
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "https://example.com", "headers": {"foo": "bar"}}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1", "disable_payload_signing": false}

        expected := {
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=foo;host;x-amz-content-sha256;x-amz-date,Signature=8f1dc7c9b9978356a0d0989fd26a95307f4f8a4aa264d8220647b7097d839952",
        		"foo": "bar",
        		"host": "example.com",
        		"x-amz-content-sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"url": "https://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-with-headers-no-body-no-payload-signing
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "https://example.com", "headers": {"foo": "bar"}}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1", "disable_payload_signing": true}

        expected := {
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=foo;host;x-amz-content-sha256;x-amz-date,Signature=c6e6db654e92172f71e18c714c123711de069ac6fd7df1348e5b28fd05532028",
        		"foo": "bar",
        		"host": "example.com",
        		"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"url": "https://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-with-headers-with-body-with-payload-signing
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "https://example.com", "headers": {"foo": "bar"}, "body": {"example": {1, 2, 3, 4}}}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1", "disable_payload_signing": false}

        expected := {
        	"body": {"example": {1, 2, 3, 4}},
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=foo;host;x-amz-content-sha256;x-amz-date,Signature=f6703a8727ec0a32f81b225a002f622e511e8a7d2ca8914894fcbb7a71d8d9d8",
        		"foo": "bar",
        		"host": "example.com",
        		"x-amz-content-sha256": "bacff6243c850423883052ac3c336fd645994442933408dfd3f9e858e69bda07",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"url": "https://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-with-headers-with-body-no-payload-signing
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "https://example.com", "headers": {"foo": "bar"}, "body": {"example": {1, 2, 3, 4}}}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1", "disable_payload_signing": true}

        expected := {
        	"body": {"example": {1, 2, 3, 4}},
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=foo;host;x-amz-content-sha256;x-amz-date,Signature=c6e6db654e92172f71e18c714c123711de069ac6fd7df1348e5b28fd05532028",
        		"foo": "bar",
        		"host": "example.com",
        		"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"url": "https://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-with-existing-sha-header-with-body-with-payload-signing
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "https://example.com", "headers": {"foo": "bar", "x-amz-content-sha256": "existing-value"}, "body": {"example": {1, 2, 3, 4}}}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1", "disable_payload_signing": false}

        expected := {
        	"body": {"example": {1, 2, 3, 4}},
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=foo;host;x-amz-content-sha256;x-amz-date,Signature=42bcac7fc6d170e09be72fdf38b62e59361265bc59d5f9156f0d6faf889e98ba",
        		"foo": "bar",
        		"host": "example.com",
        		"x-amz-content-sha256": "bacff6243c850423883052ac3c336fd645994442933408dfd3f9e858e69bda07",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"url": "https://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
  - note: providers-aws-sign_req/success-simple-with-existing-sha-header-with-body-no-payload-signing
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": "get", "url": "https://example.com", "headers": {"foo": "bar", "x-amz-content-sha256": "existing-value"}, "body": {"example": {1, 2, 3, 4}}}

        aws_config := {"aws_access_key": "MYAWSACCESSKEYGOESHERE", "aws_secret_access_key": "MYAWSSECRETACCESSKEYGOESHERE", "aws_service": "s3", "aws_region": "us-east-1", "disable_payload_signing": true}

        expected := {
        	"body": {"example": {1, 2, 3, 4}},
        	"headers": {
        		"Authorization": "AWS4-HMAC-SHA256 Credential=MYAWSACCESSKEYGOESHERE/20151228/us-east-1/s3/aws4_request,SignedHeaders=foo;host;x-amz-content-sha256;x-amz-date,Signature=edcd3ca3fd3acdfbcecad1a1d8062dbc6562d90352e294c336f9727397f9c383",
        		"foo": "bar",
        		"host": "example.com",
        		"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
        		"x-amz-date": "20151228T140825Z",
        	},
        	"method": "get",
        	"url": "https://example.com",
        }

        p if {
        	providers.aws.sign_req(req, aws_config, 1451311705000000000) == expected
        }
    want_result:
      - x: true
