canonix 0.1.3 → 0.1.4

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/.rvmrc CHANGED
@@ -1,2 +1,2 @@
1
1
  rvm_gemset_create_on_use_flag=1
2
- rvm gemset use canonix
2
+ rvm gemset use canonix
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Canonix
2
2
 
3
- XML Canonicalizer for Ruby >= 1.92
3
+ XML Canonicalizer for Ruby >= 1.9.2
4
4
 
5
5
  This is taken from XMLCanonicalizer/WSS4R and http://github.com/borisnadion/xml-canonicalizer and https://github.com/andrewferk/xmlcanonicalizer.
6
6
 
@@ -20,4 +20,4 @@ I personally have little understanding of the inner workings of this code, and w
20
20
  future version unintentionally.
21
21
  * Commit, do not mess with rakefile, version, or history.
22
22
  (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)
23
- * Send me a pull request. Bonus points for topic branches.
23
+ * Send me a pull request. Bonus points for topic branches.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "canonix"
8
- gem.summary = %Q{XML Canonicalizer for Ruby >= 1.92}
8
+ gem.summary = %Q{XML Canonicalizer for Ruby >= 1.9.2}
9
9
  gem.description = %Q{This is based on andrewferk's rewrite for Ruby 1.9 compatibility, but applies
10
10
  relevance's fix to ensure proper canonicalisation. It is intended that this be the new official
11
11
  Ruby XML Canonicaliser as the other project seems to be abandoned.}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/canonix.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{canonix}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brendon Muir"]
12
- s.date = %q{2011-07-03}
12
+ s.date = %q{2011-07-12}
13
13
  s.description = %q{This is based on andrewferk's rewrite for Ruby 1.9 compatibility, but applies
14
14
  relevance's fix to ensure proper canonicalisation. It is intended that this be the new official
15
15
  Ruby XML Canonicaliser as the other project seems to be abandoned.}
@@ -38,8 +38,8 @@ Gem::Specification.new do |s|
38
38
  ]
39
39
  s.homepage = %q{http://github.com/brendon/canonix}
40
40
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.5.0}
42
- s.summary = %q{XML Canonicalizer for Ruby >= 1.92}
41
+ s.rubygems_version = %q{1.4.2}
42
+ s.summary = %q{XML Canonicalizer for Ruby >= 1.9.2}
43
43
 
44
44
  if s.respond_to? :specification_version then
45
45
  s.specification_version = 3
@@ -1,84 +1,20 @@
1
- #require "rexml/document"
2
- #require "base64"
3
- #require "log4r"
1
+ # require "rexml/document"
2
+ # require "base64"
3
+ # require "log4r"
4
4
 
5
- #include REXML
6
- #include Log4r
5
+ # include REXML
6
+ # include Log4r
7
7
 
8
8
  require "rexml/document"
9
9
  require "base64"
10
10
 
11
11
  module XML
12
12
  include REXML
13
-
13
+
14
14
  module Util
15
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
16
  class NamespaceNode
81
- attr_reader :prefix, :uri
17
+ attr_reader :prefix, :uri
82
18
  def initialize(prefix, uri)
83
19
  @prefix = prefix
84
20
  @uri = uri
@@ -102,7 +38,6 @@ module XML
102
38
  def initialize(with_comments, excl_c14n)
103
39
  @with_comments = with_comments
104
40
  @exclusive = excl_c14n
105
- @res = ""
106
41
  @state = BEFORE_DOC_ELEMENT
107
42
  @xnl = Array.new()
108
43
  @prevVisibleNamespacesStart = 0
@@ -126,7 +61,6 @@ module XML
126
61
 
127
62
  def canonicalize(document)
128
63
  write_document_node(document)
129
- @res
130
64
  end
131
65
 
132
66
  def canonicalize_element(element, logging = true)
@@ -141,10 +75,10 @@ module XML
141
75
  ns = element.namespace(element.prefix())
142
76
  document.root().add_namespace(element.prefix(), ns)
143
77
  write_document_node(document)
144
- @res
145
78
  end
146
79
 
147
80
  def write_document_node(document)
