norad_cli 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f317f6169f280d37dcf3f342361e7c4254f5599
4
- data.tar.gz: 942032c69b1630bebd3107617799abda9e1a713f
3
+ metadata.gz: 3d7d5fad53b4b887fda38b20367eaaf423b10da0
4
+ data.tar.gz: f15052a70f7c23692472cc0e028447833995a1f2
5
5
  SHA512:
6
- metadata.gz: ba8692954a43ba7fb99e902e8f8d6351f696f3f448d988aecf58a857f4c3b8f4c6ee807670dd5dd9bf12dfcf4b20523baa690659c45ed5cad278519584fe65a4
7
- data.tar.gz: dce51da0d3e7daffe7e306885fb19b4d5f565ff46884f309bc92ca1b48b0c18fe4d0430a99e430ee31414bedf56206f847d0bdad2b5d975049b446f553218f1b
6
+ metadata.gz: f6cd71926c664c17e150b3dd14119210d9511adb20295a32def87e31d45d94d07f0c376128817d67e17ff6ede01a023dfa2562aec9c972e2e9229443a7de4033
7
+ data.tar.gz: d4a7170d6be6020b59ce6ff241a3dbb2ed76778ad0c7223bfc268149329d4ec7cfd2502c7a4cadb1aedc8b03b08905d79563efa0cae113df20eb5c23ad13fa87
data/.rubocop.yml CHANGED
@@ -18,10 +18,12 @@ Metrics/AbcSize:
18
18
  Exclude:
19
19
  - 'lib/norad_cli/support/api_security_container_seed_script.rb'
20
20
  - 'lib/norad_cli/cli/sectest.rb'
21
+ - 'lib/norad_cli/support/manifest_spec.rb'
21
22
  Metrics/BlockLength:
22
23
  Exclude:
23
24
  - 'spec/**/*'
24
25
  - 'lib/norad_cli/cli/sectest.rb'
26
+ - 'lib/norad_cli/support/manifest_spec.rb'
25
27
  Metrics/ClassLength:
26
28
  Exclude:
27
29
  - 'lib/norad_cli/cli/sectest.rb'
@@ -30,8 +32,15 @@ Style/NegatedIf:
30
32
  - 'lib/norad_cli/cli/sectest.rb'
31
33
  Security/YAMLLoad:
32
34
  Exclude:
33
- - 'lib/norad_cli/support/manifest.rb'
35
+ - 'lib/norad_cli/support/manifest.rb'
34
36
  - 'lib/norad_cli/support/api_security_container_seed_script.rb'
37
+ - 'lib/norad_cli/support/manifest_spec.rb'
35
38
  Performance/RegexpMatch:
36
39
  Exclude:
37
40
  - 'lib/norad_cli/cli/sectest.rb'
41
+ Style/RegexpLiteral:
42
+ Exclude:
43
+ - 'lib/norad_cli/support/manifest_spec.rb'
44
+ Style/Next:
45
+ Exclude:
46
+ - 'lib/norad_cli/support/manifest_spec.rb'
@@ -191,6 +191,27 @@ class Sectest < Thor
191
191
  SeedGenerator.process_manifests(options[:seedfile], options[:docsite])
192
192
  end
193
193
 
194
+ desc 'validate:image SECTESTNAME', 'Validate SECTESTNAME manifest.yml and readme.md'
195
+ define_method 'validate:image' do |name|
196
+ # Validate the readme file
197
+ ENV['sectest_name'] = name
198
+ RSpec::Core::Runner.run(["#{File.dirname(File.expand_path(__FILE__))}/../support/readme_spec.rb"], $stderr, $stdout)
199
+
200
+ # Validate the manifest file
201
+ RSpec::Core::Runner.run(["#{File.dirname(File.expand_path(__FILE__))}/../support/manifest_spec.rb"], $stderr, $stdout)
202
+ end
203
+
204
+ desc 'validate', 'Validate all manifest.yml and readme.md'
205
+ def validate
206
+ # Error check to ensure this is a plugin directory
207
+ Dir.glob('sectests/*').select do |f|
208
+ if File.directory? f
209
+ # Build all for the sectest
210
+ send('validate:image', f.split('/')[-1])
211
+ end
212
+ end
213
+ end
214
+
194
215
  no_tasks do
195
216
  def dockerfile?(img_dir)
