canonix 0.1.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/.document +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/canonix.gemspec +55 -0
- data/lib/xml/util/xmlcanonicalizer.rb +426 -0
- data/lib/xmlcanonicalizer.rb +1 -0
- data/test/complex.xml +23 -0
- data/test/expected.xml +23 -0
- data/test/helper.rb +10 -0
- data/test/saml_assertion.xml +10 -0
- data/test/saml_expected_canonical_form.xml +10 -0
- data/test/test_xmlcanonicalizer.rb +58 -0
- data/tests.watchr +62 -0
- metadata +96 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andrew Ferk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= xmlcanonicalizer
|
2
|
+
|
3
|
+
XML Canonicalizer for Ruby >= 1.92
|
4
|
+
|
5
|
+
This is taken from XMLCanonicalizer/WSS4R and http://github.com/borisnadion/xml-canonicalizer
|
6
|
+
|
7
|
+
== Note on Patches/Pull Requests
|
8
|
+
|
9
|
+
* Fork the project.
|
10
|
+
* Make your feature addition or bug fix.
|
11
|
+
* Add tests for it. This is important so I don't break it in a
|
12
|
+
future version unintentionally.
|
13
|
+
* Commit, do not mess with rakefile, version, or history.
|
14
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
15
|
+
* Send me a pull request. Bonus points for topic branches.
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2010 Andrew Ferk. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "canonix"
|
8
|
+
gem.summary = %Q{XML Canonicalizer for Ruby >= 1.92}
|
9
|
+
gem.description = %Q{This is based on andrewferk's rewrite for Ruby 1.9 compatibility, but applies
|
10
|
+
relevance's fix to ensure proper canonicalisation. It is intended that this be the new official
|
11
|
+
Ruby Canonicaliser as the other project seems to be abandoned.}
|
12
|
+
gem.email = "brendon@spike.net.nz"
|
13
|
+
gem.homepage = "http://github.com/brendon/canonix"
|
14
|
+
gem.authors = ["Brendon Muir"]
|
15
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "canonix #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/canonix.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{canonix}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Brendon Muir}]
|
12
|
+
s.date = %q{2011-06-16}
|
13
|
+
s.description = %q{This is based on andrewferk's rewrite for Ruby 1.9 compatibility, but applies
|
14
|
+
relevance's fix to ensure proper canonicalisation. It is intended that this be the new official
|
15
|
+
Ruby Canonicaliser as the other project seems to be abandoned.}
|
16
|
+
s.email = %q{brendon@spike.net.nz}
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"canonix.gemspec",
|
28
|
+
"lib/xml/util/xmlcanonicalizer.rb",
|
29
|
+
"lib/xmlcanonicalizer.rb",
|
30
|
+
"test/complex.xml",
|
31
|
+
"test/expected.xml",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/saml_assertion.xml",
|
34
|
+
"test/saml_expected_canonical_form.xml",
|
35
|
+
"test/test_xmlcanonicalizer.rb",
|
36
|
+
"tests.watchr"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/brendon/canonix}
|
39
|
+
s.require_paths = [%q{lib}]
|
40
|
+
s.rubygems_version = %q{1.8.5}
|
41
|
+
s.summary = %q{XML Canonicalizer for Ruby >= 1.92}
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,426 @@
|
|
1
|
+
#require "rexml/document"
|
2
|
+
#require "base64"
|
3
|
+
#require "log4r"
|
4
|
+
|
5
|
+
#include REXML
|
6
|
+
#include Log4r
|
7
|
+
|
8
|
+
require "rexml/document"
|
9
|
+
require "base64"
|
10
|
+
|
11
|
+
module XML
|
12
|
+
include REXML
|
13
|
+
|
14
|
+
module Util
|
15
|
+
|
16
|
+
class REXML::Instruction
|
17
|
+
def write(writer, indent=-1, transitive=false, ie_hack=false)
|
18
|
+
indent(writer, indent)
|
19
|
+
writer << START.sub(/\\/u, '')
|
20
|
+
writer << @target
|
21
|
+
writer << ' '
|
22
|
+
writer << @content if @content != nil
|
23
|
+
writer << STOP.sub(/\\/u, '')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class REXML::Attribute
|
28
|
+
def <=>(a2)
|
29
|
+
if (self === a2)
|
30
|
+
return 0
|
31
|
+
elsif (self == nil)
|
32
|
+
return -1
|
33
|
+
elsif (a2 == nil)
|
34
|
+
return 1
|
35
|
+
elsif (self.prefix() == a2.prefix())
|
36
|
+
return self.name()<=>a2.name()
|
37
|
+
end
|
38
|
+
if (self.prefix() == nil)
|
39
|
+
return -1
|
40
|
+
elsif (a2.prefix() == nil)
|
41
|
+
return 1
|
42
|
+
end
|
43
|
+
ret = self.namespace()<=>a2.namespace()
|
44
|
+
if (ret == 0)
|
45
|
+
ret = self.prefix()<=>a2.prefix()
|
46
|
+
end
|
47
|
+
return ret
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class REXML::Element
|
52
|
+
def search_namespace(prefix)
|
53
|
+
if (self.namespace(prefix) == nil)
|
54
|
+
return (self.parent().search_namespace(prefix)) if (self.parent() != nil)
|
55
|
+
else
|
56
|
+
return self.namespace(prefix)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
def rendered=(rendered)
|
60
|
+
@rendered = rendered
|
61
|
+
end
|
62
|
+
def rendered?()
|
63
|
+
return @rendered
|
64
|
+
end
|
65
|
+
def node_namespaces()
|
66
|
+
ns = Array.new()
|
67
|
+
ns.push(self.prefix())
|
68
|
+
self.attributes().each_attribute{|a|
|
69
|
+
if (a.prefix() != nil)
|
70
|
+
ns.push(a.prefix())
|
71
|
+
end
|
72
|
+
if (a.prefix() == "" && a.local_name() == "xmlns")
|
73
|
+
ns.push("xmlns")
|
74
|
+
end
|
75
|
+
}
|
76
|
+
ns
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class NamespaceNode
|
81
|
+
attr_reader :prefix, :uri
|
82
|
+
def initialize(prefix, uri)
|
83
|
+
@prefix = prefix
|
84
|
+
@uri = uri
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class XmlCanonicalizer
|
89
|
+
attr_accessor :prefix_list, :logger
|
90
|
+
|
91
|
+
BEFORE_DOC_ELEMENT = 0
|
92
|
+
INSIDE_DOC_ELEMENT = 1
|
93
|
+
AFTER_DOC_ELEMENT = 2
|
94
|
+
|
95
|
+
NODE_TYPE_ATTRIBUTE = 3
|
96
|
+
NODE_TYPE_WHITESPACE = 4
|
97
|
+
NODE_TYPE_COMMENT = 5
|
98
|
+
NODE_TYPE_PI = 6
|
99
|
+
NODE_TYPE_TEXT = 7
|
100
|
+
|
101
|
+
|
102
|
+
def initialize(with_comments, excl_c14n)
|
103
|
+
@with_comments = with_comments
|
104
|
+
@exclusive = excl_c14n
|
105
|
+
@res = ""
|
106
|
+
@state = BEFORE_DOC_ELEMENT
|
107
|
+
@xnl = Array.new()
|
108
|
+
@prevVisibleNamespacesStart = 0
|
109
|
+
@prevVisibleNamespacesEnd = 0
|
110
|
+
@visibleNamespaces = Array.new()
|
111
|
+
@inclusive_namespaces = Array.new()
|
112
|
+
@prefix_list = nil
|
113
|
+
end
|
114
|
+
|
115
|
+
def add_inclusive_namespaces(prefix_list, element, visible_namespaces)
|
116
|
+
namespaces = element.attributes()
|
117
|
+
namespaces.each_attribute{|ns|
|
118
|
+
if (ns.prefix=="xmlns")
|
119
|
+
if (prefix_list.include?(ns.local_name()))
|
120
|
+
visible_namespaces.push(NamespaceNode.new("xmlns:"+ns.local_name(), ns.value()))
|
121
|
+
end
|
122
|
+
end
|
123
|
+
}
|
124
|
+
parent = element.parent()
|
125
|
+
add_inclusive_namespaces(prefix_list, parent, visible_namespaces) if (parent)
|
126
|
+
visible_namespaces
|
127
|
+
end
|
128
|
+
|
129
|
+
def canonicalize(document)
|
130
|
+
write_document_node(document)
|
131
|
+
@res
|
132
|
+
end
|
133
|
+
|
134
|
+
def canonicalize_element(element, logging = true)
|
135
|
+
@inclusive_namespaces = add_inclusive_namespaces(@prefix_list, element, @inclusive_namespaces) if (@prefix_list)
|
136
|
+
@preserve_document = element.document()
|
137
|
+
tmp_parent = element.parent()
|
138
|
+
body_string = remove_whitespace(element.to_s().gsub("\n","").gsub("\t","").gsub("\r",""))
|
139
|
+
document = Document.new(body_string)
|
140
|
+
tmp_parent.delete_element(element)
|
141
|
+
element = tmp_parent.add_element(document.root())
|
142
|
+
@preserve_element = element
|
143
|
+
document = Document.new(element.to_s())
|
144
|
+
ns = element.namespace(element.prefix())
|
145
|
+
document.root().add_namespace(element.prefix(), ns)
|
146
|
+
write_document_node(document)
|
147
|
+
@res
|
148
|
+
end
|
149
|
+
|
150
|
+
def write_document_node(document)
|
151
|
+
@state = BEFORE_DOC_ELEMENT
|
152
|
+
if (document.class().to_s() == "REXML::Element")
|
153
|
+
write_node(document)
|
154
|
+
else
|
155
|
+
document.each_child{|child|
|
156
|
+
write_node(child)
|
157
|
+
}
|
158
|
+
end
|
159
|
+
@res
|
160
|
+
end
|
161
|
+
|
162
|
+
def write_node(node)
|
163
|
+
visible = is_node_visible(node)
|
164
|
+
if ((node.node_type() == :text) && white_text?(node.value()))
|
165
|
+
res = node.value()
|
166
|
+
res.gsub("\r\n","\n")
|
167
|
+
#res = res.delete(" ").delete("\t")
|
168
|
+
res.delete("\r")
|
169
|
+
@res = @res + res
|
170
|
+
#write_text_node(node,visible) if (@state == INSIDE_DOC_ELEMENT)
|
171
|
+
return
|
172
|
+
end
|
173
|
+
if (node.node_type() == :text)
|
174
|
+
write_text_node(node, visible)
|
175
|
+
return
|
176
|
+
end
|
177
|
+
if (node.node_type() == :element)
|
178
|
+
write_element_node(node, visible) if (!node.rendered?())
|
179
|
+
node.rendered=(true)
|
180
|
+
end
|
181
|
+
if (node.node_type() == :processing_instruction)
|
182
|
+
end
|
183
|
+
if (node.node_type() == :comment)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def write_element_node(node, visible)
|
188
|
+
savedPrevVisibleNamespacesStart = @prevVisibleNamespacesStart
|
189
|
+
savedPrevVisibleNamespacesEnd = @prevVisibleNamespacesEnd
|
190
|
+
savedVisibleNamespacesSize = @visibleNamespaces.size()
|
191
|
+
state = @state
|
192
|
+
state = INSIDE_DOC_ELEMENT if (visible && state == BEFORE_DOC_ELEMENT)
|
193
|
+
@res = @res + "<" + node.expanded_name() if (visible)
|
194
|
+
write_namespace_axis(node, visible)
|
195
|
+
write_attribute_axis(node)
|
196
|
+
@res = @res + ">" if (visible)
|
197
|
+
node.each_child{|child|
|
198
|
+
write_node(child)
|
199
|
+
}
|
200
|
+
@res = @res + "</" +node.expanded_name() + ">" if (visible)
|
201
|
+
@state = AFTER_DOC_ELEMENT if (visible && state == BEFORE_DOC_ELEMENT)
|
202
|
+
@prevVisibleNamespacesStart = savedPrevVisibleNamespacesStart
|
203
|
+
@prevVisibleNamespacesEnd = savedPrevVisibleNamespacesEnd
|
204
|
+
@visibleNamespaces.slice!(savedVisibleNamespacesSize, @visibleNamespaces.size() - savedVisibleNamespacesSize) if (@visibleNamespaces.size() > savedVisibleNamespacesSize)
|
205
|
+
end
|
206
|
+
|
207
|
+
def write_namespace_axis(node, visible)
|
208
|
+
doc = node.document()
|
209
|
+
has_empty_namespace = false
|
210
|
+
list = Array.new()
|
211
|
+
cur = node
|
212
|
+
#while ((cur != nil) && (cur != doc) && (cur.node_type() != :document))
|
213
|
+
namespaces = cur.node_namespaces()
|
214
|
+
namespaces.each{|prefix|
|
215
|
+
next if ((prefix == "xmlns") && (node.namespace(prefix) == ""))
|
216
|
+
namespace = cur.namespace(prefix)
|
217
|
+
next if (is_namespace_node(namespace))
|
218
|
+
next if (node.namespace(prefix) != cur.namespace(prefix))
|
219
|
+
next if (prefix == "xml" && namespace == "http://www.w3.org/XML/1998/namespace")
|
220
|
+
next if (!is_node_visible(cur))
|
221
|
+
rendered = is_namespace_rendered(prefix, namespace)
|
222
|
+
@visibleNamespaces.push(NamespaceNode.new("xmlns:"+prefix,namespace)) if (visible)
|
223
|
+
if ((!rendered) && !list.include?(prefix))
|
224
|
+
list.push(prefix)
|
225
|
+
end
|
226
|
+
has_empty_namespace = true if (prefix == nil)
|
227
|
+
}
|
228
|
+
if (visible && !has_empty_namespace && !is_namespace_rendered(nil, nil))
|
229
|
+
@res = @res + ' xmlns=""'
|
230
|
+
end
|
231
|
+
#TODO: ns of inclusive_list
|
232
|
+
#=begin
|
233
|
+
if ((@prefix_list) && (node.to_s() == node.parent().to_s()))
|
234
|
+
#list.push(node.prefix())
|
235
|
+
@inclusive_namespaces.each{|ns|
|
236
|
+
prefix = ns.prefix().split(":")[1]
|
237
|
+
list.push(prefix) if (!list.include?(prefix) && (!node.attributes.prefixes.include?(prefix)))
|
238
|
+
}
|
239
|
+
@prefix_list = nil
|
240
|
+
end
|
241
|
+
#=end
|
242
|
+
list.sort!()
|
243
|
+
list.each{|prefix|
|
244
|
+
next if (prefix == "")
|
245
|
+
ns = node.namespace(prefix)
|
246
|
+
ns = @preserve_element.namespace(prefix) if (ns == nil)
|
247
|
+
@res = @res + normalize_string(" " + prefix + '="' + ns + '"', NODE_TYPE_TEXT) if (prefix == "xmlns")
|
248
|
+
@res = @res + normalize_string(" xmlns:" + prefix + '="' + ns + '"', NODE_TYPE_TEXT) if (prefix != nil && prefix != "xmlns")
|
249
|
+
}
|
250
|
+
if (visible)
|
251
|
+
@prevVisibleNamespacesStart = @prevVisibleNamespacesEnd
|
252
|
+
@prevVisibleNamespacesEnd = @visibleNamespaces.size()
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def write_attribute_axis(node)
|
257
|
+
list = Array.new()
|
258
|
+
node.attributes.keys.sort.each{|key|
|
259
|
+
attr = node.attributes.get_attribute(key)
|
260
|
+
list.push(attr) if (!is_namespace_node(attr.value()) && !is_namespace_decl(attr))
|
261
|
+
}
|
262
|
+
if (!@exclusive && node.parent() != nil && node.parent().parent() != nil)
|
263
|
+
cur = node.parent()
|
264
|
+
while (cur != nil)
|
265
|
+
#next if (cur.attributes() == nil)
|
266
|
+
cur.each_attribute{|attribute|
|
267
|
+
next if (attribute.prefix() != "xml")
|
268
|
+
next if (attribute.prefix().index("xmlns") == 0)
|
269
|
+
next if (node.namespace(attribute.prefix()) == attribute.value())
|
270
|
+
found = true
|
271
|
+
list.each{|n|
|
272
|
+
if (n.prefix() == "xml" && n.value() == attritbute.value())
|
273
|
+
found = true
|
274
|
+
break
|
275
|
+
end
|
276
|
+
}
|
277
|
+
next if (found)
|
278
|
+
list.push(attribute)
|
279
|
+
}
|
280
|
+
end
|
281
|
+
end
|
282
|
+
list.each{|attribute|
|
283
|
+
if (attribute != nil)
|
284
|
+
if (attribute.name() != "xmlns")
|
285
|
+
@res = @res + " " + normalize_string(attribute.to_string(), NODE_TYPE_ATTRIBUTE).gsub("'",'"')
|
286
|
+
end
|
287
|
+
# else
|
288
|
+
# @res = @res + " " + normalize_string(attribute.name()+'="'+attribute.to_s()+'"', NODE_TYPE_ATTRIBUTE).gsub("'",'"')
|
289
|
+
#end
|
290
|
+
end
|
291
|
+
}
|
292
|
+
end
|
293
|
+
|
294
|
+
def is_namespace_node(namespace_uri)
|
295
|
+
return (namespace_uri == "http://www.w3.org/2000/xmlns/")
|
296
|
+
end
|
297
|
+
|
298
|
+
def is_namespace_rendered(prefix, uri)
|
299
|
+
is_empty_ns = prefix == nil && uri == nil
|
300
|
+
if (is_empty_ns)
|
301
|
+
start = 0
|
302
|
+
else
|
303
|
+
start = @prevVisibleNamespacesStart
|
304
|
+
end
|
305
|
+
@visibleNamespaces.each{|ns|
|
306
|
+
if (ns.prefix() == "xmlns:"+prefix.to_s() && ns.uri() == uri)
|
307
|
+
return true
|
308
|
+
end
|
309
|
+
}
|
310
|
+
return is_empty_ns
|
311
|
+
#(@visibleNamespaces.size()-1).downto(start) {|i|
|
312
|
+
# ns = @visibleNamespaces[i]
|
313
|
+
# return true if (ns.prefix() == "xmlns:"+prefix.to_s() && ns.uri() == uri)
|
314
|
+
# #p = ns.prefix() if (ns.prefix().index("xmlns") == 0)
|
315
|
+
# #return ns.uri() == uri if (p == prefix)
|
316
|
+
#}
|
317
|
+
#return is_empty_ns
|
318
|
+
end
|
319
|
+
|
320
|
+
def is_node_visible(node)
|
321
|
+
return true if (@xnl.size() == 0)
|
322
|
+
@xnl.each{|element|
|
323
|
+
return true if (element == node)
|
324
|
+
}
|
325
|
+
return false
|
326
|
+
end
|
327
|
+
|
328
|
+
def normalize_string(input, type)
|
329
|
+
sb = ""
|
330
|
+
return input
|
331
|
+
end
|
332
|
+
#input.each_byte{|b|
|
333
|
+
# if (b ==60 && (type == NODE_TYPE_ATTRIBUTE || is_text_node(type)))
|
334
|
+
# sb = sb + "<"
|
335
|
+
# elsif (b == 62 && is_text_node(type))
|
336
|
+
# sb = sb + ">"
|
337
|
+
# elsif (b == 38 && (is_text_node(type) || is_text_node(type))) #Ampersand
|
338
|
+
# sb = sb + "&"
|
339
|
+
# elsif (b == 34 && is_text_node(type)) #Quote
|
340
|
+
# sb = sb + """
|
341
|
+
# elsif (b == 9 && is_text_node(type)) #Tabulator
|
342
|
+
# sb = sb + "	"
|
343
|
+
# elsif (b == 11 && is_text_node(type)) #CR
|
344
|
+
# sb = sb + "
"
|
345
|
+
# elsif (b == 13 && (type == NODE_TYPE_ATTRIBUTE || (is_text_node(type) && type != NODE_TYPE_WHITESPACE) || type == NODE_TYPE_COMMENT || type == NODE_TYPE_PI))
|
346
|
+
# sb = sb + "
"
|
347
|
+
# elsif (b == 13)
|
348
|
+
# next
|
349
|
+
# else
|
350
|
+
# sb = sb.concat(b)
|
351
|
+
# end
|
352
|
+
#}
|
353
|
+
#sb
|
354
|
+
#end
|
355
|
+
|
356
|
+
def write_text_node(node, visible)
|
357
|
+
if (visible)
|
358
|
+
@res = @res + normalize_string(node.value(), node.node_type())
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
def white_text?(text)
|
363
|
+
return true if ((text.strip() == "") || (text.strip() == nil))
|
364
|
+
return false
|
365
|
+
end
|
366
|
+
|
367
|
+
def is_namespace_decl(attribute)
|
368
|
+
#return true if (attribute.name() == "xmlns")
|
369
|
+
return true if (attribute.prefix().index("xmlns") == 0)
|
370
|
+
return false
|
371
|
+
end
|
372
|
+
|
373
|
+
def is_text_node(type)
|
374
|
+
return true if (type == NODE_TYPE_TEXT || type == NODE_TYPE_CDATA || type == NODE_TYPE_WHITESPACE)
|
375
|
+
return false
|
376
|
+
end
|
377
|
+
|
378
|
+
def remove_whitespace(string)
|
379
|
+
new_string = ""
|
380
|
+
in_white = false
|
381
|
+
string.each_byte{|b|
|
382
|
+
#if (in_white && b == 32)
|
383
|
+
#else
|
384
|
+
if !(in_white && b == 32)
|
385
|
+
new_string = new_string + b.chr()
|
386
|
+
end
|
387
|
+
if (b == 62) #>
|
388
|
+
in_white = true
|
389
|
+
end
|
390
|
+
if (b == 60) #<
|
391
|
+
in_white = false
|
392
|
+
end
|
393
|
+
}
|
394
|
+
new_string
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end #Util
|
398
|
+
end #XML
|
399
|
+
|
400
|
+
|
401
|
+
if __FILE__ == $0
|
402
|
+
document = Document.new(File.new(ARGV[0]))
|
403
|
+
body = nil
|
404
|
+
c = WSS4R::Security::Util::XmlCanonicalizer.new(false, true)
|
405
|
+
|
406
|
+
if (ARGV.size() == 3)
|
407
|
+
body = ARGV[2]
|
408
|
+
if (body == "true")
|
409
|
+
element = XPath.match(document, "/soap:Envelope/soap:Body")[0]
|
410
|
+
element = XPath.first(document, "/soap:Envelope/soap:Header/wsse:Security/Signature/SignedInfo")
|
411
|
+
result = c.canonicalize_element(element)
|
412
|
+
puts("-----")
|
413
|
+
puts(result)
|
414
|
+
puts("-----")
|
415
|
+
puts(result.size())
|
416
|
+
puts("-----")
|
417
|
+
puts(CryptHash.new().digest_b64(result))
|
418
|
+
end
|
419
|
+
else
|
420
|
+
result = c.canonicalize(document)
|
421
|
+
end
|
422
|
+
|
423
|
+
file = File.new(ARGV[1], "wb")
|
424
|
+
file.write(result)
|
425
|
+
file.close()
|
426
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'xml/util/xmlcanonicalizer'
|
data/test/complex.xml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<samlp:ArtifactResponse IssueInstant='2010-09-10T00:00:50-05:00' Version='2.0' xmlns:samlp='urn:oasis:names:tc:SAML:2.0:protocol' ID='122401A9D1742640618954CDD50CEC459150836A' xmlns='urn:oasis:names:tc:SAML:2.0:assertion'><samlp:Status><samlp:StatusCode ID='A6B45394506685EAD93131AD335775015C49B52C' Value='urn:oasis:names:tc:SAML:2.0:status:Failure'/></samlp:Status><samlp:Assertion IssueInstant='2010-09-10T00:00:50-05:00' ID='11B542652811C7A1AC8B8265D92AB293CCA66B26'><Issuer>example.net</Issuer><Subject><NameID Format='urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'/><SubjectConfirmation Method='urn:oasis:names:tc:SAML:2.0:cm:bearer'/></Subject><Conditions NotBefore='2010-09-10T00:00:50-05:00' NotOnOrAfter='2010-09-10T12:00:50-05:00'/><AuthnStatement AuthnInstant='2010-09-10T00:00:50-05:00'><AuthnContext><AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PreviousSession</AuthnContextClassRef></AuthnContext></AuthnStatement><AttributeStatement><Attribute Name='urn:example:profiles'><AttributeValue FriendlyName='type' type='example:profile:attribute'>Person</AttributeValue><AttributeValue FriendlyName='SessionID' type='example:profile:attribute'>02b5e2df689b97067dc51a0cd2029510</AttributeValue><AttributeValue FriendlyName='Role' type='example:profile:role'>Public</AttributeValue></Attribute></AttributeStatement></samlp:Assertion><ds:Signature xmlns:ds='http://www.w3.org/2000/09/xmldsig#'><ds:SignedInfo><ds:CanonicalizationMethod Algorithm='http://www.w3.org/2001/10/xml-exc-c14n#'/><ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/><ds:Reference URI='122401A9D1742640618954CDD50CEC459150836A'><ds:Transforms><ds:Transform Algorithm='http://www.w3.org/2000/09/xmldsig#enveloped-signature'/><ds:Transform Algorithm='http://www.w3.org/2001/10/xml-exc-c14n#'><InclusiveNamespaces PrefixList='#default saml ds xs xsi'/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/><ds:DigestValue>dQskOs0c6N7GbFJ13SbozqhEQTM=
|
2
|
+
</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>d2rgUtclTSl7q68kZTkaFo8/rBZk/NEmkeKT7qM5doiVhHF4FrMuv7NdQVbQ
|
3
|
+
Vi//wyYk6i9u8s13tsYnliSo+4xGbWl112LrAp8U2E8pLjMxqLYQHXw6qV3h
|
4
|
+
TLhKw/k8sYS54nOye9t7M0VxHl+sKfX+YZFr8EI3ST2/BKFqm5c=
|
5
|
+
</ds:SignatureValue><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIIDFTCCAn4CAQAwDQYJKoZIhvcNAQEEBQAwgdIxCzAJBgNVBAYTAlVTMRIw
|
6
|
+
EAYDVQQIEwlNaW5uZXNvdGExEjAQBgNVBAcTCVJvY2hlc3RlcjElMCMGA1UE
|
7
|
+
ChMcQ29ycG9yYXRlIFdlYiBTZXJ2aWNlcywgSW5jLjFAMD4GA1UECxM3TWF5
|
8
|
+
byBNZWRpY2FsIExhYm9yYXRvcmllcyBQcm9maWxlIE1hbmFnZXIgSG9zdGVk
|
9
|
+
IGJ5IENXUzEVMBMGA1UEAxMMbWF5by5jd3MubmV0MRswGQYJKoZIhvcNAQkB
|
10
|
+
FgxseWxlQGN3cy5uZXQwHhcNMDcwODAxMTg1ODUzWhcNMzIwNzI1MTg1ODUz
|
11
|
+
WjCB0jELMAkGA1UEBhMCVVMxEjAQBgNVBAgTCU1pbm5lc290YTESMBAGA1UE
|
12
|
+
BxMJUm9jaGVzdGVyMSUwIwYDVQQKExxDb3Jwb3JhdGUgV2ViIFNlcnZpY2Vz
|
13
|
+
LCBJbmMuMUAwPgYDVQQLEzdNYXlvIE1lZGljYWwgTGFib3JhdG9yaWVzIFBy
|
14
|
+
b2ZpbGUgTWFuYWdlciBIb3N0ZWQgYnkgQ1dTMRUwEwYDVQQDEwxtYXlvLmN3
|
15
|
+
cy5uZXQxGzAZBgkqhkiG9w0BCQEWDGx5bGVAY3dzLm5ldDCBnzANBgkqhkiG
|
16
|
+
9w0BAQEFAAOBjQAwgYkCgYEA2+1yxxQTeBR+/ducTSVj7eR8krq/OI2LnYxh
|
17
|
+
un18kVplOiDwUauqxZZL+ItZhC19/48k3f9YyGsRS1r2YNgOvWKXT8/GEMyI
|
18
|
+
/Wk44l/7aUbNeVvdtXBdGdexy972RYH9jOkp4LRWQoJ4l6y1Bt7XesU8p/8Q
|
19
|
+
Yd1V/LqUNHQmcq0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQAdSKl3LDTh6Z/p
|
20
|
+
P31zMKHOx5VEHnyUmzfd5vl0tfB8a6uMv3NKe2knwHjx7vwwGboVsCS7X6Uu
|
21
|
+
x+scXbkA8Rod34PyMQAKqzN8ePTlWywPrtbFJzRROj/7Du2uz83osacuW0bv
|
22
|
+
0AoM/vII4Xbyc/f1OTZvI1ygIVlnbmGI+xJATQ==
|
23
|
+
</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature></samlp:ArtifactResponse>
|
data/test/expected.xml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<samlp:ArtifactResponse xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns="urn:oasis:names:tc:SAML:2.0:assertion" ID="122401A9D1742640618954CDD50CEC459150836A" IssueInstant="2010-09-10T00:00:50-05:00" Version="2.0"><samlp:Status><samlp:StatusCode ID="A6B45394506685EAD93131AD335775015C49B52C" Value="urn:oasis:names:tc:SAML:2.0:status:Failure"></samlp:StatusCode></samlp:Status><samlp:Assertion ID="11B542652811C7A1AC8B8265D92AB293CCA66B26" IssueInstant="2010-09-10T00:00:50-05:00"><Issuer>example.net</Issuer><Subject><NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"></NameID><SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"></SubjectConfirmation></Subject><Conditions NotBefore="2010-09-10T00:00:50-05:00" NotOnOrAfter="2010-09-10T12:00:50-05:00"></Conditions><AuthnStatement AuthnInstant="2010-09-10T00:00:50-05:00"><AuthnContext><AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PreviousSession</AuthnContextClassRef></AuthnContext></AuthnStatement><AttributeStatement><Attribute Name="urn:example:profiles"><AttributeValue FriendlyName="type" type="example:profile:attribute">Person</AttributeValue><AttributeValue FriendlyName="SessionID" type="example:profile:attribute">02b5e2df689b97067dc51a0cd2029510</AttributeValue><AttributeValue FriendlyName="Role" type="example:profile:role">Public</AttributeValue></Attribute></AttributeStatement></samlp:Assertion><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod><ds:Reference URI="122401A9D1742640618954CDD50CEC459150836A"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><InclusiveNamespaces PrefixList="#default saml ds xs xsi"></InclusiveNamespaces></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>dQskOs0c6N7GbFJ13SbozqhEQTM=
|
2
|
+
</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>d2rgUtclTSl7q68kZTkaFo8/rBZk/NEmkeKT7qM5doiVhHF4FrMuv7NdQVbQ
|
3
|
+
Vi//wyYk6i9u8s13tsYnliSo+4xGbWl112LrAp8U2E8pLjMxqLYQHXw6qV3h
|
4
|
+
TLhKw/k8sYS54nOye9t7M0VxHl+sKfX+YZFr8EI3ST2/BKFqm5c=
|
5
|
+
</ds:SignatureValue><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIIDFTCCAn4CAQAwDQYJKoZIhvcNAQEEBQAwgdIxCzAJBgNVBAYTAlVTMRIw
|
6
|
+
EAYDVQQIEwlNaW5uZXNvdGExEjAQBgNVBAcTCVJvY2hlc3RlcjElMCMGA1UE
|
7
|
+
ChMcQ29ycG9yYXRlIFdlYiBTZXJ2aWNlcywgSW5jLjFAMD4GA1UECxM3TWF5
|
8
|
+
byBNZWRpY2FsIExhYm9yYXRvcmllcyBQcm9maWxlIE1hbmFnZXIgSG9zdGVk
|
9
|
+
IGJ5IENXUzEVMBMGA1UEAxMMbWF5by5jd3MubmV0MRswGQYJKoZIhvcNAQkB
|
10
|
+
FgxseWxlQGN3cy5uZXQwHhcNMDcwODAxMTg1ODUzWhcNMzIwNzI1MTg1ODUz
|
11
|
+
WjCB0jELMAkGA1UEBhMCVVMxEjAQBgNVBAgTCU1pbm5lc290YTESMBAGA1UE
|
12
|
+
BxMJUm9jaGVzdGVyMSUwIwYDVQQKExxDb3Jwb3JhdGUgV2ViIFNlcnZpY2Vz
|
13
|
+
LCBJbmMuMUAwPgYDVQQLEzdNYXlvIE1lZGljYWwgTGFib3JhdG9yaWVzIFBy
|
14
|
+
b2ZpbGUgTWFuYWdlciBIb3N0ZWQgYnkgQ1dTMRUwEwYDVQQDEwxtYXlvLmN3
|
15
|
+
cy5uZXQxGzAZBgkqhkiG9w0BCQEWDGx5bGVAY3dzLm5ldDCBnzANBgkqhkiG
|
16
|
+
9w0BAQEFAAOBjQAwgYkCgYEA2+1yxxQTeBR+/ducTSVj7eR8krq/OI2LnYxh
|
17
|
+
un18kVplOiDwUauqxZZL+ItZhC19/48k3f9YyGsRS1r2YNgOvWKXT8/GEMyI
|
18
|
+
/Wk44l/7aUbNeVvdtXBdGdexy972RYH9jOkp4LRWQoJ4l6y1Bt7XesU8p/8Q
|
19
|
+
Yd1V/LqUNHQmcq0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQAdSKl3LDTh6Z/p
|
20
|
+
P31zMKHOx5VEHnyUmzfd5vl0tfB8a6uMv3NKe2knwHjx7vwwGboVsCS7X6Uu
|
21
|
+
x+scXbkA8Rod34PyMQAKqzN8ePTlWywPrtbFJzRROj/7Du2uz83osacuW0bv
|
22
|
+
0AoM/vII4Xbyc/f1OTZvI1ygIVlnbmGI+xJATQ==
|
23
|
+
</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature></samlp:ArtifactResponse>
|
data/test/helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
<saml:Assertion ID='s272db1ff577ed4463edc408a3d7f3571aebf1696a' IssueInstant='2010-10-28T13:35:36Z' Version='2.0' xmlns:saml='urn:oasis:names:tc:SAML:2.0:assertion'>
|
2
|
+
<saml:Issuer>http://dev.example.com:8080/opensso</saml:Issuer><saml:Subject>
|
3
|
+
<saml:NameID Format='urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' NameQualifier='http://dev.example.com:8080/opensso'>person@example.com</saml:NameID><saml:SubjectConfirmation Method='urn:oasis:names:tc:SAML:2.0:cm:bearer'>
|
4
|
+
<saml:SubjectConfirmationData InResponseTo='294e5540-c4c6-012d-1a98-0017f2dcb387' NotOnOrAfter='2010-10-28T13:45:36Z' Recipient='http://localhost:3000/auth/authenticate'/></saml:SubjectConfirmation>
|
5
|
+
</saml:Subject><saml:Conditions NotBefore='2010-10-28T13:25:36Z' NotOnOrAfter='2010-10-28T13:45:36Z'>
|
6
|
+
<saml:AudienceRestriction>
|
7
|
+
<saml:Audience>saml-example</saml:Audience>
|
8
|
+
</saml:AudienceRestriction>
|
9
|
+
</saml:Conditions>
|
10
|
+
<saml:AuthnStatement AuthnInstant='2010-10-28T13:35:36Z' SessionIndex='s2eddbcf944c22056cec33d0ea24a54217a164f601'><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement><saml:Attribute Name='name'><saml:AttributeValue xsi:type='xs:string' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>happy</saml:AttributeValue></saml:Attribute><saml:Attribute Name='uuid'><saml:AttributeValue xsi:type='xs:string' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>3c678d50-c357-012d-1a87-0017f2dcb387</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="s272db1ff577ed4463edc408a3d7f3571aebf1696a" IssueInstant="2010-10-28T13:35:36Z" Version="2.0">
|
2
|
+
<saml:Issuer>http://dev.example.com:8080/opensso</saml:Issuer><saml:Subject>
|
3
|
+
<saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" NameQualifier="http://dev.example.com:8080/opensso">person@example.com</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
|
4
|
+
<saml:SubjectConfirmationData InResponseTo="294e5540-c4c6-012d-1a98-0017f2dcb387" NotOnOrAfter="2010-10-28T13:45:36Z" Recipient="http://localhost:3000/auth/authenticate"></saml:SubjectConfirmationData></saml:SubjectConfirmation>
|
5
|
+
</saml:Subject><saml:Conditions NotBefore="2010-10-28T13:25:36Z" NotOnOrAfter="2010-10-28T13:45:36Z">
|
6
|
+
<saml:AudienceRestriction>
|
7
|
+
<saml:Audience>saml-example</saml:Audience>
|
8
|
+
</saml:AudienceRestriction>
|
9
|
+
</saml:Conditions>
|
10
|
+
<saml:AuthnStatement AuthnInstant="2010-10-28T13:35:36Z" SessionIndex="s2eddbcf944c22056cec33d0ea24a54217a164f601"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement><saml:Attribute Name="name"><saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">happy</saml:AttributeValue></saml:Attribute><saml:Attribute Name="uuid"><saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">3c678d50-c357-012d-1a87-0017f2dcb387</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(File.expand_path(__FILE__))+'/helper'
|
2
|
+
|
3
|
+
class TestXmlcanonicalizer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should "canonicalize a simple xml file" do
|
6
|
+
xml_canonicalizer = XML::Util::XmlCanonicalizer.new(true,true)
|
7
|
+
xml = "<foo bar='test'/>";
|
8
|
+
rexml = REXML::Document.new(xml);
|
9
|
+
xml_canonicalized = xml_canonicalizer.canonicalize(rexml);
|
10
|
+
xml_expect = "<foo bar=\"test\"></foo>";
|
11
|
+
assert_equal xml_expect, xml_canonicalized
|
12
|
+
end
|
13
|
+
|
14
|
+
should "canonicalize a complex xml file" do
|
15
|
+
fp = File.new(File.dirname(File.expand_path(__FILE__))+'/complex.xml','r')
|
16
|
+
xml = ''
|
17
|
+
while (l = fp.gets)
|
18
|
+
xml += l
|
19
|
+
end
|
20
|
+
fp.close
|
21
|
+
|
22
|
+
xml_canonicalizer = XML::Util::XmlCanonicalizer.new(true,true)
|
23
|
+
rexml = REXML::Document.new(xml);
|
24
|
+
xml_canonicalized = xml_canonicalizer.canonicalize(rexml);
|
25
|
+
|
26
|
+
fp = File.new(File.dirname(File.expand_path(__FILE__))+'/expected.xml','r')
|
27
|
+
xml_expect = ''
|
28
|
+
while (l = fp.gets)
|
29
|
+
xml_expect += l
|
30
|
+
end
|
31
|
+
fp.close
|
32
|
+
|
33
|
+
assert_equal xml_expect, xml_canonicalized
|
34
|
+
end
|
35
|
+
|
36
|
+
should "canonicalize a saml xml file correctly" do
|
37
|
+
fp = File.new(File.dirname(File.expand_path(__FILE__))+'/saml_assertion.xml','r')
|
38
|
+
xml = ''
|
39
|
+
while (l = fp.gets)
|
40
|
+
xml += l
|
41
|
+
end
|
42
|
+
fp.close
|
43
|
+
|
44
|
+
xml_canonicalizer = XML::Util::XmlCanonicalizer.new(false,true)
|
45
|
+
rexml = REXML::Document.new(xml);
|
46
|
+
xml_canonicalized = xml_canonicalizer.canonicalize(rexml);
|
47
|
+
|
48
|
+
fp = File.new(File.dirname(File.expand_path(__FILE__))+'/saml_expected_canonical_form.xml','r')
|
49
|
+
xml_expect = ''
|
50
|
+
while (l = fp.gets)
|
51
|
+
xml_expect += l
|
52
|
+
end
|
53
|
+
fp.close
|
54
|
+
|
55
|
+
assert_equal xml_expect, xml_canonicalized
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/tests.watchr
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Run me with:
|
2
|
+
#
|
3
|
+
# $ watchr specs.watchr
|
4
|
+
|
5
|
+
# --------------------------------------------------
|
6
|
+
# Convenience Methods
|
7
|
+
# --------------------------------------------------
|
8
|
+
def all_test_files
|
9
|
+
Dir['test/**/test_*.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
def run_test_matching(thing_to_match)
|
13
|
+
matches = all_test_files.grep(/#{thing_to_match}/i)
|
14
|
+
if matches.empty?
|
15
|
+
puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"
|
16
|
+
else
|
17
|
+
run matches.join(' ')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(files_to_run)
|
22
|
+
puts("Running: #{files_to_run}")
|
23
|
+
system("ruby -Ilib -Itest #{files_to_run}")
|
24
|
+
no_int_for_you
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_all_tests
|
28
|
+
run(all_test_files.join(' '))
|
29
|
+
end
|
30
|
+
|
31
|
+
# --------------------------------------------------
|
32
|
+
# Watchr Rules
|
33
|
+
# --------------------------------------------------
|
34
|
+
watch('^test/test_(.*)\.rb' ) { |m| run_test_matching(m[1]) }
|
35
|
+
#watch('^app/(.*)\.rb' ) { |m| run_test_matching(m[1]) }
|
36
|
+
#watch('^app/views/(.*)/(.*)') { |m| run_test_matching(m[1]) }
|
37
|
+
watch('^lib/(.*)\.rb' ) { |m| run_test_matching(m[1]) }
|
38
|
+
watch('^lib/xml/util/xmlcanonicalizer.rb') { run('test/test_xmlcanonicalizer.rb')}
|
39
|
+
|
40
|
+
# --------------------------------------------------
|
41
|
+
# Signal Handling
|
42
|
+
# --------------------------------------------------
|
43
|
+
|
44
|
+
def no_int_for_you
|
45
|
+
@sent_an_int = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
Signal.trap 'INT' do
|
49
|
+
if @sent_an_int then
|
50
|
+
puts " A second INT? Ok, I get the message. Shutting down now."
|
51
|
+
exit
|
52
|
+
else
|
53
|
+
puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
|
54
|
+
@sent_an_int = true
|
55
|
+
Kernel.sleep 1.5
|
56
|
+
run_all_tests
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
puts "Save a file to get watchr's attention."
|
61
|
+
|
62
|
+
# vim:ft=ruby
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: canonix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brendon Muir
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-16 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thoughtbot-shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: |-
|
35
|
+
This is based on andrewferk's rewrite for Ruby 1.9 compatibility, but applies
|
36
|
+
relevance's fix to ensure proper canonicalisation. It is intended that this be the new official
|
37
|
+
Ruby Canonicaliser as the other project seems to be abandoned.
|
38
|
+
email: brendon@spike.net.nz
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- canonix.gemspec
|
53
|
+
- lib/xml/util/xmlcanonicalizer.rb
|
54
|
+
- lib/xmlcanonicalizer.rb
|
55
|
+
- test/complex.xml
|
56
|
+
- test/expected.xml
|
57
|
+
- test/helper.rb
|
58
|
+
- test/saml_assertion.xml
|
59
|
+
- test/saml_expected_canonical_form.xml
|
60
|
+
- test/test_xmlcanonicalizer.rb
|
61
|
+
- tests.watchr
|
62
|
+
homepage: http://github.com/brendon/canonix
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.5
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: XML Canonicalizer for Ruby >= 1.92
|
95
|
+
test_files: []
|
96
|
+
|