fuzzbert 1.0.0

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.
@@ -0,0 +1,113 @@
1
+ require 'rspec'
2
+ require 'fuzzbert'
3
+
4
+ describe FuzzBert::Executor do
5
+
6
+ describe "new" do
7
+ let(:test) do
8
+ test = FuzzBert::Test.new(lambda { |data| data })
9
+ FuzzBert::TestSuite.create("suite") do
10
+ deploy { |data| data }
11
+ data("1") { FuzzBert::Generators.random }
12
+ end
13
+ end
14
+
15
+ it "takes a mandatory (array of) TestSuite as first argument" do
16
+ -> { FuzzBert::Executor.new }.should raise_error ArgumentError
17
+ FuzzBert::Executor.new(test).should be_an_instance_of(FuzzBert::Executor)
18
+ FuzzBert::Executor.new([test]).should be_an_instance_of(FuzzBert::Executor)
19
+ end
20
+
21
+ it "allows a pool_size argument" do
22
+ size = 1
23
+ executor = FuzzBert::Executor.new(test, pool_size: size)
24
+ executor.pool_size.should == size
25
+ end
26
+
27
+ it "allows a limit argument" do
28
+ limit = 42
29
+ executor = FuzzBert::Executor.new(test, limit: limit)
30
+ executor.limit.should == limit
31
+ end
32
+
33
+ it "allows a handler argument" do
34
+ handler = FuzzBert::Handler::Console.new
35
+ executor = FuzzBert::Executor.new(test, handler: handler)
36
+ executor.handler.should == handler
37
+ end
38
+
39
+ it "defaults pool_size to 4" do
40
+ FuzzBert::Executor.new(test).pool_size.should == 4
41
+ end
42
+
43
+ it "defaults limit to -1" do
44
+ FuzzBert::Executor.new(test).limit.should == -1
45
+ end
46
+
47
+ it "defaults handler to a FileOutputHandler" do
48
+ FuzzBert::Executor.new(test).handler.should be_an_instance_of(FuzzBert::Handler::FileOutput)
49
+ end
50
+ end
51
+
52
+ describe "#run" do
53
+ subject { FuzzBert::Executor.new(suite, pool_size: 1, limit: 1, handler: handler).run }
54
+
55
+ class TestHandler
56
+ def initialize(&blk)
57
+ @handler = blk
58
+ end
59
+
60
+ def handle(id, data, pid, status)
61
+ @handler.call(id, data, pid, status)
62
+ end
63
+ end
64
+
65
+ context "doesn't complain when test succeeds" do
66
+ let (:suite) do
67
+ FuzzBert::TestSuite.create("suite") do
68
+ deploy { |data| data }
69
+ data("1") { -> { "a" } }
70
+ end
71
+ end
72
+ let (:handler) { TestHandler.new { |i, d, p, s| raise RuntimeError.new } }
73
+ it { -> { subject }.should_not raise_error }
74
+ end
75
+
76
+ context "reports an unrescued exception" do
77
+ called = false
78
+ let (:suite) do
79
+ FuzzBert::TestSuite.create("suite") do
80
+ deploy { |data| raise "boo!" }
81
+ data("1") { -> { "a" } }
82
+ end
83
+ end
84
+ let (:handler) { TestHandler.new { |i, d, p, s| called = true } }
85
+ it { -> { subject }.should_not raise_error; called.should be_true }
86
+ end
87
+
88
+ context "allows rescued exceptions" do
89
+ let (:suite) do
90
+ FuzzBert::TestSuite.create("suite") do
91
+ deploy { |data| begin; raise "boo!"; rescue RuntimeError; end }
92
+ data("1") { -> { "a" } }
93
+ end
94
+ end
95
+ let (:handler) { TestHandler.new { |i, d, p, s| raise RuntimeError.new } }
96
+ it { -> { subject }.should_not raise_error }
97
+ end
98
+
99
+ context "can handle SEGV" do
100
+ called = false
101
+ let (:suite) do
102
+ FuzzBert::TestSuite.create("suite") do
103
+ deploy { |data| Process.kill(:SEGV, Process.pid) }
104
+ data("1") { -> { "a" } }
105
+ end
106
+ end
107
+ let (:handler) { TestHandler.new { |i, d, p, s| called = true } }
108
+ let (:generator) { FuzzBert::Generator.new("test") { "a" } }
109
+ it { -> { subject }.should_not raise_error; called.should be_true }
110
+ end if false #don't want to SEGV every time
111
+ end
112
+
113
+ end
@@ -0,0 +1,25 @@
1
+ require 'rspec'
2
+ require 'fuzzbert'
3
+
4
+ describe FuzzBert::Generator do
5
+
6
+ describe "new" do
7
+ it "takes a description and a generator" do
8
+ desc = "desc"
9
+ value = "test"
10
+ gen = FuzzBert::Generator.new(desc, FuzzBert::Generators.fixed(value))
11
+ gen.description.should == desc
12
+ gen.to_data.should == value
13
+ end
14
+
15
+ it "takes a block that is executed when to_data is called when no explicit generator is given" do
16
+ value = "test"
17
+ desc = "desc"
18
+ gen = FuzzBert::Generator.new(desc) { value }
19
+ gen.description.should == desc
20
+ gen.to_data.should == value
21
+ end
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,32 @@
1
+ require 'rspec'
2
+ require 'fuzzbert'
3
+
4
+ describe FuzzBert::Mutator do
5
+
6
+ describe "new" do
7
+ it "takes a (valid) base value" do
8
+ value = "test"
9
+ mut = FuzzBert::Mutator.new(value)
10
+ end
11
+ end
12
+
13
+ it "includes Generation" do
14
+ mut = FuzzBert::Mutator.new("value")
15
+ mut.generator.should_not be_nil
16
+ end
17
+
18
+ describe "#to_data" do
19
+ it "mutates the base value in exactly one position" do
20
+ value = "FuzzBert"
21
+ mut = FuzzBert::Mutator.new(value)
22
+ mutated = mut.to_data
23
+ diff = 0
24
+ value.each_byte.each_with_index do |b, i|
25
+ diff += 1 unless b == mutated[i].ord
26
+ end
27
+ diff.should == 1
28
+ end
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,84 @@
1
+ require 'rspec'
2
+ require 'fuzzbert'
3
+
4
+ describe FuzzBert::Template do
5
+
6
+ describe "new" do
7
+ it "takes a String parameter" do
8
+ FuzzBert::Template.new("test").should be_an_instance_of(FuzzBert::Template)
9
+ end
10
+ end
11
+
12
+ describe "set" do
13
+ it "allows to define callbacks for template variables" do
14
+ t = FuzzBert::Template.new "a${var}c"
15
+ t.set(:var) { "b" }
16
+ t.to_data.should == "abc"
17
+ end
18
+
19
+ it "takes only Symbols to reference the template variables" do
20
+ t = FuzzBert::Template.new "a${var}c"
21
+ t.set("var") { "b" }
22
+ -> { t.to_data }.should raise_error
23
+ end
24
+ end
25
+
26
+ describe "to_data" do
27
+ it "can replace multiple template variables that possess a callback defined by set" do
28
+ t = FuzzBert::Template.new "a${var1}c${var2}"
29
+ t.set(:var1) { "b" }
30
+ t.set(:var2) { "d" }
31
+ t.to_data.should == "abcd"
32
+ end
33
+
34
+ specify "the dollar sign can be escaped with a backslash" do
35
+ t = FuzzBert::Template.new "a\\${var}c"
36
+ t.to_data.should == "a${var}c"
37
+ end
38
+
39
+ specify "a backslash can be escaped with another backslash" do
40
+ t = FuzzBert::Template.new "a\\\\c"
41
+ t.to_data.should == "a\\c"
42
+ end
43
+
44
+ it "raises an error if no closing brace is found for an open one" do
45
+ -> { FuzzBert::Template.new "a${bc" }.should raise_error
46
+ end
47
+
48
+ it "does allow curly braces within a template variable identifier" do
49
+ t = FuzzBert::Template.new "a${v{ar}c"
50
+ t.set("v{ar".to_sym) { "b" }
51
+ t.to_data.should == "abc"
52
+ end
53
+
54
+ it "does allow backslashes within a template variable identifier" do
55
+ t = FuzzBert::Template.new "a${v\\ar}c"
56
+ t.set("v\\ar".to_sym) { "b" }
57
+ t.to_data.should == "abc"
58
+ end
59
+
60
+ it "allows text only" do
61
+ t = FuzzBert::Template.new "abc"
62
+ t.to_data.should == "abc"
63
+ end
64
+
65
+ it "allows variables only" do
66
+ t = FuzzBert::Template.new "${a}${b}${c}"
67
+ t.set(:a) { "a" }
68
+ t.set(:b) { "b" }
69
+ t.set(:c) { "c" }
70
+ t.to_data.should == "abc"
71
+ end
72
+
73
+ it "allows heredoc strings" do
74
+ t = FuzzBert::Template.new <<-EOS
75
+ { user: { id: ${id}, name: "${name}" } }
76
+ EOS
77
+
78
+ t.set(:id) { "5" }
79
+ t.set(:name) { "FuzzBert" }
80
+ t.to_data.should == "{ user: { id: 5, name: \"FuzzBert\" } }\n"
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,20 @@
1
+ require 'rspec'
2
+ require 'fuzzbert'
3
+
4
+ describe FuzzBert::Test do
5
+
6
+ describe "new" do
7
+ it "takes a mandatory proc argument" do
8
+ -> { FuzzBert::Test.new }.should raise_error
9
+ FuzzBert::Test.new( lambda { |data| data }).should be_an_instance_of(FuzzBert::Test)
10
+ end
11
+ end
12
+
13
+ describe "#run" do
14
+ it "executes the block passed on creation with the data passed to it" do
15
+ value = "test"
16
+ t = FuzzBert::Test.new( lambda { |data| data })
17
+ t.run(value).should == value
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fuzzbert
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Martin Bosslet
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A random testing / fuzzer framework for Ruby.
15
+ email: Martin.Bosslet@gmail.com
16
+ executables:
17
+ - fuzzbert
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.md
21
+ files:
22
+ - lib/fuzzbert.rb
23
+ - lib/fuzzbert/error_handler.rb
24
+ - lib/fuzzbert/test.rb
25
+ - lib/fuzzbert/autorun.rb
26
+ - lib/fuzzbert/autorun.rb~
27
+ - lib/fuzzbert/generators.rb
28
+ - lib/fuzzbert/mutator.rb
29
+ - lib/fuzzbert/template.rb
30
+ - lib/fuzzbert/rake_task.rb
31
+ - lib/fuzzbert/test_suite.rb
32
+ - lib/fuzzbert/generator.rb
33
+ - lib/fuzzbert/container.rb
34
+ - lib/fuzzbert/executor.rb
35
+ - lib/fuzzbert/version.rb
36
+ - lib/fuzzbert/dsl.rb
37
+ - lib/fuzzbert/generation.rb
38
+ - LICENSE
39
+ - README.md
40
+ - spec/autorun_spec.rb
41
+ - spec/template_spec.rb
42
+ - spec/mutator_spec.rb
43
+ - spec/executor_spec.rb
44
+ - spec/dsl_spec.rb
45
+ - spec/generator_spec.rb
46
+ - spec/test_spec.rb
47
+ - bin/fuzzbert
48
+ homepage: https://github.com/krypt/FuzzBert
49
+ licenses:
50
+ - MIT
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Fuzz your applications and libraries with minimal effort.
73
+ test_files:
74
+ - spec/autorun_spec.rb
75
+ - spec/template_spec.rb
76
+ - spec/mutator_spec.rb
77
+ - spec/executor_spec.rb
78
+ - spec/dsl_spec.rb
79
+ - spec/generator_spec.rb
80
+ - spec/test_spec.rb