hakiri 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,4 +16,4 @@ capybara-*.html
16
16
  **.orig
17
17
  *.gem
18
18
  /manifest.json
19
- .ruby-version
19
+ .ruby-version
@@ -0,0 +1 @@
1
+ hakiri_cli
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - jruby-19mode
7
+ - rbx-19mode
8
+ env:
9
+ - JRUBY_OPTS=--1.9 RBXOPT=-X19
10
+ script: "./test/ci/ci_runner.sh"
data/Gemfile CHANGED
@@ -1,3 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
4
+
5
+ group :test do
6
+ platforms :ruby do
7
+ gem "cane", "~> 2.6.0"
8
+ gem "simplecov", ">= 0.8.0.pre"
9
+ end
10
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hakiri (0.3.2)
4
+ hakiri (0.4.0)
5
5
  active_support
6
6
  bundler
7
7
  commander
@@ -17,15 +17,24 @@ GEM
17
17
  active_support (3.0.0)
18
18
  activesupport (= 3.0.0)
19
19
  activesupport (3.0.0)
20
+ cane (2.6.0)
21
+ parallel
20
22
  commander (4.1.3)
21
23
  highline (~> 1.6.11)
22
24
  highline (1.6.19)
23
25
  i18n (0.6.4)
24
26
  json_pure (1.8.0)
25
27
  mime-types (1.23)
28
+ minitest (5.0.6)
29
+ multi_json (1.7.7)
30
+ parallel (0.7.1)
26
31
  rake (10.1.0)
27
32
  rest-client (1.6.7)
28
33
  mime-types (>= 1.16)
34
+ simplecov (0.8.0.pre)
35
+ multi_json
36
+ simplecov-html (~> 0.7.1)
37
+ simplecov-html (0.7.1)
29
38
  terminal-table (1.4.5)
30
39
 
31
40
  PLATFORMS
@@ -33,4 +42,7 @@ PLATFORMS
33
42
  ruby
34
43
 
35
44
  DEPENDENCIES
45
+ cane (~> 2.6.0)
36
46
  hakiri!
