<commit_before>require 'saml_idp/xml_security'
require 'saml_idp/service_provider'
module SamlIdp
  class Request
    def self.from_deflated_request(raw)
      zstream  = Zlib::Inflate.new(-Zlib::MAX_WBITS)
      decoded = Base64.decode64(raw)
      begin
        inflated = zstream.inflate(decoded).tap do
          zstream.finish
          zstream.close
        end
      rescue Zlib::DataError # not compressed
        inflated = decoded
      end
      new(inflated)
    end

    attr_accessor :raw_xml

    delegate :config, to: :SamlIdp
    private :config
    delegate :xpath, to: :document
    private :xpath

    def initialize(raw_xml = "")
      self.raw_xml = raw_xml
    end

    def request_id
      authn_request["ID"]
    end

    def acs_url
      authn_request["AssertionConsumerServiceURL"]
    end

    def valid_signature?
      service_provider.valid_signature? document
    end

    def service_provider?
      service_provider.valid?
    end

    def service_provider
      @service_provider ||= ServiceProvider.new((service_provider_finder[issuer] || {}).merge(identifier: issuer))
    end

    def issuer
      xpath("//saml:Issuer", saml: assertion).first.try :content
    end

    def document
      @document ||= Saml::XML::Document.parse(raw_xml)
    end
    private :document

    def authn_request
      xpath("//samlp:AuthnRequest", samlp: samlp).first<commit_msg>be sure acs_url is a string<commit_after>require 'saml_idp/xml_security'
require 'saml_idp/service_provider'
module SamlIdp
  class Request
    def self.from_deflated_request(raw)
      zstream  = Zlib::Inflate.new(-Zlib::MAX_WBITS)
      decoded = Base64.decode64(raw)
      begin
        inflated = zstream.inflate(decoded).tap do
          zstream.finish
          zstream.close
        end
      rescue Zlib::DataError # not compressed
        inflated = decoded
      end
      new(inflated)
    end

    attr_accessor :raw_xml

    delegate :config, to: :SamlIdp
    private :config
    delegate :xpath, to: :document
    private :xpath

    def initialize(raw_xml = "")
      self.raw_xml = raw_xml
    end

    def request_id
      authn_request["ID"]
    end

    def acs_url
      authn_request["AssertionConsumerServiceURL"].to_s
    end

    def valid_signature?
      service_provider.valid_signature? document
    end

    def service_provider?
      service_provider.valid?
    end

    def service_provider
      @service_provider ||= ServiceProvider.new((service_provider_finder[issuer] || {}).merge(identifier: issuer))
    end

    def issuer
      xpath("//saml:Issuer", saml: assertion).first.try :content
    end

    def document
      @document ||= Saml::XML::Document.parse(raw_xml)
    end
    private :document

    def authn_request
      xpath("//samlp:AuthnRequest", samlp: samlp).first
{'fraction_non_alphanumeric': 0.08780661215783861, 'fraction_numerical': 0.0028439388553146107, 'mean_word_length': 2.737051792828685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7022705', 'n_tokens_mistral': 918, 'n_tokens_neox': 885, 'n_words': 188}