-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update specs for Stack and Security sections (#138)
* 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
1 parent
b1c75db
commit 8866884
Showing
28 changed files
with
268 additions
and
4,997 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 43 additions & 40 deletions
83
spec/inquisition/outputter/doc/tpl/security/patch_level_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 6 additions & 17 deletions
23
spec/inquisition/outputter/doc/tpl/stack/collector_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
spec/inquisition/outputter/doc/tpl/stack/exception_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
64
spec/inquisition/outputter/doc/tpl/stack/instrumentation_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.