196
217
  # Ensure the Dockerfile exists for the new tool
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+ require 'safe_yaml'
3
+ SafeYAML::OPTIONS[:default_mode] = :safe
4
+
5
+ class Manifest
6
+ attr_accessor :values
7
+
8
+ def initialize(manifest_file)
9
+ f = File.new manifest_file, 'r'
10
+ @values = YAML.load f.read
11
+ end
12
+
13
+ def name
14
+ "#{@values['registry']}/#{@values['name']}:#{@values['version']}"
15
+ end
16
+ end
17
+
18
+ describe Manifest do
19
+ def testing_for(s)
20
+ puts "Testing for #{s}..."
21
+ end
22
+
23
+ def ok
24
+ puts 'OK'
25
+ end
26
+
27
+ def symbolize(h)
28
+ h.each_with_object({}) do |p, obj|
29
+ obj[p.first.to_sym] = p.last
30
+ end
31
+ end
32
+
33
+ def manifest_name_check(manifest)
34
+ testing_for 'valid name'
35
+ expect(manifest.values['name']).to_not eq(nil)
36
+ expect(manifest.values['name'] =~ %r{\A[A-Za-z][A-Za-z0-9_-]+\z}).to_not eq(nil)
37
+ end
38
+
39
+ def manifest_version_check(manifest)
40
+ testing_for 'existence of version'
41
+ expect(manifest.values['version']).to_not eq(nil)
42
+ expect(manifest.values['version'].is_a?(String)).to eq(true)
43
+ expect(manifest.values['version']).to match(/\A[a-zA-Z0-9:._-]+\z/)
44
+ end
45
+
46
+ def manifest_registry_check(manifest)
47
+ testing_for 'existence of registry'
48
+ expect(manifest.values['registry']).to_not eq(nil)
49
+ expect(manifest.values['registry'].is_a?(String)).to eq(true)
50
+ end
51
+
52
+ def manifest_test_types_check(manifest)
53
+ testing_for 'test types'
54
+ expect(manifest.values['test_types']).to_not eq(nil)
55
+ expect(manifest.values['test_types'].empty?).to eq(false)
56
+ end
57
+
58
+ def manifest_configurable_check(manifest)
59
+ testing_for 'configurability'
60
+ if manifest.values['configurable']
61
+ expect(manifest.values['default_config']).to_not be(nil)
62
+ else
63
+ expect(manifest.values['default_config']).to be(nil)
64
+ end
65
+ end
66
+ CONFIG_SHIM = { ssh_user: '', ssh_key: '', target: '' }.freeze
67
+ it 'validates the manifest file of all containers' do
68
+ next if File.exist?("sectests/#{ENV['sectest_name']}/.parent_only")
69
+ puts "Looking for valid manifest in: #{p}..."
70
+ manifest = Manifest.new "sectests/#{ENV['sectest_name']}/manifest.yml"
71
+ ok
72
+ manifest_name_check(manifest)
73
+ ok
74
+ manifest_version_check manifest
75
+ ok
76
+ manifest_registry_check manifest
77
+ ok
78
+ testing_for 'valid prog args'
79
+ expect(manifest.values['prog_args']).to_not eq(nil)
80
+ expect(manifest.values['prog_args'].scan('%{target}').length).to eq(1)
81
+ category = manifest.values['category']
82
+ assert false unless category == 'blackbox' || category == 'whitebox'
83
+ if category == 'blackbox'
84
+ expect(manifest.values['prog_args'].scan('%{ssh_user}').length).to eq(0)
85
+ expect(manifest.values['prog_args'].scan('%{ssh_key}').length).to eq(0)
86
+ else
87
+ expect(manifest.values['prog_args'].scan('%{ssh_user}').length).to eq(1)
88
+ expect(manifest.values['prog_args'].scan('%{ssh_key}').length).to eq(1)
89
+ end
90
+ ok
91
+ manifest_test_types_check manifest
92
+ ok
93
+ manifest_configurable_check manifest
94
+ ok
95
+ testing_for 'variants'
96
+ puts 'No variants for this repo' unless Dir.exist?("sectests/#{ENV['sectest_name']}/variants")
97
+ ok
98
+ Dir.glob("sectests/#{ENV['sectest_name']}/variants/*").each do |variant|
99
+ v_manifest = Manifest.new "#{variant}/manifest.yml"
100
+ manifest_name_check v_manifest
101
+ ok
102
+ manifest_registry_check v_manifest
103
+ ok
104
+ manifest_version_check v_manifest
105
+ ok
106
+ manifest_test_types_check v_manifest
107
+ ok
108
+ manifest_configurable_check v_manifest
109
+ ok
110
+ if v_manifest.values['default_config'] && manifest.values['default_config']
111
+ testing_for 'default config keys match base config keys'
112
+ expect(v_manifest.values['default_config'].keys).to match_array(manifest.values['default_config'].keys)
113
+ ok
114
+ end
115
+ end
116
+ puts
117
+ end
118
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ class Readme
3
+ end
4
+
5
+ describe Readme do
6
+ def testing_for(s)
7
+ puts "Testing for #{s}..."
8
+ end
9
+
10
+ def ok
11
+ puts 'OK'
12
+ end
13
+
14
+ it 'requires each tool to have a README' do
15
+ next if File.exist?("sectests/#{ENV['sectest_name']}/.parent_only")
16
+ puts "Looking for README.md in: sectests/#{ENV['sectest_name']}..."
17
+ readme = File.read "sectests/#{ENV['sectest_name']}/README.md"
18
+ ok
19
+
20
+ testing_for 'variant READMEs'
21
+ puts 'No variants for this tool' unless Dir.exist?("sectests/#{ENV['sectest_name']}/variants")
22
+ ok
23
+ Dir.glob("sectests/#{ENV['sectest_name']}/variants/*").each do |variant|
24
+ readme = File.read "#{variant}/README.md"
25
+ ok
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module NoradCli
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norad_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hitchcock
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-03-07 00:00:00.000000000 Z
13
+ date: 2017-03-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: git
@@ -194,8 +194,8 @@ files:
194
194
  - lib/norad_cli/cli/secrepo.rb
195
195
  - lib/norad_cli/cli/sectest.rb
196
196
  - lib/norad_cli/support/api_security_container_seed_script.rb
197
- - lib/norad_cli/support/manifest.rb
198
- - lib/norad_cli/support/readme.rb
197
+ - lib/norad_cli/support/manifest_spec.rb
198
+ - lib/norad_cli/support/readme_spec.rb
199
199
  - lib/norad_cli/templates/.gitignore
200
200
  - lib/norad_cli/templates/.rspec
201
201
  - lib/norad_cli/templates/CONTRIBUTING.md
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'safe_yaml'
3
- SafeYAML::OPTIONS[:default_mode] = :safe
4
-
5
- class Manifest
6
- attr_accessor :values
7
-
8
- def initialize(manifest_file)
9
- f = File.new manifest_file, 'r'
10
- @values = YAML.load f.read
11
- end
12
-
13
- def name
14
- "#{@values['registry']}/#{@values['name']}:#{@values['version']}"
15
- end
16
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
- class Readme
3
- end