information_card 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,188 @@
1
+ require 'test_helper'
2
+
3
+ class XmlCanonicalizerTest < Test::Unit::TestCase
4
+ include InformationCard
5
+
6
+ INPUT_SAML_ASSERTION =
7
+ %(<saml:Assertion AssertionID="uuid:324e84c9-29bc-46a5-8775-3efdc6af7312"
8
+ IssueInstant="2007-04-12T22:44:02.734Z"
9
+ xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
10
+ MinorVersion="1"
11
+ Issuer="http://schemas.xmlsoap.org/ws/2005/05/identity/issuer/self"
12
+ MajorVersion="1">
13
+ <saml:Conditions NotBefore="2007-04-12T22:44:02.734Z" NotOnOrAfter="2007-04-12T23:44:02.734Z">
14
+ <saml:AudienceRestrictionCondition>
15
+ <saml:Audience>https://informationcardruby.com/</saml:Audience>
16
+ </saml:AudienceRestrictionCondition>
17
+ </saml:Conditions>
18
+ <saml:AttributeStatement>
19
+ <saml:Subject>
20
+ <saml:SubjectConfirmation>
21
+ <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod>
22
+ </saml:SubjectConfirmation>
23
+ </saml:Subject>
24
+ <saml:Attribute AttributeName="givenname" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
25
+ <saml:AttributeValue>John</saml:AttributeValue>
26
+ </saml:Attribute>
27
+ <saml:Attribute AttributeName="surname" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
28
+ <saml:AttributeValue>Smith</saml:AttributeValue>
29
+ </saml:Attribute>
30
+ <saml:Attribute AttributeName="emailaddress" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
31
+ <saml:AttributeValue>jsmith@email.com</saml:AttributeValue>
32
+ </saml:Attribute>
33
+ <saml:Attribute AttributeName="privatepersonalidentifier" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
34
+ <saml:AttributeValue>wA+KnezOWCMKX6LmVzSVF9b1im1iZaUVShLA2d+IZtg=</saml:AttributeValue>
35
+ </saml:Attribute>
36
+ </saml:AttributeStatement>
37
+ </saml:Assertion>
38
+ )
39
+
40
+ CANONICALIZED_SAML_ASSERTION =
41
+ %(<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" AssertionID="uuid:324e84c9-29bc-46a5-8775-3efdc6af7312" IssueInstant="2007-04-12T22:44:02.734Z" Issuer="http://schemas.xmlsoap.org/ws/2005/05/identity/issuer/self" MajorVersion="1" MinorVersion="1">
42
+ <saml:Conditions NotBefore="2007-04-12T22:44:02.734Z" NotOnOrAfter="2007-04-12T23:44:02.734Z">
43
+ <saml:AudienceRestrictionCondition>
44
+ <saml:Audience>https://informationcardruby.com/</saml:Audience>
45
+ </saml:AudienceRestrictionCondition>
46
+ </saml:Conditions>
47
+ <saml:AttributeStatement>
48
+ <saml:Subject>
49
+ <saml:SubjectConfirmation>
50
+ <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod>
51
+ </saml:SubjectConfirmation>
52
+ </saml:Subject>
53
+ <saml:Attribute AttributeName="givenname" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
54
+ <saml:AttributeValue>John</saml:AttributeValue>
55
+ </saml:Attribute>
56
+ <saml:Attribute AttributeName="surname" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
57
+ <saml:AttributeValue>Smith</saml:AttributeValue>
58
+ </saml:Attribute>
59
+ <saml:Attribute AttributeName="emailaddress" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
60
+ <saml:AttributeValue>jsmith@email.com</saml:AttributeValue>
61
+ </saml:Attribute>
62
+ <saml:Attribute AttributeName="privatepersonalidentifier" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
63
+ <saml:AttributeValue>wA+KnezOWCMKX6LmVzSVF9b1im1iZaUVShLA2d+IZtg=</saml:AttributeValue>
64
+ </saml:Attribute>
65
+ </saml:AttributeStatement>
66
+ </saml:Assertion>)
67
+
68
+
69
+ def setup
70
+ @canonicalizer = XmlCanonicalizer.new
71
+ end
72
+
73
+ def test_should_canonicalize_full_saml_assertion_as_element
74
+ signed_doc = REXML::Document.new(INPUT_SAML_ASSERTION)
75
+ signed_element = REXML::XPath.first(signed_doc, "saml:Assertion")
76
+ assert_equal CANONICALIZED_SAML_ASSERTION, @canonicalizer.canonicalize(signed_element)
77
+ end
78
+
79
+ def test_should_canonicalize_full_saml_assertion_as_document
80
+ assert_xml CANONICALIZED_SAML_ASSERTION, INPUT_SAML_ASSERTION
81
+ end
82
+
83
+ def test_should_convert_line_breaks
84
+ input = "<person>\n<name>John</name>\r\n<age>25</age>\r</person>"
85
+ expected = "<person>\n<name>John</name>\n<age>25</age>\n</person>"
86
+ assert_xml(expected, input)
87
+ end
88
+
89
+ def test_should_normalize_white_space_between_attribute_values
90
+ input = "<person first=\"Dr. \t\tBob\" last=\"Smit\th\" phone=\"\t555\t 1234\"></person>"
91
+ expected = %(<person first="Dr. Bob" last="Smit h" phone="555 1234"></person>)
92
+ assert_xml(expected, input)
93
+ end
94
+
95
+ def test_should_preserve_quote_within_node_text
96
+ input = "<person>Mr Bob's Wild Adventure</person>"
97
+ expected = "<person>Mr Bob's Wild Adventure</person>"
98
+ assert_xml(expected, input)
99
+ end
100
+
101
+ def test_should_preserve_quote_and_normalize_white_space_within_node_text
102
+ input = "<person>Mr Bob' s Wild Adventure</person>"
103
+ expected = "<person>Mr Bob' s Wild Adventure</person>"
104
+ assert_xml(expected, input)
105
+ end
106
+
107
+ def test_should_double_quote_attribute_values
108
+ input = "<product id='1234' name=\"turbine\" xlmns='http://namespace'></product>"
109
+ expected = %(<product id="1234" name="turbine" xlmns="http://namespace"></product>)
110
+ assert_xml(expected, input)
111
+ end
112
+
113
+ def test_should_replace_special_character_quote_in_attribute_values
114
+ input = "<person first='John Smith \"JS\"'></person>"
115
+ expected = %(<person first="John Smith &quot;JS&quot;"></person>)
116
+ assert_xml(expected, input)
117
+ end
118
+
119
+ def test_should_replace_special_character_amp_in_attribute_values
120
+ input = "<product company=\"Smith & Smith\"></product>"
121
+ expected = %(<product company="Smith &amp; Smith"></product>)
122
+ assert_xml(expected, input)
123
+ end
124
+
125
+ def test_should_replace_special_character_less_than_in_attribute_values
126
+ input = "<product description=\"< 10 pounds\"></product>"
127
+ expected = %(<product description="&lt; 10 pounds"></product>)
128
+ assert_xml(expected, input)
129
+ end
130
+
131
+ def test_should_resolv_entity_references
132
+ input = %(<?xml version="1.0"?><!DOCTYPE person [<!ENTITY comment "This is a person.">]><person><notes>&comment;</notes></person>)
133
+ expected = %(<person><notes>This is a person.</notes></person>)
134
+ assert_xml(expected, input)
135
+ end
136
+
137
+ def test_should_remove_xml_and_dtd_declarations
138
+ input = %(<?xml version="1.0"?><!DOCTYPE person [<!ATTLIST person name CDATA "None"><!ENTITY comment "This is a person.">]><person name="Bob"></person>)
139
+ expected = %(<person name="Bob"></person>)
140
+ assert_xml(expected, input)
141
+ end
142
+
143
+ def test_should_remove_white_space_outside_the_outer_most_element
144
+ input = %( <person name="Bob"></person>)
145
+ expected = %(<person name="Bob"></person>)
146
+ assert_xml(expected, input)
147
+ end
148
+
149
+ def test_should_normalize_white_space_in_start_and_end_elements
150
+ input = %(<person first = "bob" id="1234" last="smith" ></person >)
151
+ expected = %(<person first="bob" id="1234" last="smith"></person>)
152
+ assert_xml(expected, input)
153
+ end
154
+
155
+ def test_should_normalize_white_space_in_start_and_end_elements_when_no_attributes_exist
156
+ input = %(<person ><name >Bob</name ></person >)
157
+ expected = %(<person><name>Bob</name></person>)
158
+ assert_xml(expected, input)
159
+ end
160
+
161
+ def test_should_expand_empty_elements
162
+ input = %(<person/>)
163
+ expected = %(<person></person>)
164
+ assert_xml(expected, input)
165
+ end
166
+
167
+ def test_should_expand_empty_elements_with_attributes
168
+ input = %(<person id="1234"/>)
169
+ expected = %(<person id="1234"></person>)
170
+ assert_xml(expected, input)
171
+ end
172
+
173
+ def test_should_remove_unnecessary_namespace_declarations
174
+ input = %(<person xmlns="http://www.mynamespace.com/person"><id>123</id><name xmlns="http://www.mynamespace.com/person">John</name></person>)
175
+ expected = %(<person xmlns="http://www.mynamespace.com/person"><id>123</id><name>John</name></person>)
176
+ assert_xml(expected, input)
177
+ end
178
+
179
+ def test_should_order_namespace_declarations_and_attributes
180
+ input = %(<person last="Smith" first="John" xmlns="http://www.mynamespace.com/person"></person>)
181
+ expected = %(<person xmlns="http://www.mynamespace.com/person" first="John" last="Smith"></person>)
182
+ assert_xml(expected, input)
183
+ end
184
+
185
+ def assert_xml(expected, input)
186
+ assert_equal expected, @canonicalizer.canonicalize(REXML::Document.new(input))
187
+ end
188
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.1
3
+ specification_version: 1
4
+ name: information_card
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-06-19 00:00:00 -06:00
8
+ summary: A library for processing information cards
9
+ require_paths:
10
+ - lib
11
+ email: informationcard-users@rubyforge.org
12
+ homepage: http://informationcardruby.com
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: information_card
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Joe Poon, Jason Sallis
31
+ files:
32
+ - lib/information_card
33
+ - lib/information_card.rb
34
+ - lib/information_card/certificate_util.rb
35
+ - lib/information_card/claim_types.rb
36
+ - lib/information_card/config.rb
37
+ - lib/information_card/decrypter.rb
38
+ - lib/information_card/identity_token.rb
39
+ - lib/information_card/invalid_token.rb
40
+ - lib/information_card/namespaces.rb
41
+ - lib/information_card/processor.rb
42
+ - lib/information_card/saml_token.rb
43
+ - lib/information_card/xml_canonicalizer.rb
44
+ - test/certificate_util_test.rb
45
+ - test/claim_types_test.rb
46
+ - test/decrypter_test.rb
47
+ - test/fixtures
48
+ - test/processor_test.rb
49
+ - test/saml_token_test.rb
50
+ - test/test_helper.rb
51
+ - test/xml_canonicalizer_test.rb
52
+ - test/fixtures/certificates
53
+ - test/fixtures/encrypted_information_cards
54
+ - test/fixtures/saml_tokens
55
+ - test/fixtures/certificates/test.crt
56
+ - test/fixtures/certificates/test.key
57
+ - test/fixtures/encrypted_information_cards/jack_deer.xml
58
+ - test/fixtures/encrypted_information_cards/john_smith.xml
59
+ - test/fixtures/saml_tokens/jack_deer.xml
60
+ - test/fixtures/saml_tokens/john_smith.xml
61
+ - Rakefile
62
+ - LICENSE
63
+ - CHANGELOG
64
+ - README
65
+ test_files: []
66
+
67
+ rdoc_options: []
68
+
69
+ extra_rdoc_files:
70
+ - README
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ requirements: []
76
+
77
+ dependencies: []
78
+