81
+ @res = ""
148
82
  @state = BEFORE_DOC_ELEMENT
149
83
  if (document.class().to_s() == "REXML::Element")
150
84
  write_node(document)
@@ -161,19 +95,18 @@ module XML
161
95
  if ((node.node_type() == :text) && white_text?(node.value()))
162
96
  res = node.value()
163
97
  res.gsub("\r\n","\n")
164
- #res = res.delete(" ").delete("\t")
98
+ # res = res.delete(" ").delete("\t")
165
99
  res.delete("\r")
166
100
  @res = @res + res
167
- #write_text_node(node,visible) if (@state == INSIDE_DOC_ELEMENT)
101
+ # write_text_node(node,visible) if (@state == INSIDE_DOC_ELEMENT)
168
102
  return
169
103
  end
170
104
  if (node.node_type() == :text)
171
105
  write_text_node(node, visible)
172
106
  return
173
- end
107
+ end
174
108
  if (node.node_type() == :element)
175
- write_element_node(node, visible) if (!node.rendered?())
176
- node.rendered=(true)
109
+ write_element_node(node, visible)
177
110
  end
178
111
  if (node.node_type() == :processing_instruction)
179
112
  end
@@ -192,13 +125,13 @@ module XML
192
125
  write_attribute_axis(node)
193
126
  @res = @res + ">" if (visible)
194
127
  node.each_child{|child|
195
- write_node(child)
196
- }
128
+ write_node(child)
129
+ }
197
130
  @res = @res + "</" +node.expanded_name() + ">" if (visible)
198
131
  @state = AFTER_DOC_ELEMENT if (visible && state == BEFORE_DOC_ELEMENT)
199
132
  @prevVisibleNamespacesStart = savedPrevVisibleNamespacesStart
200
133
  @prevVisibleNamespacesEnd = savedPrevVisibleNamespacesEnd
201
- @visibleNamespaces.slice!(savedVisibleNamespacesSize, @visibleNamespaces.size() - savedVisibleNamespacesSize) if (@visibleNamespaces.size() > savedVisibleNamespacesSize)
134
+ @visibleNamespaces.slice!(savedVisibleNamespacesSize, @visibleNamespaces.size() - savedVisibleNamespacesSize) if (@visibleNamespaces.size() > savedVisibleNamespacesSize)
202
135
  end
203
136
 
204
137
  def write_namespace_axis(node, visible)
@@ -206,10 +139,9 @@ module XML
206
139
  has_empty_namespace = false
207
140
  list = Array.new()
208
141
  cur = node
209
- #while ((cur != nil) && (cur != doc) && (cur.node_type() != :document))
210
- namespaces = cur.node_namespaces()
211
- namespaces.each{|prefix|
212
- next if ((prefix == "xmlns") && (node.namespace(prefix) == ""))
142
+ # while ((cur != nil) && (cur != doc) && (cur.node_type() != :document))
143
+ node_namespaces(cur).each{|prefix|
144
+ next if ((prefix == "xmlns") && (node.namespace(prefix) == ""))
213
145
  namespace = cur.namespace(prefix)
214
146
  next if (is_namespace_node(namespace))
215
147
  next if (node.namespace(prefix) != cur.namespace(prefix))
@@ -222,14 +154,14 @@ module XML
222
154
  end
223
155
  has_empty_namespace = true if (prefix == nil)
224
156
  }
225
- if (visible && !has_empty_namespace && !is_namespace_rendered(nil, nil))
157
+ if (visible && !has_empty_namespace && !is_namespace_rendered(nil, nil))
226
158
  @res = @res + ' xmlns=""'
227
159
  end
228
160
 
229
161
  #: ns of inclusive_list
230
162
  if self.inclusive_namespaces && !self.inclusive_namespaces.empty?
231
163
  self.inclusive_namespaces.each{|prefix|
232
- list.push(prefix) if (!list.include?(prefix) && (node.attributes.prefixes.include?(prefix)))
164
+ list.push(prefix) if (!list.include?(prefix) && (node.attributes.prefixes.include?(prefix)))
233
165
  }
234
166
  end
235
167
 
@@ -243,10 +175,24 @@ module XML
243
175
  }
