nokofuzzi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc497826c8b4596ff1927646342c101a2dc26baf
4
+ data.tar.gz: 4928ad9752a166ffc87b43b79078858f2a4ddee3
5
+ SHA512:
6
+ metadata.gz: f9624350d8279d3ef6b8b3ceb2558871958d0b6071734e6bddb2441b5e7e5e6d84d0a41e09433d272001d3bb56f2947339cbeb185deedcf9893f1b93f64d830e
7
+ data.tar.gz: e36cb2e4c796459d2dbcaa91d3fa5e284459353cd05779420ae7f3c4a9a2e11af83a11ef9649e298183a5815464cf2b146ff6484137993f8fd94e155595f0f97
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Thomas Powell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ nokofuzzi
2
+ =========
3
+
4
+ Fuzz testing iterators for Nokogiri
data/lib/nokofuzzi.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'nokogiri'
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class Document
6
+ def each_missing
7
+ self.xpath('//*').map { |xml_node| xml_node.path }.each do |xpath|
8
+ xml_dup = self.dup
9
+ xml_node = xml_dup.xpath(xpath)
10
+ xml_node_xml = xml_node.to_xml
11
+ xml_node.remove
12
+ yield(xml_node_xml, xml_dup.to_xml)
13
+ end
14
+ end
15
+ def each_leaf_missing
16
+ # TODO
17
+ end
18
+ def each_leaf_fuzzed
19
+ # TODO
20
+ end
21
+ def without_xpath(xpath)
22
+ xml_dup = self.dup
23
+ xml_dup.xpath(xpath).each do |xml_node|
24
+ xml_node.remove
25
+ end
26
+ xml_dup
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../lib/nokofuzzi.rb'
2
+ describe Nokogiri::XML::Document do
3
+
4
+ describe '#without_xpath' do
5
+ let(:source_xml) { Nokogiri::XML('<node><a><c></c></a><b><c></c></b></node>')}
6
+ let(:expected_b_c_xml) { Nokogiri::XML('<node><a><c></c></a><b></b></node>') }
7
+ let(:expected_c_xml) { Nokogiri::XML('<node><a></a><b></b></node>') }
8
+ it "expects removing //b/c to remove the <c> node inside <b>" do
9
+ expect(source_xml.without_xpath('//b/c').to_xml).to eq(expected_b_c_xml.to_xml)
10
+ end
11
+ it "expects removing //c to removed all <c> nodes" do
12
+ expect(source_xml.without_xpath('//c').to_xml).to eq(expected_c_xml.to_xml)
13
+ end
14
+ end
15
+
16
+ describe '#each_missing' do
17
+ let(:source_xml) { Nokogiri::XML('<node><a></a><b><c></c></b></node>')}
18
+ let(:altered_xmls) do
19
+ xmls = []
20
+ source_xml.each_missing do |node, xml|
21
+ xmls << xml
22
+ end
23
+ xmls
24
+ end
25
+ let(:removed_nodes) do
26
+ removed_nodes = []
27
+ source_xml.each_missing do |node, xml|
28
+ removed_nodes << node
29
+ end
30
+ removed_nodes.map { |string| Nokogiri::XML(string).to_xml }
31
+ end
32
+ let(:expected_removed_nodes) do
33
+ [
34
+ '<node><a></a><b><c></c></b></node>',
35
+ '<a></a>',
36
+ '<b><c></c></b>',
37
+ '<c></c>'
38
+ ]
39
+ end
40
+ let(:expected_altered_xmls) do
41
+ [
42
+ '',
43
+ '<node><b><c></c></b></node>',
44
+ '<node><a></a></node>',
45
+ '<node><a></a><b></b></node>',
46
+ ]
47
+ end
48
+
49
+ it "has one removed node for each tag" do
50
+ expect(removed_nodes.count).to eq 4
51
+ end
52
+ it "removed nodes contain each of the expected removed nodes" do
53
+ expected_removed_nodes.each do |removed|
54
+ expect(removed_nodes).to include(Nokogiri::XML(removed).to_xml)
55
+ end
56
+ end
57
+ it "altered xmls contain each of the expected altered xmls" do
58
+ expected_altered_xmls.each do |altered|
59
+ expect(altered_xmls).to include(Nokogiri::XML(altered).to_xml)
60
+ end
61
+ end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nokofuzzi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Powell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.9'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.9'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ description: Monkey patch all the Nokogiri things
48
+ email:
49
+ - twilliampowell@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - README.md
54
+ - LICENSE
55
+ files:
56
+ - LICENSE
57
+ - README.md
58
+ - lib/nokofuzzi.rb
59
+ - spec/nokofuzzi_spec.rb
60
+ homepage: https://github.com/stringsn88keys/nokofuzzi
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options:
66
+ - "--charset"
67
+ - UTF-8
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Iterators for Nokogiri for fuzz testing of applications
86
+ test_files:
87
+ - spec/nokofuzzi_spec.rb
88
+ has_rdoc: