lib/api-tester/modules/server_information.rb in api-tester-1.0.0 vs lib/api-tester/modules/server_information.rb in api-tester-1.1.1
- old
+ new
@@ -1,17 +1,19 @@
-require 'pry'
+# frozen_string_literal: true
module ApiTester
+ # Module for ensuring the server isn't broadcasting information about itself
module ServerInformation
- def self.go contract
+ def self.go(contract)
reports = []
endpoint = contract.endpoints[0]
- response = endpoint.default_call
+ response = endpoint.default_call contract.base_url
- [:server, :x_powered_by, :x_aspnetmvc_version, :x_aspnet_version].each do |server_key|
- if response.headers[server_key] then
- reports << ServerBroadcastReport.new(response.headers[server_key], server_key)
+ %i[server x_powered_by x_aspnetmvc_version x_aspnet_version].each do |key|
+ if response.headers[key]
+ reports << ServerBroadcastReport.new(response.headers[key],
+ key)
end
end
reports
end
@@ -20,20 +22,21 @@
10
end
end
end
+# Report used by module
class ServerBroadcastReport
attr_accessor :server_info
attr_accessor :server_key
- def initialize server_info, server_key
+ def initialize(server_info, server_key)
self.server_info = server_info
self.server_key = server_key
end
def print
- puts "Found server information being broadcast in headers:"
- puts " #{self.server_info}"
- puts " as #{self.server_key}"
+ puts 'Found server information being broadcast in headers:'
+ puts " #{server_info}"
+ puts " as #{server_key}"
end
end