244
176
  if (visible)
245
177
  @prevVisibleNamespacesStart = @prevVisibleNamespacesEnd
246
- @prevVisibleNamespacesEnd = @visibleNamespaces.size()
178
+ @prevVisibleNamespacesEnd = @visibleNamespaces.size()
247
179
  end
248
180
  end
249
181
 
182
+ def node_namespaces(node)
183
+ ns = Array.new()
184
+ ns.push(node.prefix())
185
+ node.attributes().each_attribute{|a|
186
+ if (a.prefix() != nil)
187
+ ns.push(a.prefix())
188
+ end
189
+ if (a.prefix() == "" && a.local_name() == "xmlns")
190
+ ns.push("xmlns")
191
+ end
192
+ }
193
+ ns
194
+ end
195
+
250
196
  def write_attribute_axis(node)
251
197
  list = Array.new()
252
198
  node.attributes.keys.sort.each{|key|
@@ -256,7 +202,7 @@ module XML
256
202
  if (!@exclusive && node.parent() != nil && node.parent().parent() != nil)
257
203
  cur = node.parent()
258
204
  while (cur != nil)
259
- #next if (cur.attributes() == nil)
205
+ # next if (cur.attributes() == nil)
260
206
  cur.each_attribute{|attribute|
261
207
  next if (attribute.prefix() != "xml")
262
208
  next if (attribute.prefix().index("xmlns") == 0)
@@ -277,10 +223,9 @@ module XML
277
223
  if (attribute != nil)
278
224
  if (attribute.name() != "xmlns")
279
225
  @res = @res + " " + normalize_string(attribute.to_string(), NODE_TYPE_ATTRIBUTE).gsub("'",'"')
226
+ # else
227
+ # @res = @res + " " + normalize_string(attribute.name()+'="'+attribute.to_s()+'"', NODE_TYPE_ATTRIBUTE).gsub("'",'"')
280
228
  end
281
- # else
282
- # @res = @res + " " + normalize_string(attribute.name()+'="'+attribute.to_s()+'"', NODE_TYPE_ATTRIBUTE).gsub("'",'"')
283
- #end
284
229
  end
285
230
  }
286
231
  end
@@ -302,13 +247,13 @@ module XML
302
247
  end
303
248
  }
304
249
  return is_empty_ns
305
- #(@visibleNamespaces.size()-1).downto(start) {|i|
250
+ # (@visibleNamespaces.size()-1).downto(start) {|i|
306
251
  # ns = @visibleNamespaces[i]
307
- # return true if (ns.prefix() == "xmlns:"+prefix.to_s() && ns.uri() == uri)
308
- # #p = ns.prefix() if (ns.prefix().index("xmlns") == 0)
309
- # #return ns.uri() == uri if (p == prefix)
310
- #}
311
- #return is_empty_ns
252
+ # return true if (ns.prefix() == "xmlns:"+prefix.to_s() && ns.uri() == uri)
253
+ # # p = ns.prefix() if (ns.prefix().index("xmlns") == 0)
254
+ # # return ns.uri() == uri if (p == prefix)
255
+ # }
256
+ # return is_empty_ns
312
257
  end
313
258
 
314
259
  def is_node_visible(node)
@@ -322,30 +267,29 @@ module XML
322
267
  def normalize_string(input, type)
323
268
  sb = ""
324
269
  return input
270
+ # input.each_byte{|b|
271
+ # if (b == 60 && (type == NODE_TYPE_ATTRIBUTE || is_text_node(type)))
272
+ # sb = sb + "&lt;"
273
+ # elsif (b == 62 && is_text_node(type))
274
+ # sb = sb + "&gt;"
275
+ # elsif (b == 38 && (is_text_node(type) || is_text_node(type))) #Ampersand
276
+ # sb = sb + "&amp;"
277
+ # elsif (b == 34 && is_text_node(type)) #Quote
278
+ # sb = sb + "&quot;"
279
+ # elsif (b == 9 && is_text_node(type)) #Tabulator
280
+ # sb = sb + "&#x9;"
281
+ # elsif (b == 11 && is_text_node(type)) #CR
282
+ # sb = sb + "&#xA;"
283
+ # elsif (b == 13 && (type == NODE_TYPE_ATTRIBUTE || (is_text_node(type) && type != NODE_TYPE_WHITESPACE) || type == NODE_TYPE_COMMENT || type == NODE_TYPE_PI))
284
+ # sb = sb + "&#xD;"
285
+ # elsif (b == 13)
286
+ # next
287
+ # else
288
+ # sb = sb.concat(b)
289
+ # end
290
+ # }
291
+ # sb
325
292
  end
