From 069a6b2917ef2950f5bf2daa3c5a4d6d3f4d2ea8 Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 14 Jul 2016 18:22:01 +0800 Subject: [PATCH] fix defeault rspec test for ruby, update security petstore --- .../resources/ruby/api_client_spec.mustache | 94 ++-------------- .../ruby/configuration_spec.mustache | 17 +-- .../petstore-security-test/ruby/README.md | 26 ++--- .../ruby/docs/FakeApi.md | 24 ++--- .../ruby/docs/ModelReturn.md | 2 +- .../ruby/lib/petstore.rb | 8 +- .../ruby/lib/petstore/api/fake_api.rb | 32 +++--- .../ruby/lib/petstore/api_client.rb | 15 ++- .../ruby/lib/petstore/api_error.rb | 8 +- .../ruby/lib/petstore/configuration.rb | 41 ++++--- .../ruby/lib/petstore/models/model_return.rb | 12 +-- .../ruby/lib/petstore/version.rb | 8 +- .../ruby/petstore.gemspec | 16 +-- .../ruby/spec/api/fake_api_spec.rb | 16 +-- .../ruby/spec/api_client_spec.rb | 102 +++--------------- .../ruby/spec/configuration_spec.rb | 25 +++-- .../ruby/spec/models/model_return_spec.rb | 8 +- .../ruby/spec/spec_helper.rb | 8 +- 18 files changed, 167 insertions(+), 295 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache b/modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache index fa6b3530d73..df32f34490f 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache @@ -43,53 +43,6 @@ describe {{moduleName}}::ApiClient do end end - describe "#update_params_for_auth!" do - it "sets header api-key parameter with prefix" do - {{moduleName}}.configure do |c| - c.api_key_prefix['api_key'] = 'PREFIX' - c.api_key['api_key'] = 'special-key' - end - - api_client = {{moduleName}}::ApiClient.new - - config2 = {{moduleName}}::Configuration.new do |c| - c.api_key_prefix['api_key'] = 'PREFIX2' - c.api_key['api_key'] = 'special-key2' - end - api_client2 = {{moduleName}}::ApiClient.new(config2) - - auth_names = ['api_key', 'unknown'] - - header_params = {} - query_params = {} - api_client.update_params_for_auth! header_params, query_params, auth_names - expect(header_params).to eq({'api_key' => 'PREFIX special-key'}) - expect(query_params).to eq({}) - - header_params = {} - query_params = {} - api_client2.update_params_for_auth! header_params, query_params, auth_names - expect(header_params).to eq({'api_key' => 'PREFIX2 special-key2'}) - expect(query_params).to eq({}) - end - - it "sets header api-key parameter without prefix" do - {{moduleName}}.configure do |c| - c.api_key_prefix['api_key'] = nil - c.api_key['api_key'] = 'special-key' - end - - api_client = {{moduleName}}::ApiClient.new - - header_params = {} - query_params = {} - auth_names = ['api_key', 'unknown'] - api_client.update_params_for_auth! header_params, query_params, auth_names - expect(header_params).to eq({'api_key' => 'special-key'}) - expect(query_params).to eq({}) - end - end - describe "params_encoding in #build_request" do let(:config) { {{moduleName}}::Configuration.new } let(:api_client) { {{moduleName}}::ApiClient.new(config) } @@ -155,49 +108,18 @@ describe {{moduleName}}::ApiClient do expect(data).to be_instance_of(Hash) expect(data).to eq({:message => 'Hello'}) end - - it "handles Hash" do - api_client = {{moduleName}}::ApiClient.new - headers = {'Content-Type' => 'application/json'} - response = double('response', headers: headers, body: '{"pet": {"id": 1}}') - data = api_client.deserialize(response, 'Hash') - expect(data).to be_instance_of(Hash) - expect(data.keys).to eq([:pet]) - - pet = data[:pet] - expect(pet).to be_instance_of({{moduleName}}::Pet) - expect(pet.id).to eq(1) - end - - it "handles Hash>" do - api_client = {{moduleName}}::ApiClient.new - headers = {'Content-Type' => 'application/json'} - response = double('response', headers: headers, body: '{"data": {"pet": {"id": 1}}}') - result = api_client.deserialize(response, 'Hash>') - expect(result).to be_instance_of(Hash) - expect(result.keys).to match_array([:data]) - - data = result[:data] - expect(data).to be_instance_of(Hash) - expect(data.keys).to match_array([:pet]) - - pet = data[:pet] - expect(pet).to be_instance_of({{moduleName}}::Pet) - expect(pet.id).to eq(1) - end end describe "#object_to_hash" do it "ignores nils and includes empty arrays" do - api_client = {{moduleName}}::ApiClient.new - pet = {{moduleName}}::Pet.new - pet.id = 1 - pet.name = '' - pet.status = nil - pet.photo_urls = nil - pet.tags = [] - expected = {id: 1, name: '', tags: []} - expect(api_client.object_to_hash(pet)).to eq(expected) + # uncomment below to test object_to_hash for model + #api_client = {{moduleName}}::ApiClient.new + #_model = {{moduleName}}::ModelName.new + # update the model attribute below + #_model.id = 1 + # update the expected value (hash) below + #expected = {id: 1, name: '', tags: []} + #expect(api_client.object_to_hash(_model)).to eq(expected) end end diff --git a/modules/swagger-codegen/src/main/resources/ruby/configuration_spec.mustache b/modules/swagger-codegen/src/main/resources/ruby/configuration_spec.mustache index 6ea22543491..2955eaa2503 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/configuration_spec.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/configuration_spec.mustache @@ -8,21 +8,26 @@ describe {{moduleName}}::Configuration do let(:config) { {{moduleName}}::Configuration.default } before(:each) do - {{moduleName}}.configure do |c| - c.host = 'petstore.swagger.io' - c.base_path = 'v2' - end + # uncomment below to setup host and base_path + #require 'URI' + #uri = URI.parse("{{{basePath}}}") + #{{moduleName}}.configure do |c| + # c.host = uri.host + # c.base_path = uri.path + #end end describe '#base_url' do it 'should have the default value' do - expect(config.base_url).to eq('http://petstore.swagger.io/v2') + # uncomment below to test default value of the base path + #expect(config.base_url).to eq("{{{basePath}}}") end it 'should remove trailing slashes' do [nil, '', '/', '//'].each do |base_path| config.base_path = base_path - expect(config.base_url).to eq('http://petstore.swagger.io') + # uncomment below to test trailing slashes + #expect(config.base_url).to eq("{{{basePath}}}") end end end diff --git a/samples/client/petstore-security-test/ruby/README.md b/samples/client/petstore-security-test/ruby/README.md index cffafe4e93c..905a00d2242 100644 --- a/samples/client/petstore-security-test/ruby/README.md +++ b/samples/client/petstore-security-test/ruby/README.md @@ -1,14 +1,14 @@ # petstore -Petstore - the Ruby gem for the Swagger Petstore */ ' \" +Petstore - the Ruby gem for the Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: -- API version: 1.0.0 */ ' \" +- API version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r - Package version: 1.0.0 -- Build date: 2016-06-28T17:34:19.923+08:00 +- Build date: 2016-07-14T18:21:54.437+08:00 - Build package: class io.swagger.codegen.languages.RubyClientCodegen ## Installation @@ -58,25 +58,25 @@ require 'petstore' api_instance = Petstore::FakeApi.new opts = { - test_code_inject____end: "test_code_inject____end_example" # String | To test code injection */ ' \" + test_code_inject____end____rn_n_r: "test_code_inject____end____rn_n_r_example" # String | To test code injection */ ' \" =_end -- \\r\\n \\n \\r } begin - #To test code injection */ ' \" - api_instance.test_code_inject____end(opts) + #To test code injection */ ' \" =_end -- \\r\\n \\n \\r + api_instance.test_code_inject____end__rn_n_r(opts) rescue Petstore::ApiError => e - puts "Exception when calling FakeApi->test_code_inject____end: #{e}" + puts "Exception when calling FakeApi->test_code_inject____end__rn_n_r: #{e}" end ``` ## Documentation for API Endpoints -All URIs are relative to *https://petstore.swagger.io */ ' " =end/v2 */ ' " =end* +All URIs are relative to *https://petstore.swagger.io */ ' \" =_end -- \\r\\n \\n \\r/v2 */ ' \" =_end -- \\r\\n \\n \\r* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*Petstore::FakeApi* | [**test_code_inject____end**](docs/FakeApi.md#test_code_inject____end) | **PUT** /fake | To test code injection */ ' \" +*Petstore::FakeApi* | [**test_code_inject____end__rn_n_r**](docs/FakeApi.md#test_code_inject____end__rn_n_r) | **PUT** /fake | To test code injection */ ' \" =_end -- \\r\\n \\n \\r ## Documentation for Models @@ -90,7 +90,7 @@ Class | Method | HTTP request | Description ### api_key - **Type**: API key -- **API key parameter name**: api_key */ ' " =end +- **API key parameter name**: api_key */ ' " =end -- \r\n \n \r - **Location**: HTTP header ### petstore_auth @@ -99,6 +99,6 @@ Class | Method | HTTP request | Description - **Flow**: implicit - **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog - **Scopes**: - - write:pets: modify pets in your account */ ' " =end - - read:pets: read your pets */ ' " =end + - write:pets: modify pets in your account */ ' " =end -- \r\n \n \r + - read:pets: read your pets */ ' " =end -- \r\n \n \r diff --git a/samples/client/petstore-security-test/ruby/docs/FakeApi.md b/samples/client/petstore-security-test/ruby/docs/FakeApi.md index 5e50ff46976..43e3d617072 100644 --- a/samples/client/petstore-security-test/ruby/docs/FakeApi.md +++ b/samples/client/petstore-security-test/ruby/docs/FakeApi.md @@ -1,16 +1,16 @@ # Petstore::FakeApi -All URIs are relative to *https://petstore.swagger.io */ ' " =end/v2 */ ' " =end* +All URIs are relative to *https://petstore.swagger.io */ ' \" =_end -- \\r\\n \\n \\r/v2 */ ' \" =_end -- \\r\\n \\n \\r* Method | HTTP request | Description ------------- | ------------- | ------------- -[**test_code_inject____end**](FakeApi.md#test_code_inject____end) | **PUT** /fake | To test code injection */ ' \" +[**test_code_inject____end__rn_n_r**](FakeApi.md#test_code_inject____end__rn_n_r) | **PUT** /fake | To test code injection */ ' \" =_end -- \\r\\n \\n \\r -# **test_code_inject____end** -> test_code_inject____end(opts) +# **test_code_inject____end__rn_n_r** +> test_code_inject____end__rn_n_r(opts) -To test code injection */ ' \" +To test code injection */ ' \" =_end -- \\r\\n \\n \\r ### Example ```ruby @@ -20,14 +20,14 @@ require 'petstore' api_instance = Petstore::FakeApi.new opts = { - test_code_inject____end: "test_code_inject____end_example" # String | To test code injection */ ' \" + test_code_inject____end____rn_n_r: "test_code_inject____end____rn_n_r_example" # String | To test code injection */ ' \" =_end -- \\r\\n \\n \\r } begin - #To test code injection */ ' \" - api_instance.test_code_inject____end(opts) + #To test code injection */ ' \" =_end -- \\r\\n \\n \\r + api_instance.test_code_inject____end__rn_n_r(opts) rescue Petstore::ApiError => e - puts "Exception when calling FakeApi->test_code_inject____end: #{e}" + puts "Exception when calling FakeApi->test_code_inject____end__rn_n_r: #{e}" end ``` @@ -35,7 +35,7 @@ end Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **test_code_inject____end** | **String**| To test code injection */ ' \" | [optional] + **test_code_inject____end____rn_n_r** | **String**| To test code injection */ ' \" =_end -- \\r\\n \\n \\r | [optional] ### Return type @@ -47,8 +47,8 @@ No authorization required ### HTTP request headers - - **Content-Type**: application/json, */ " =end - - **Accept**: application/json, */ " =end + - **Content-Type**: application/json, */ \" =_end -- + - **Accept**: application/json, */ \" =_end -- diff --git a/samples/client/petstore-security-test/ruby/docs/ModelReturn.md b/samples/client/petstore-security-test/ruby/docs/ModelReturn.md index 37ae0c6a878..e12d8622c10 100644 --- a/samples/client/petstore-security-test/ruby/docs/ModelReturn.md +++ b/samples/client/petstore-security-test/ruby/docs/ModelReturn.md @@ -3,6 +3,6 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**_return** | **Integer** | property description */ ' \" | [optional] +**_return** | **Integer** | property description */ ' \" =_end -- \\r\\n \\n \\r | [optional] diff --git a/samples/client/petstore-security-test/ruby/lib/petstore.rb b/samples/client/petstore-security-test/ruby/lib/petstore.rb index 31046bb564c..415b6587c88 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" -Contact: apiteam@swagger.io */ ' \" +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/api/fake_api.rb b/samples/client/petstore-security-test/ruby/lib/petstore/api/fake_api.rb index 2610eda73b2..0c985ea308e 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/api/fake_api.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/api/fake_api.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" -Contact: apiteam@swagger.io */ ' \" +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,24 +31,24 @@ module Petstore @api_client = api_client end - # To test code injection */ ' \" + # To test code injection */ ' \" =_end -- \\r\\n \\n \\r # # @param [Hash] opts the optional parameters - # @option opts [String] :test_code_inject____end To test code injection */ ' \" + # @option opts [String] :test_code_inject____end____rn_n_r To test code injection */ ' \" =_end -- \\r\\n \\n \\r # @return [nil] - def test_code_inject____end(opts = {}) - test_code_inject____end_with_http_info(opts) + def test_code_inject____end__rn_n_r(opts = {}) + test_code_inject____end__rn_n_r_with_http_info(opts) return nil end - # To test code injection */ ' \" + # To test code injection */ ' \" =_end -- \\r\\n \\n \\r # # @param [Hash] opts the optional parameters - # @option opts [String] :test_code_inject____end To test code injection */ ' \" + # @option opts [String] :test_code_inject____end____rn_n_r To test code injection */ ' \" =_end -- \\r\\n \\n \\r # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers - def test_code_inject____end_with_http_info(opts = {}) + def test_code_inject____end__rn_n_r_with_http_info(opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: FakeApi.test_code_inject____end ..." + @api_client.config.logger.debug "Calling API: FakeApi.test_code_inject____end__rn_n_r ..." end # resource path local_var_path = "/fake".sub('{format}','json') @@ -60,16 +60,16 @@ module Petstore header_params = {} # HTTP header 'Accept' (if needed) - local_header_accept = ['application/json', '*/ " =end'] + local_header_accept = ['application/json', '*/ \" =_end -- '] local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result # HTTP header 'Content-Type' - local_header_content_type = ['application/json', '*/ " =end'] + local_header_content_type = ['application/json', '*/ \" =_end -- '] header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type) # form parameters form_params = {} - form_params["test code inject */ ' " =end"] = opts[:'test_code_inject____end'] if !opts[:'test_code_inject____end'].nil? + form_params["test code inject */ ' " =end -- \r\n \n \r"] = opts[:'test_code_inject____end____rn_n_r'] if !opts[:'test_code_inject____end____rn_n_r'].nil? # http body (model) post_body = nil @@ -81,7 +81,7 @@ module Petstore :body => post_body, :auth_names => auth_names) if @api_client.config.debugging - @api_client.config.logger.debug "API called: FakeApi#test_code_inject____end\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + @api_client.config.logger.debug "API called: FakeApi#test_code_inject____end__rn_n_r\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/api_client.rb b/samples/client/petstore-security-test/ruby/lib/petstore/api_client.rb index 5fcc0a7a31f..0f525411427 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/api_client.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" -Contact: apiteam@swagger.io */ ' \" +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); @@ -99,6 +99,9 @@ module Petstore update_params_for_auth! header_params, query_params, opts[:auth_names] + # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) + _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 + req_opts = { :method => http_method, :headers => header_params, @@ -106,11 +109,13 @@ module Petstore :params_encoding => @config.params_encoding, :timeout => @config.timeout, :ssl_verifypeer => @config.verify_ssl, + :ssl_verifyhost => _verify_ssl_host, :sslcert => @config.cert_file, :sslkey => @config.key_file, :verbose => @config.debugging } + # set custom cert, if provided req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert if [:post, :patch, :put, :delete].include?(http_method) @@ -216,7 +221,7 @@ module Petstore # @return [Tempfile] the file downloaded def download_file(response) content_disposition = response.headers['Content-Disposition'] - if content_disposition + if content_disposition and content_disposition =~ /filename=/i filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] prefix = sanitize_filename(filename) else diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/api_error.rb b/samples/client/petstore-security-test/ruby/lib/petstore/api_error.rb index 0ff375826e1..bb13b3a440d 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/api_error.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/api_error.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" -Contact: apiteam@swagger.io */ ' \" +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/configuration.rb b/samples/client/petstore-security-test/ruby/lib/petstore/configuration.rb index 865cb05e653..86c40326971 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/configuration.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/configuration.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" -Contact: apiteam@swagger.io */ ' \" +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); @@ -87,7 +87,7 @@ module Petstore # Default to 0 (never times out). attr_accessor :timeout - ### TLS/SSL + ### TLS/SSL setting # Set this to false to skip verifying SSL certificate when calling API from https server. # Default to true. # @@ -96,13 +96,16 @@ module Petstore # @return [true, false] attr_accessor :verify_ssl - # Set this to customize parameters encoding of array parameter with multi collectionFormat. - # Default to nil. + ### TLS/SSL setting + # Set this to false to skip verifying SSL host name + # Default to true. # - # @see The params_encoding option of Ethon. Related source code: - # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 - attr_accessor :params_encoding + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :verify_ssl_host + ### TLS/SSL setting # Set this to customize the certificate file to verify the peer. # # @return [String] the path to the certificate file @@ -111,24 +114,34 @@ module Petstore # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 attr_accessor :ssl_ca_cert + ### TLS/SSL setting # Client certificate file (for client certificate) attr_accessor :cert_file + ### TLS/SSL setting # Client private key file (for client certificate) attr_accessor :key_file + # Set this to customize parameters encoding of array parameter with multi collectionFormat. + # Default to nil. + # + # @see The params_encoding option of Ethon. Related source code: + # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 + attr_accessor :params_encoding + attr_accessor :inject_format attr_accessor :force_ending_format def initialize @scheme = 'https' - @host = 'petstore.swagger.io */ ' " =end' - @base_path = '/v2 */ ' " =end' + @host = 'petstore.swagger.io */ ' " =end -- \r\n \n \r' + @base_path = '/v2 */ ' \" =_end -- \\r\\n \\n \\r' @api_key = {} @api_key_prefix = {} @timeout = 0 @verify_ssl = true + @verify_ssl_host = true @params_encoding = nil @cert_file = nil @key_file = nil @@ -192,8 +205,8 @@ module Petstore { type: 'api_key', in: 'header', - key: 'api_key */ ' " =end', - value: api_key_with_prefix('api_key */ ' " =end') + key: 'api_key */ ' " =end -- \r\n \n \r', + value: api_key_with_prefix('api_key */ ' " =end -- \r\n \n \r') }, 'petstore_auth' => { diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/models/model_return.rb b/samples/client/petstore-security-test/ruby/lib/petstore/models/model_return.rb index a275f56cea2..3c348cab3dc 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/models/model_return.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/models/model_return.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" -Contact: apiteam@swagger.io */ ' \" +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,9 +24,9 @@ limitations under the License. require 'date' module Petstore - # Model for testing reserved words */ ' \" + # Model for testing reserved words */ ' \" =_end -- \\r\\n \\n \\r class ModelReturn - # property description */ ' \" + # property description */ ' \" =_end -- \\r\\n \\n \\r attr_accessor :_return diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/version.rb b/samples/client/petstore-security-test/ruby/lib/petstore/version.rb index 909f534e2bc..231de777b40 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/version.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/version.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" -Contact: apiteam@swagger.io */ ' \" +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/client/petstore-security-test/ruby/petstore.gemspec b/samples/client/petstore-security-test/ruby/petstore.gemspec index 7599769396f..e07446df1c7 100644 --- a/samples/client/petstore-security-test/ruby/petstore.gemspec +++ b/samples/client/petstore-security-test/ruby/petstore.gemspec @@ -1,12 +1,12 @@ # -*- encoding: utf-8 -*- # =begin -#Swagger Petstore */ ' \" +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" -Contact: apiteam@swagger.io */ ' \" +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,11 +31,11 @@ Gem::Specification.new do |s| s.version = Petstore::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Swagger-Codegen"] - s.email = ["apiteam@swagger.io */ ' \" "] + s.email = ["apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r"] s.homepage = "https://github.com/swagger-api/swagger-codegen" - s.summary = "Swagger Petstore */ ' \" Ruby Gem" - s.description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" " - s.license = "Apache 2.0 */ ' \" " + s.summary = "Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r Ruby Gem" + s.description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- " + s.license = "Apache 2.0 */ ' \" =_end -- \\r\\n \\n \\r" s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3' diff --git a/samples/client/petstore-security-test/ruby/spec/api/fake_api_spec.rb b/samples/client/petstore-security-test/ruby/spec/api/fake_api_spec.rb index 080d03f7b90..d4bd283231c 100644 --- a/samples/client/petstore-security-test/ruby/spec/api/fake_api_spec.rb +++ b/samples/client/petstore-security-test/ruby/spec/api/fake_api_spec.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" =end +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" =end -Contact: apiteam@swagger.io */ ' \" =end +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,13 +43,13 @@ describe 'FakeApi' do end end - # unit tests for test_code_inject____end - # To test code injection */ ' \" =end + # unit tests for test_code_inject____end__rn_n_r + # To test code injection */ ' \" =_end -- \\r\\n \\n \\r # # @param [Hash] opts the optional parameters - # @option opts [String] :test_code_inject____end To test code injection */ ' \" =end + # @option opts [String] :test_code_inject____end____rn_n_r To test code injection */ ' \" =_end -- \\r\\n \\n \\r # @return [nil] - describe 'test_code_inject____end test' do + describe 'test_code_inject____end__rn_n_r test' do it "should work" do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end diff --git a/samples/client/petstore-security-test/ruby/spec/api_client_spec.rb b/samples/client/petstore-security-test/ruby/spec/api_client_spec.rb index 23bc75a9685..a871ed7979e 100644 --- a/samples/client/petstore-security-test/ruby/spec/api_client_spec.rb +++ b/samples/client/petstore-security-test/ruby/spec/api_client_spec.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" =end +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" =end -Contact: apiteam@swagger.io */ ' \" =end +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); @@ -62,53 +62,6 @@ describe Petstore::ApiClient do end end - describe "#update_params_for_auth!" do - it "sets header api-key parameter with prefix" do - Petstore.configure do |c| - c.api_key_prefix['api_key'] = 'PREFIX' - c.api_key['api_key'] = 'special-key' - end - - api_client = Petstore::ApiClient.new - - config2 = Petstore::Configuration.new do |c| - c.api_key_prefix['api_key'] = 'PREFIX2' - c.api_key['api_key'] = 'special-key2' - end - api_client2 = Petstore::ApiClient.new(config2) - - auth_names = ['api_key', 'unknown'] - - header_params = {} - query_params = {} - api_client.update_params_for_auth! header_params, query_params, auth_names - expect(header_params).to eq({'api_key' => 'PREFIX special-key'}) - expect(query_params).to eq({}) - - header_params = {} - query_params = {} - api_client2.update_params_for_auth! header_params, query_params, auth_names - expect(header_params).to eq({'api_key' => 'PREFIX2 special-key2'}) - expect(query_params).to eq({}) - end - - it "sets header api-key parameter without prefix" do - Petstore.configure do |c| - c.api_key_prefix['api_key'] = nil - c.api_key['api_key'] = 'special-key' - end - - api_client = Petstore::ApiClient.new - - header_params = {} - query_params = {} - auth_names = ['api_key', 'unknown'] - api_client.update_params_for_auth! header_params, query_params, auth_names - expect(header_params).to eq({'api_key' => 'special-key'}) - expect(query_params).to eq({}) - end - end - describe "params_encoding in #build_request" do let(:config) { Petstore::Configuration.new } let(:api_client) { Petstore::ApiClient.new(config) } @@ -174,49 +127,18 @@ describe Petstore::ApiClient do expect(data).to be_instance_of(Hash) expect(data).to eq({:message => 'Hello'}) end - - it "handles Hash" do - api_client = Petstore::ApiClient.new - headers = {'Content-Type' => 'application/json'} - response = double('response', headers: headers, body: '{"pet": {"id": 1}}') - data = api_client.deserialize(response, 'Hash') - expect(data).to be_instance_of(Hash) - expect(data.keys).to eq([:pet]) - - pet = data[:pet] - expect(pet).to be_instance_of(Petstore::Pet) - expect(pet.id).to eq(1) - end - - it "handles Hash>" do - api_client = Petstore::ApiClient.new - headers = {'Content-Type' => 'application/json'} - response = double('response', headers: headers, body: '{"data": {"pet": {"id": 1}}}') - result = api_client.deserialize(response, 'Hash>') - expect(result).to be_instance_of(Hash) - expect(result.keys).to match_array([:data]) - - data = result[:data] - expect(data).to be_instance_of(Hash) - expect(data.keys).to match_array([:pet]) - - pet = data[:pet] - expect(pet).to be_instance_of(Petstore::Pet) - expect(pet.id).to eq(1) - end end describe "#object_to_hash" do it "ignores nils and includes empty arrays" do - api_client = Petstore::ApiClient.new - pet = Petstore::Pet.new - pet.id = 1 - pet.name = '' - pet.status = nil - pet.photo_urls = nil - pet.tags = [] - expected = {id: 1, name: '', tags: []} - expect(api_client.object_to_hash(pet)).to eq(expected) + # uncomment below to test object_to_hash for model + #api_client = Petstore::ApiClient.new + #_model = Petstore::ModelName.new + # update the model attribute below + #_model.id = 1 + # update the expected value (hash) below + #expected = {id: 1, name: '', tags: []} + #expect(api_client.object_to_hash(_model)).to eq(expected) end end diff --git a/samples/client/petstore-security-test/ruby/spec/configuration_spec.rb b/samples/client/petstore-security-test/ruby/spec/configuration_spec.rb index a8493ab6774..b154008fd82 100644 --- a/samples/client/petstore-security-test/ruby/spec/configuration_spec.rb +++ b/samples/client/petstore-security-test/ruby/spec/configuration_spec.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" =end +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" =end -Contact: apiteam@swagger.io */ ' \" =end +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,21 +27,26 @@ describe Petstore::Configuration do let(:config) { Petstore::Configuration.default } before(:each) do - Petstore.configure do |c| - c.host = 'petstore.swagger.io' - c.base_path = 'v2' - end + # uncomment below to setup host and base_path + #require 'URI' + #uri = URI.parse("https://petstore.swagger.io */ ' \" =_end -- \\r\\n \\n \\r/v2 */ ' \" =_end -- \\r\\n \\n \\r") + #Petstore.configure do |c| + # c.host = uri.host + # c.base_path = uri.path + #end end describe '#base_url' do it 'should have the default value' do - expect(config.base_url).to eq('http://petstore.swagger.io/v2') + # uncomment below to test default value of the base path + #expect(config.base_url).to eq("https://petstore.swagger.io */ ' \" =_end -- \\r\\n \\n \\r/v2 */ ' \" =_end -- \\r\\n \\n \\r") end it 'should remove trailing slashes' do [nil, '', '/', '//'].each do |base_path| config.base_path = base_path - expect(config.base_url).to eq('http://petstore.swagger.io') + # uncomment below to test trailing slashes + #expect(config.base_url).to eq("https://petstore.swagger.io */ ' \" =_end -- \\r\\n \\n \\r/v2 */ ' \" =_end -- \\r\\n \\n \\r") end end end diff --git a/samples/client/petstore-security-test/ruby/spec/models/model_return_spec.rb b/samples/client/petstore-security-test/ruby/spec/models/model_return_spec.rb index 202c52797e7..d2c318398a4 100644 --- a/samples/client/petstore-security-test/ruby/spec/models/model_return_spec.rb +++ b/samples/client/petstore-security-test/ruby/spec/models/model_return_spec.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" =end +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" =end -Contact: apiteam@swagger.io */ ' \" =end +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/client/petstore-security-test/ruby/spec/spec_helper.rb b/samples/client/petstore-security-test/ruby/spec/spec_helper.rb index fd56fb9ba7e..aae36e43d6a 100644 --- a/samples/client/petstore-security-test/ruby/spec/spec_helper.rb +++ b/samples/client/petstore-security-test/ruby/spec/spec_helper.rb @@ -1,10 +1,10 @@ =begin -#Swagger Petstore */ ' \" =end +#Swagger Petstore */ ' \" =_end -- \\r\\n \\n \\r -#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =_end -- -OpenAPI spec version: 1.0.0 */ ' \" =end -Contact: apiteam@swagger.io */ ' \" =end +OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r +Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git Licensed under the Apache License, Version 2.0 (the "License");