Class: Pedant::CheckPluginTypeNotSpecified

Inherits:
Check
  • Object
show all
Defined in:
lib/pedant/checks/plugin_type_not_specified.rb

Instance Attribute Summary

Attributes inherited from Check

#result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Check

all, depends, #fail, #fatal, friendly_name, inherited, #initialize, initialize!, list, #pass, provides, ready?, #report, #skip, #warn

Constructor Details

This class inherits a constructor from Pedant::Check

Class Method Details

.requiresObject



29
30
31
# File 'lib/pedant/checks/plugin_type_not_specified.rb', line 29

def self.requires
  super + [:main, :trees]
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pedant/checks/plugin_type_not_specified.rb', line 33

def run
  # This check only applies to plugins.
  return skip unless @kb[:main].extname == '.nasl'

  args = []

  tree = @kb[:trees][@kb[:main]]

  tree.all(:Call).each do |node|
    next unless node.name.ident.name == 'script_set_attribute'
    next unless node.name.indexes == []
    next unless node.arg.has_key? 'attribute'

    # Pull out the attribute argument.
    arg = node.arg['attribute']
    next if !arg.is_a? Nasl::String
    next if arg.text != 'plugin_type'

    # Pull out the value argument.
    arg = node.arg['value']
    next if !arg.is_a? Nasl::String

    # Ensure that the plugin type is valid.
    unless ['combined', 'local', 'reputation', 'remote', 'settings', 'summary', 'thirdparty'].include? arg.text
      report(:info, "Plugin is of unknown type #{arg.text}:\n#{arg.context(node)}")
      return fail
    end

    args << [arg, node]
  end

  case args.length
  when 0
    report(:error, "Plugin does not specify a type.")
    fail
  when 1
    arg = args.first[0]
    call = args.first[1]
    report(:info, "Plugin is of type #{arg.text}:\n#{arg.context(call)}")
    pass
  else
    report(:error, "Plugin specifies multiple types.")
    args.each { |arg, call| report(:error, arg.context(call)) }
    fail
  end
end