---
cases:
  - note: providers-aws-sign_req/failure-simple-missing http request keys
    query: data.test.p = x
    modules:
      - |
        package test

        req := {}

        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,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_error_code: eval_type_error
    want_error: 'providers.aws.sign_req: operand 1 missing required request parameters(s): {"method", "url"}'
    strict_error: true
  - note: providers-aws-sign_req/failure-simple-invalid type http request keys
    query: data.test.p = x
    modules:
      - |
        package test

        req := {"method": set(), "url": set()}

        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,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_error_code: eval_type_error
    want_error: 'providers.aws.sign_req: operand 1 invalid values for required request parameters(s): {"method", "url"}'
    strict_error: true
  - note: providers-aws-sign_req/failure-simple-missing aws keys
    query: data.test.p = x
    modules:
      - |
        package test

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

        aws_config := {"example": "example"}

        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_error_code: eval_type_error
    want_error: 'providers.aws.sign_req: operand 2 missing required AWS config parameters(s): {"aws_access_key", "aws_region", "aws_secret_access_key", "aws_service"}'
    strict_error: true
  - note: providers-aws-sign_req/failure-simple-invalid type aws keys
    query: data.test.p = x
    modules:
      - |
        package test

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

        aws_config := {
        	"aws_access_key": 1,
        	"aws_secret_access_key": 2,
        	"aws_session_token": 3,
        	"aws_service": 4,
        	"aws_region": 5,
        }

        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_error_code: eval_type_error
    want_error: 'providers.aws.sign_req: operand 2 invalid values for required AWS config parameters(s): {"aws_access_key", "aws_region", "aws_secret_access_key", "aws_service"}'
    strict_error: true
  - note: providers-aws-sign_req/failure-simple-bad timestamp
    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,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, -1e9) == expected
        }
    want_error_code: eval_type_error
    want_error: "providers.aws.sign_req: operand 3 could not convert time_ns value into a unix timestamp"
    strict_error: true
  - note: providers-aws-sign_req/failure-simple-bad-type-payload-signing-config
    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_error_code: eval_type_error
    want_error: "providers.aws.sign_req: operand 2 invalid value for 'disable_payload_signing' in AWS config"
    strict_error: true
