Skip to content

Commit

Permalink
Service specific protocol tests (#3049)
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp authored Jun 19, 2024
1 parent f1b85a9 commit 24f1619
Show file tree
Hide file tree
Showing 13 changed files with 724 additions and 52 deletions.
4 changes: 1 addition & 3 deletions gems/aws-sdk-apigateway/spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Aws
module APIGateway
describe Client do

let(:client) { Client.new(stub_responses:true) }
let(:client) { Client.new(stub_responses: true) }

it 'supports maps for querystrings' do
resp = client.get_sdk({
Expand All @@ -21,9 +21,7 @@ module APIGateway
})

expect(resp.context.http_request.endpoint.to_s).to match(/\?abc=xyz&key=value&string=string$/)

end

end
end
end
30 changes: 30 additions & 0 deletions gems/aws-sdk-apigateway/spec/protocols_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require_relative 'spec_helper'

module Aws
module APIGateway
describe Client do

let(:client) { Client.new(stub_responses: true) }

# {
# id: "ApiGatewayAccept",
# documentation: "API Gateway requires that this Accept header is set on all requests.",
# protocol: restJson1,
# method: "GET",
# uri: "/restapis",
# headers: {
# "Accept": "application/json",
# },
# body: "",
# params: {},
# }
it 'ApiGatewayAccept' do
resp = client.get_rest_apis
request = resp.context.http_request
expect(request.headers['accept']).to eq('application/json')
end
end
end
end
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Fix trailing slash in endpoint URLs for rest-json and rest-xml services.

3.197.1 (2024-06-19)
------------------

Expand Down
4 changes: 3 additions & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/rest/request/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def uri(base_uri, params)
private

def apply_path_params(uri, params)
path = uri.path.sub(%r{/$}, '') + @path_pattern.split('?')[0]
path = uri.path.sub(%r{/$}, '')
# handle trailing slash
path += @path_pattern.split('?')[0] if path.empty? || @path_pattern != '/'
uri.path = path.gsub(/{.+?}/) do |placeholder|
param_value_for_placeholder(placeholder, params)
end
Expand Down
2 changes: 2 additions & 0 deletions gems/aws-sdk-glacier/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Require `account_id` to be non-empty and set it to the default.

1.62.0 (2024-06-05)
------------------

Expand Down
12 changes: 10 additions & 2 deletions gems/aws-sdk-glacier/lib/aws-sdk-glacier/plugins/account_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ class AccountId < Seahorse::Client::Plugin
your `:credentials` belong to.
DOCS

handle_request(step: :initialize) do |context|
context.params[:account_id] ||= context.config.account_id
class Handler < Seahorse::Client::Handler
def call(context)
context.params[:account_id] ||= context.config.account_id
if context.params[:account_id].empty?
context.params[:account_id] = '-'
end
@handler.call(context)
end
end

handler(Handler, step: :initialize)

end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ module Plugins
class ApiVersion < Seahorse::Client::Plugin

class Handler < Seahorse::Client::Handler

def call(context)
version = context.config.api.version
context.http_request.headers['x-amz-glacier-version'] = version
@handler.call(context)
end

end

handler(Handler)
Expand Down
12 changes: 0 additions & 12 deletions gems/aws-sdk-glacier/spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,8 @@ module Glacier
)
end

describe 'api verison' do

it 'sends the API version as a header' do
resp = client.list_vaults
expect(resp.context.http_request.headers['x-amz-glacier-version']).to eq('2012-06-01')
end

end

describe 'errors' do

it 'extracts the error code form the header' do
client.handle(step: :send) do |context|
context.http_response.signal_headers(409, {})
Expand All @@ -67,11 +58,9 @@ module Glacier
client.list_vaults(account_id: '12345')
}.to raise_error(Errors::AccessDeniedException)
end

end

describe ':account_id' do

it 'defaults to -' do
resp = client.list_vaults
expect(resp.context.http_request.endpoint.path).to eq('/-/vaults')
Expand All @@ -88,7 +77,6 @@ module Glacier
resp = client.list_vaults(account_id: 'xyz')
expect(resp.context.http_request.endpoint.path).to eq('/xyz/vaults')
end

end
end
end
Expand Down
137 changes: 137 additions & 0 deletions gems/aws-sdk-glacier/spec/protocols_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# frozen_string_literal: true

require_relative 'spec_helper'

module Aws
module Glacier
describe Client do

let(:client) { Client.new(stub_responses: true) }

describe '#upload_archive' do
# {
# id: "GlacierVersionHeader",
# documentation: "Glacier requires that a version header be set on all requests.",
# protocol: restJson1,
# method: "POST",
# uri: "/foo/vaults/bar/archives",
# headers: {
# "X-Amz-Glacier-Version": "2012-06-01",
# },
# body: "",
# params: {
# accountId: "foo",
# vaultName: "bar",
# },
# },
it 'GlacierVersionHeader' do
resp = client.upload_archive(
account_id: 'foo',
vault_name: 'bar'
)
request = resp.context.http_request
expect(request.headers['x-amz-glacier-version']).to eq('2012-06-01')
end