326
- #input.each_byte{|b|
327
- # if (b ==60 && (type == NODE_TYPE_ATTRIBUTE || is_text_node(type)))
328
- # sb = sb + "&lt;"
329
- # elsif (b == 62 && is_text_node(type))
330
- # sb = sb + "&gt;"
331
- # elsif (b == 38 && (is_text_node(type) || is_text_node(type))) #Ampersand
332
- # sb = sb + "&amp;"
333
- # elsif (b == 34 && is_text_node(type)) #Quote
334
- # sb = sb + "&quot;"
335
- # elsif (b == 9 && is_text_node(type)) #Tabulator
336
- # sb = sb + "&#x9;"
337
- # elsif (b == 11 && is_text_node(type)) #CR
338
- # sb = sb + "&#xA;"
339
- # elsif (b == 13 && (type == NODE_TYPE_ATTRIBUTE || (is_text_node(type) && type != NODE_TYPE_WHITESPACE) || type == NODE_TYPE_COMMENT || type == NODE_TYPE_PI))
340
- # sb = sb + "&#xD;"
341
- # elsif (b == 13)
342
- # next
343
- # else
344
- # sb = sb.concat(b)
345
- # end
346
- #}
347
- #sb
348
- #end
349
293
 
350
294
  def write_text_node(node, visible)
351
295
  if (visible)
@@ -359,7 +303,7 @@ module XML
359
303
  end
360
304
 
361
305
  def is_namespace_decl(attribute)
362
- #return true if (attribute.name() == "xmlns")
306
+ # return true if (attribute.name() == "xmlns")
363
307
  return true if (attribute.prefix().index("xmlns") == 0)
364
308
  return false
365
309
  end
@@ -373,8 +317,8 @@ module XML
373
317
  new_string = ""
374
318
  in_white = false
