dot_net_services 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/LICENSE +21 -24
  2. data/README +26 -16
  3. data/Rakefile +65 -0
  4. data/lib/acs/saml_token_provider.rb +54 -0
  5. data/lib/acs/shared_secret_token_provider.rb +55 -0
  6. data/lib/acs/simple_api_auth_token_provider.rb +57 -0
  7. data/lib/acs/simple_web_token_provider.rb +54 -0
  8. data/lib/acs/token_constants.rb +112 -0
  9. data/lib/acs/token_info.rb +33 -0
  10. data/lib/acs/token_provider.rb +74 -0
  11. data/lib/acs/token_validator.rb +114 -0
  12. data/lib/common/dot_net_services_environment.rb +61 -0
  13. data/lib/common/environment.yml +23 -0
  14. data/lib/common/host_name_config.yml +45 -0
  15. data/lib/dot_net_services.rb +31 -144
  16. data/lib/service_bus/http_proxy.rb +34 -0
  17. data/lib/service_bus/locked_message_info.rb +34 -0
  18. data/lib/service_bus/message_buffer.rb +313 -0
  19. data/lib/service_bus/message_buffer_constants.rb +48 -0
  20. data/lib/service_bus/message_buffer_policy.rb +55 -0
  21. data/lib/service_bus/requests.rb +95 -0
  22. data/test/config/test_config.yml +40 -0
  23. data/test/dot_net_services_environment_test.rb +54 -0
  24. data/test/message_buffer_test.rb +96 -0
  25. data/test/token_test.rb +98 -0
  26. metadata +50 -48
  27. data/lib/dot_net_services/authentication.rb +0 -168
  28. data/lib/dot_net_services/error.rb +0 -4
  29. data/lib/dot_net_services/message_buffer.rb +0 -283
  30. data/lib/dot_net_services/session.rb +0 -308
  31. data/lib/net/http/create_mb.rb +0 -14
  32. data/lib/net/http/retrieve.rb +0 -14
  33. data/lib/net/http/subscribe.rb +0 -14
  34. data/lib/net/http/unsubscribe.rb +0 -14
  35. data/spec/integration/TestService/Service/AnonymousResourceService.cs +0 -9
  36. data/spec/integration/TestService/Service/App.config +0 -32
  37. data/spec/integration/TestService/Service/PlainTextService.cs +0 -37
  38. data/spec/integration/TestService/Service/Program.cs +0 -49
  39. data/spec/integration/TestService/Service/Properties/AssemblyInfo.cs +0 -33
  40. data/spec/integration/TestService/Service/ResourceContract.cs +0 -17
  41. data/spec/integration/TestService/Service/ResourceService.cs +0 -58
  42. data/spec/integration/TestService/Service/Service.csproj +0 -71
  43. data/spec/integration/TestService/TestService.sln +0 -33
  44. data/spec/integration/end_to_end_spec.rb +0 -84
  45. data/spec/integration/vmb_spec.rb +0 -30
  46. data/spec/spec_helper.rb +0 -23
  47. data/spec/unit/dot_net_services/authentication_spec.rb +0 -289
  48. data/spec/unit/dot_net_services/message_buffer_spec.rb +0 -161
  49. data/spec/unit/dot_net_services/session_spec.rb +0 -247
