Skip to content

Commit

Permalink
Update specs for Stack and Security sections (#138)
Browse files Browse the repository at this point in the history
* Rename produce shared example to produceable

* Update specs for PatchLevel class

* Update specs for Collector class

* Update specs for Exception class

* Update specs for Instrumentation class

* Update specs for Jobs class

* Cleanup

* Add missing specs for exception & instrumentation views

* Remove public folder

* Fix CodeClimate issues

* Fix mistake
  • Loading branch information
chubchenko authored and rostikkkk2 committed Dec 26, 2019
1 parent b1c75db commit 8866884
Show file tree
Hide file tree
Showing 28 changed files with 268 additions and 4,997 deletions.
2 changes: 1 addition & 1 deletion lib/inquisition/outputter/doc/tpl/security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def brakeman
end

def patch_level
@bundler_audit ||= begin
@patch_level ||= begin
Template.new('security/patch_level').render(PatchLevel.call(@issues))
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/inquisition/outputter/doc/tpl/security/patch_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class PatchLevel
class Wrapper < SimpleDelegator
def group
group_by do |issue|
context = issue.context

OpenStruct.new(
name: issue.context.name,
homepage: issue.context.__materialize__&.homepage
name: context.name,
homepage: context.__materialize__&.homepage
)
end
end
Expand Down
28 changes: 12 additions & 16 deletions lib/inquisition/outputter/doc/tpl/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,23 @@ def db
end

def jobs
@jobs || begin
@jobs ||= begin
Template.new('stack/jobs').render(Stack::Jobs.new)
end
end

def exception_and_instrumentation
@exception_and_instrumentation ||= begin
Template.new('stack/exception_and_instrumentation').render(
Class.new do
def produce
binding
end

def exception
Exception.new
end
def exception
@exception ||= begin
Template.new('stack/exception').render(
Exception.new
)
end
end

def instrumentation
Instrumentation.new
end
end.new
def instrumentation
@instrumentation ||= begin
Template.new('stack/instrumentation').render(
Instrumentation.new
)
end
end
Expand Down
17 changes: 0 additions & 17 deletions public/application.css

This file was deleted.

119 changes: 0 additions & 119 deletions public/application.js

This file was deleted.

Binary file removed public/webfonts/fa-solid-900.eot
Binary file not shown.
4,649 changes: 0 additions & 4,649 deletions public/webfonts/fa-solid-900.svg

This file was deleted.

Binary file removed public/webfonts/fa-solid-900.ttf
Binary file not shown.
Binary file removed public/webfonts/fa-solid-900.woff
Binary file not shown.
Binary file removed public/webfonts/fa-solid-900.woff2
Binary file not shown.
4 changes: 3 additions & 1 deletion spec/inquisition/outputter/doc/tpl/home_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
RSpec.describe Inquisition::Outputter::Doc::TPL::Home do
include_examples 'produce', described_class.new
include_examples 'produceable' do
subject(:tpl) { described_class.new }
end

subject(:home) { described_class.new }

Expand Down
4 changes: 3 additions & 1 deletion spec/inquisition/outputter/doc/tpl/layout_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
RSpec.describe Inquisition::Outputter::Doc::TPL::Layout do
include_examples 'produce', described_class.new([])
include_examples 'produceable' do
subject(:tpl) { described_class.new([]) }
end

describe '#home' do
subject(:layout) { described_class.new([]) }
Expand Down
4 changes: 3 additions & 1 deletion spec/inquisition/outputter/doc/tpl/security/brakeman_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
RSpec.describe Inquisition::Outputter::Doc::TPL::Security::Brakeman do
include_examples 'produce', described_class.new([])
include_examples 'produceable' do
subject(:tpl) { described_class.new([]) }
end

describe '.call' do
let(:issue) do
Expand Down
83 changes: 43 additions & 40 deletions spec/inquisition/outputter/doc/tpl/security/patch_level_spec.rb
Original file line number Diff line number Diff line change
@@ -1,63 +1,66 @@
RSpec.describe Inquisition::Outputter::Doc::TPL::Security::PatchLevel do
include_examples 'produce', described_class.new([])
include_examples 'produceable' do
subject(:tpl) { described_class.new([]) }
end

describe '.call' do
let(:issue) do
Inquisition::Issue.new(
category: Inquisition::Category::SECURITY,
path: 'app/controllers/users_controller.rb',
line: 42,
severity: Inquisition::Severity::HIGH,
message: 'Potentially dangerous key allowed for mass assignment',
context: 'Cross-Site Scripting',
runner: Inquisition::Bundler::Audit::Runner.new
)
end
let(:issue) { instance_double(Inquisition::Issue) }
let(:collector) { instance_double(Inquisition::Outputter::Doc::TPL::Security::Collector) }
let(:wrapper) { instance_double(described_class::Wrapper) }
let(:wrapper) { instance_double(Inquisition::Outputter::Doc::TPL::Security::PatchLevel::Wrapper) }

before do
allow(described_class::Wrapper).to receive(:new).and_return(wrapper)
allow(Inquisition::Outputter::Doc::TPL::Security::Collector).to receive(:new).and_return(collector)
allow(collector).to receive(:call).and_return([issue])
allow(Inquisition::Outputter::Doc::TPL::Security::PatchLevel::Wrapper).to receive(:new).and_return(wrapper)
allow(described_class).to receive(:new)

described_class.call([issue])
end

it do
expect(described_class::Wrapper).to have_received(:new).with(
[issue]
expect(Inquisition::Outputter::Doc::TPL::Security::Collector).to have_received(:new).with(
[issue], Inquisition::Bundler::Audit::Runner
)
end

it { expect(described_class).to have_received(:new).with(wrapper) }
end

describe Inquisition::Outputter::Doc::TPL::Security::PatchLevel::Wrapper do
subject(:wrapper) { described_class.new([issue, issue]) }

let(:gem) { instance_double(Bundler::LazySpecification, name: 'test') }
let(:stub) { double(Bundler::StubSpecification, homepage: 'test') }
let(:struct) { double(OpenStruct, name: gem.name, homepage: stub.homepage) }
let(:result) { { struct => [issue, issue] } }
let(:issue) do
Inquisition::Issue.new(
category: Inquisition::Category::SECURITY,
path: 'app/controllers/users_controller.rb',
line: 42,
severity: Inquisition::Severity::HIGH,
message: 'Potentially dangerous key allowed for mass assignment',
context: gem,
runner: Inquisition::Bundler::Audit::Runner.new
)
it do
expect(
Inquisition::Outputter::Doc::TPL::Security::PatchLevel::Wrapper
).to have_received(:new).with([issue])
end

before do
allow(OpenStruct).to receive(:new).with(name: gem.name, homepage: stub.homepage).and_return(struct)
allow(gem).to receive(:__materialize__).and_return(stub)
it do
expect(
described_class
).to have_received(:new).with(wrapper)
end
end

describe Inquisition::Outputter::Doc::TPL::Security::PatchLevel::Wrapper do
describe '#group' do
it { expect(wrapper.group).to eq(result) }
subject(:wrapper) { described_class.new([issue, issue]) }

let(:issue) do
Inquisition::Issue.new(
path: nil,
line: nil,
severity: Inquisition::Severity::HIGH,
category: Inquisition::Category::SECURITY,
message: 'Loofah XSS Vulnerability',
runner: nil,
context: context
)
end
let(:context) do
instance_double(Bundler::LazySpecification,
name: 'loofah',
__materialize__: double(:__materialize__, homepage: 'https://github.com/flavorjones/loofah'))
end
let(:gem) do
OpenStruct.new(name: 'loofah', homepage: 'https://github.com/flavorjones/loofah')
end

it { expect(wrapper.group).to eq(gem => [issue, issue]) }
end
end
end
4 changes: 3 additions & 1 deletion spec/inquisition/outputter/doc/tpl/security_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
RSpec.describe Inquisition::Outputter::Doc::TPL::Security do
include_examples 'produce', described_class.new([])
include_examples 'produceable' do
subject(:tpl) { described_class.new([]) }
end

describe '#brakeman' do
subject(:security) { described_class.new([]) }
Expand Down
23 changes: 6 additions & 17 deletions spec/inquisition/outputter/doc/tpl/stack/collector_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
RSpec.describe Inquisition::Outputter::Doc::TPL::Stack::Collector do
describe '#call' do
subject(:call) { described_class.new([gem]).call }
subject(:collector) { described_class.new(%w[rails puma]) }

let(:gem) { 'sidekiq' }
let(:homepage) { 'test' }
let(:stub) { double('Bundler::StubSpecification', name: gem, homepage: homepage) }
let(:bundler_runtime) { instance_double('Bundler::Runtime', specs: { gem => stub }) }
let(:struct) { double(OpenStruct, name: gem, homepage: homepage) }

before do
stub_const('RUBY_PLATFORM', 'x86_64-linux')
allow(Bundler).to receive(:load).and_return(bundler_runtime)
allow(OpenStruct).to receive(:new).with(name: gem, homepage: homepage).and_return(struct)
allow(bundler_runtime.specs).to receive(:find_by_name_and_platform).with(gem, RUBY_PLATFORM).and_return(stub)
call
end

it 'returns OpenStruct data' do
expect(call).to contain_exactly(struct)
it do
expect(collector.call(type: :gem)).to contain_exactly(
OpenStruct.new(name: 'rails', homepage: 'http://rubyonrails.org', type: :gem),
OpenStruct.new(name: 'puma', homepage: 'http://puma.io', type: :gem)
)
end
end
end
58 changes: 51 additions & 7 deletions spec/inquisition/outputter/doc/tpl/stack/exception_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,59 @@
RSpec.describe Inquisition::Outputter::Doc::TPL::Stack::Exception do
include_examples 'produce', described_class.new
include_examples 'produceable' do
subject(:tpl) { described_class.new }
end

include_examples 'collection'
describe '#collection' do
subject(:exception) { described_class.new }

include_examples 'empty?'
let(:collector) { instance_double(Inquisition::Outputter::Doc::TPL::Stack::Collector) }

describe '#trouble' do
subject(:trouble) { described_class.new.trouble }
before do
allow(Inquisition::Outputter::Doc::TPL::Stack::Collector).to receive(:new).with(
described_class::KNOWN
).and_return(collector)
allow(collector).to receive(:call).with(description: described_class::DESCRIPTION).and_return([])

exception.collection
end

it do
expect(Inquisition::Outputter::Doc::TPL::Stack::Collector).to have_received(:new).with(described_class::KNOWN)
end

it { expect(collector).to have_received(:call).with(description: described_class::DESCRIPTION) }
end

describe '#empty?' do
subject(:exception) { described_class.new }

let(:collector) { instance_double(Inquisition::Outputter::Doc::TPL::Stack::Collector) }

it 'returns instance of NoExceptionPkg' do
expect(trouble).to be_an_instance_of(Inquisition::Outputter::Doc::TPL::Stack::NoExceptionPkg)
before do
allow(Inquisition::Outputter::Doc::TPL::Stack::Collector).to receive(:new).with(
described_class::KNOWN
).and_return(collector)
allow(collector).to receive(:call).with(description: described_class::DESCRIPTION).and_return(collection)
end

context 'when there is at least one used gem' do
let(:collection) do
[OpenStruct.new(name: 'airbrake', homepage: 'https://airbrake.io/', description: described_class::DESCRIPTION)]
end

it { is_expected.not_to be_empty }
end

context 'when there are no used gems' do
let(:collection) { [] }

it { is_expected.to be_empty }
end
end

describe '#trouble' do
subject(:exception) { described_class.new }

it { expect(exception.trouble).to be_an_instance_of(Inquisition::Outputter::Doc::TPL::Stack::NoExceptionPkg) }
end
end
64 changes: 57 additions & 7 deletions spec/inquisition/outputter/doc/tpl/stack/instrumentation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,65 @@
RSpec.describe Inquisition::Outputter::Doc::TPL::Stack::Instrumentation do
include_examples 'produce', described_class.new
include_examples 'produceable' do
subject(:tpl) { described_class.new }
end

include_examples 'collection'
describe '#collection' do
subject(:exception) { described_class.new }

include_examples 'empty?'
let(:collector) { instance_double(Inquisition::Outputter::Doc::TPL::Stack::Collector) }

describe '#trouble' do
subject(:trouble) { described_class.new.trouble }
before do
allow(Inquisition::Outputter::Doc::TPL::Stack::Collector).to receive(:new).with(
described_class::KNOWN
).and_return(collector)
allow(collector).to receive(:call).with(description: described_class::DESCRIPTION).and_return([])

exception.collection
end

it do
expect(Inquisition::Outputter::Doc::TPL::Stack::Collector).to have_received(:new).with(described_class::KNOWN)
end

it { expect(collector).to have_received(:call).with(description: described_class::DESCRIPTION) }
end

describe '#empty?' do
subject(:exception) { described_class.new }

let(:collector) { instance_double(Inquisition::Outputter::Doc::TPL::Stack::Collector) }

it 'returns instance of NoInstrumentationPkg' do
expect(trouble).to be_an_instance_of(Inquisition::Outputter::Doc::TPL::Stack::NoInstrumentationPkg)
before do
allow(Inquisition::Outputter::Doc::TPL::Stack::Collector).to receive(:new).with(
described_class::KNOWN
).and_return(collector)
allow(collector).to receive(:call).with(description: described_class::DESCRIPTION).and_return(collection)
end

context 'when there is at least one used gem' do
let(:collection) do
[
OpenStruct.new(
name: 'skylight',
homepage: 'https://www.skylight.io/',
description: described_class::DESCRIPTION
)
]
end

it { is_expected.not_to be_empty }
end

context 'when there are no used gems' do
let(:collection) { [] }

it { is_expected.to be_empty }
end
end

describe '#trouble' do
subject(:exception) { described_class.new }

it { expect(exception.trouble).to be_an_instance_of(Inquisition::Outputter::Doc::TPL::Stack::NoInstrumentationPkg) }
end
end
Loading

0 comments on commit 8866884

Please sign in to comment.