lib/esteid/validation.rb in esteid-1.0.3 vs lib/esteid/validation.rb in esteid-1.0.4

- old
+ new

@@ -30,20 +30,25 @@ def initialize(request) @eid_public_key = request.headers[EstEID.config.public_key_header] end def valid? + return false unless eid_public_key_present? status == "GOOD" end def status return soap_error_code if soap_fault? response.body.dig(:check_certificate_response, :status) end private + def eid_public_key_present? + !@eid_public_key.nil? && !@eid_public_key.empty? + end + def client @client ||= ::Savon.client( endpoint: EstEID.config.digidoc_endpoint_url, namespace: "http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl", raise_errors: false, @@ -53,19 +58,19 @@ ) end def response @response ||= client.call("CheckCertificate") do |locals| - locals.message "Certificate" => @certificate + locals.message "Certificate" => @eid_public_key end end def soap_fault? response.http.body =~ /<*Fault>/ end def soap_error_code - response.body[:fault][:faultstring] + response.body.dig(:fault, :faultstring) end def error_status(status) return if valid?