47
+ minitest (~> 5.0.0)
48
+ simplecov (>= 0.8.0.pre)
data/README.md CHANGED
@@ -90,15 +90,15 @@ Hakiri supports vulnerability detection for a collection of gems listed in [the
90
90
  $ hakiri gemfile:scan
91
91
  ~~~
92
92
 
93
- To scan a specific `Gemfile.lock` add the `-m` parameter at the end:
93
+ To scan a specific `Gemfile.lock` add the `-g` parameter at the end:
94
94
 
95
95
  ~~~
96
- $ hakiri gemfile:scan -m ../Gemfile.lock
96
+ $ hakiri gemfile:scan -g ../Gemfile.lock
97
97
  ~~~
98
98
 
99
- This will scan your `Gemfile.lock` and check with the server whether it has any vulnerable gems. It only checks gems that are [supported by Hakiri]((https://www.hakiriup.com/docs/manifest-file)).
99
+ This will scan your `Gemfile.lock` and check with the server whether it has any vulnerable gems. It only checks gems that are [supported by Hakiri](https://www.hakiriup.com/docs/manifest-file).
100
100
 
101
- You can also [sync your gems]((https://www.hakiriup.com/docs/syncing-with-the-cloud)) with the cloud and get notified when new vulnerabilities come out.
101
+ You can also [sync your gems](https://www.hakiriup.com/docs/syncing-with-the-cloud) with the cloud and get notified when new vulnerabilities come out.
102
102
 
103
103
  ## Advanced Usage
104
104
 
data/Rakefile CHANGED
@@ -0,0 +1,3 @@
1
+ Dir["./tasks/**/*.rake"].sort.each{ |task| load task }
2
+
3
+ task default: :test
data/bin/hakiri CHANGED
@@ -38,12 +38,13 @@ command 'system:sync' do |c|
38
38
  c.summary = 'Sync your system\'s software versions with the cloud.'
39
39
  c.description = 'This command grabs your custom stack JSON file, and syncs it with your project on www.hakiriup.com.'
40
40
  c.option '--manifest STRING', String, 'Path to your manifest JSON file stack'
41
- c.option '--project INTEGER', Integer, 'Your project ID.'
41
+ c.option '--stack INTEGER', Integer, 'Your stack ID.'
42
42
  c.option '--force', 'Force syncing without asking for it first.'
43
43
 
44
44
  c.action do |args, options|
45
45
  options.default :manifest => './manifest.json'
46
- options.default :project => nil
46
+ options.default :stack => nil
47
+
47
48
  cli = Hakiri::System.new(args, options)
48
49
  cli.sync
49
50
  end
@@ -79,13 +80,26 @@ command 'gemfile:sync' do |c|
79
80
  c.summary = 'Sync your system\'s Gemfile.lock gem versions with the cloud.'
80
81
  c.description = 'This command grabs your Gemfile.lock file, and syncs it with your project on www.hakiriup.com.'
81
82
  c.option '--gemfile STRING', String, 'Path to your Gemfile.lock'
82
- c.option '--project INTEGER', Integer, 'Your project ID.'
83
+ c.option '--stack INTEGER', Integer, 'Your stack ID.'
83
84
  c.option '--force', 'Force syncing without asking for it first.'
84
85
 
85
86
  c.action do |args, options|
86
87
  options.default :gemfile => './Gemfile.lock'
87
- options.default :project => nil
88
+ options.default :stack => nil
89
+
88
90
  cli = Hakiri::Gemfile.new(args, options)
89
91
  cli.sync
90
92
  end
93
+ end
94
+
95
+ command 'code:report' do |c|
96
+ c.syntax = 'hakiri code:report [options]'
97
+ c.summary = 'Check code report on the latest push.'
98
+ c.description = 'This command connects to Hakiri and returns a report on vulnerabilities from the latest push.'
99
+ c.option '--stack INTEGER', Integer, 'Your stack ID.'
100
+
101
+ c.action do |args, options|
102
+ cli = Hakiri::Code.new(args, options)
103
+ cli.report
104
+ end
91
105
  end
@@ -22,4 +22,6 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency 'i18n'
23
23
  s.add_dependency 'rest-client'
24
24
  s.add_dependency 'json_pure'
25
+
26
+ s.add_development_dependency 'minitest', '~> 5.0.0'
25
27
  end
@@ -10,6 +10,7 @@ require 'bundler/lockfile_parser'
10
10
 
11
11
  require 'hakiri/cli/cli'
12
12
  require 'hakiri/cli/system'
13
+ require 'hakiri/cli/code'
13
14
  require 'hakiri/cli/manifest'
14
15
  require 'hakiri/cli/gemfile'
15
16
 
@@ -17,7 +18,7 @@ require 'hakiri/stack'
17
18
  require 'hakiri/version'
18
19
  require 'hakiri/http_client'
19
20
 
20
- require 'hakiri/technologies/technology'
21
+ require 'hakiri/technology'
21
22
  require 'hakiri/technologies/apache'
22
23
  require 'hakiri/technologies/apache_tomcat'
23
24
  require 'hakiri/technologies/java'
@@ -0,0 +1,44 @@
1
+ class Hakiri::Code < Hakiri::Cli
2
+ #
3
+ # Walks the user through code report process.
4
+ #
5
+ def report
6
+ if @http_client.auth_token
7
+ say '-----> Loading code report...'
8
+ response = @http_client.code_report(@options.stack)
9
+
10
+ if response[:errors]
11
+ response[:errors].each do |error|
12
+ say "! Server Error: #{error}"
13
+ end
14
+ else
15
+ say " Repo: #{response[:repository][:name]}"
16
+ say " Branch: #{response[:repository][:branch]}"
17
+ say " Latest commit: #{response[:last_commit_id]}"
18
+
19
+ if response[:warnings_count] == 0
20
+ say ' No warnings were found in your code. Keep it up!'
21
+ else
22
+ say "! #{response[:warnings_count]} warnings were found in the code"
23
+
24
+ if agree 'Show all of them? (yes or no) '
25
+ puts ' '
26
+ response[:warnings].each do |warning|
27
+ say warning[:warning_type]
28
+ say warning[:message]
29
+
30
+ if warning[:line]
31
+ say "| Detected in #{warning[:file]} on line #{warning[:line]}"
32
+ else
33
+ say "| Detected in #{warning[:file]}"
34
+ end
35
+ puts ' '
36
+ end
37
+ end
38
+ end
39
+ end
40
+ else
41
+ say '! You have to setup HAKIRI_AUTH_TOKEN environmental variable with your Hakiri authentication token.'
42
+ end
43
+ end
44
+ end
@@ -15,7 +15,7 @@ class Hakiri::Gemfile < Hakiri::Cli
15
15
 
16
16
  # GETTING VULNERABILITIES
17
17
  say '-----> Searching for vulnerabilities...'
18
- params = ({ :technologies => @stack.technologies }.to_param)
18
+ params = { :technologies => @stack.technologies }
19
19
  response = @http_client.get_issues(params)
20
20
 
21
21
  if response[:errors]
@@ -73,9 +73,9 @@ class Hakiri::Gemfile < Hakiri::Cli
73
73
  end
74
74
 
75
75
  # CHECK VERSIONS ON THE SERVER
76
- params = { :project_id => @options.project, :technologies => @stack.technologies }
76
+ params = { :technologies => @stack.technologies }
77
77
  say '-----> Checking software versions on www.hakiriup.com...'
78
- response = @http_client.check_versions_diff(params)
78
+ response = @http_client.check_versions_diff(@options.stack, params)
79
79
 
80
80
  if response[:errors]
81
81
  response[:errors].each do |error|
@@ -109,8 +109,8 @@ class Hakiri::Gemfile < Hakiri::Cli
109
109
 
110
110
  if update or @options.force
111
111
  say '-----> Syncing versions with www.hakiriup.com...'
112
- params = ({ :project_id => @options.project, :technologies => @stack.technologies }.to_param)
113
- response = @http_client.sync_project_versions(response[:project][:id], params)
112
+ params = { :stack => @options.stack, :technologies => @stack.technologies }
113
+ response = @http_client.sync_stack_versions(response[:project][:stack][:id], params)
114
114
 
115
115
  if response[:errors]
116
116
  response[:errors].each do |error|
@@ -7,8 +7,8 @@ class Hakiri::Manifest < Hakiri::Cli
7
7
  def generate
8
8
  FileUtils::copy_file "#{File.dirname(__FILE__)}/manifest.json", "#{Dir.pwd}/manifest.json"
9
9
  File.chmod 0755, "#{Dir.pwd}/manifest.json"
10
- say '-----> Generating the manifest file...'
11
- say " Generated the manifest file in #{Dir.pwd}/manifest.json"
10
+ say '-----> Generating a manifest file...'
11
+ say " Generated a manifest file in #{Dir.pwd}/manifest.json"
12
12
  say " Edit it and run \"hakiri system:scan\""
13
13
  end
14
14
  end
@@ -19,7 +19,7 @@ class Hakiri::System < Hakiri::Cli
19
19
 
20
20
  # GETTING VULNERABILITIES
21
21
  say '-----> Searching for vulnerabilities...'
22
- params = ({ :technologies => @stack.technologies }.to_param)
22
+ params = { :technologies => @stack.technologies }
23
23
  response = @http_client.get_issues(params)
24
24
 
25
25
  if response[:errors]
@@ -79,9 +79,9 @@ class Hakiri::System < Hakiri::Cli
79
79
  end
80
80
 
81
81
  # CHECK VERSIONS ON THE SERVER
82
- params = { :project_id => @options.project, :technologies => @stack.technologies }
82
+ params = { :technologies => @stack.technologies }
83
83
  say '-----> Checking software versions on www.hakiriup.com...'
84
- response = @http_client.check_versions_diff(params)
84
+ response = @http_client.check_versions_diff(@options.stack, params)
85
85
 
86
86
  if response[:errors]
87
87
  response[:errors].each do |error|
@@ -115,8 +115,8 @@ class Hakiri::System < Hakiri::Cli
115
115
 
116
116
  if update or @options.force
117
117
  say '-----> Syncing versions with www.hakiriup.com...'
118
- params = ({ :project_id => @options.project, :technologies => @stack.technologies }.to_param)
119
- response = @http_client.sync_project_versions(response[:project][:id], params)
118
+ params = { :stack => @options.stack, :technologies => @stack.technologies }
119
+ response = @http_client.sync_stack_versions(response[:project][:stack][:id], params)
120
120
 
121
121
  if response[:errors]
122
122
  response[:errors].each do |error|
@@ -193,7 +193,7 @@ class Hakiri::System < Hakiri::Cli
193
193
  end
194
194
 
195
195
  say '-----> Searching for vulnerabilities...'
196
- params = ({ :technologies => @stack.technologies }.to_param)
196
+ params = { :technologies => @stack.technologies }
197
197
  response = @http_client.get_issues(params)
198
198
 
199
199
  if response[:errors]
@@ -8,7 +8,7 @@ class Hakiri::HttpClient
8
8
  #
9
9
  def initialize
10
10
  @auth_token = (ENV['HAKIRI_AUTH_TOKEN'] or nil)
11
- @api_url = (ENV['HAKIRI_API_URL'] or 'https://www.hakiriup.com/api/v1')
11
+ @api_url = 'http://0.0.0.0:5000/api/v1' or (ENV['HAKIRI_API_URL'] or 'https://www.hakiriup.com/api/v1')
12
12
  end
13
13
 
14
14
  #
@@ -21,10 +21,9 @@ class Hakiri::HttpClient
21
21
  # Returns a hash of technologies with vulnerabilities.
22
22
  #
23
23
  def get_issues(params)
24
- # { |response, request, result, &block|
25
- # JSON.parse(.to_str, symbolize_names: true)
26
- # "! Server Error: #{response.code}"
27
- RestClient.post "#{@api_url}/issues.json?auth_token=#{@auth_token}", params do |response, request, result, &block|
24
+ params[:auth_token] = @auth_token
25
+
26
+ RestClient.post "#{@api_url}/issues/scan.json", params do |response, request, result, &block|
28
27
  case response.code
29
28
  when 200
30
29
  JSON.parse(response.to_str, :symbolize_names => true)
@@ -37,14 +36,19 @@ class Hakiri::HttpClient
37
36
  #
38
37
  # Checks system and server version differences.
39
38
  #
39
+ # @param [Integer] stack_id
40
+ # Stack ID.
41
+ #
40
42
  # @param [String] params
41
43
  # Hash of technologies with versions converted to a string.
42
44
  #
43
45
  # @return [Hash]
44
46
  # Returns a hash of differences between technologies.
45
47
  #
46
- def check_versions_diff(params)
47
- RestClient.post "#{@api_url}/versions/diffs.json?auth_token=#{@auth_token}", params do |response, request, result, &block|
48
+ def check_versions_diff(stack_id, params)
49
+ params[:auth_token] = @auth_token
50
+
51
+ RestClient.post "#{@api_url}/stacks/#{stack_id}/versions/diffs.json", params do |response, request, result, &block|
48
52
  case response.code
49
53
  when 200
50
54
  JSON.parse(response.to_str, :symbolize_names => true)
@@ -55,7 +59,10 @@ class Hakiri::HttpClient
55
59
  end
56
60
 
57
61
  #
58
- # Checks system and server version differences.
62
+ # Syncs system and server versions.
63
+ #
64
+ # @param [Integer] stack_id
65
+ # Stack ID.
59
66
  #
60
67
  # @param [String] params
61
68
  # Hash of technologies with versions converted to a string.
@@ -63,8 +70,30 @@ class Hakiri::HttpClient
63
70
  # @return [Hash]
64
71
  # Returns a hash of updated versions.
65
72
  #
66
- def sync_project_versions(project_id, params)
67
- RestClient.put "#{@api_url}/projects/#{project_id}.json?auth_token=#{@auth_token}", params do |response, request, result, &block|
73
+ def sync_stack_versions(stack_id, params)
74
+ params[:auth_token] = @auth_token
75
+
76
+ RestClient.put "#{@api_url}/stacks/#{stack_id}/versions/update_all.json", params do |response, request, result, &block|
77
+ case response.code
78
+ when 200
79
+ JSON.parse(response.to_str, :symbolize_names => true)
80
+ else
81
+ { :errors => [response.code] }
82
+ end
83
+ end
84
+ end
85
+
86
+ #
87
+ # Gets latest build data.
88
+ #
89
+ # @param [Integer] stack_id
90
+ # Stack ID.
91
+ #
92
+ # @return [Hash]
93
+ # Returns a hash with build fields, repository fields and an array of warnings.
94
+ #
95
+ def code_report(stack_id)
96
+ RestClient.get "#{@api_url}/stacks/#{stack_id}/builds/last.json?auth_token=#{@auth_token}" do |response, request, result, &block|
68
97
  case response.code
69
98
  when 200
70
99
  JSON.parse(response.to_str, :symbolize_names => true)
@@ -1,3 +1,3 @@
1
1
  module Hakiri
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,7 @@
1
+ begin
2
+ require "cane/rake_task"
3
+
4
+ Cane::RakeTask.new
5
+ rescue LoadError
6
+ warn "unable to load 'cane'"
7
+ end
@@ -0,0 +1,8 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new(:test) do |t|
4
+ t.libs << "lib"
5
+ t.libs << "test"
6
+ t.pattern = "test/**/*_test.rb"
7
+ t.verbose = false
8
+ end
@@ -0,0 +1,8 @@
1
+ engine=$(ruby -e 'puts RUBY_ENGINE')
2
+
3
+ case $engine in
4
+ "ruby" )
5
+ bundle exec rake test cane;;
6
+ * )
7
+ bundle exec rake test;;
8
+ esac
@@ -0,0 +1,20 @@
1
+ require "test_helper"
2
+
3
+ describe Hakiri::HttpClient do
4
+ subject { Hakiri::HttpClient.new }
5
+
6
+ it { subject.must_respond_to :auth_token }
7
+ it { subject.must_respond_to :auth_token= }
8
+ it { subject.must_respond_to :api_url }
9
+ it { subject.must_respond_to :api_url= }
10
+
11
+ describe "#get_issues" do
12
+ end
13
+
14
+ describe "#check_versions_diff" do
15
+ end
16
+
17
+ describe "#sync_project_versions" do
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ require "test_helper"
2
+
3
+ describe Hakiri::Stack do
4
+ subject { Hakiri::Stack.new }
5
+
6
+ it { subject.must_respond_to :technologies }
7
+ it { subject.must_respond_to :technologies= }
8
+ it { subject.must_respond_to :default_command }
9
+ it { subject.must_respond_to :default_command= }
10
+
11
+ describe "#build_from_json_file" do
12
+ end
13
+
14
+ describe "#build_from_input" do
15
+ end
16
+
17
+ describe "#fetch_versions" do
18
+ end
19
+
20
+ end
@@ -0,0 +1,5 @@
1
+ require "test_helper"
2
+
3
+ describe Hakiri::Technology do
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ describe Hakiri do
4
+
5
+ it { Hakiri.must_be_kind_of Module }
6
+
7
+ end
@@ -0,0 +1,18 @@
1
+ begin
2
+ require "simplecov"
3
+ SimpleCov.start do
4
+ add_filter "test"
5
+ command_name "Minitest"
6
+ end
7
+ rescue LoadError
8
+ warn "unable to load 'simplecov'"
9
+ end
10
+
11
+ require "minitest/autorun"
12
+ require "minitest/pride"
13
+
14
+ require File.expand_path("../../lib/hakiri", __FILE__)
15
+
16
+ # Requires supporting ruby files with custom matchers and macros, etc,
17
+ # in test/support/ and its subdirectories.
18
+ Dir[File.join("./test/support/**/*.rb")].sort.each { |f| require f }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hakiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-04 00:00:00.000000000 Z
12
+ date: 2013-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -139,6 +139,22 @@ dependencies:
139
139
  - - ! '>='
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: minitest
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 5.0.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 5.0.0
142
158
  description: Hakiri is a CLI for www.hakiriup.com—a cloud security platform for Ruby
143
159
  on Rails apps.
144
160
  email: vasinov@me.com
@@ -148,6 +164,8 @@ extensions: []
148
164
  extra_rdoc_files: []
149
165
  files:
150
166
  - .gitignore
167
+ - .ruby-gemset
168
+ - .travis.yml
151
169
  - Gemfile
152
170
  - Gemfile.lock
153
171
  - LICENSE
@@ -157,6 +175,7 @@ files:
157
175
  - hakiri.gemspec
158
176
  - lib/hakiri.rb
159
177
  - lib/hakiri/cli/cli.rb
178
+ - lib/hakiri/cli/code.rb
160
179
  - lib/hakiri/cli/gemfile.rb
161
180
  - lib/hakiri/cli/manifest.json
162
181
  - lib/hakiri/cli/manifest.rb
@@ -177,11 +196,20 @@ files:
177
196
  - lib/hakiri/technologies/redis.rb
178
197
  - lib/hakiri/technologies/ruby.rb
179
198
  - lib/hakiri/technologies/ruby_on_rails.rb
180
- - lib/hakiri/technologies/technology.rb
181
199
  - lib/hakiri/technologies/thin.rb
182
200
  - lib/hakiri/technologies/trinidad.rb
183
201
  - lib/hakiri/technologies/unicorn.rb
202
+ - lib/hakiri/technology.rb
184
203
  - lib/hakiri/version.rb
204
+ - tasks/bundler.rake
205
+ - tasks/cane.rake
206
+ - tasks/test.rake
207
+ - test/ci/ci_runner.sh
208
+ - test/hakiri/http_client_test.rb
209
+ - test/hakiri/stack_test.rb
210
+ - test/hakiri/technology_test.rb
211
+ - test/hakiri_test.rb
212
+ - test/test_helper.rb
185
213
  homepage: https://www.hakiriup.com
186
214
  licenses:
187
215
  - MIT