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.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +45 -0
  5. data/LICENSE +21 -0
  6. data/README.md +794 -0
  7. data/Rakefile +40 -0
  8. data/bin/maestrano-console +9 -0
  9. data/lib/maestrano.rb +271 -0
  10. data/lib/maestrano/account/bill.rb +14 -0
  11. data/lib/maestrano/account/recurring_bill.rb +14 -0
  12. data/lib/maestrano/api/error/authentication_error.rb +8 -0
  13. data/lib/maestrano/api/error/base_error.rb +24 -0
  14. data/lib/maestrano/api/error/connection_error.rb +8 -0
  15. data/lib/maestrano/api/error/invalid_request_error.rb +14 -0
  16. data/lib/maestrano/api/list_object.rb +37 -0
  17. data/lib/maestrano/api/object.rb +187 -0
  18. data/lib/maestrano/api/operation/base.rb +215 -0
  19. data/lib/maestrano/api/operation/create.rb +18 -0
  20. data/lib/maestrano/api/operation/delete.rb +13 -0
  21. data/lib/maestrano/api/operation/list.rb +18 -0
  22. data/lib/maestrano/api/operation/update.rb +59 -0
  23. data/lib/maestrano/api/resource.rb +47 -0
  24. data/lib/maestrano/api/util.rb +122 -0
  25. data/lib/maestrano/open_struct.rb +11 -0
  26. data/lib/maestrano/saml/attribute_value.rb +15 -0
  27. data/lib/maestrano/saml/metadata.rb +64 -0
  28. data/lib/maestrano/saml/request.rb +93 -0
  29. data/lib/maestrano/saml/response.rb +201 -0
  30. data/lib/maestrano/saml/schemas/saml20assertion_schema.xsd +283 -0
  31. data/lib/maestrano/saml/schemas/saml20protocol_schema.xsd +302 -0
  32. data/lib/maestrano/saml/schemas/xenc_schema.xsd +146 -0
  33. data/lib/maestrano/saml/schemas/xmldsig_schema.xsd +318 -0
  34. data/lib/maestrano/saml/settings.rb +37 -0
  35. data/lib/maestrano/saml/validation_error.rb +7 -0
  36. data/lib/maestrano/sso.rb +86 -0
  37. data/lib/maestrano/sso/base_group.rb +31 -0
  38. data/lib/maestrano/sso/base_membership.rb +25 -0
  39. data/lib/maestrano/sso/base_user.rb +75 -0
  40. data/lib/maestrano/sso/group.rb +24 -0
  41. data/lib/maestrano/sso/session.rb +107 -0
  42. data/lib/maestrano/sso/user.rb +34 -0
  43. data/lib/maestrano/version.rb +3 -0
  44. data/lib/maestrano/xml_security/signed_document.rb +170 -0
  45. data/maestrano.gemspec +32 -0
  46. data/maestrano.png +0 -0
  47. data/test/helpers/api_helpers.rb +115 -0
  48. data/test/helpers/saml_helpers.rb +62 -0
  49. data/test/maestrano/account/bill_test.rb +48 -0
  50. data/test/maestrano/account/recurring_bill_test.rb +49 -0
  51. data/test/maestrano/api/list_object_test.rb +20 -0
  52. data/test/maestrano/api/object_test.rb +28 -0
  53. data/test/maestrano/api/resource_test.rb +343 -0
  54. data/test/maestrano/api/util_test.rb +31 -0
  55. data/test/maestrano/maestrano_test.rb +260 -0
  56. data/test/maestrano/open_struct_test.rb +10 -0
  57. data/test/maestrano/saml/request_test.rb +168 -0
  58. data/test/maestrano/saml/response_test.rb +290 -0
  59. data/test/maestrano/saml/settings_test.rb +51 -0
  60. data/test/maestrano/sso/base_group_test.rb +54 -0
  61. data/test/maestrano/sso/base_membership_test.rb +45 -0
  62. data/test/maestrano/sso/base_user_test.rb +114 -0
  63. data/test/maestrano/sso/group_test.rb +47 -0
  64. data/test/maestrano/sso/session_test.rb +161 -0
  65. data/test/maestrano/sso/user_test.rb +65 -0
  66. data/test/maestrano/sso_test.rb +105 -0
  67. data/test/maestrano/xml_security/signed_document.rb +163 -0
  68. data/test/support/saml/certificates/certificate1 +12 -0
  69. data/test/support/saml/certificates/r1_certificate2_base64 +1 -0
  70. data/test/support/saml/responses/adfs_response_sha1.xml +46 -0
  71. data/test/support/saml/responses/adfs_response_sha256.xml +46 -0
  72. data/test/support/saml/responses/adfs_response_sha384.xml +46 -0
  73. data/test/support/saml/responses/adfs_response_sha512.xml +46 -0
  74. data/test/support/saml/responses/no_signature_ns.xml +48 -0
  75. data/test/support/saml/responses/open_saml_response.xml +56 -0
  76. data/test/support/saml/responses/r1_response6.xml.base64 +1 -0
  77. data/test/support/saml/responses/response1.xml.base64 +1 -0
  78. data/test/support/saml/responses/response2.xml.base64 +79 -0
  79. data/test/support/saml/responses/response3.xml.base64 +66 -0
  80. data/test/support/saml/responses/response4.xml.base64 +93 -0
  81. data/test/support/saml/responses/response5.xml.base64 +102 -0
  82. data/test/support/saml/responses/response_with_ampersands.xml +139 -0
  83. data/test/support/saml/responses/response_with_ampersands.xml.base64 +93 -0
  84. data/test/support/saml/responses/response_with_multiple_attribute_values.xml +57 -0
  85. data/test/support/saml/responses/simple_saml_php.xml +71 -0
  86. data/test/support/saml/responses/starfield_response.xml.base64 +1 -0
  87. data/test/support/saml/responses/wrapped_response_2.xml.base64 +150 -0
  88. data/test/test_helper.rb +47 -0
  89. metadata +315 -0
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ module Maestrano
4
+ module API
5
+ class UtilTest < Test::Unit::TestCase
6
+ should "symbolize_names should convert names to symbols" do
7
+ start = {
8
+ 'foo' => 'bar',
9
+ 'array' => [{ 'foo' => 'bar' }],
10
+ 'nested' => {
11
+ 1 => 2,
12
+ :symbol => 9,
13
+ 'string' => nil
14
+ }
15
+ }
16
+ finish = {
17
+ :foo => 'bar',
18
+ :array => [{ :foo => 'bar' }],
19
+ :nested => {
20
+ 1 => 2,
21
+ :symbol => 9,
22
+ :string => nil
23
+ }
24
+ }
25
+
26
+ symbolized = Maestrano::API::Util.symbolize_names(start)
27
+ assert_equal(finish, symbolized)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,260 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class MaestranoTest < Test::Unit::TestCase
4
+ setup do
5
+ @config = {
6
+ 'environment' => 'production',
7
+ 'app.host' => 'http://mysuperapp.com',
8
+
9
+ 'api.id' => 'app-f54ds4f8',
10
+ 'api.key' => 'someapikey',
11
+
12
+ 'sso.enabled' => false,
13
+ 'sso.slo_enabled' => false,
14
+ 'sso.init_path' => '/mno/sso/init',
15
+ 'sso.consume_path' => '/mno/sso/consume',
16
+ 'sso.creation_mode' => 'real',
17
+ 'sso.idm' => 'http://idp.mysuperapp.com',
18
+
19
+ 'webhook.account.groups_path' => '/mno/groups/:id',
20
+ 'webhook.account.group_users_path' => '/mno/groups/:group_id/users/:id',
21
+ }
22
+
23
+ Maestrano.configure do |config|
24
+ config.environment = @config['environment']
25
+ config.app.host = @config['app.host']
26
+
27
+ config.api.id = @config['api.id']
28
+ config.api.key = @config['api.key']
29
+
30
+ config.sso.enabled = @config['sso.enabled']
31
+ config.sso.slo_enabled = @config['sso.slo_enabled']
32
+ config.sso.idm = @config['sso.idm']
33
+ config.sso.init_path = @config['sso.init_path']
34
+ config.sso.consume_path = @config['sso.consume_path']
35
+ config.sso.creation_mode = @config['sso.creation_mode']
36
+
37
+ config.webhook.account.groups_path = @config['webhook.account.groups_path' ]
38
+ config.webhook.account.group_users_path = @config['webhook.account.group_users_path' ]
39
+ end
40
+ end
41
+
42
+ context "new style configuration" do
43
+ should "return the specified parameters" do
44
+ @config.keys.each do |key|
45
+ assert_equal @config[key], Maestrano.param(key)
46
+ end
47
+ end
48
+
49
+ should "set the sso.creation_mode to 'real' by default" do
50
+ Maestrano.config = Maestrano::Configuration.new
51
+ Maestrano.configure { |config| config.app.host = "https://someapp.com" }
52
+ assert_equal 'real', Maestrano.param('sso.creation_mode')
53
+ end
54
+
55
+ should "build the api_token based on the app_id and api_key" do
56
+ Maestrano.configure { |config| config.app_id = "bla"; config.api_key = "blo" }
57
+ assert_equal "bla:blo", Maestrano.param('api.token')
58
+ end
59
+
60
+ should "assign the sso.idm to app.host if not provided" do
61
+ Maestrano.config = Maestrano::Configuration.new
62
+ Maestrano.configure { |config| config.app.host = "https://someapp.com" }
63
+ assert_equal Maestrano.param('app.host'), Maestrano.param('sso.idm')
64
+ end
65
+
66
+ should "force assign the api.lang" do
67
+ Maestrano.configure { |config| config.api.lang = "bla" }
68
+ assert_equal 'ruby', Maestrano.param('api.lang')
69
+ end
70
+
71
+ should "force assign the api.lang_version" do
72
+ Maestrano.configure { |config| config.api.lang_version = "123456" }
73
+ assert_equal "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})", Maestrano.param('api.lang_version')
74
+ end
75
+
76
+ should "force assign the api.version" do
77
+ Maestrano.configure { |config| config.api.version = "1245" }
78
+ assert_equal Maestrano::VERSION, Maestrano.param('api.version')
79
+ end
80
+
81
+ should "force slo_enabled to false if sso is disabled" do
82
+ Maestrano.configure { |config| config.sso.slo_enabled = true; config.sso.enabled = false }
83
+ assert_false Maestrano.param('sso.slo_enabled')
84
+ end
85
+
86
+ context "with environment params" do
87
+ should "return the right test parameters" do
88
+ Maestrano.configure { |config| config.environment = 'test' }
89
+
90
+ ['api.host','api.base','sso.idp', 'sso.name_id_format', 'sso.x509_certificate'].each do |parameter|
91
+ assert_equal Maestrano::Configuration::EVT_CONFIG['test'][parameter], Maestrano.param(parameter)
92
+ end
93
+ end
94
+
95
+ should "return the right production parameters" do
96
+ Maestrano.configure { |config| config.environment = 'production' }
97
+
98
+ ['api.host','api.base','sso.idp', 'sso.name_id_format', 'sso.x509_certificate'].each do |parameter|
99
+ assert_equal Maestrano::Configuration::EVT_CONFIG['production'][parameter], Maestrano.param(parameter)
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+
106
+ context "old style configuration" do
107
+ setup do
108
+ @config = {
109
+ environment: 'production',
110
+ api_key: 'someapikey',
111
+ sso_enabled: false,
112
+ app_host: 'http://mysuperapp.com',
113
+ sso_app_init_path: '/mno/sso/init',
114
+ sso_app_consume_path: '/mno/sso/consume',
115
+ user_creation_mode: 'real',
116
+ }
117
+
118
+ Maestrano.configure do |config|
119
+ config.environment = @config[:environment]
120
+ config.api_key = @config[:api_key]
121
+ config.sso_enabled = @config[:sso_enabled]
122
+ config.app_host = @config[:app_host]
123
+ config.sso_app_init_path = @config[:sso_app_init_path]
124
+ config.sso_app_consume_path = @config[:sso_app_consume_path]
125
+ config.user_creation_mode = @config[:user_creation_mode]
126
+ end
127
+ end
128
+
129
+ should "build the api_token based on the app_id and api_key" do
130
+ Maestrano.configure { |config| config.app_id = "bla"; config.api_key = "blo" }
131
+ assert_equal "bla:blo", Maestrano.param(:api_token)
132
+ end
133
+
134
+ should "assign the sso.idm if explicitly set to nil" do
135
+ Maestrano.configure { |config| config.sso.idm = nil }
136
+ assert_equal Maestrano.param('app.host'), Maestrano.param('sso.idm')
137
+ end
138
+
139
+ should "force assign the api.lang" do
140
+ Maestrano.configure { |config| config.api.lang = "bla" }
141
+ assert_equal 'ruby', Maestrano.param('api.lang')
142
+ end
143
+
144
+ should "force assign the api.lang_version" do
145
+ Maestrano.configure { |config| config.api.lang_version = "123456" }
146
+ assert_equal "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})", Maestrano.param('api.lang_version')
147
+ end
148
+
149
+ should "force assign the api.version" do
150
+ Maestrano.configure { |config| config.api.version = "1245" }
151
+ assert_equal Maestrano::VERSION, Maestrano.param('api.version')
152
+ end
153
+
154
+ should "return the specified parameters" do
155
+ @config.keys.each do |key|
156
+ assert Maestrano.param(key) == @config[key]
157
+ end
158
+ end
159
+
160
+ context "with environment params" do
161
+ should "return the right test parameters" do
162
+ Maestrano.configure { |config| config.environment = 'test' }
163
+
164
+ ['api_host','api_base','sso_name_id_format', 'sso_x509_certificate'].each do |parameter|
165
+ key = Maestrano::Configuration.new.legacy_param_to_new(parameter)
166
+ assert_equal Maestrano::Configuration::EVT_CONFIG['test'][key], Maestrano.param(parameter)
167
+ end
168
+ end
169
+
170
+ should "return the right production parameters" do
171
+ Maestrano.configure { |config| config.environment = 'production' }
172
+
173
+ ['api_host','api_base','sso_name_id_format', 'sso_x509_certificate'].each do |parameter|
174
+ key = Maestrano::Configuration.new.legacy_param_to_new(parameter)
175
+ assert_equal Maestrano::Configuration::EVT_CONFIG['production'][key], Maestrano.param(parameter)
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ context "authenticate" do
182
+ should "return true if app_id and api_key match" do
183
+ assert Maestrano.authenticate(Maestrano.param(:app_id),Maestrano.param(:api_key))
184
+ end
185
+
186
+ should "return false otherwise" do
187
+ assert !Maestrano.authenticate(Maestrano.param(:app_id) + 'a',Maestrano.param(:api_key))
188
+ assert !Maestrano.authenticate(Maestrano.param(:app_id),Maestrano.param(:api_key) + 'a')
189
+ end
190
+ end
191
+
192
+ context "mask_user_uid" do
193
+ should "return the composite uid if creation_mode is virtual" do
194
+ Maestrano.configure { |c| c.user_creation_mode = 'virtual' }
195
+ assert_equal 'usr-1.cld-1', Maestrano.mask_user('usr-1','cld-1')
196
+ end
197
+
198
+ should "not double up the composite uid" do
199
+ Maestrano.configure { |c| c.user_creation_mode = 'virtual' }
200
+ assert_equal 'usr-1.cld-1', Maestrano.mask_user('usr-1.cld-1','cld-1')
201
+ end
202
+
203
+ should "return the real uid if creation_mode is real" do
204
+ Maestrano.configure { |c| c.user_creation_mode = 'real' }
205
+ assert_equal 'usr-1', Maestrano.mask_user('usr-1','cld-1')
206
+ end
207
+ end
208
+
209
+ context "unmask_user_uid" do
210
+ should "return the right uid if composite" do
211
+ assert_equal 'usr-1', Maestrano.unmask_user('usr-1.cld-1')
212
+ end
213
+
214
+ should "return the right uid if non composite" do
215
+ assert_equal 'usr-1', Maestrano.unmask_user('usr-1')
216
+ end
217
+ end
218
+
219
+ context "to_metadata" do
220
+ should "should return the right hash" do
221
+ expected = {
222
+ 'environment' => @config['environment'],
223
+ 'app' => {
224
+ 'host' => @config['app.host']
225
+ },
226
+ 'api' => {
227
+ 'id' => @config['api.id'],
228
+ 'version' => Maestrano::VERSION,
229
+ 'verify_ssl_certs' => false,
230
+ 'lang' => 'ruby',
231
+ 'lang_version' => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
232
+ 'host' => Maestrano::Configuration::EVT_CONFIG[@config['environment']]['api.host'],
233
+ 'base' => Maestrano::Configuration::EVT_CONFIG[@config['environment']]['api.base'],
234
+
235
+ },
236
+ 'sso' => {
237
+ 'enabled' => @config['sso.enabled'],
238
+ 'slo_enabled' => @config['sso.slo_enabled'],
239
+ 'init_path' => @config['sso.init_path'],
240
+ 'consume_path' => @config['sso.consume_path'],
241
+ 'creation_mode' => @config['sso.creation_mode'],
242
+ 'idm' => @config['sso.idm'],
243
+ 'idp' => Maestrano::Configuration::EVT_CONFIG[@config['environment']]['sso.idp'],
244
+ 'name_id_format' => Maestrano::Configuration::EVT_CONFIG[@config['environment']]['sso.name_id_format'],
245
+ 'x509_fingerprint' => Maestrano::Configuration::EVT_CONFIG[@config['environment']]['sso.x509_fingerprint'],
246
+ 'x509_certificate' => Maestrano::Configuration::EVT_CONFIG[@config['environment']]['sso.x509_certificate'],
247
+ },
248
+ 'webhook' => {
249
+ 'account' => {
250
+ 'groups_path' => @config['webhook.account.groups_path'],
251
+ 'group_users_path' => @config['webhook.account.group_users_path'],
252
+ }
253
+ }
254
+ }
255
+
256
+ assert_equal expected, Maestrano.to_metadata
257
+ end
258
+ end
259
+
260
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Maestrano
4
+ class MaestranoOpenStructTest < Test::Unit::TestCase
5
+ should "return the right attributes" do
6
+ o = Maestrano::OpenStruct.new(bla: 'hello', ha: 'yo')
7
+ assert_equal [:bla,:ha], o.attributes
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,168 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ module Maestrano
4
+ module Saml
5
+ class RequestTest < Test::Unit::TestCase
6
+
7
+ context "Request" do
8
+ should "create the deflated SAMLRequest URL parameter" do
9
+ settings = Maestrano::Saml::Settings.new
10
+ settings.idp_sso_target_url = "http://example.com"
11
+ request = Maestrano::Saml::Request.new
12
+ request.settings = settings
13
+ auth_url = request.redirect_url
14
+ assert auth_url =~ /^http:\/\/example\.com\?SAMLRequest=/
15
+
16
+ payload = CGI.unescape(auth_url.split("=").last)
17
+ decoded = Base64.decode64(payload)
18
+
19
+ zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
20
+ inflated = zstream.inflate(decoded)
21
+ zstream.finish
22
+ zstream.close
23
+ assert_match /^<samlp:AuthnRequest/, inflated
24
+ end
25
+
26
+ should "create the deflated SAMLRequest URL parameter including the Destination" do
27
+ settings = Maestrano::Saml::Settings.new
28
+ settings.idp_sso_target_url = "http://example.com"
29
+ request = Maestrano::Saml::Request.new
30
+ request.settings = settings
31
+ auth_url = request.redirect_url
32
+ payload = CGI.unescape(auth_url.split("=").last)
33
+ decoded = Base64.decode64(payload)
34
+
35
+ zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
36
+ inflated = zstream.inflate(decoded)
37
+ zstream.finish
38
+ zstream.close
39
+
40
+ assert_match /<samlp:AuthnRequest[^<]* Destination='http:\/\/example.com'/, inflated
41
+ end
42
+
43
+ should "create the SAMLRequest URL parameter without deflating" do
44
+ settings = Maestrano::Saml::Settings.new
45
+ settings.compress_request = false
46
+ settings.idp_sso_target_url = "http://example.com"
47
+ request = Maestrano::Saml::Request.new
48
+ request.settings = settings
49
+ auth_url = request.redirect_url
50
+ assert auth_url =~ /^http:\/\/example\.com\?SAMLRequest=/
51
+
52
+ payload = CGI.unescape(auth_url.split("=").last)
53
+ decoded = Base64.decode64(payload)
54
+ assert_match /^<samlp:AuthnRequest/, decoded
55
+ end
56
+
57
+ should "create the SAMLRequest URL parameter with IsPassive" do
58
+ settings = Maestrano::Saml::Settings.new
59
+ settings.idp_sso_target_url = "http://example.com"
60
+ settings.passive = true
61
+ request = Maestrano::Saml::Request.new
62
+ request.settings = settings
63
+ auth_url = request.redirect_url
64
+ assert auth_url =~ /^http:\/\/example\.com\?SAMLRequest=/
65
+ payload = CGI.unescape(auth_url.split("=").last)
66
+ decoded = Base64.decode64(payload)
67
+
68
+ zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
69
+ inflated = zstream.inflate(decoded)
70
+ zstream.finish
71
+ zstream.close
72
+
73
+ assert_match /<samlp:AuthnRequest[^<]* IsPassive='true'/, inflated
74
+ end
75
+
76
+ should "create the SAMLRequest URL parameter with ProtocolBinding" do
77
+ settings = Maestrano::Saml::Settings.new
78
+ settings.idp_sso_target_url = "http://example.com"
79
+ settings.protocol_binding = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
80
+ request = Maestrano::Saml::Request.new
81
+ request.settings = settings
82
+ auth_url = request.redirect_url
83
+ assert auth_url =~ /^http:\/\/example\.com\?SAMLRequest=/
84
+ payload = CGI.unescape(auth_url.split("=").last)
85
+ decoded = Base64.decode64(payload)
86
+
87
+ zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
88
+ inflated = zstream.inflate(decoded)
89
+ zstream.finish
90
+ zstream.close
91
+
92
+ assert_match /<samlp:AuthnRequest[^<]* ProtocolBinding='urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'/, inflated
93
+ end
94
+
95
+ should "accept extra parameters" do
96
+ settings = Maestrano::Saml::Settings.new
97
+ settings.idp_sso_target_url = "http://example.com"
98
+
99
+ request = Maestrano::Saml::Request.new
100
+ request.settings = settings
101
+ request.params = { :hello => "there" }
102
+ auth_url = request.redirect_url
103
+ assert auth_url =~ /&hello=there$/
104
+
105
+ request = Maestrano::Saml::Request.new
106
+ request.settings = settings
107
+ request.params = { :hello => nil }
108
+ auth_url = request.redirect_url
109
+ assert auth_url =~ /&hello=$/
110
+ end
111
+
112
+ context "when the target url doesn't contain a query string" do
113
+ should "create the SAMLRequest parameter correctly" do
114
+ settings = Maestrano::Saml::Settings.new
115
+ settings.idp_sso_target_url = "http://example.com"
116
+
117
+ request = Maestrano::Saml::Request.new
118
+ request.settings = settings
119
+ auth_url = request.redirect_url
120
+ assert auth_url =~ /^http:\/\/example.com\?SAMLRequest/
121
+ end
122
+ end
123
+
124
+ context "when the target url contains a query string" do
125
+ should "create the SAMLRequest parameter correctly" do
126
+ settings = Maestrano::Saml::Settings.new
127
+ settings.idp_sso_target_url = "http://example.com?field=value"
128
+
129
+ request = Maestrano::Saml::Request.new
130
+ request.settings = settings
131
+ auth_url = request.redirect_url
132
+ assert auth_url =~ /^http:\/\/example.com\?field=value&SAMLRequest/
133
+ end
134
+ end
135
+
136
+ context "with session" do
137
+ should "pass the group_id from session to the url" do
138
+ settings = Maestrano::Saml::Settings.new
139
+ settings.idp_sso_target_url = "http://example.com"
140
+ session = {mno_group_uid: 'cld-1'}
141
+
142
+ request = Maestrano::Saml::Request.new
143
+ request.settings = settings
144
+ request.session = session
145
+ auth_url = request.redirect_url
146
+ assert auth_url =~ /&group_id=cld-1/
147
+ end
148
+
149
+ should "pass ignore the group_id from session if already present in the params" do
150
+ settings = Maestrano::Saml::Settings.new
151
+ settings.idp_sso_target_url = "http://example.com"
152
+ session = {mno_group_uid: 'cld-1'}
153
+
154
+ request = Maestrano::Saml::Request.new
155
+ request.settings = settings
156
+ request.params = {group_id: 'cld-2'}
157
+ request.session = session
158
+ auth_url = request.redirect_url
159
+
160
+ assert auth_url =~ /&group_id=cld-2/
161
+ assert auth_url !~ /&group_id=cld-1/
162
+ end
163
+ end
164
+
165
+ end
166
+ end
167
+ end
168
+ end