Class: SamlTool::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/saml_tool/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(saml) ⇒ Validator



5
6
7
# File 'lib/saml_tool/validator.rb', line 5

def initialize(saml)
  @saml = saml
end

Instance Attribute Details

#samlObject (readonly)

Returns the value of attribute saml.



4
5
6
# File 'lib/saml_tool/validator.rb', line 4

def saml
  @saml
end

Instance Method Details

#errorsObject



14
15
16
# File 'lib/saml_tool/validator.rb', line 14

def errors
  @errors ||= []
end

#saml_documentObject



35
36
37
# File 'lib/saml_tool/validator.rb', line 35

def saml_document
  @saml_document ||= Nokogiri::XML(saml)
end

#schema_pathObject



31
32
33
# File 'lib/saml_tool/validator.rb', line 31

def schema_path
  File.expand_path('../schema/', File.dirname(__FILE__))
end

#valid?Boolean



9
10
11
12
# File 'lib/saml_tool/validator.rb', line 9

def valid?
  validate
  errors.empty?
end

#validateObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/saml_tool/validator.rb', line 19

def validate
  # Need to load schema with other schemas in path
  # see http://ktulu.com.ar/blog/2011/06/26/resolving-validation-errors-using-nokogiri-and-schemas/
  Dir.chdir(schema_path) do
    schema = Nokogiri::XML::Schema(File.read('localised-saml-schema-protocol-2.0.xsd'))

    schema.validate(saml_document).each do |error|
      errors << error.message unless errors.include? error.message
    end
  end
end