maestrano-ruby-test 0.8.3
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.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +45 -0
- data/LICENSE +21 -0
- data/README.md +794 -0
- data/Rakefile +40 -0
- data/bin/maestrano-console +9 -0
- data/lib/maestrano.rb +271 -0
- data/lib/maestrano/account/bill.rb +14 -0
- data/lib/maestrano/account/recurring_bill.rb +14 -0
- data/lib/maestrano/api/error/authentication_error.rb +8 -0
- data/lib/maestrano/api/error/base_error.rb +24 -0
- data/lib/maestrano/api/error/connection_error.rb +8 -0
- data/lib/maestrano/api/error/invalid_request_error.rb +14 -0
- data/lib/maestrano/api/list_object.rb +37 -0
- data/lib/maestrano/api/object.rb +187 -0
- data/lib/maestrano/api/operation/base.rb +215 -0
- data/lib/maestrano/api/operation/create.rb +18 -0
- data/lib/maestrano/api/operation/delete.rb +13 -0
- data/lib/maestrano/api/operation/list.rb +18 -0
- data/lib/maestrano/api/operation/update.rb +59 -0
- data/lib/maestrano/api/resource.rb +47 -0
- data/lib/maestrano/api/util.rb +122 -0
- data/lib/maestrano/open_struct.rb +11 -0
- data/lib/maestrano/saml/attribute_value.rb +15 -0
- data/lib/maestrano/saml/metadata.rb +64 -0
- data/lib/maestrano/saml/request.rb +93 -0
- data/lib/maestrano/saml/response.rb +201 -0
- data/lib/maestrano/saml/schemas/saml20assertion_schema.xsd +283 -0
- data/lib/maestrano/saml/schemas/saml20protocol_schema.xsd +302 -0
- data/lib/maestrano/saml/schemas/xenc_schema.xsd +146 -0
- data/lib/maestrano/saml/schemas/xmldsig_schema.xsd +318 -0
- data/lib/maestrano/saml/settings.rb +37 -0
- data/lib/maestrano/saml/validation_error.rb +7 -0
- data/lib/maestrano/sso.rb +86 -0
- data/lib/maestrano/sso/base_group.rb +31 -0
- data/lib/maestrano/sso/base_membership.rb +25 -0
- data/lib/maestrano/sso/base_user.rb +75 -0
- data/lib/maestrano/sso/group.rb +24 -0
- data/lib/maestrano/sso/session.rb +107 -0
- data/lib/maestrano/sso/user.rb +34 -0
- data/lib/maestrano/version.rb +3 -0
- data/lib/maestrano/xml_security/signed_document.rb +170 -0
- data/maestrano.gemspec +32 -0
- data/maestrano.png +0 -0
- data/test/helpers/api_helpers.rb +115 -0
- data/test/helpers/saml_helpers.rb +62 -0
- data/test/maestrano/account/bill_test.rb +48 -0
- data/test/maestrano/account/recurring_bill_test.rb +49 -0
- data/test/maestrano/api/list_object_test.rb +20 -0
- data/test/maestrano/api/object_test.rb +28 -0
- data/test/maestrano/api/resource_test.rb +343 -0
- data/test/maestrano/api/util_test.rb +31 -0
- data/test/maestrano/maestrano_test.rb +260 -0
- data/test/maestrano/open_struct_test.rb +10 -0
- data/test/maestrano/saml/request_test.rb +168 -0
- data/test/maestrano/saml/response_test.rb +290 -0
- data/test/maestrano/saml/settings_test.rb +51 -0
- data/test/maestrano/sso/base_group_test.rb +54 -0
- data/test/maestrano/sso/base_membership_test.rb +45 -0
- data/test/maestrano/sso/base_user_test.rb +114 -0
- data/test/maestrano/sso/group_test.rb +47 -0
- data/test/maestrano/sso/session_test.rb +161 -0
- data/test/maestrano/sso/user_test.rb +65 -0
- data/test/maestrano/sso_test.rb +105 -0
- data/test/maestrano/xml_security/signed_document.rb +163 -0
- data/test/support/saml/certificates/certificate1 +12 -0
- data/test/support/saml/certificates/r1_certificate2_base64 +1 -0
- data/test/support/saml/responses/adfs_response_sha1.xml +46 -0
- data/test/support/saml/responses/adfs_response_sha256.xml +46 -0
- data/test/support/saml/responses/adfs_response_sha384.xml +46 -0
- data/test/support/saml/responses/adfs_response_sha512.xml +46 -0
- data/test/support/saml/responses/no_signature_ns.xml +48 -0
- data/test/support/saml/responses/open_saml_response.xml +56 -0
- data/test/support/saml/responses/r1_response6.xml.base64 +1 -0
- data/test/support/saml/responses/response1.xml.base64 +1 -0
- data/test/support/saml/responses/response2.xml.base64 +79 -0
- data/test/support/saml/responses/response3.xml.base64 +66 -0
- data/test/support/saml/responses/response4.xml.base64 +93 -0
- data/test/support/saml/responses/response5.xml.base64 +102 -0
- data/test/support/saml/responses/response_with_ampersands.xml +139 -0
- data/test/support/saml/responses/response_with_ampersands.xml.base64 +93 -0
- data/test/support/saml/responses/response_with_multiple_attribute_values.xml +57 -0
- data/test/support/saml/responses/simple_saml_php.xml +71 -0
- data/test/support/saml/responses/starfield_response.xml.base64 +1 -0
- data/test/support/saml/responses/wrapped_response_2.xml.base64 +150 -0
- data/test/test_helper.rb +47 -0
- metadata +315 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
module Maestrano
|
|
4
|
+
module Saml
|
|
5
|
+
class SamlTest < Test::Unit::TestCase
|
|
6
|
+
include SamlTestHelper
|
|
7
|
+
|
|
8
|
+
context "Response" do
|
|
9
|
+
should "raise an exception when response is initialized with nil" do
|
|
10
|
+
assert_raises(ArgumentError) { Maestrano::Saml::Response.new(nil) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
should "be able to parse a document which contains ampersands" do
|
|
14
|
+
Maestrano::XMLSecurity::SignedDocument.any_instance.stubs(:digests_match?).returns(true)
|
|
15
|
+
Maestrano::Saml::Response.any_instance.stubs(:validate_conditions).returns(true)
|
|
16
|
+
|
|
17
|
+
response = Maestrano::Saml::Response.new(ampersands_response)
|
|
18
|
+
settings = Maestrano::Saml::Settings.new
|
|
19
|
+
settings.idp_cert_fingerprint = 'c51985d947f1be57082025050846eb27f6cab783'
|
|
20
|
+
response.settings = settings
|
|
21
|
+
response.validate!
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
should "adapt namespace" do
|
|
25
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
26
|
+
assert !response.name_id.nil?
|
|
27
|
+
response = Maestrano::Saml::Response.new(response_document_2)
|
|
28
|
+
assert !response.name_id.nil?
|
|
29
|
+
response = Maestrano::Saml::Response.new(response_document_3)
|
|
30
|
+
assert !response.name_id.nil?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
should "default to raw input when a response is not Base64 encoded" do
|
|
34
|
+
decoded = Base64.decode64(response_document_2)
|
|
35
|
+
response = Maestrano::Saml::Response.new(decoded)
|
|
36
|
+
assert response.document
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "Assertion" do
|
|
40
|
+
should "only retreive an assertion with an ID that matches the signature's reference URI" do
|
|
41
|
+
response = Maestrano::Saml::Response.new(wrapped_response_2)
|
|
42
|
+
response.stubs(:conditions).returns(nil)
|
|
43
|
+
settings = Maestrano::Saml::Settings.new
|
|
44
|
+
settings.idp_cert_fingerprint = signature_fingerprint_1
|
|
45
|
+
response.settings = settings
|
|
46
|
+
assert response.name_id.nil?
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "#validate!" do
|
|
51
|
+
should "raise when encountering a condition that prevents the document from being valid" do
|
|
52
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
53
|
+
assert_raise(Maestrano::Saml::ValidationError) do
|
|
54
|
+
response.validate!
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "#is_valid?" do
|
|
60
|
+
should "return false when response is initialized with blank data" do
|
|
61
|
+
response = Maestrano::Saml::Response.new('')
|
|
62
|
+
assert !response.is_valid?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
should "return false if settings have not been set" do
|
|
66
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
67
|
+
assert !response.is_valid?
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
should "return true when the response is initialized with valid data" do
|
|
71
|
+
response = Maestrano::Saml::Response.new(response_document_4)
|
|
72
|
+
response.stubs(:conditions).returns(nil)
|
|
73
|
+
assert !response.is_valid?
|
|
74
|
+
settings = Maestrano::Saml::Settings.new
|
|
75
|
+
assert !response.is_valid?
|
|
76
|
+
response.settings = settings
|
|
77
|
+
assert !response.is_valid?
|
|
78
|
+
settings.idp_cert_fingerprint = signature_fingerprint_1
|
|
79
|
+
assert response.is_valid?
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
should "should be idempotent when the response is initialized with invalid data" do
|
|
83
|
+
response = Maestrano::Saml::Response.new(response_document_4)
|
|
84
|
+
response.stubs(:conditions).returns(nil)
|
|
85
|
+
settings = Maestrano::Saml::Settings.new
|
|
86
|
+
response.settings = settings
|
|
87
|
+
assert !response.is_valid?
|
|
88
|
+
assert !response.is_valid?
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
should "should be idempotent when the response is initialized with valid data" do
|
|
92
|
+
response = Maestrano::Saml::Response.new(response_document_4)
|
|
93
|
+
response.stubs(:conditions).returns(nil)
|
|
94
|
+
settings = Maestrano::Saml::Settings.new
|
|
95
|
+
response.settings = settings
|
|
96
|
+
settings.idp_cert_fingerprint = signature_fingerprint_1
|
|
97
|
+
assert response.is_valid?
|
|
98
|
+
assert response.is_valid?
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
should "return true when using certificate instead of fingerprint" do
|
|
102
|
+
response = Maestrano::Saml::Response.new(response_document_4)
|
|
103
|
+
response.stubs(:conditions).returns(nil)
|
|
104
|
+
settings = Maestrano::Saml::Settings.new
|
|
105
|
+
response.settings = settings
|
|
106
|
+
settings.idp_cert = signature_1
|
|
107
|
+
assert response.is_valid?
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
should "not allow signature wrapping attack" do
|
|
111
|
+
response = Maestrano::Saml::Response.new(response_document_4)
|
|
112
|
+
response.stubs(:conditions).returns(nil)
|
|
113
|
+
settings = Maestrano::Saml::Settings.new
|
|
114
|
+
settings.idp_cert_fingerprint = signature_fingerprint_1
|
|
115
|
+
response.settings = settings
|
|
116
|
+
assert response.is_valid?
|
|
117
|
+
assert response.name_id == "test@onelogin.com"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
should "support dynamic namespace resolution on signature elements" do
|
|
121
|
+
response = Maestrano::Saml::Response.new(fixture("no_signature_ns.xml"))
|
|
122
|
+
response.stubs(:conditions).returns(nil)
|
|
123
|
+
settings = Maestrano::Saml::Settings.new
|
|
124
|
+
response.settings = settings
|
|
125
|
+
settings.idp_cert_fingerprint = "28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA"
|
|
126
|
+
Maestrano::XMLSecurity::SignedDocument.any_instance.expects(:validate_signature).returns(true)
|
|
127
|
+
assert response.validate!
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
should "validate ADFS assertions" do
|
|
131
|
+
response = Maestrano::Saml::Response.new(fixture(:adfs_response_sha256))
|
|
132
|
+
response.stubs(:conditions).returns(nil)
|
|
133
|
+
settings = Maestrano::Saml::Settings.new
|
|
134
|
+
settings.idp_cert_fingerprint = "28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA"
|
|
135
|
+
response.settings = settings
|
|
136
|
+
assert response.validate!
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
should "validate the digest" do
|
|
140
|
+
response = Maestrano::Saml::Response.new(r1_response_document_6)
|
|
141
|
+
response.stubs(:conditions).returns(nil)
|
|
142
|
+
settings = Maestrano::Saml::Settings.new
|
|
143
|
+
settings.idp_cert = Base64.decode64(r1_signature_2)
|
|
144
|
+
response.settings = settings
|
|
145
|
+
assert response.validate!
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
should "validate SAML 2.0 XML structure" do
|
|
149
|
+
resp_xml = Base64.decode64(response_document_4).gsub(/emailAddress/,'test')
|
|
150
|
+
response = Maestrano::Saml::Response.new(Base64.encode64(resp_xml))
|
|
151
|
+
response.stubs(:conditions).returns(nil)
|
|
152
|
+
settings = Maestrano::Saml::Settings.new
|
|
153
|
+
settings.idp_cert_fingerprint = signature_fingerprint_1
|
|
154
|
+
response.settings = settings
|
|
155
|
+
assert_raises(Maestrano::Saml::ValidationError, 'Digest mismatch'){ response.validate! }
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
context "#name_id" do
|
|
160
|
+
should "extract the value of the name id element" do
|
|
161
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
162
|
+
assert_equal "support@onelogin.com", response.name_id
|
|
163
|
+
|
|
164
|
+
response = Maestrano::Saml::Response.new(response_document_3)
|
|
165
|
+
assert_equal "someone@example.com", response.name_id
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
should "be extractable from an OpenSAML response" do
|
|
169
|
+
response = Maestrano::Saml::Response.new(fixture(:open_saml))
|
|
170
|
+
assert_equal "someone@example.org", response.name_id
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
should "be extractable from a Simple SAML PHP response" do
|
|
174
|
+
response = Maestrano::Saml::Response.new(fixture(:simple_saml_php))
|
|
175
|
+
assert_equal "someone@example.com", response.name_id
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
context "#check_conditions" do
|
|
180
|
+
should "check time conditions" do
|
|
181
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
182
|
+
assert !response.send(:validate_conditions, true)
|
|
183
|
+
response = Maestrano::Saml::Response.new(response_document_6)
|
|
184
|
+
assert response.send(:validate_conditions, true)
|
|
185
|
+
time = Time.parse("2011-06-14T18:25:01.516Z")
|
|
186
|
+
Time.stubs(:now).returns(time)
|
|
187
|
+
response = Maestrano::Saml::Response.new(response_document_5)
|
|
188
|
+
assert response.send(:validate_conditions, true)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
should "optionally allow for clock drift" do
|
|
192
|
+
# The NotBefore condition in the document is 2011-06-14T18:21:01.516Z
|
|
193
|
+
Time.stubs(:now).returns(Time.parse("2011-06-14T18:21:01Z"))
|
|
194
|
+
response = Maestrano::Saml::Response.new(response_document_5, :allowed_clock_drift => 0.515)
|
|
195
|
+
assert !response.send(:validate_conditions, true)
|
|
196
|
+
|
|
197
|
+
Time.stubs(:now).returns(Time.parse("2011-06-14T18:21:01Z"))
|
|
198
|
+
response = Maestrano::Saml::Response.new(response_document_5, :allowed_clock_drift => 0.516)
|
|
199
|
+
assert response.send(:validate_conditions, true)
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
context "#attributes" do
|
|
204
|
+
should "extract the first attribute in a hash accessed via its symbol" do
|
|
205
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
206
|
+
assert_equal "demo", response.attributes[:uid]
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
should "extract the first attribute in a hash accessed via its name" do
|
|
210
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
211
|
+
assert_equal "demo", response.attributes["uid"]
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
should "extract all attributes" do
|
|
215
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
216
|
+
assert_equal "demo", response.attributes[:uid]
|
|
217
|
+
assert_equal "value", response.attributes[:another_value]
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
should "work for implicit namespaces" do
|
|
221
|
+
response = Maestrano::Saml::Response.new(response_document_3)
|
|
222
|
+
assert_equal "someone@example.com", response.attributes["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"]
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
should "not raise on responses without attributes" do
|
|
226
|
+
response = Maestrano::Saml::Response.new(response_document_4)
|
|
227
|
+
assert_equal Hash.new, response.attributes
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
context "#multiple values" do
|
|
231
|
+
should "extract single value as string" do
|
|
232
|
+
response = Maestrano::Saml::Response.new(fixture(:response_with_multiple_attribute_values))
|
|
233
|
+
assert_equal "demo", response.attributes[:uid]
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
should "extract first of multiple values as string for b/w compatibility" do
|
|
237
|
+
response = Maestrano::Saml::Response.new(fixture(:response_with_multiple_attribute_values))
|
|
238
|
+
assert_equal 'value1', response.attributes[:another_value]
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
should "return array with all attributes when asked" do
|
|
242
|
+
response = Maestrano::Saml::Response.new(fixture(:response_with_multiple_attribute_values))
|
|
243
|
+
assert_equal ['value2', 'value1'], response.attributes[:another_value].values
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
should "return last of multiple values when multiple Attribute tags in XML" do
|
|
247
|
+
response = Maestrano::Saml::Response.new(fixture(:response_with_multiple_attribute_values))
|
|
248
|
+
assert_equal 'role2', response.attributes[:role]
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
should "return all of multiple values in reverse order when multiple Attribute tags in XML" do
|
|
252
|
+
response = Maestrano::Saml::Response.new(fixture(:response_with_multiple_attribute_values))
|
|
253
|
+
assert_equal ['role2', 'role1'], response.attributes[:role].values
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
context "#session_expires_at" do
|
|
259
|
+
should "extract the value of the SessionNotOnOrAfter attribute" do
|
|
260
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
261
|
+
assert response.session_expires_at.is_a?(Time)
|
|
262
|
+
|
|
263
|
+
response = Maestrano::Saml::Response.new(response_document_2)
|
|
264
|
+
assert response.session_expires_at.nil?
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
context "#issuer" do
|
|
269
|
+
should "return the issuer inside the response assertion" do
|
|
270
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
271
|
+
assert_equal "https://app.onelogin.com/saml/metadata/13590", response.issuer
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
should "return the issuer inside the response" do
|
|
275
|
+
response = Maestrano::Saml::Response.new(response_document_2)
|
|
276
|
+
assert_equal "wibble", response.issuer
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
context "#success" do
|
|
281
|
+
should "find a status code that says success" do
|
|
282
|
+
response = Maestrano::Saml::Response.new(response_document)
|
|
283
|
+
response.success?
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
module Maestrano
|
|
4
|
+
module Saml
|
|
5
|
+
class SettingsTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
context "Settings" do
|
|
8
|
+
setup do
|
|
9
|
+
@settings = Maestrano::Saml::Settings.new
|
|
10
|
+
end
|
|
11
|
+
should "should provide getters and settings" do
|
|
12
|
+
accessors = [
|
|
13
|
+
:assertion_consumer_service_url, :issuer, :sp_name_qualifier,
|
|
14
|
+
:idp_sso_target_url, :idp_cert_fingerprint, :name_identifier_format,
|
|
15
|
+
:idp_slo_target_url, :name_identifier_value, :sessionindex,
|
|
16
|
+
:assertion_consumer_logout_service_url,
|
|
17
|
+
:passive, :protocol_binding
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
accessors.each do |accessor|
|
|
21
|
+
value = Kernel.rand
|
|
22
|
+
@settings.send("#{accessor}=".to_sym, value)
|
|
23
|
+
assert_equal value, @settings.send(accessor)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "create settings from hash" do
|
|
28
|
+
|
|
29
|
+
config = {
|
|
30
|
+
:assertion_consumer_service_url => "http://app.muda.no/sso",
|
|
31
|
+
:issuer => "http://muda.no",
|
|
32
|
+
:sp_name_qualifier => "http://sso.muda.no",
|
|
33
|
+
:idp_sso_target_url => "http://sso.muda.no/sso",
|
|
34
|
+
:idp_slo_target_url => "http://sso.muda.no/slo",
|
|
35
|
+
:idp_cert_fingerprint => "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
|
36
|
+
:name_identifier_format => Maestrano::Saml::Settings::NAMEID_TRANSIENT,
|
|
37
|
+
:passive => true,
|
|
38
|
+
:protocol_binding => Maestrano::Saml::Settings::PROTOCOL_BINDING_POST
|
|
39
|
+
}
|
|
40
|
+
@settings = Maestrano::Saml::Settings.new(config)
|
|
41
|
+
|
|
42
|
+
config.each do |k,v|
|
|
43
|
+
assert_equal v, @settings.send(k)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
module Maestrano
|
|
4
|
+
module SSO
|
|
5
|
+
class BaseGroupTest < Test::Unit::TestCase
|
|
6
|
+
include SamlTestHelper
|
|
7
|
+
|
|
8
|
+
setup do
|
|
9
|
+
@saml_response = Maestrano::Saml::Response.new(response_document)
|
|
10
|
+
@saml_response.stubs(:attributes).returns({
|
|
11
|
+
'mno_session' => 'f54sd54fd64fs5df4s3d48gf2',
|
|
12
|
+
'mno_session_recheck' => Time.now.utc.iso8601,
|
|
13
|
+
'group_uid' => 'cld-1',
|
|
14
|
+
'group_end_free_trial' => Time.now.utc.iso8601,
|
|
15
|
+
'group_role' => 'Admin',
|
|
16
|
+
'uid' => "usr-1",
|
|
17
|
+
'virtual_uid' => "usr-1.cld-1",
|
|
18
|
+
'email' => "j.doe@doecorp.com",
|
|
19
|
+
'virtual_email' => "usr-1.cld-1@mail.maestrano.com",
|
|
20
|
+
'name' => "John",
|
|
21
|
+
"surname" => "Doe",
|
|
22
|
+
"country" => "AU",
|
|
23
|
+
"company_name" => "DoeCorp"
|
|
24
|
+
})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "have a local_id accessor" do
|
|
28
|
+
assert Maestrano::SSO::BaseGroup.new(@saml_response).respond_to?(:local_id) == true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
should "extract the rights attributes from the saml response" do
|
|
32
|
+
group = Maestrano::SSO::BaseGroup.new(@saml_response)
|
|
33
|
+
assert group.uid == @saml_response.attributes['group_uid']
|
|
34
|
+
assert group.free_trial_end_at == Time.iso8601(@saml_response.attributes['group_end_free_trial'])
|
|
35
|
+
assert group.company_name == @saml_response.attributes['company_name']
|
|
36
|
+
assert group.country == @saml_response.attributes['country']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
should "have the right hash representation" do
|
|
40
|
+
sso_group = Maestrano::SSO::BaseGroup.new(@saml_response)
|
|
41
|
+
assert sso_group.to_hash == {
|
|
42
|
+
provider: 'maestrano',
|
|
43
|
+
uid: sso_group.uid,
|
|
44
|
+
info: {
|
|
45
|
+
free_trial_end_at: sso_group.free_trial_end_at,
|
|
46
|
+
company_name: sso_group.company_name,
|
|
47
|
+
country: sso_group.country,
|
|
48
|
+
},
|
|
49
|
+
extra: {}
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
module Maestrano
|
|
4
|
+
module SSO
|
|
5
|
+
class BaseMembershipTest < Test::Unit::TestCase
|
|
6
|
+
include SamlTestHelper
|
|
7
|
+
|
|
8
|
+
setup do
|
|
9
|
+
@saml_response = Maestrano::Saml::Response.new(response_document)
|
|
10
|
+
@saml_response.stubs(:attributes).returns({
|
|
11
|
+
'mno_session' => 'f54sd54fd64fs5df4s3d48gf2',
|
|
12
|
+
'mno_session_recheck' => Time.now.utc.iso8601,
|
|
13
|
+
'group_uid' => 'cld-1',
|
|
14
|
+
'group_end_free_trial' => Time.now.utc.iso8601,
|
|
15
|
+
'group_role' => 'Admin',
|
|
16
|
+
'uid' => "usr-1",
|
|
17
|
+
'virtual_uid' => "usr-1.cld-1",
|
|
18
|
+
'email' => "j.doe@doecorp.com",
|
|
19
|
+
'virtual_email' => "usr-1.cld-1@mail.maestrano.com",
|
|
20
|
+
'name' => "John",
|
|
21
|
+
"surname" => "Doe",
|
|
22
|
+
"country" => "AU",
|
|
23
|
+
"company_name" => "DoeCorp"
|
|
24
|
+
})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "extract the rights attributes from the saml response" do
|
|
28
|
+
membership = Maestrano::SSO::BaseMembership.new(@saml_response)
|
|
29
|
+
assert membership.group_uid == @saml_response.attributes['group_uid']
|
|
30
|
+
assert membership.user_uid == @saml_response.attributes['uid']
|
|
31
|
+
assert membership.role == @saml_response.attributes['group_role']
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
should "have the right hash representation" do
|
|
35
|
+
membership = Maestrano::SSO::BaseMembership.new(@saml_response)
|
|
36
|
+
assert membership.to_hash == {
|
|
37
|
+
provider: 'maestrano',
|
|
38
|
+
group_uid: membership.group_uid,
|
|
39
|
+
user_uid: membership.user_uid,
|
|
40
|
+
role: membership.role,
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
module Maestrano
|
|
4
|
+
module SSO
|
|
5
|
+
class BaseUserTest < Test::Unit::TestCase
|
|
6
|
+
include SamlTestHelper
|
|
7
|
+
|
|
8
|
+
setup do
|
|
9
|
+
@saml_response = Maestrano::Saml::Response.new(response_document)
|
|
10
|
+
@saml_response.stubs(:attributes).returns({
|
|
11
|
+
'mno_session' => 'f54sd54fd64fs5df4s3d48gf2',
|
|
12
|
+
'mno_session_recheck' => Time.now.utc.iso8601,
|
|
13
|
+
'group_uid' => 'cld-1',
|
|
14
|
+
'group_end_free_trial' => Time.now.utc.iso8601,
|
|
15
|
+
'group_role' => 'Admin',
|
|
16
|
+
'uid' => "usr-1",
|
|
17
|
+
'virtual_uid' => "usr-1.cld-1",
|
|
18
|
+
'email' => "j.doe@doecorp.com",
|
|
19
|
+
'virtual_email' => "usr-1.cld-1@mail.maestrano.com",
|
|
20
|
+
'name' => "John",
|
|
21
|
+
"surname" => "Doe",
|
|
22
|
+
"country" => "AU",
|
|
23
|
+
"company_name" => "DoeCorp"
|
|
24
|
+
})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "have a local_id accessor" do
|
|
28
|
+
assert Maestrano::SSO::BaseUser.new(@saml_response).respond_to?(:local_id) == true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
should "extract the rights attributes from the saml response" do
|
|
32
|
+
user = Maestrano::SSO::BaseUser.new(@saml_response)
|
|
33
|
+
assert user.sso_session == @saml_response.attributes['mno_session']
|
|
34
|
+
assert user.sso_session_recheck == Time.iso8601(@saml_response.attributes['mno_session_recheck'])
|
|
35
|
+
assert user.group_uid == @saml_response.attributes['group_uid']
|
|
36
|
+
assert user.group_role == @saml_response.attributes['group_role']
|
|
37
|
+
assert user.uid == @saml_response.attributes['uid']
|
|
38
|
+
assert user.virtual_uid == @saml_response.attributes['virtual_uid']
|
|
39
|
+
assert user.email == @saml_response.attributes['email']
|
|
40
|
+
assert user.virtual_email == @saml_response.attributes['virtual_email']
|
|
41
|
+
assert user.first_name == @saml_response.attributes['name']
|
|
42
|
+
assert user.last_name == @saml_response.attributes['surname']
|
|
43
|
+
assert user.country == @saml_response.attributes['country']
|
|
44
|
+
assert user.company_name == @saml_response.attributes['company_name']
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "to_hash presentation" do
|
|
48
|
+
should "have the right representation when user_creation_mode is virtual" do
|
|
49
|
+
Maestrano.configure { |config| config.user_creation_mode = 'virtual' }
|
|
50
|
+
sso_user = Maestrano::SSO::BaseUser.new(@saml_response)
|
|
51
|
+
assert_equal sso_user.to_hash, {
|
|
52
|
+
provider: 'maestrano',
|
|
53
|
+
uid: sso_user.virtual_uid,
|
|
54
|
+
info: {
|
|
55
|
+
email: sso_user.virtual_email,
|
|
56
|
+
first_name: sso_user.first_name,
|
|
57
|
+
last_name: sso_user.last_name,
|
|
58
|
+
country: sso_user.country,
|
|
59
|
+
company_name: sso_user.company_name,
|
|
60
|
+
},
|
|
61
|
+
extra: {
|
|
62
|
+
uid: sso_user.uid,
|
|
63
|
+
virtual_uid: sso_user.virtual_uid,
|
|
64
|
+
real_email: sso_user.email,
|
|
65
|
+
virtual_email: sso_user.virtual_email,
|
|
66
|
+
group: {
|
|
67
|
+
uid: sso_user.group_uid,
|
|
68
|
+
role: sso_user.group_role
|
|
69
|
+
},
|
|
70
|
+
session: {
|
|
71
|
+
uid: sso_user.uid,
|
|
72
|
+
token: sso_user.sso_session,
|
|
73
|
+
recheck: sso_user.sso_session_recheck,
|
|
74
|
+
group_uid: sso_user.group_uid
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
should "have the right representation when user_creation_mode is real" do
|
|
81
|
+
Maestrano.configure { |config| config.user_creation_mode = 'real' }
|
|
82
|
+
sso_user = Maestrano::SSO::BaseUser.new(@saml_response)
|
|
83
|
+
assert_equal sso_user.to_hash, {
|
|
84
|
+
provider: 'maestrano',
|
|
85
|
+
uid: sso_user.uid,
|
|
86
|
+
info: {
|
|
87
|
+
email: sso_user.email,
|
|
88
|
+
first_name: sso_user.first_name,
|
|
89
|
+
last_name: sso_user.last_name,
|
|
90
|
+
country: sso_user.country,
|
|
91
|
+
company_name: sso_user.company_name,
|
|
92
|
+
},
|
|
93
|
+
extra: {
|
|
94
|
+
uid: sso_user.uid,
|
|
95
|
+
virtual_uid: sso_user.virtual_uid,
|
|
96
|
+
real_email: sso_user.email,
|
|
97
|
+
virtual_email: sso_user.virtual_email,
|
|
98
|
+
group: {
|
|
99
|
+
uid: sso_user.group_uid,
|
|
100
|
+
role: sso_user.group_role,
|
|
101
|
+
},
|
|
102
|
+
session: {
|
|
103
|
+
uid: sso_user.uid,
|
|
104
|
+
token: sso_user.sso_session,
|
|
105
|
+
recheck: sso_user.sso_session_recheck,
|
|
106
|
+
group_uid: sso_user.group_uid
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|