dot_net_services 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +5 -0
- data/Rakefile +1 -1
- data/lib/acs/saml_token_provider.rb +4 -4
- data/lib/acs/shared_secret_token_provider.rb +4 -4
- data/lib/acs/simple_api_auth_token_provider.rb +4 -4
- data/lib/acs/simple_web_token_provider.rb +4 -4
- data/lib/acs/token_provider.rb +4 -3
- data/lib/acs/token_validator.rb +1 -1
- data/lib/dot_net_services.rb +10 -9
- data/lib/service_bus/message_buffer.rb +14 -6
- data/lib/service_bus/message_buffer_policy.rb +1 -1
- data/lib/service_bus/requests.rb +2 -4
- data/test/config/test_config.yml +3 -3
- data/test/message_buffer_test.rb +95 -95
- data/test/token_test.rb +98 -98
- metadata +2 -2
data/README
CHANGED
@@ -28,6 +28,11 @@ API: http://dotnetservicesruby.com/documentation/classes/DotNetServices.html
|
|
28
28
|
|
29
29
|
A demo application that demonstrates usage of the API (gem) will be added soon.
|
30
30
|
|
31
|
+
== Test environment
|
32
|
+
|
33
|
+
* The gem installation has been tested on 32-bit Windows Server Enterprise edition, 64-bit Windows Vista and Mac os (10.5 leopard) along with ruby 1.8.6.
|
34
|
+
* All the unit tests have been tested on 32-bit Windows Server Enterprise edition.
|
35
|
+
|
31
36
|
== Contacts
|
32
37
|
|
33
38
|
Users maillist: http://rubyforge.org/mailman/listinfo/dotnetsrv-ruby-users
|
data/Rakefile
CHANGED
@@ -21,10 +21,10 @@
|
|
21
21
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
22
|
|
23
23
|
require 'cgi'
|
24
|
-
require "#{__FILE__}
|
25
|
-
require "#{__FILE__}
|
26
|
-
require "#{__FILE__}
|
27
|
-
require "#{__FILE__}
|
24
|
+
require "#{File.dirname(__FILE__)}/token_provider"
|
25
|
+
require "#{File.dirname(__FILE__)}/token_constants"
|
26
|
+
require "#{File.dirname(__FILE__)}/token_info"
|
27
|
+
require "#{File.dirname(__FILE__)}/../service_bus/http_proxy"
|
28
28
|
|
29
29
|
class SamlTokenProvider < TokenProvider
|
30
30
|
include DotNetServices::HTTPRequests
|
@@ -21,10 +21,10 @@
|
|
21
21
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
22
|
|
23
23
|
require 'cgi'
|
24
|
-
require "#{__FILE__}
|
25
|
-
require "#{__FILE__}
|
26
|
-
require "#{__FILE__}
|
27
|
-
require "#{__FILE__}
|
24
|
+
require "#{File.dirname(__FILE__)}/token_provider"
|
25
|
+
require "#{File.dirname(__FILE__)}/token_constants"
|
26
|
+
require "#{File.dirname(__FILE__)}/token_info"
|
27
|
+
require "#{File.dirname(__FILE__)}/../service_bus/http_proxy"
|
28
28
|
|
29
29
|
class SharedSecretTokenProvider < TokenProvider
|
30
30
|
attr_reader :issuer_name, :issuer_secret
|
@@ -21,10 +21,10 @@
|
|
21
21
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
22
|
|
23
23
|
require 'cgi'
|
24
|
-
require "#{__FILE__}
|
25
|
-
require "#{__FILE__}
|
26
|
-
require "#{__FILE__}
|
27
|
-
require "#{__FILE__}
|
24
|
+
require "#{File.dirname(__FILE__)}/token_provider"
|
25
|
+
require "#{File.dirname(__FILE__)}/token_constants"
|
26
|
+
require "#{File.dirname(__FILE__)}/token_info"
|
27
|
+
require "#{File.dirname(__FILE__)}/../service_bus/http_proxy"
|
28
28
|
|
29
29
|
class SimpleApiAuthTokenProvider < TokenProvider
|
30
30
|
attr_reader :wrap_name, :wrap_secret
|
@@ -21,10 +21,10 @@
|
|
21
21
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
22
|
|
23
23
|
require 'cgi'
|
24
|
-
require "#{__FILE__}
|
25
|
-
require "#{__FILE__}
|
26
|
-
require "#{__FILE__}
|
27
|
-
require "#{__FILE__}
|
24
|
+
require "#{File.dirname(__FILE__)}/token_provider"
|
25
|
+
require "#{File.dirname(__FILE__)}/token_constants"
|
26
|
+
require "#{File.dirname(__FILE__)}/token_info"
|
27
|
+
require "#{File.dirname(__FILE__)}/../service_bus/http_proxy"
|
28
28
|
|
29
29
|
class SimpleWebTokenProvider < TokenProvider
|
30
30
|
include DotNetServices::HTTPRequests
|
data/lib/acs/token_provider.rb
CHANGED
@@ -23,9 +23,10 @@
|
|
23
23
|
require 'base64'
|
24
24
|
require 'rubygems'
|
25
25
|
require 'hmac-sha2'
|
26
|
-
|
27
|
-
require "#{__FILE__}
|
28
|
-
require "#{__FILE__}
|
26
|
+
|
27
|
+
require "#{File.dirname(__FILE__)}/token_constants"
|
28
|
+
require "#{File.dirname(__FILE__)}/../service_bus/requests"
|
29
|
+
require "#{File.dirname(__FILE__)}/../service_bus/http_proxy"
|
29
30
|
|
30
31
|
class TokenProvider
|
31
32
|
include DotNetServices::HTTPRequests
|
data/lib/acs/token_validator.rb
CHANGED
data/lib/dot_net_services.rb
CHANGED
@@ -20,13 +20,14 @@
|
|
20
20
|
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
21
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
22
|
|
23
|
-
require "#{__FILE__}
|
24
|
-
|
25
|
-
require "#{__FILE__}
|
26
|
-
require "#{__FILE__}
|
27
|
-
require "#{__FILE__}
|
28
|
-
require "#{__FILE__}
|
29
|
-
require "#{__FILE__}
|
30
|
-
require "#{__FILE__}
|
31
|
-
require "#{__FILE__}
|
23
|
+
require "#{File.dirname(__FILE__)}/acs/shared_secret_token_provider"
|
24
|
+
|
25
|
+
require "#{File.dirname(__FILE__)}/acs/simple_api_auth_token_provider"
|
26
|
+
require "#{File.dirname(__FILE__)}/acs/simple_web_token_provider"
|
27
|
+
require "#{File.dirname(__FILE__)}/acs/saml_token_provider"
|
28
|
+
require "#{File.dirname(__FILE__)}/acs/token_constants"
|
29
|
+
require "#{File.dirname(__FILE__)}/acs/token_info"
|
30
|
+
require "#{File.dirname(__FILE__)}/acs/token_provider"
|
31
|
+
require "#{File.dirname(__FILE__)}/acs/token_validator"
|
32
|
+
require "#{File.dirname(__FILE__)}/service_bus/message_buffer"
|
32
33
|
|
@@ -20,12 +20,12 @@
|
|
20
20
|
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
21
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
22
|
|
23
|
-
require "#{__FILE__}
|
24
|
-
require "#{__FILE__}
|
25
|
-
require "#{__FILE__}
|
26
|
-
require "#{__FILE__}
|
27
|
-
require "#{__FILE__}
|
28
|
-
require "#{__FILE__}
|
23
|
+
require "#{File.dirname(__FILE__)}/http_proxy"
|
24
|
+
require "#{File.dirname(__FILE__)}/requests"
|
25
|
+
require "#{File.dirname(__FILE__)}/message_buffer_policy"
|
26
|
+
require "#{File.dirname(__FILE__)}/locked_message_info"
|
27
|
+
require "#{File.dirname(__FILE__)}/../acs/shared_secret_token_provider"
|
28
|
+
require "#{File.dirname(__FILE__)}/../common/dot_net_services_environment"
|
29
29
|
|
30
30
|
# This class contains implementation to
|
31
31
|
# * Create a message buffer
|
@@ -86,6 +86,7 @@ class MessageBuffer
|
|
86
86
|
request_uri, msg_buffer_uri = msg_buffer_uris(msg_buffer_name)
|
87
87
|
raise 'Message buffer URI not found' unless msg_buffer_uri
|
88
88
|
token = acquire_authorization_token(request_uri, msg_buffer_uri)
|
89
|
+
yield(token) if block_given?
|
89
90
|
begin
|
90
91
|
options = {}
|
91
92
|
header = {
|
@@ -111,6 +112,7 @@ class MessageBuffer
|
|
111
112
|
def policy(msg_buffer_name)
|
112
113
|
request_uri, msg_buffer_uri = msg_buffer_uris(msg_buffer_name)
|
113
114
|
token = acquire_authorization_token(request_uri, msg_buffer_uri)
|
115
|
+
yield(token) if block_given?
|
114
116
|
options = {}
|
115
117
|
header = {
|
116
118
|
'Content-type' => MessageBufferConstants.content_type_property_for_atom_xml,
|
@@ -135,6 +137,7 @@ class MessageBuffer
|
|
135
137
|
def delete_message_buffer(msg_buffer_name)
|
136
138
|
request_uri, msg_buffer_uri = msg_buffer_uris(msg_buffer_name)
|
137
139
|
token = acquire_authorization_token(request_uri, msg_buffer_uri)
|
140
|
+
yield(token) if block_given?
|
138
141
|
options = {}
|
139
142
|
header = {
|
140
143
|
'Content-type' => MessageBufferConstants.content_type_property_for_atom_xml,
|
@@ -160,6 +163,7 @@ class MessageBuffer
|
|
160
163
|
msg_buffer_uri = message_uri(msg_buffer_name, send_path)
|
161
164
|
message = formatted_message(msg_str)
|
162
165
|
token = acquire_authorization_token(request_uri, msg_buffer_uri)
|
166
|
+
yield(token) if block_given?
|
163
167
|
send_uri = msg_buffer_uri + "?" + timeout_parameter + "=" + timeout
|
164
168
|
options = {}
|
165
169
|
header = {
|
@@ -182,6 +186,7 @@ class MessageBuffer
|
|
182
186
|
lock_duration_parameter = MessageBufferConstants.lock_duration_parameter
|
183
187
|
msg_buffer_uri = message_uri(msg_buffer_name, retrieve_path)
|
184
188
|
token = acquire_authorization_token(request_uri, msg_buffer_uri)
|
189
|
+
yield(token) if block_given?
|
185
190
|
retrieve_url = msg_buffer_uri + "?" + timeout_parameter + "=" + timeout + "&" + lock_duration_parameter + "=" + lock_duration
|
186
191
|
options = {}
|
187
192
|
header = {
|
@@ -209,6 +214,7 @@ class MessageBuffer
|
|
209
214
|
def delete_locked_message(message_uri, lock_id)
|
210
215
|
lock_id_parameter = MessageBufferConstants.lock_id_parameter
|
211
216
|
token = acquire_authorization_token(request_uri, message_uri)
|
217
|
+
yield(token) if block_given?
|
212
218
|
delete_uri = message_uri + "?" + lock_id_parameter + "=" + lock_id
|
213
219
|
options = {}
|
214
220
|
header = {
|
@@ -230,6 +236,7 @@ class MessageBuffer
|
|
230
236
|
# * Lock Uri
|
231
237
|
def release_lock(lock_uri)
|
232
238
|
token = acquire_authorization_token(request_uri, lock_uri)
|
239
|
+
yield(token) if block_given?
|
233
240
|
options = {}
|
234
241
|
header = {
|
235
242
|
'Content-type' => MessageBufferConstants.content_type_property_for_text,
|
@@ -254,6 +261,7 @@ class MessageBuffer
|
|
254
261
|
timeout_parameter = MessageBufferConstants.timeout_parameter
|
255
262
|
msg_buffer_uri = message_uri(msg_buffer_name, retrieve_path)
|
256
263
|
token = acquire_authorization_token(request_uri, msg_buffer_uri)
|
264
|
+
yield(token) if block_given?
|
257
265
|
retrieve_url = msg_buffer_uri.to_s + "?" + timeout_parameter.to_s + "=" + timeout.to_s
|
258
266
|
options = {}
|
259
267
|
header = {
|
@@ -20,7 +20,7 @@
|
|
20
20
|
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
21
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
22
|
|
23
|
-
require "#{__FILE__}
|
23
|
+
require "#{File.dirname(__FILE__)}/message_buffer_constants"
|
24
24
|
|
25
25
|
class MessageBufferPolicy
|
26
26
|
|
data/lib/service_bus/requests.rb
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
22
|
|
23
23
|
require 'net/https'
|
24
|
-
require "#{__FILE__}
|
24
|
+
require "#{File.dirname(__FILE__)}/message_buffer_constants"
|
25
25
|
|
26
26
|
module DotNetServices # :nodoc:
|
27
27
|
module HTTPRequests # :nodoc:
|
@@ -38,9 +38,7 @@ module DotNetServices # :nodoc:
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def proxy
|
41
|
-
|
42
|
-
# @http_web_proxy || Net::HTTP
|
43
|
-
@http_web_proxy || Net::HTTP::Proxy('itgproxy.redmond.corp.microsoft.com', '80')
|
41
|
+
@http_web_proxy || Net::HTTP
|
44
42
|
end
|
45
43
|
|
46
44
|
def get(url, options = {})
|
data/test/config/test_config.yml
CHANGED
@@ -22,10 +22,10 @@
|
|
22
22
|
|
23
23
|
simple_api_auth:
|
24
24
|
wrap_name: infocorp
|
25
|
-
wrap_password:
|
25
|
+
wrap_password: iTy6x9SDRQqS8d+PR00cAoVcc5HVz7YsfwGYzrhTIDk=
|
26
26
|
applies_to: http://localhost/SalesDashboard/
|
27
27
|
solution_name: rubyservice
|
28
|
-
trusted_key:
|
28
|
+
trusted_key: P4DbHC+HrgOGwkbOsgxTOP6xoUTCrwLMA++smRuADaY=
|
29
29
|
|
30
30
|
#Setting the proxy is optional. You may also set http_web_proxy_username and http_web_proxy_password if you need to.
|
31
31
|
proxy:
|
@@ -34,7 +34,7 @@ proxy:
|
|
34
34
|
|
35
35
|
type_token:
|
36
36
|
issuer_name: owner
|
37
|
-
issuer_key:
|
37
|
+
issuer_key: 1Rk38uPaY0/Fs0aD3bWsTSLCuFx2VVJIqRzhDFo3wlo=
|
38
38
|
rest_applies_to: http://rubyservice.servicebus.windows.net/whatver/
|
39
39
|
rest_request_uri: https://rubyservice-sb.accesscontrol.windows.net/WRAPv0.8/
|
40
40
|
|
data/test/message_buffer_test.rb
CHANGED
@@ -1,96 +1,96 @@
|
|
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 'test/unit'
|
24
|
-
require '
|
25
|
-
require "../lib/
|
26
|
-
require
|
27
|
-
|
28
|
-
class MessageBufferTest < Test::Unit::TestCase
|
29
|
-
|
30
|
-
def setup
|
31
|
-
@config = YAML.load(File.open('config/test_config.yml'))
|
32
|
-
@issuer_name = @config['type_token']['issuer_name']
|
33
|
-
@issuer_secret = @config['type_token']['issuer_secret']
|
34
|
-
@solution_name = @config['simple_api_auth']['solution_name']
|
35
|
-
@service_name = TokenConstants.simple_auth_authentication_type
|
36
|
-
@issuer_name = @config['type_token']['issuer_name']
|
37
|
-
@issuer_key = @config['type_token']['issuer_key']
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_create_message_buffer
|
41
|
-
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
42
|
-
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
43
|
-
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
44
|
-
assert policy_msg = msg_buffer.policy("ThisIsNotAMessageBuffer")
|
45
|
-
assert policy_msg.match(/<entry/)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_delete_message_buffer
|
49
|
-
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
50
|
-
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
51
|
-
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
52
|
-
assert msg_buffer.delete_message_buffer("ThisIsNotAMessageBuffer")
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_send_message
|
56
|
-
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
57
|
-
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
58
|
-
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
59
|
-
message_text = 'This is not a message in ThisIsNotAMessageBuffer'
|
60
|
-
assert msg_buffer.send_message('ThisIsNotAMessageBuffer', message_text)
|
61
|
-
assert message = msg_buffer.retrieve_message('ThisIsNotAMessageBuffer')
|
62
|
-
assert message.include?(message_text)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_peek_lock
|
66
|
-
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
67
|
-
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
68
|
-
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
69
|
-
message_text = 'This is not a message in ThisIsNotAMessageBuffer'
|
70
|
-
assert msg_buffer.send_message('ThisIsNotAMessageBuffer', message_text)
|
71
|
-
assert locked_message_info = msg_buffer.peek_lock('ThisIsNotAMessageBuffer')
|
72
|
-
assert_not_nil locked_message_info.message_uri
|
73
|
-
assert_not_nil locked_message_info.lock_uri
|
74
|
-
assert_not_nil locked_message_info.lock_id
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_release_lock
|
78
|
-
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
79
|
-
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
80
|
-
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
81
|
-
message_text = 'This is not a message in ThisIsNotAMessageBuffer'
|
82
|
-
assert msg_buffer.send_message('ThisIsNotAMessageBuffer', message_text)
|
83
|
-
assert locked_message_info = msg_buffer.peek_lock('ThisIsNotAMessageBuffer')
|
84
|
-
assert msg_buffer.release_lock(locked_message_info.lock_uri)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_delete_locked_message
|
88
|
-
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
89
|
-
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
90
|
-
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
91
|
-
message_text = 'This is not a message in ThisIsNotAMessageBuffer'
|
92
|
-
assert msg_buffer.send_message('ThisIsNotAMessageBuffer', message_text)
|
93
|
-
assert locked_message_info = msg_buffer.peek_lock('ThisIsNotAMessageBuffer')
|
94
|
-
assert msg_buffer.delete_locked_message(locked_message_info.message_uri, locked_message_info.lock_id)
|
95
|
-
end
|
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 'test/unit'
|
24
|
+
require 'yaml'
|
25
|
+
require "../lib/service_bus/message_buffer"
|
26
|
+
require "../lib/acs/token_constants"
|
27
|
+
|
28
|
+
class MessageBufferTest < Test::Unit::TestCase
|
29
|
+
|
30
|
+
def setup
|
31
|
+
@config = YAML.load(File.open('config/test_config.yml'))
|
32
|
+
@issuer_name = @config['type_token']['issuer_name']
|
33
|
+
@issuer_secret = @config['type_token']['issuer_secret']
|
34
|
+
@solution_name = @config['simple_api_auth']['solution_name']
|
35
|
+
@service_name = TokenConstants.simple_auth_authentication_type
|
36
|
+
@issuer_name = @config['type_token']['issuer_name']
|
37
|
+
@issuer_key = @config['type_token']['issuer_key']
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_create_message_buffer
|
41
|
+
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
42
|
+
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
43
|
+
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
44
|
+
assert policy_msg = msg_buffer.policy("ThisIsNotAMessageBuffer")
|
45
|
+
assert policy_msg.match(/<entry/)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_delete_message_buffer
|
49
|
+
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
50
|
+
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
51
|
+
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
52
|
+
assert msg_buffer.delete_message_buffer("ThisIsNotAMessageBuffer")
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_send_message
|
56
|
+
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
57
|
+
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
58
|
+
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
59
|
+
message_text = 'This is not a message in ThisIsNotAMessageBuffer'
|
60
|
+
assert msg_buffer.send_message('ThisIsNotAMessageBuffer', message_text)
|
61
|
+
assert message = msg_buffer.retrieve_message('ThisIsNotAMessageBuffer')
|
62
|
+
assert message.include?(message_text)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_peek_lock
|
66
|
+
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
67
|
+
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
68
|
+
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
69
|
+
message_text = 'This is not a message in ThisIsNotAMessageBuffer'
|
70
|
+
assert msg_buffer.send_message('ThisIsNotAMessageBuffer', message_text)
|
71
|
+
assert locked_message_info = msg_buffer.peek_lock('ThisIsNotAMessageBuffer')
|
72
|
+
assert_not_nil locked_message_info.message_uri
|
73
|
+
assert_not_nil locked_message_info.lock_uri
|
74
|
+
assert_not_nil locked_message_info.lock_id
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_release_lock
|
78
|
+
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
79
|
+
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
80
|
+
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
81
|
+
message_text = 'This is not a message in ThisIsNotAMessageBuffer'
|
82
|
+
assert msg_buffer.send_message('ThisIsNotAMessageBuffer', message_text)
|
83
|
+
assert locked_message_info = msg_buffer.peek_lock('ThisIsNotAMessageBuffer')
|
84
|
+
assert msg_buffer.release_lock(locked_message_info.lock_uri)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_delete_locked_message
|
88
|
+
msg_buffer = MessageBuffer.new(@issuer_name, @issuer_key, @solution_name, @service_name, @config['proxy'])
|
89
|
+
msg_buffer_policy_obj = MessageBufferPolicy.new("Required", "None", "PT5M", 10)
|
90
|
+
assert msg_buffer.create_message_buffer("ThisIsNotAMessageBuffer", msg_buffer_policy_obj)
|
91
|
+
message_text = 'This is not a message in ThisIsNotAMessageBuffer'
|
92
|
+
assert msg_buffer.send_message('ThisIsNotAMessageBuffer', message_text)
|
93
|
+
assert locked_message_info = msg_buffer.peek_lock('ThisIsNotAMessageBuffer')
|
94
|
+
assert msg_buffer.delete_locked_message(locked_message_info.message_uri, locked_message_info.lock_id)
|
95
|
+
end
|
96
96
|
end
|
data/test/token_test.rb
CHANGED
@@ -1,98 +1,98 @@
|
|
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 'test/unit'
|
24
|
-
require "../lib/acs/simple_api_auth_token_provider"
|
25
|
-
require "../lib/acs/shared_secret_token_provider"
|
26
|
-
require "../lib/acs/simple_web_token_provider"
|
27
|
-
require "../lib/acs/saml_token_provider"
|
28
|
-
require "../lib/acs/token_constants"
|
29
|
-
require "../lib/common/dot_net_services_environment"
|
30
|
-
require "../lib/acs/token_validator"
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
class TokenTest < Test::Unit::TestCase
|
35
|
-
def setup
|
36
|
-
@config = YAML.load(File.open('config/test_config.yml'))
|
37
|
-
@wrap_name = @config['simple_api_auth']['wrap_name']
|
38
|
-
@wrap_password = @config['simple_api_auth']['wrap_password']
|
39
|
-
@issuer_name = @config['type_token']['issuer_name']
|
40
|
-
@issuer_key = @config['type_token']['issuer_key']
|
41
|
-
@solution_name = @config['simple_api_auth']['solution_name']
|
42
|
-
@service_name = TokenConstants.simple_auth_authentication_type
|
43
|
-
@simple_api_auth_applies_to = @config['simple_api_auth']['applies_to']
|
44
|
-
@trusted_signing_key = @config['simple_api_auth']['trusted_key']
|
45
|
-
|
46
|
-
@request_uri = @config['type_token']['rest_request_uri']
|
47
|
-
@applies_to = @config['type_token']['rest_applies_to']
|
48
|
-
|
49
|
-
if @config['proxy']['http_web_proxy_server'] && @config['proxy']['http_web_proxy_port']
|
50
|
-
@http_web_proxy = Net::HTTP::Proxy(@config['proxy']['http_web_proxy_server'], @config['proxy']['http_web_proxy_port'])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_simple_api_auth_token
|
55
|
-
saatp = SimpleApiAuthTokenProvider.new(@wrap_name, @wrap_password, @config['proxy'])
|
56
|
-
request_uri = "https://#{@solution_name}.#{DotNetServicesEnvironment.acm_host_name}/#{@service_name}/"
|
57
|
-
token_info = saatp.token(request_uri, @simple_api_auth_applies_to)
|
58
|
-
assert token_valid?(token_info.token), "TOKEN VALIDITY FAILED!"
|
59
|
-
assert token_claims_valid?(token_info.token), "TOKEN VALIDITY FAILED!"
|
60
|
-
assert_not_nil token_info.token
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_shared_secret_token
|
64
|
-
sstp = SharedSecretTokenProvider.new(@issuer_name, @issuer_key, @config['proxy'])
|
65
|
-
token_info = sstp.token(@request_uri, @applies_to)
|
66
|
-
assert_not_nil token_info.token, "Shared Secret Token acquired is nil" #msg_buffer_uri = applies_to
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_simple_web_token
|
70
|
-
simple_web_token_provider = SimpleWebTokenProvider.new(@issuer_name, @issuer_key, @config['proxy'])
|
71
|
-
token_info = simple_web_token_provider.token(@request_uri, @applies_to)
|
72
|
-
assert_not_nil token_info.token
|
73
|
-
end
|
74
|
-
|
75
|
-
# TODO: Replace SimpleWebTokenProvider with SamlToken once Saml token is implemented.
|
76
|
-
def test_saml_token
|
77
|
-
#~ saml_token_provider = SimpleWebTokenProvider.new(saml_token, @http_web_proxy)
|
78
|
-
#~ token_info = saml_token_provider.token(@request_uri, @applies_to)
|
79
|
-
#~ assert_not_nil token_info.token
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
|
84
|
-
def token_valid?(token)
|
85
|
-
tv = TokenValidator.new(@service_name, @solution_name, @simple_api_auth_applies_to, @trusted_signing_key, @service_name + " " + token)
|
86
|
-
tv.validate
|
87
|
-
end
|
88
|
-
|
89
|
-
def token_claims_valid?(token)
|
90
|
-
tv = TokenValidator.new(@service_name, @solution_name, @simple_api_auth_applies_to, @trusted_signing_key, @service_name + " " + token)
|
91
|
-
tv.populate_claims(CGI::unescape(token))
|
92
|
-
valid_claim = tv.validate_claims({"ViewRegion"=>"true"})
|
93
|
-
invalid_claim = tv.validate_claims({"InvalidClaim"=>"true"})
|
94
|
-
incorrect_claim = tv.validate_claims({"ViewRegion"=>"false"})
|
95
|
-
valid_claim && !invalid_claim && !incorrect_claim
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
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 'test/unit'
|
24
|
+
require "../lib/acs/simple_api_auth_token_provider"
|
25
|
+
require "../lib/acs/shared_secret_token_provider"
|
26
|
+
require "../lib/acs/simple_web_token_provider"
|
27
|
+
require "../lib/acs/saml_token_provider"
|
28
|
+
require "../lib/acs/token_constants"
|
29
|
+
require "../lib/common/dot_net_services_environment"
|
30
|
+
require "../lib/acs/token_validator"
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
class TokenTest < Test::Unit::TestCase
|
35
|
+
def setup
|
36
|
+
@config = YAML.load(File.open('config/test_config.yml'))
|
37
|
+
@wrap_name = @config['simple_api_auth']['wrap_name']
|
38
|
+
@wrap_password = @config['simple_api_auth']['wrap_password']
|
39
|
+
@issuer_name = @config['type_token']['issuer_name']
|
40
|
+
@issuer_key = @config['type_token']['issuer_key']
|
41
|
+
@solution_name = @config['simple_api_auth']['solution_name']
|
42
|
+
@service_name = TokenConstants.simple_auth_authentication_type
|
43
|
+
@simple_api_auth_applies_to = @config['simple_api_auth']['applies_to']
|
44
|
+
@trusted_signing_key = @config['simple_api_auth']['trusted_key']
|
45
|
+
|
46
|
+
@request_uri = @config['type_token']['rest_request_uri']
|
47
|
+
@applies_to = @config['type_token']['rest_applies_to']
|
48
|
+
|
49
|
+
if @config['proxy']['http_web_proxy_server'] && @config['proxy']['http_web_proxy_port']
|
50
|
+
@http_web_proxy = Net::HTTP::Proxy(@config['proxy']['http_web_proxy_server'], @config['proxy']['http_web_proxy_port'])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_simple_api_auth_token
|
55
|
+
saatp = SimpleApiAuthTokenProvider.new(@wrap_name, @wrap_password, @config['proxy'])
|
56
|
+
request_uri = "https://#{@solution_name}.#{DotNetServicesEnvironment.acm_host_name}/#{@service_name}/"
|
57
|
+
token_info = saatp.token(request_uri, @simple_api_auth_applies_to)
|
58
|
+
assert token_valid?(token_info.token), "TOKEN VALIDITY FAILED!"
|
59
|
+
assert token_claims_valid?(token_info.token), "TOKEN VALIDITY FAILED!"
|
60
|
+
assert_not_nil token_info.token
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_shared_secret_token
|
64
|
+
sstp = SharedSecretTokenProvider.new(@issuer_name, @issuer_key, @config['proxy'])
|
65
|
+
token_info = sstp.token(@request_uri, @applies_to)
|
66
|
+
assert_not_nil token_info.token, "Shared Secret Token acquired is nil" #msg_buffer_uri = applies_to
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_simple_web_token
|
70
|
+
simple_web_token_provider = SimpleWebTokenProvider.new(@issuer_name, @issuer_key, @config['proxy'])
|
71
|
+
token_info = simple_web_token_provider.token(@request_uri, @applies_to)
|
72
|
+
assert_not_nil token_info.token
|
73
|
+
end
|
74
|
+
|
75
|
+
# TODO: Replace SimpleWebTokenProvider with SamlToken once Saml token is implemented.
|
76
|
+
def test_saml_token
|
77
|
+
#~ saml_token_provider = SimpleWebTokenProvider.new(saml_token, @http_web_proxy)
|
78
|
+
#~ token_info = saml_token_provider.token(@request_uri, @applies_to)
|
79
|
+
#~ assert_not_nil token_info.token
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def token_valid?(token)
|
85
|
+
tv = TokenValidator.new(@service_name, @solution_name, @simple_api_auth_applies_to, @trusted_signing_key, @service_name + " " + token)
|
86
|
+
tv.validate
|
87
|
+
end
|
88
|
+
|
89
|
+
def token_claims_valid?(token)
|
90
|
+
tv = TokenValidator.new(@service_name, @solution_name, @simple_api_auth_applies_to, @trusted_signing_key, @service_name + " " + token)
|
91
|
+
tv.populate_claims(CGI::unescape(token))
|
92
|
+
valid_claim = tv.validate_claims({"ViewRegion"=>"true"})
|
93
|
+
invalid_claim = tv.validate_claims({"InvalidClaim"=>"true"})
|
94
|
+
incorrect_claim = tv.validate_claims({"ViewRegion"=>"false"})
|
95
|
+
valid_claim && !invalid_claim && !incorrect_claim
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dot_net_services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ""
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-24 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|