@@ -0,0 +1,313 @@
1
+ # Copyright (c) 2009, Persistent Systems Limited
2
+ #
3
+ # Redistribution and use, with or without modification, are permitted
4
+ # provided that the following conditions are met:
5
+ # - Redistributions of source code must retain the above copyright notice,
6
+ # this list of conditions and the following disclaimer.
7
+ # - Neither the name of Persistent Systems Limited nor the names of its contributors
8
+ # may be used to endorse or promote products derived from this software
9
+ # without specific prior written permission.
10
+ #
11
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
12
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
15
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
18
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
21
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ require "#{__FILE__}/../http_proxy"
24
+ require "#{__FILE__}/../requests"
25
+ require "#{__FILE__}/../message_buffer_policy"
26
+ require "#{__FILE__}/../locked_message_info"
27
+ require "#{__FILE__}/../../acs/shared_secret_token_provider"
28
+ require "#{__FILE__}/../../common/dot_net_services_environment"
29
+
30
+ # This class contains implementation to
31
+ # * Create a message buffer
32
+ # * Retrieve message buffer policy for a given message buffer name
33
+ # * Delete a message buffer
34
+ # * Send message to a message buffer
35
+ # * Make a peek lock on a message buffer
36
+ # * Delete a locked message in the given message buffer
37
+ # * Release lock on a locked message buffer
38
+ # * Retrieve a message from the given message buffer
39
+ #
40
+ # The class includes DotNetServices::HTTPRequests module that holds implementations to make HTTP requests
41
+ class MessageBuffer
42
+ include HTTPProxy
43
+ include DotNetServices::HTTPRequests
44
+
45
+ HTTP_STATUS_CODE_OK = '200'
46
+ HTTP_STATUS_CODE_CREATED = '201'
47
+ HTTP_STATUS_CODE_ACCEPTED = '202'
48
+ HTTP_STATUS_CODE_NORESPONSE = '204'
49
+ HTTP_STATUS_CODE_BADREQUEST = '400'
50
+ HTTP_STATUS_CODE_INTERNAL_SERVER_ERROR = '500'
51
+ HTTP_HEADER_EXPECT = '100-continue'
52
+
53
+ ACCEPTED_RESPONSE_CODES = [HTTP_STATUS_CODE_ACCEPTED, HTTP_STATUS_CODE_CREATED, HTTP_STATUS_CODE_OK]
54
+
55
+ DEFAULT_LOCK_DURATION = "120"
56
+ DEFAULT_RECEIVE_TIMEOUT = "60"
57
+ DEFAULT_SEND_TIMEOUT = "60"
58
+
59
+ # Initializes the Mesasge Buffer object with following settings
60
+ # * issuer_name
61
+ # * issuer_key (issuer_secret or Management key)
62
+ # * solution_name
63
+ # * service_name
64
+ # * proxy - OPTIONAL hash with keys
65
+ # * 'http_web_proxy_server'
66
+ # * 'http_web_proxy_port'
67
+ # * 'http_web_proxy_username'
68
+ # * 'http_web_proxy_password'
69
+ def initialize(issuer_name, issuer_key, solution_name, service_name, proxy = {})
70
+ @issuer_name = issuer_name
71
+ @issuer_key = issuer_key
72
+ @solution_name = solution_name
73
+ @service_name = service_name
74
+ @proxy = proxy
75
+ set_http_web_proxy(proxy)
76
+ @acm_host_name = DotNetServicesEnvironment.acm_host_name
77
+ @service_bus_host_name = DotNetServicesEnvironment.service_bus_host_name
78
+ end
79
+
80
+ # Creates a message buffer. Accepts following params
81
+ # * msg_buffer_name
82
+ # * msg_buffer_policy_obj (+MessageBufferPolicy+)
83
+ def create_message_buffer(msg_buffer_name, msg_buffer_policy_obj)
84
+ raise 'Message Buffer Policy cannot be nil' unless msg_buffer_policy_obj
85
+ msg_buffer_policy = msg_buffer_policy_obj.message_buffer_policy
86
+ request_uri, msg_buffer_uri = msg_buffer_uris(msg_buffer_name)
87
+ raise 'Message buffer URI not found' unless msg_buffer_uri
88
+ token = acquire_authorization_token(request_uri, msg_buffer_uri)
89
+ begin
90
+ options = {}
91
+ header = {
92
+ 'Content-type' => MessageBufferConstants.content_type_property_for_atom_xml,
93
+ 'Authorization' => authorization(token),
94
+ 'Expect' => HTTP_HEADER_EXPECT
95
+ }
96
+
97
+ options.store(:header, header)
98
+ response = put(msg_buffer_uri, msg_buffer_policy, options)
99
+ if ACCEPTED_RESPONSE_CODES.include?(response.code)
100
+ return response.body
101
+ else
102
+ raise("Unexpected response code #{response.code}")
103
+ end
104
+ rescue
105
+ raise "Unexpected exception occured in create_message_buffer"
106
+ end
107
+ end
108
+
109
+ # Fetches policy of the given message buffer. Expects -
110
+ # * Message Buffer Name
111
+ def policy(msg_buffer_name)
112
+ request_uri, msg_buffer_uri = msg_buffer_uris(msg_buffer_name)
113
+ token = acquire_authorization_token(request_uri, msg_buffer_uri)
114
+ options = {}
115
+ header = {
116
+ 'Content-type' => MessageBufferConstants.content_type_property_for_atom_xml,
117
+ 'Expect' => HTTP_HEADER_EXPECT,
118
+ 'Authorization' => authorization(token)
119
+ }
120
+
121
+ options.store(:header, header)
122
+ response = get(msg_buffer_uri, options)
123
+ if response.code == HTTP_STATUS_CODE_OK
124
+ body = response.body
125
+ if body.match(/<entry xmlns=/)
126
+ return body
127
+ else
128
+ raise 'Unexpected response body while trying to get the message buffer policy'
129
+ end
130
+ end
131
+ end
132
+
133
+ # Deletes message buffer. Expects -
134
+ # * Message Buffer Name
135
+ def delete_message_buffer(msg_buffer_name)
136
+ request_uri, msg_buffer_uri = msg_buffer_uris(msg_buffer_name)
137
+ token = acquire_authorization_token(request_uri, msg_buffer_uri)
138
+ options = {}
139
+ header = {
140
+ 'Content-type' => MessageBufferConstants.content_type_property_for_atom_xml,
141
+ 'Expect' => HTTP_HEADER_EXPECT,
142
+ 'Authorization' => authorization(token)
143
+ }
144
+ options.store(:header, header)
145
+ response = delete(msg_buffer_uri, options)
146
+ if response.code == HTTP_STATUS_CODE_OK
147
+ return response.body
148
+ else
149
+ raise "Unexpected response code #{response.code}"
150
+ end
151
+ end
152
+
153
+ # Sends given message to given message buffer. Expects -
154
+ # * Message Buffer Name
155
+ # * Message body
156
+ # * timeout(Default = DEFAULT_SEND_TIMEOUT)
157
+ def send_message(msg_buffer_name, msg_str, timeout = DEFAULT_SEND_TIMEOUT)
158
+ send_path = MessageBufferConstants.path_for_send_message
159
+ timeout_parameter = MessageBufferConstants.timeout_parameter
160
+ msg_buffer_uri = message_uri(msg_buffer_name, send_path)
161
+ message = formatted_message(msg_str)
162
+ token = acquire_authorization_token(request_uri, msg_buffer_uri)
163
+ send_uri = msg_buffer_uri + "?" + timeout_parameter + "=" + timeout
164
+ options = {}
165
+ header = {
166
+ 'Content-type' => MessageBufferConstants.content_type_property_for_text,
167
+ 'Expect' => HTTP_HEADER_EXPECT,
168
+ 'Authorization' => authorization(token)
169
+ }
170
+ options.store(:header, header)
171
+ response = post(send_uri, message, options)
172
+ ACCEPTED_RESPONSE_CODES.include?(response.code) || raise("Unexpected response code #{response.code}")
173
+ end
174
+
175
+ # Makes a peek lock on given message buffer. Expects -
176
+ # * Message Buffer Name
177
+ # * Timeout(Default = DEFAULT_SEND_TIMEOUT)
178
+ # * Lock Duration(Default = DEFAULT_LOCK_DURATION)
179
+ def peek_lock(msg_buffer_name, timeout = DEFAULT_RECEIVE_TIMEOUT, lock_duration = DEFAULT_LOCK_DURATION)
180
+ retrieve_path = MessageBufferConstants.path_for_retrieve_message
181
+ timeout_parameter = MessageBufferConstants.timeout_parameter
182
+ lock_duration_parameter = MessageBufferConstants.lock_duration_parameter
183
+ msg_buffer_uri = message_uri(msg_buffer_name, retrieve_path)
184
+ token = acquire_authorization_token(request_uri, msg_buffer_uri)
185
+ retrieve_url = msg_buffer_uri + "?" + timeout_parameter + "=" + timeout + "&" + lock_duration_parameter + "=" + lock_duration
186
+ options = {}
187
+ header = {
188
+ 'Content-type' => MessageBufferConstants.content_type_property_for_text,
189
+ 'Expect' => HTTP_HEADER_EXPECT,
190
+ 'Authorization' => authorization(token) ,
191
+ 'Accept' => "*/*"
192
+ }
193
+ options.store(:header,header)
194
+ response = post(retrieve_url, "", options)
195
+ if ACCEPTED_RESPONSE_CODES.include?(response.code)
196
+ return LockedMessageInfo.new(
197
+ response['X-MS-LOCK-ID'],
198
+ response['X-MS-LOCK-LOCATION'],
199
+ response['X-MS-MESSAGE-LOCATION']
200
+ )
201
+ else
202
+ raise "Unexpected response code #{response.code}"
203
+ end
204
+ end
205
+
206
+ # Deletes a locked message. Expects following arguments obtained as part of the response of peek_lock-
207
+ # * Message Buffer Uri
208
+ # * Lock Id
209
+ def delete_locked_message(message_uri, lock_id)
210
+ lock_id_parameter = MessageBufferConstants.lock_id_parameter
211
+ token = acquire_authorization_token(request_uri, message_uri)
212
+ delete_uri = message_uri + "?" + lock_id_parameter + "=" + lock_id
213
+ options = {}
214
+ header = {
215
+ 'Content-type' => MessageBufferConstants.content_type_property_for_atom_xml,
216
+ 'Expect' => HTTP_HEADER_EXPECT,
217
+ 'Authorization' => "#{MessageBufferConstants.shared_secret_header} #{CGI::unescape(token)}",
218
+ 'Accept' => "*/*"
219
+ }
220
+ options.store(:header,header)
221
+ response = delete(delete_uri, options)
222
+ if response.code == HTTP_STATUS_CODE_OK
223
+ return response.body
224
+ else
225
+ raise "Unexpected response code #{response.code}"
226
+ end
227
+ end
228
+
229
+ # Releases lock. Expects following arguments obtained as part of the response of peek_lock-
230
+ # * Lock Uri
231
+ def release_lock(lock_uri)
232
+ token = acquire_authorization_token(request_uri, lock_uri)
233
+ options = {}
234
+ header = {
235
+ 'Content-type' => MessageBufferConstants.content_type_property_for_text,
236
+ 'Expect' => HTTP_HEADER_EXPECT,
237
+ 'Authorization' => authorization(token) ,
238
+ 'Accept' => "*/*"
239
+ }
240
+ options.store(:header,header)
241
+ response = delete(lock_uri,options)
242
+ if response.code == HTTP_STATUS_CODE_OK
243
+ return response.body
244
+ else
245
+ raise "Unexpected response code #{response.code}"
246
+ end
247
+ end
248
+
249
+ # Retrieve the message in the message buffer. Expects -
250
+ # * Message Buffer Name
251
+ # * Timeout(Default = DEFAULT_SEND_TIMEOUT)
252
+ def retrieve_message(msg_buffer_name, timeout = DEFAULT_RECEIVE_TIMEOUT)
253
+ retrieve_path = MessageBufferConstants.path_for_retrieve_message
254
+ timeout_parameter = MessageBufferConstants.timeout_parameter
255
+ msg_buffer_uri = message_uri(msg_buffer_name, retrieve_path)
256
+ token = acquire_authorization_token(request_uri, msg_buffer_uri)
257
+ retrieve_url = msg_buffer_uri.to_s + "?" + timeout_parameter.to_s + "=" + timeout.to_s
258
+ options = {}
259
+ header = {
260
+ 'Content-type' => MessageBufferConstants.content_type_property_for_text,
261
+ 'Authorization' => "#{MessageBufferConstants.shared_secret_header} #{CGI.unescape(token)}"
262
+ }
263
+ options.store(:header,header)
264
+ response = delete(retrieve_url,options)
265
+ if response.code == HTTP_STATUS_CODE_OK
266
+ return response.body
267
+ else
268
+ raise "Unexpected response code #{response.code}"
269
+ end
270
+ end
271
+
272
+ private
273
+
274
+ def acquire_authorization_token(request_uri, msg_buffer_uri)
275
+ begin
276
+ shared_secret_token_provider = SharedSecretTokenProvider.new(@issuer_name, @issuer_key, @proxy)
277
+ token_info = shared_secret_token_provider.token(request_uri, msg_buffer_uri) #msg_buffer_uri = applies_to
278
+ token_info.token
279
+ rescue
280
+ raise 'Unable to acquire ACS (Shared Secret) Token'
281
+ end
282
+ end
283
+
284
+ def authorization(token)
285
+ "#{MessageBufferConstants.shared_secret_header} #{CGI::unescape(token)}"
286
+ end
287
+
288
+ def msg_buffer_uris(msg_buffer_name)
289
+ return request_uri, message_buffer_create_uri(msg_buffer_name)
290
+ end
291
+
292
+ def request_uri
293
+ "https://#{@solution_name}-sb.#{@acm_host_name}/#{@service_name}/" #The slash at the end is ESSENTIAL
294
+ end
295
+
296
+ def message_buffer_create_uri(message_buffer_name)
297
+ "http://#{@solution_name}.#{@service_bus_host_name}/#{message_buffer_name}/" #The slash at the end is ESSENTIAL
298
+ end
299
+
300
+ # This method returns the message in xml format
301
+ def formatted_message(message)
302
+ msg = "<s:Envelope xmlns:s='http://www.w3.org/2003/05/soap-envelope' xmlns:a='http://www.w3.org/2005/08/addressing'>"
303
+ msg += "<s:Header><a:Action s:mustUnderstand='1'/></s:Header>"
304
+ msg += "<s:Body><string xmlns='#{MessageBufferConstants.message_namespace}'>#{message}</string></s:Body>"
305
+ msg += "</s:Envelope>"
306
+ msg
307
+ end
308
+
309
+ def message_uri(message_buffer_name, send_path)
310
+ "http://#{@solution_name}.#{@service_bus_host_name}/#{message_buffer_name}/#{send_path}"
311
+ end
312
+
313
+ end
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2009, Persistent Systems Limited
2
+ #
3
+ # Redistribution and use, with or without modification, are permitted
4
+ # provided that the following conditions are met:
5
+ # - Redistributions of source code must retain the above copyright notice,
6
+ # this list of conditions and the following disclaimer.
7
+ # - Neither the name of Persistent Systems Limited nor the names of its contributors
8
+ # may be used to endorse or promote products derived from this software
9
+ # without specific prior written permission.
10
+ #
11
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
12
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
15
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
18
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
21
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ class MessageBufferConstants # :nodoc:
24
+ @shared_secret_header = 'WRAPv0.8'
25
+ @content_type_property_for_atom_xml = 'application/atom+xml;type=entry;charset=utf-8'
26
+ @content_type_property_for_text = 'text/xml;charset=utf-8'
27
+ @path_for_send_message = 'messages'
28
+ @path_for_retrieve_message = 'messages/head'
29
+ @message_namespace = 'http://schemas.microsoft.com/2003/10/Serialization/'
30
+ @message_buffer_policy_namespace = 'http://schemas.microsoft.com/netservices/2009/05/servicebus/connect'
31
+ @lock_duration_parameter = 'lockduration'
32
+ @timeout_parameter = 'timeout'
33
+ @lock_id_parameter = 'lockid'
34
+
35
+ class << self
36
+ attr_accessor :shared_secret_header,
37
+ :content_type_property_for_atom_xml,
38
+ :content_type_property_for_text,
39
+ :path_for_send_message,
40
+ :path_for_retrieve_message,
41
+ :message_namespace,
42
+ :message_buffer_policy_namespace,
43
+ :lock_duration_parameter,
44
+ :timeout_parameter,
45
+ :lock_id_parameter
46
+ end
47
+ end
48
+
@@ -0,0 +1,55 @@
1
+ # Copyright (c) 2009, Persistent Systems Limited
2
+ #
3
+ # Redistribution and use, with or without modification, are permitted
4
+ # provided that the following conditions are met:
5
+ # - Redistributions of source code must retain the above copyright notice,
6
+ # this list of conditions and the following disclaimer.
7
+ # - Neither the name of Persistent Systems Limited nor the names of its contributors
8
+ # may be used to endorse or promote products derived from this software
9
+ # without specific prior written permission.
10
+ #
11
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
12
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
15
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
18
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
21
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ require "#{__FILE__}/../message_buffer_constants"
24
+
25
+ class MessageBufferPolicy
26
+
27
+ # Initializes message buffer policy. Does not expect any parameters by default.
28
+ # * Authorization - DEFAULT = "Required"
29
+ # * Transport Protection - DEFAULT = "None"
30
+ # * Expires After - DEFAULT = "PT5M"
31
+ # * Max Message Count - DEFAULT = 10
32
+ def initialize(authorization = "Required", transport_protection = "None", expires_after = "PT5M", max_message_count = 10)
33
+ @authorization = authorization
34
+ @transport_protection = transport_protection
35
+ @expires_after = expires_after
36
+ @max_message_count = max_message_count
37
+ @message_buffer_policy_name = message_buffer_policy
38
+ end
39
+
40
+ # Returns the message buffer policy in atom format
41
+ def message_buffer_policy
42
+ xml_str = "<entry xmlns='http://www.w3.org/2005/Atom'><content type='text/xml'><MessageBufferPolicy xmlns:i='http://www.w3.org/2001/XMLSchema-instance' "
43
+ xml_str += "xmlns='#{MessageBufferConstants.message_buffer_policy_namespace}'>"
44
+ xml_str += "<Authorization>#{@authorization}</Authorization>"
45
+ xml_str += "<TransportProtection>#{@transport_protection}</TransportProtection>"
46
+ xml_str += "<ExpiresAfter>#{@expires_after}</ExpiresAfter>"
47
+ xml_str += "<MaxMessageCount>#{@max_message_count}</MaxMessageCount>"
48
+ xml_str += "</MessageBufferPolicy></content></entry>"
49
+ xml_str
50
+ end
51
+
52
+ #TODO, there could be a static method that accepts the policy in xml and returns the msg_buffer_policy object. Another kind of constructor
53
+
54
+ end
55
+
@@ -0,0 +1,95 @@
1
+ # Copyright (c) 2009, Persistent Systems Limited
2
+ #
3
+ # Redistribution and use, with or without modification, are permitted
4
+ # provided that the following conditions are met:
5
+ # - Redistributions of source code must retain the above copyright notice,
6
+ # this list of conditions and the following disclaimer.
7
+ # - Neither the name of Persistent Systems Limited nor the names of its contributors
8
+ # may be used to endorse or promote products derived from this software
9
+ # without specific prior written permission.
10
+ #
11
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
12
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
15
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
18
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
21
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ require 'net/https'
24
+ require "#{__FILE__}/../message_buffer_constants"
25
+
26
+ module DotNetServices # :nodoc:
27
+ module HTTPRequests # :nodoc:
28
+
29
+ module ToHash # :nodoc:
30
+ def to_hash
31
+ data_hash = {}
32
+ self.split('&').each do |param_pair|
33
+ param, val = param_pair.split('=')
34
+ data_hash.store(param, val)
35
+ end
36
+ data_hash
37
+ end
38
+ end
39
+
40
+ def proxy
41
+ #TODO Uncomment the following line of code and comment the next line of code BEFORE RELEASE
42
+ # @http_web_proxy || Net::HTTP
43
+ @http_web_proxy || Net::HTTP::Proxy('itgproxy.redmond.corp.microsoft.com', '80')
44
+ end
45
+
46
+ def get(url, options = {})
47
+ header = options[:header] if options[:header]
48
+ url = URI.parse(url)
49
+ req = Net::HTTP::Get.new(url.path, header)
50
+ req.basic_auth options[:http_username], options[:http_password] if options[:http_username] && options[:http_password]
51
+ res = proxy.start(url.host, url.port) do |http|
52
+ yield(req, http) if block_given?
53
+ http.request(req)
54
+ end
55
+ res
56
+ end
57
+
58
+ def delete(url, options = {})
59
+ header = options[:header] if options[:header]
60
+ url = URI.parse(url)
61
+ url_path = (url.query && url.query != '') ? (url.path + '?' + url.query) : url.path
62
+ req = Net::HTTP::Delete.new(url_path, header)
63
+ req.basic_auth options[:http_username], options[:http_password] if options[:http_username] && options[:http_password]
64
+ res = proxy.start(url.host, url.port) do |http|
65
+ yield(req, http) if block_given?
66
+ http.request(req)
67
+ end
68
+ res
69
+ end
70
+
71
+ def post(url, data, options = {})
72
+ header = options[:header] if options[:header]
73
+ url = URI.parse(url)
74
+ url_path = (url.query && url.query != '') ? (url.path + '?' + url.query) : url.path
75
+ http = proxy.new(url.host, url.port)
76
+ http.use_ssl = true if options[:use_ssl]
77
+ http = http.start
78
+ yield(req, http) if block_given?
79
+ res = http.post(url_path, data, header)
80
+ res
81
+ end
82
+
83
+ def put(url , data, options = {})
84
+ header = options[:header] if options[:header]
85
+ url = URI.parse(url)
86
+ url_path = (url.query && url.query != '') ? (url.path + '?' + url.query) : url.path
87
+ http = proxy.new(url.host, url.port)
88
+ yield(req, http) if block_given?
89
+ http = http.start
90
+ res = http.put(url_path, data, header)
91
+ res
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2009, Persistent Systems Limited
2
+ #
3
+ # Redistribution and use, with or without modification, are permitted
4
+ # provided that the following conditions are met:
5
+ # - Redistributions of source code must retain the above copyright notice,
6
+ # this list of conditions and the following disclaimer.
7
+ # - Neither the name of Persistent Systems Limited nor the names of its contributors
8
+ # may be used to endorse or promote products derived from this software
9
+ # without specific prior written permission.
10
+ #
11
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
12
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
15
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
18
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
21
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ simple_api_auth:
24
+ wrap_name: infocorp
25
+ wrap_password: eFBmEieKwRht6W6bSTuKLG8pTTVudbHmkjzJ++DukFc=
26
+ applies_to: http://localhost/SalesDashboard/
27
+ solution_name: rubyservice
28
+ trusted_key: YtO+yRw7gIXvU2ObK0P4W6hsCQPmQPlo/geg8zJDrb0=
29
+
30
+ #Setting the proxy is optional. You may also set http_web_proxy_username and http_web_proxy_password if you need to.
31
+ proxy:
32
+ http_web_proxy_server: itgproxy.redmond.corp.microsoft.com
33
+ http_web_proxy_port: 80
34
+
35
+ type_token:
36
+ issuer_name: owner
37
+ issuer_key: Jtt77GMAGljdnTXqvHlwijwGobEJXfT4+xlXAnLQoB4=
38
+ rest_applies_to: http://rubyservice.servicebus.windows.net/whatver/
39
+ rest_request_uri: https://rubyservice-sb.accesscontrol.windows.net/WRAPv0.8/
40
+
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2009, Persistent Systems Limited
2
+ #
3
+ # Redistribution and use, with or without modification, are permitted
4
+ # provided that the following conditions are met:
5
+ # - Redistributions of source code must retain the above copyright notice,
6
+ # this list of conditions and the following disclaimer.
7
+ # - Neither the name of Persistent Systems Limited nor the names of its contributors
8
+ # may be used to endorse or promote products derived from this software
9
+ # without specific prior written permission.
10
+ #
11
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
12
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
15
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
18
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
21
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ require '../lib/common/dot_net_services_environment'
24
+ require 'test/unit'
25
+
26
+ class DotNetServicesEnvironmentTest < Test::Unit::TestCase
27
+ def setup
28
+ @dnse = DotNetServicesEnvironment
29
+ @host_names = @dnse::HOST_NAMES
30
+ end
31
+
32
+ def test_acm_host_name
33
+ assert_equal @host_names["default"]["acm"], @dnse.acm_host_name
34
+ assert_equal @host_names["int"]["acm"], @dnse.acm_host_name("int")
35
+ assert_equal @host_names["ppe"]["acm"], @dnse.acm_host_name("ppe")
36
+ assert_equal @host_names["prod"]["acm"], @dnse.acm_host_name("prod")
37
+ end
38
+
39
+ def test_sts_host_name
40
+ assert_equal @host_names["default"]["sts"], @dnse.sts_host_name
41
+ assert_equal @host_names["int"]["sts"], @dnse.sts_host_name("int")
42
+ assert_equal @host_names["ppe"]["sts"], @dnse.sts_host_name("ppe")
43
+ assert_equal @host_names["prod"]["sts"], @dnse.sts_host_name("prod")
44
+ end
45
+
46
+ def test_service_bus_host_name
47
+ assert_equal @host_names["default"]["service_bus"], @dnse.service_bus_host_name
48
+ assert_equal @host_names["int"]["service_bus"], @dnse.service_bus_host_name("int")
49
+ assert_equal @host_names["ppe"]["service_bus"], @dnse.service_bus_host_name("ppe")
50
+ assert_equal @host_names["prod"]["service_bus"], @dnse.service_bus_host_name("prod")
51
+ end
52
+
53
+ end
54
+