375
319
  string.each_byte{|b|
376
- #if (in_white && b == 32)
377
- #else
320
+ # if (in_white && b == 32)
321
+ # else
378
322
  if !(in_white && b == 32)
379
323
  new_string = new_string + b.chr()
380
324
  end
@@ -388,7 +332,7 @@ module XML
388
332
  new_string
389
333
  end
390
334
  end
391
- end #Util
335
+ end #Util
392
336
  end #XML
393
337
 
394
338
 
@@ -397,7 +341,7 @@ if __FILE__ == $0
397
341
  body = nil
398
342
  c = WSS4R::Security::Util::XmlCanonicalizer.new(false, true)
399
343
 
400
- if (ARGV.size() == 3)
344
+ if (ARGV.size() == 3)
401
345
  body = ARGV[2]
402
346
  if (body == "true")
403
347
  element = XPath.match(document, "/soap:Envelope/soap:Body")[0]
@@ -406,15 +350,15 @@ if __FILE__ == $0
406
350
  puts("-----")
407
351
  puts(result)
408
352
  puts("-----")
409
- puts(result.size())
353
+ puts(result.size())
410
354
  puts("-----")
411
355
  puts(CryptHash.new().digest_b64(result))
412
356
  end
413
- else
357
+ else
414
358
  result = c.canonicalize(document)
415
359
  end
416
360
 
417
361
  file = File.new(ARGV[1], "wb")
418
362
  file.write(result)
419
363
  file.close()
420
- end
364
+ end
@@ -1 +1 @@
1
- require 'xml/util/xmlcanonicalizer'
1
+ require 'xml/util/xmlcanonicalizer'
data/test/helper.rb CHANGED
@@ -8,3 +8,15 @@ require 'xmlcanonicalizer'
8
8
 
9
9
  class Test::Unit::TestCase
10
10
  end
11
+
12
+ def fixture_path(name)
13
+ File.join(File.dirname(__FILE__), name)
14
+ end
15
+
16
+ def fixture(name)
17
+ File.read(fixture_path(name))
18
+ end
19
+
20
+ def rexml_fixture(name)
21
+ REXML::Document.new(fixture(name))
22
+ end
@@ -1,79 +1,105 @@
1
1
  require File.dirname(File.expand_path(__FILE__))+'/helper'
2
2
 
3
- class TestXmlcanonicalizer < Test::Unit::TestCase
3
+ class TestXmlCanonicalizer < Test::Unit::TestCase
4
4
 
5
5
  should "canonicalize a simple xml file" do
6
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>";
7
+
8
+ xml = "<foo bar='test'/>"
9
+ rexml = REXML::Document.new(xml)
10
+ xml_canonicalized = xml_canonicalizer.canonicalize(rexml)
11
+
12
+ xml_expect = "<foo bar=\"test\"></foo>"
11
13
  assert_equal xml_expect, xml_canonicalized
12
14
  end
13
15
 
14
16
  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
17
  xml_canonicalizer = XML::Util::XmlCanonicalizer.new(true,true)
23
- rexml = REXML::Document.new(xml);
24
- xml_canonicalized = xml_canonicalizer.canonicalize(rexml);
25
18
 
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
19
+ rexml = rexml_fixture("complex.xml")
20
+ xml_canonicalized = xml_canonicalizer.canonicalize(rexml)
32
21
 
22
+ xml_expect = fixture("expected.xml")
33
23
  assert_equal xml_expect, xml_canonicalized
34
24
  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
25
+
26
+ should "canonicalize multiple documents" do
27
+ xml_canonicalizer = XML::Util::XmlCanonicalizer.new(true,true)
28
+
29
+ rexml_1 = rexml_fixture("complex.xml")
30
+ xml_canonicalizer.canonicalize(rexml_1)
31
+
32
+ rexml_2 = rexml_fixture("complex.xml")
33
+ xml_canonicalized_2 = xml_canonicalizer.canonicalize(rexml_2)
34
+
35
+ xml_expect = fixture("expected.xml")
36
+ assert_equal xml_expect, xml_canonicalized_2
37
+ end
38
+
39
+ should "canonicalize the same document multiple times" do
40
+ xml_canonicalizer = XML::Util::XmlCanonicalizer.new(true,true)
41
+
42
+ rexml = rexml_fixture("complex.xml")
43
+ xml_canonicalized_1 = xml_canonicalizer.canonicalize(rexml)
44
+ xml_canonicalized_2 = xml_canonicalizer.canonicalize(rexml)
45
+
46
+ assert_equal xml_canonicalized_1, xml_canonicalized_2
47
+ end
48
+
49
+ should "canonicalize an xml element correctly" do
50
+ xml_canonicalizer = XML::Util::XmlCanonicalizer.new(true,true)
43
51
 
52
+ rexml = rexml_fixture("complex.xml")
53
+ element = REXML::XPath.first(rexml, "//AttributeValue[@FriendlyName='type']")
54
+ element_canonicalized = xml_canonicalizer.canonicalize(element)
55
+
56
+ element_expected = '<AttributeValue FriendlyName="type" type="example:profile:attribute">Person</AttributeValue>'
57
+ assert_equal element_expected, element_canonicalized
58
+ end
59
+
60
+ should "canonicalize the same element multiple times" do
61
+ xml_canonicalizer = XML::Util::XmlCanonicalizer.new(true,true)
62
+
63
+ rexml = rexml_fixture("complex.xml")
64
+ element = REXML::XPath.first(rexml, "//AttributeValue[@FriendlyName='type']")
65
+ element_canonicalized_1 = xml_canonicalizer.canonicalize(element)
66
+ element_canonicalized_2 = xml_canonicalizer.canonicalize(element)
67
+
68
+ assert_equal element_canonicalized_1, element_canonicalized_2
69
+ end
70
+
71
+ should "canonicalize multiple xml elements correctly" do
72
+ xml_canonicalizer = XML::Util::XmlCanonicalizer.new(true,true)
73
+
74
+ rexml = rexml_fixture("complex.xml")
75
+
76
+ element_1 = REXML::XPath.first(rexml, "//AttributeValue[@FriendlyName='type']")
77
+ xml_canonicalizer.canonicalize(element_1)
78
+
79
+ element_2 = REXML::XPath.first(rexml, "//AuthnStatement")
80
+ element_2_canonicalized = xml_canonicalizer.canonicalize(element_2)
81
+ element_2_expected = '<AuthnStatement AuthnInstant="2010-09-10T00:00:50-05:00"><AuthnContext><AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PreviousSession</AuthnContextClassRef></AuthnContext></AuthnStatement>'
82
+ assert_equal element_2_expected, element_2_canonicalized
83
+ end
84
+
85
+ should "canonicalize a saml xml file correctly" do
44
86
  xml_canonicalizer = XML::Util::XmlCanonicalizer.new(false,true)
45
- rexml = REXML::Document.new(xml);
46
- xml_canonicalized = xml_canonicalizer.canonicalize(rexml);
47
87
 
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
88
+ rexml = rexml_fixture("saml_assertion.xml")
89
+ xml_canonicalized = xml_canonicalizer.canonicalize(rexml)
54
90
 
91
+ xml_expect = fixture("saml_expected_canonical_form.xml")
55
92
  assert_equal xml_expect, xml_canonicalized
56
93
  end
57
94
 
58
95
  should "canonicalize a saml file with inclusive namespaces" do
59
- fp = File.new(File.dirname(File.expand_path(__FILE__))+'/saml_with_inclusive_ns_assertion.xml','r')
60
- xml = ''
61
- while (l = fp.gets)
62
- xml += l
63
- end
64
- fp.close
65
-
66
96
  xml_canonicalizer = XML::Util::XmlCanonicalizer.new(false,true)
67
- rexml = REXML::Document.new(xml);
97
+
98
+ rexml = rexml_fixture("saml_with_inclusive_ns_assertion.xml")
68
99
  xml_canonicalizer.inclusive_namespaces = %w(ds saml samlp xs)
69
- xml_canonicalized = xml_canonicalizer.canonicalize(rexml);
70
-
71
- fp = File.new(File.dirname(File.expand_path(__FILE__))+'/saml_with_inclusive_ns_expected_canonical_form.xml','r')
72
- xml_expect = ''
73
- while (l = fp.gets)
74
- xml_expect += l
75
- end
76
- fp.close
100
+ xml_canonicalized = xml_canonicalizer.canonicalize(rexml)
101
+
102
+ xml_expect = fixture("saml_with_inclusive_ns_expected_canonical_form.xml")
77
103
  assert_equal xml_expect, xml_canonicalized #, (xml_canonicalized.to_s + "\n\n" + xml_expect)
78
104
  end
79
105
 
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canonix
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease:
5
- version: 0.1.3
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 4
10
+ version: 0.1.4
6
11
  platform: ruby
7
12
  authors:
8
13
  - Brendon Muir
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-07-03 00:00:00 +12:00
18
+ date: 2011-07-12 00:00:00 +12:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -21,6 +26,9 @@ dependencies:
21
26
  requirements:
22
27
  - - ">="
23
28
  - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
24
32
  version: "0"
25
33
  type: :development
26
34
  version_requirements: *id001
@@ -67,19 +75,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
75
  requirements:
68
76
  - - ">="
69
77
  - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
70
81
  version: "0"
71
82
  required_rubygems_version: !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ">="
75
86
  - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
76
90
  version: "0"
77
91
  requirements: []
78
92
 
79
93
  rubyforge_project:
80
- rubygems_version: 1.5.0
94
+ rubygems_version: 1.4.2
81
95
  signing_key:
82
96
  specification_version: 3
83
- summary: XML Canonicalizer for Ruby >= 1.92
97
+ summary: XML Canonicalizer for Ruby >= 1.9.2
84
98
  test_files: []
85
99