security-report-parser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +20 -0
- data/Rakefile +5 -0
- data/bin/security-report-parser +5 -0
- data/bin/stubs/autospec +16 -0
- data/bin/stubs/htmldiff +16 -0
- data/bin/stubs/ldiff +16 -0
- data/bin/stubs/rake +16 -0
- data/bin/stubs/rspec +16 -0
- data/lib/parser/checker.rb +37 -0
- data/lib/parser/cli.rb +19 -0
- data/lib/parser/config.rb +48 -0
- data/lib/parser/event.rb +38 -0
- data/lib/parser/event_description.rb +28 -0
- data/lib/parser/reporter.rb +45 -0
- data/lib/parser/sheet.rb +35 -0
- data/lib/parser/version.rb +7 -0
- data/lib/parser.rb +16 -0
- data/security-report-parser.gemspec +32 -0
- data/spec/fixtures/config.yml +4 -0
- data/spec/fixtures/fs.xls +0 -0
- data/spec/fixtures/full_config.yml +11 -0
- data/spec/parser/checker_spec.rb +30 -0
- data/spec/parser/config_spec.rb +31 -0
- data/spec/parser/event_description_spec.rb +23 -0
- data/spec/parser/event_spec.rb +28 -0
- data/spec/parser/reporter_spec.rb +46 -0
- data/spec/parser/sheet_spec.rb +15 -0
- data/spec/parser_spec.rb +29 -0
- data/spec/spec_helper.rb +7 -0
- metadata +224 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Timur Vafin
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Security Report Parser
|
|
2
|
+
|
|
3
|
+
Used to parse montly reports from our security guard.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
gem install security-report-parser
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
security-report-parser --config /path/to/configuration.yml /path/to/report.xls
|
|
12
|
+
|
|
13
|
+
## Contributing
|
|
14
|
+
|
|
15
|
+
1. Fork it
|
|
16
|
+
3. `bundle install --binstubs=bin/stubs --path=.bundle`
|
|
17
|
+
3. Create your feature branch (`git checkout -b my-new-feature`)
|
|
18
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
|
19
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
|
20
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/stubs/autospec
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# This file was generated by Bundler.
|
|
4
|
+
#
|
|
5
|
+
# The application 'autospec' is installed as part of a gem, and
|
|
6
|
+
# this file is here to facilitate running it.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'pathname'
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../Gemfile",
|
|
11
|
+
Pathname.new(__FILE__).realpath)
|
|
12
|
+
|
|
13
|
+
require 'rubygems'
|
|
14
|
+
require 'bundler/setup'
|
|
15
|
+
|
|
16
|
+
load Gem.bin_path('rspec-core', 'autospec')
|
data/bin/stubs/htmldiff
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# This file was generated by Bundler.
|
|
4
|
+
#
|
|
5
|
+
# The application 'htmldiff' is installed as part of a gem, and
|
|
6
|
+
# this file is here to facilitate running it.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'pathname'
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../Gemfile",
|
|
11
|
+
Pathname.new(__FILE__).realpath)
|
|
12
|
+
|
|
13
|
+
require 'rubygems'
|
|
14
|
+
require 'bundler/setup'
|
|
15
|
+
|
|
16
|
+
load Gem.bin_path('diff-lcs', 'htmldiff')
|
data/bin/stubs/ldiff
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# This file was generated by Bundler.
|
|
4
|
+
#
|
|
5
|
+
# The application 'ldiff' is installed as part of a gem, and
|
|
6
|
+
# this file is here to facilitate running it.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'pathname'
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../Gemfile",
|
|
11
|
+
Pathname.new(__FILE__).realpath)
|
|
12
|
+
|
|
13
|
+
require 'rubygems'
|
|
14
|
+
require 'bundler/setup'
|
|
15
|
+
|
|
16
|
+
load Gem.bin_path('diff-lcs', 'ldiff')
|
data/bin/stubs/rake
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# This file was generated by Bundler.
|
|
4
|
+
#
|
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
|
6
|
+
# this file is here to facilitate running it.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'pathname'
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../Gemfile",
|
|
11
|
+
Pathname.new(__FILE__).realpath)
|
|
12
|
+
|
|
13
|
+
require 'rubygems'
|
|
14
|
+
require 'bundler/setup'
|
|
15
|
+
|
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/stubs/rspec
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# This file was generated by Bundler.
|
|
4
|
+
#
|
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
|
6
|
+
# this file is here to facilitate running it.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'pathname'
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../Gemfile",
|
|
11
|
+
Pathname.new(__FILE__).realpath)
|
|
12
|
+
|
|
13
|
+
require 'rubygems'
|
|
14
|
+
require 'bundler/setup'
|
|
15
|
+
|
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'active_support/core_ext/date_time/calculations'
|
|
2
|
+
|
|
3
|
+
module Parser
|
|
4
|
+
class Checker
|
|
5
|
+
def self.unusual?(datetime)
|
|
6
|
+
new(datetime).unusual?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def initialize(datetime)
|
|
10
|
+
@datetime = datetime
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def unusual?
|
|
14
|
+
return true if weekend? || before? || after?
|
|
15
|
+
false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def weekend?
|
|
21
|
+
@datetime.saturday? || @datetime.sunday?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def before?
|
|
25
|
+
@datetime < datetime_at(Parser.configuration.from)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def after?
|
|
29
|
+
@datetime > datetime_at(Parser.configuration.till)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def datetime_at(time)
|
|
33
|
+
hour, minute = time.split(':')
|
|
34
|
+
@datetime.change(hour: hour.to_i, minute: minute.to_i)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/parser/cli.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'thor'
|
|
2
|
+
|
|
3
|
+
module Parser
|
|
4
|
+
class CLI < Thor
|
|
5
|
+
option :config
|
|
6
|
+
desc 'parse FILE', 'Parse report and show some unsual activity'
|
|
7
|
+
def parse(file)
|
|
8
|
+
if options[:config] && File.exists?(options[:config])
|
|
9
|
+
Parser.configuration.load!(options[:config])
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
Sheet.new(file).each_event do |event|
|
|
13
|
+
puts Parser::Reporter.report(event)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
default_task :parse
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'active_support/core_ext/hash/keys'
|
|
3
|
+
|
|
4
|
+
module Parser
|
|
5
|
+
class Config
|
|
6
|
+
DEFAULTS = {
|
|
7
|
+
from: '11:00',
|
|
8
|
+
till: '20:00',
|
|
9
|
+
users: {
|
|
10
|
+
1 => 'Timur Vafin',
|
|
11
|
+
2 => 'Alexey Mamaev',
|
|
12
|
+
3 => 'Oleg Kurnosov'
|
|
13
|
+
}
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
OPTIONS = [:from, :till, :users]
|
|
17
|
+
|
|
18
|
+
attr_accessor *OPTIONS
|
|
19
|
+
|
|
20
|
+
def initialize
|
|
21
|
+
reset!
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def load!(file)
|
|
25
|
+
config = config_from_file(file)
|
|
26
|
+
|
|
27
|
+
OPTIONS.each do |key|
|
|
28
|
+
set_option(key, config[key]) if config.include?(key)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def reset!
|
|
33
|
+
OPTIONS.each do |key|
|
|
34
|
+
set_option(key, DEFAULTS[key])
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def config_from_file(file)
|
|
41
|
+
@config_from_file ||= YAML.load(File.read(file)).symbolize_keys
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def set_option(key, value)
|
|
45
|
+
self.send("#{key}=", value)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/lib/parser/event.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Parser
|
|
4
|
+
class Event
|
|
5
|
+
DATETIME = '%s %s +0400'
|
|
6
|
+
PARSE_FORMAT = '%d/%m/%y %T %Z'
|
|
7
|
+
|
|
8
|
+
def initialize(date, time, description)
|
|
9
|
+
@date, @time, @description = date, time, description
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def datetime
|
|
13
|
+
@datetime ||= DateTime.strptime(DATETIME % [@date, @time], PARSE_FORMAT)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def description
|
|
17
|
+
@description
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def user_name
|
|
21
|
+
parsed_description.user_name
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def event_type
|
|
25
|
+
parsed_description.event_type
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def unusual?
|
|
29
|
+
Checker.unusual?(datetime)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def parsed_description
|
|
35
|
+
@parsed_description ||= EventDescription.new(description)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Parser
|
|
4
|
+
class EventDescription
|
|
5
|
+
def initialize(description)
|
|
6
|
+
@description = description.to_s
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def user_name
|
|
10
|
+
Parser.configuration.users[user_key] || 'Unknown User'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def event_type
|
|
14
|
+
return :open if @description.include?('Снятие')
|
|
15
|
+
return :close if @description.include?('Постановка')
|
|
16
|
+
|
|
17
|
+
:unknown
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def user_key
|
|
23
|
+
if match = @description.match(/\d+/)
|
|
24
|
+
match[0].to_i
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'ansi/code'
|
|
2
|
+
|
|
3
|
+
module Parser
|
|
4
|
+
class Reporter
|
|
5
|
+
EVENT_TYPE_COLORS = {
|
|
6
|
+
open: :green,
|
|
7
|
+
close: :blue,
|
|
8
|
+
unknown: :white
|
|
9
|
+
}.freeze
|
|
10
|
+
|
|
11
|
+
def self.report(event)
|
|
12
|
+
new(event).report
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def initialize(event)
|
|
16
|
+
@event = event
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def report
|
|
20
|
+
"#{datetime} #{user_name}: #{description}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def datetime
|
|
26
|
+
@event.datetime.strftime('%Y %b %e %a %T')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def user_name
|
|
30
|
+
with_color { @event.user_name }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def description
|
|
34
|
+
if @event.unusual?
|
|
35
|
+
ANSI.red { @event.description }
|
|
36
|
+
else
|
|
37
|
+
@event.description
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def with_color
|
|
42
|
+
ANSI.send(EVENT_TYPE_COLORS[@event.event_type]) { yield }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/parser/sheet.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spreadsheet'
|
|
2
|
+
|
|
3
|
+
module Parser
|
|
4
|
+
class Sheet
|
|
5
|
+
EVENT_CODE = '1914'
|
|
6
|
+
|
|
7
|
+
def initialize(file)
|
|
8
|
+
@file = file
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def events
|
|
12
|
+
@events ||= [].tap do |events|
|
|
13
|
+
worksheet.each do |row|
|
|
14
|
+
events << Event.new(row[4], row[5], row[10]) if row_is_event?(row)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def each_event
|
|
20
|
+
events.each do |event|
|
|
21
|
+
yield(event)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def worksheet
|
|
28
|
+
@worksheet ||= Spreadsheet.open(@file).worksheet(0)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def row_is_event?(row)
|
|
32
|
+
row[1] == EVENT_CODE
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/parser.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'parser/version'
|
|
2
|
+
require 'parser/config'
|
|
3
|
+
require 'parser/checker'
|
|
4
|
+
require 'parser/event_description'
|
|
5
|
+
require 'parser/event'
|
|
6
|
+
require 'parser/reporter'
|
|
7
|
+
require 'parser/sheet'
|
|
8
|
+
require 'parser/cli'
|
|
9
|
+
|
|
10
|
+
module Parser
|
|
11
|
+
extend self
|
|
12
|
+
|
|
13
|
+
def configuration
|
|
14
|
+
@configuration ||= Config.new
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
|
|
6
|
+
require 'parser/version'
|
|
7
|
+
|
|
8
|
+
Gem::Specification.new do |spec|
|
|
9
|
+
spec.name = 'security-report-parser'
|
|
10
|
+
spec.version = Security::Report::Parser::VERSION
|
|
11
|
+
spec.authors = ["Timur Vafin"]
|
|
12
|
+
spec.email = ["timur.vafin@flatstack.com"]
|
|
13
|
+
spec.description = %q{Used to parse montly reports from our security guard.}
|
|
14
|
+
spec.summary = %q{Used to parse montly reports from our security guard.}
|
|
15
|
+
spec.homepage = ''
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files`.split($/)
|
|
19
|
+
spec.executables = spec.files.grep(%r{^/bin/}) { |f| File.basename(f) }
|
|
20
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
|
21
|
+
spec.require_paths = ['lib']
|
|
22
|
+
|
|
23
|
+
spec.add_dependency 'activesupport'
|
|
24
|
+
spec.add_dependency 'spreadsheet'
|
|
25
|
+
spec.add_dependency 'ansi'
|
|
26
|
+
spec.add_dependency 'thor'
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
|
29
|
+
spec.add_development_dependency 'rake'
|
|
30
|
+
spec.add_development_dependency 'rspec'
|
|
31
|
+
spec.add_development_dependency 'debugger'
|
|
32
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Parser::Checker do
|
|
4
|
+
subject(:checker) do
|
|
5
|
+
->(datetime) { Parser::Checker.unusual?(DateTime.parse(datetime)) }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context 'on weekends' do
|
|
9
|
+
it 'detects unusual at any time' do
|
|
10
|
+
expect(checker['2013-04-13 02:00']).to eq(true)
|
|
11
|
+
expect(checker['2013-04-14 12:00']).to eq(true)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context 'on workdays' do
|
|
16
|
+
it 'detects unusual time before 11:00' do
|
|
17
|
+
expect(checker['2013-04-10 09:00']).to eq(true)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'detects unusual time after 20:00' do
|
|
21
|
+
expect(checker['2013-04-10 21:00']).to eq(true)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'detects usual time between 11:00-20:00' do
|
|
25
|
+
expect(checker['2013-04-10 11:00']).to eq(false)
|
|
26
|
+
expect(checker['2013-04-10 15:00']).to eq(false)
|
|
27
|
+
expect(checker['2013-04-10 20:00']).to eq(false)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Parser::Config do
|
|
4
|
+
subject(:config) { Parser::Config.new }
|
|
5
|
+
|
|
6
|
+
context 'without configuration file' do
|
|
7
|
+
let(:file) { nil }
|
|
8
|
+
|
|
9
|
+
it 'set default values' do
|
|
10
|
+
expect(config.from).to eq('11:00')
|
|
11
|
+
expect(config.till).to eq('20:00')
|
|
12
|
+
expect(config.users).to eq({
|
|
13
|
+
1 => 'Timur Vafin',
|
|
14
|
+
2 => 'Alexey Mamaev',
|
|
15
|
+
3 => 'Oleg Kurnosov'
|
|
16
|
+
})
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'with configuration file' do
|
|
21
|
+
before do
|
|
22
|
+
config.load!('spec/fixtures/config.yml')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'set values from file' do
|
|
26
|
+
expect(config.from).to eq('8:00')
|
|
27
|
+
expect(config.till).to eq('23:00')
|
|
28
|
+
expect(config.users).to eq({1 => 'John Smith'})
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Parser::EventDescription do
|
|
6
|
+
subject(:description) do
|
|
7
|
+
->(description) { Parser::EventDescription.new(description) }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'parse user name' do
|
|
11
|
+
expect(description['Снятие с охраны ключом 1'].user_name).to eq('Timur Vafin')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'parse event type' do
|
|
15
|
+
expect(description['Снятие с охраны ключом 1'].event_type).to eq(:open)
|
|
16
|
+
expect(description['Постановка с охраны ключом 1'].event_type).to eq(:close)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'show unknown user name' do
|
|
20
|
+
expect(description['Снятие с охраны ключом 123'].user_name).to eq('Unknown User')
|
|
21
|
+
expect(description['Invalid string'].user_name).to eq('Unknown User')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Parser::Event do
|
|
6
|
+
subject(:event) { Parser::Event.new('02/03/13', '08:32:38', 'Снятие с охраны ключом 1') }
|
|
7
|
+
|
|
8
|
+
it 'datetime' do
|
|
9
|
+
expect(event.datetime.to_s).to eq('2013-03-02T08:32:38+04:00')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'description' do
|
|
13
|
+
expect(event.description).to eq('Снятие с охраны ключом 1')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'type' do
|
|
17
|
+
expect(event.event_type).to eq(:open)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'user name' do
|
|
21
|
+
expect(event.user_name).to eq('Timur Vafin')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'determines unsual' do
|
|
25
|
+
Parser::Checker.should_receive(:unusual?).with(event.datetime) { true }
|
|
26
|
+
expect(event.unusual?).to eql(true)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Parser::Reporter do
|
|
6
|
+
let(:event) do
|
|
7
|
+
double(Parser::Event,
|
|
8
|
+
datetime: double(strftime: 'datetime'),
|
|
9
|
+
user_name: 'user_name',
|
|
10
|
+
description: 'description',
|
|
11
|
+
unusual?: false
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
subject(:report) { Parser::Reporter.report(event) }
|
|
16
|
+
|
|
17
|
+
context 'open' do
|
|
18
|
+
before do
|
|
19
|
+
event.stub(:event_type) { :open }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'report' do
|
|
23
|
+
expect(report).to eq("datetime \e[32muser_name\e[0m: description")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'close' do
|
|
28
|
+
before do
|
|
29
|
+
event.stub(:event_type) { :close }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'report' do
|
|
33
|
+
expect(report).to eq("datetime \e[34muser_name\e[0m: description")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'unusual' do
|
|
37
|
+
before do
|
|
38
|
+
event.stub(:unusual?) { true }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'report' do
|
|
42
|
+
expect(report).to eq("datetime \e[34muser_name\e[0m: \e[31mdescription\e[0m")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Parser::Sheet do
|
|
4
|
+
let(:sheet) { Parser::Sheet.new('spec/fixtures/fs.xls') }
|
|
5
|
+
|
|
6
|
+
it 'collect events' do
|
|
7
|
+
expect(sheet.events.size).to eq(52)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'iterates over events' do
|
|
11
|
+
sheet.each_event do |event|
|
|
12
|
+
expect(event).to be_an_instance_of(Parser::Event)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/spec/parser_spec.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Parser do
|
|
4
|
+
describe '.configuration' do
|
|
5
|
+
subject(:config) { Parser.configuration }
|
|
6
|
+
|
|
7
|
+
it 'instance of Config' do
|
|
8
|
+
expect(config).to be_an_instance_of(Parser::Config)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'have options' do
|
|
12
|
+
expect(config.from).to eq('11:00')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context 'with config file' do
|
|
16
|
+
before do
|
|
17
|
+
config.load!('spec/fixtures/config.yml')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'load config file' do
|
|
21
|
+
expect(config.from).to eq('8:00')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'reset defaults' do
|
|
25
|
+
expect { config.reset! }.to change { config.from }.from('8:00').to('11:00')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: security-report-parser
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.0.1
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Timur Vafin
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: activesupport
|
|
16
|
+
type: :runtime
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
none: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ! '>='
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '0'
|
|
28
|
+
none: false
|
|
29
|
+
prerelease: false
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: spreadsheet
|
|
32
|
+
type: :runtime
|
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
none: false
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
none: false
|
|
45
|
+
prerelease: false
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: ansi
|
|
48
|
+
type: :runtime
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
none: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ! '>='
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0'
|
|
60
|
+
none: false
|
|
61
|
+
prerelease: false
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: thor
|
|
64
|
+
type: :runtime
|
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
none: false
|
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ! '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
none: false
|
|
77
|
+
prerelease: false
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
79
|
+
name: bundler
|
|
80
|
+
type: :development
|
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ~>
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '1.3'
|
|
86
|
+
none: false
|
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - ~>
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: '1.3'
|
|
92
|
+
none: false
|
|
93
|
+
prerelease: false
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: rake
|
|
96
|
+
type: :development
|
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ! '>='
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
none: false
|
|
103
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ! '>='
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
none: false
|
|
109
|
+
prerelease: false
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rspec
|
|
112
|
+
type: :development
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ! '>='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
none: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ! '>='
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
none: false
|
|
125
|
+
prerelease: false
|
|
126
|
+
- !ruby/object:Gem::Dependency
|
|
127
|
+
name: debugger
|
|
128
|
+
type: :development
|
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
|
130
|
+
requirements:
|
|
131
|
+
- - ! '>='
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: '0'
|
|
134
|
+
none: false
|
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - ! '>='
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '0'
|
|
140
|
+
none: false
|
|
141
|
+
prerelease: false
|
|
142
|
+
description: Used to parse montly reports from our security guard.
|
|
143
|
+
email:
|
|
144
|
+
- timur.vafin@flatstack.com
|
|
145
|
+
executables: []
|
|
146
|
+
extensions: []
|
|
147
|
+
extra_rdoc_files: []
|
|
148
|
+
files:
|
|
149
|
+
- .gitignore
|
|
150
|
+
- .rspec
|
|
151
|
+
- Gemfile
|
|
152
|
+
- LICENSE.txt
|
|
153
|
+
- README.md
|
|
154
|
+
- Rakefile
|
|
155
|
+
- bin/security-report-parser
|
|
156
|
+
- bin/stubs/autospec
|
|
157
|
+
- bin/stubs/htmldiff
|
|
158
|
+
- bin/stubs/ldiff
|
|
159
|
+
- bin/stubs/rake
|
|
160
|
+
- bin/stubs/rspec
|
|
161
|
+
- lib/parser.rb
|
|
162
|
+
- lib/parser/checker.rb
|
|
163
|
+
- lib/parser/cli.rb
|
|
164
|
+
- lib/parser/config.rb
|
|
165
|
+
- lib/parser/event.rb
|
|
166
|
+
- lib/parser/event_description.rb
|
|
167
|
+
- lib/parser/reporter.rb
|
|
168
|
+
- lib/parser/sheet.rb
|
|
169
|
+
- lib/parser/version.rb
|
|
170
|
+
- security-report-parser.gemspec
|
|
171
|
+
- spec/fixtures/config.yml
|
|
172
|
+
- spec/fixtures/fs.xls
|
|
173
|
+
- spec/fixtures/full_config.yml
|
|
174
|
+
- spec/parser/checker_spec.rb
|
|
175
|
+
- spec/parser/config_spec.rb
|
|
176
|
+
- spec/parser/event_description_spec.rb
|
|
177
|
+
- spec/parser/event_spec.rb
|
|
178
|
+
- spec/parser/reporter_spec.rb
|
|
179
|
+
- spec/parser/sheet_spec.rb
|
|
180
|
+
- spec/parser_spec.rb
|
|
181
|
+
- spec/spec_helper.rb
|
|
182
|
+
homepage: ''
|
|
183
|
+
licenses:
|
|
184
|
+
- MIT
|
|
185
|
+
post_install_message:
|
|
186
|
+
rdoc_options: []
|
|
187
|
+
require_paths:
|
|
188
|
+
- lib
|
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
|
+
requirements:
|
|
191
|
+
- - ! '>='
|
|
192
|
+
- !ruby/object:Gem::Version
|
|
193
|
+
segments:
|
|
194
|
+
- 0
|
|
195
|
+
hash: 4567418744484905582
|
|
196
|
+
version: '0'
|
|
197
|
+
none: false
|
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
|
+
requirements:
|
|
200
|
+
- - ! '>='
|
|
201
|
+
- !ruby/object:Gem::Version
|
|
202
|
+
segments:
|
|
203
|
+
- 0
|
|
204
|
+
hash: 4567418744484905582
|
|
205
|
+
version: '0'
|
|
206
|
+
none: false
|
|
207
|
+
requirements: []
|
|
208
|
+
rubyforge_project:
|
|
209
|
+
rubygems_version: 1.8.23
|
|
210
|
+
signing_key:
|
|
211
|
+
specification_version: 3
|
|
212
|
+
summary: Used to parse montly reports from our security guard.
|
|
213
|
+
test_files:
|
|
214
|
+
- spec/fixtures/config.yml
|
|
215
|
+
- spec/fixtures/fs.xls
|
|
216
|
+
- spec/fixtures/full_config.yml
|
|
217
|
+
- spec/parser/checker_spec.rb
|
|
218
|
+
- spec/parser/config_spec.rb
|
|
219
|
+
- spec/parser/event_description_spec.rb
|
|
220
|
+
- spec/parser/event_spec.rb
|
|
221
|
+
- spec/parser/reporter_spec.rb
|
|
222
|
+
- spec/parser/sheet_spec.rb
|
|
223
|
+
- spec/parser_spec.rb
|
|
224
|
+
- spec/spec_helper.rb
|