# {
# id: "GlacierChecksums",
# documentation: "Glacier requires checksum headers that are cumbersome to provide.",
# protocol: restJson1,
# method: "POST",
# uri: "/foo/vaults/bar/archives",
# headers: {
# "X-Amz-Glacier-Version": "2012-06-01",
# "X-Amz-Content-Sha256": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9",
# "X-Amz-Sha256-Tree-Hash": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9",
# },
# body: "hello world",
# params: {
# accountId: "foo",
# vaultName: "bar",
# body: "hello world"
# },
# appliesTo: "client",
# },
it 'GlacierChecksums' do
resp = client.upload_archive(
account_id: 'foo',
vault_name: 'bar',
body: 'hello world'
)
request = resp.context.http_request
expect(request.headers['x-amz-glacier-version']).to eq('2012-06-01')
expect(request.headers['x-amz-content-sha256'])
.to eq('b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9')
expect(request.headers['x-amz-sha256-tree-hash'])
.to eq('b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9')
end

# {
# id: "GlacierAccountId",
# documentation: """
# Glacier requires that the account id be set, but you can just use a
# hyphen (-) to indicate the current account. This should be default
# behavior if the customer provides a null or empty string.""",
# protocol: restJson1,
# method: "POST",
# uri: "/-/vaults/bar/archives",
# headers: {
# "X-Amz-Glacier-Version": "2012-06-01",
# },
# body: "",
# params: {
# accountId: "",
# vaultName: "bar",
# },
# appliesTo: "client",
# }
it 'GlacierAccountId' do
resp = client.upload_archive(
account_id: '',
vault_name: 'bar'
)
request = resp.context.http_request
expect(request.headers['x-amz-glacier-version']).to eq('2012-06-01')
expect(request.endpoint.path).to eq('/-/vaults/bar/archives')
end
end

describe '#upload_multipart_part' do
# {
# id: "GlacierMultipartChecksums",
# documentation: "Glacier requires checksum headers that are cumbersome to provide.",
# protocol: restJson1,
# method: "PUT",
# uri: "/foo/vaults/bar/multipart-uploads/baz",
# headers: {
# "X-Amz-Glacier-Version": "2012-06-01",
# "X-Amz-Content-Sha256": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9",
# "X-Amz-Sha256-Tree-Hash": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9",
# },
# body: "hello world",
# params: {
# accountId: "foo",
# vaultName: "bar",
# uploadId: "baz",
# body: "hello world"
# },
# appliesTo: "client",
# }
it 'GlacierMultipartChecksums' do
resp = client.upload_multipart_part(
account_id: 'foo',
vault_name: 'bar',
upload_id: 'baz',
body: 'hello world'
)
request = resp.context.http_request
expect(request.headers['x-amz-glacier-version']).to eq('2012-06-01')
expect(request.headers['x-amz-content-sha256'])
.to eq('b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9')
expect(request.headers['x-amz-sha256-tree-hash'])
.to eq('b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9')
end
end
end
end
end
31 changes: 0 additions & 31 deletions gems/aws-sdk-machinelearning/spec/client_spec.rb

This file was deleted.

50 changes: 50 additions & 0 deletions gems/aws-sdk-machinelearning/spec/protocols_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

require_relative 'spec_helper'

module Aws
module MachineLearning
describe Client do

let(:client) { Client.new(stub_responses: true) }

describe '#predict' do
# {
# id: "MachinelearningPredictEndpoint",
# documentation: """
# MachineLearning's api makes use of generated endpoints that the
# customer is then expected to use for the Predict operation. Having
# to alter the endpoint for a specific operation would be cumbersome,
# so an AWS client should be able to do it for them.""",
# protocol: awsJson1_1,
# method: "POST",
# uri: "/",
# host: "example.com",
# resolvedHost: "custom.example.com",
# body: "{\"MLModelId\": \"foo\", \"Record\": {}, \"PredictEndpoint\": \"https://custom.example.com/\"}",
# bodyMediaType: "application/json",
# headers: {"Content-Type": "application/x-amz-json-1.1"},
# params: {
# MLModelId: "foo",
# Record: {},
# PredictEndpoint: "https://custom.example.com/",
# }
# }
it 'MachinelearningPredictEndpoint' do
endpoint = 'https://custom.example.com/'
body = '{"MLModelId":"foo","Record":{},"PredictEndpoint":"https://custom.example.com/"}'
headers = { 'Content-Type' => 'application/x-amz-json-1.1' }
resp = client.predict(
ml_model_id: 'foo',
record: {},
predict_endpoint: endpoint
)
request = resp.context.http_request
expect(request.endpoint.to_s).to eq(endpoint)
expect(request.body_contents).to eq(body)
expect(request.headers['content-type']).to eq(headers['Content-Type'])
end
end
end
end
end
2 changes: 1 addition & 1 deletion gems/aws-sdk-s3/spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ module S3
it 'uses path style addressing for DNS incompatible bucket names' do
client = Client.new(stub_responses: true)
resp = client.head_bucket(bucket: 'Bucket123')
expect(resp.context.http_request.endpoint.path).to eq('/Bucket123/')
expect(resp.context.http_request.endpoint.path).to eq('/Bucket123')
end
end

Expand Down
Loading

0 comments on commit 24f1619

Please sign in to comment.