t2-server 1.1.0 → 1.2.0
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 +15 -0
- data/.gitignore +1 -0
- data/.ruby-env +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -1
- data/CHANGES.rdoc +49 -0
- data/README.rdoc +10 -8
- data/bin/t2-delete-runs +0 -3
- data/lib/t2-server-cli.rb +16 -9
- data/lib/t2-server/exceptions.rb +7 -19
- data/lib/t2-server/net/connection.rb +14 -6
- data/lib/t2-server/net/credentials.rb +12 -1
- data/lib/t2-server/net/parameters.rb +3 -3
- data/lib/t2-server/port.rb +12 -29
- data/lib/t2-server/run.rb +54 -35
- data/lib/t2-server/server.rb +3 -4
- data/lib/t2-server/xml.rb +0 -1
- data/lib/t2-server/xml/methods.rb +97 -4
- data/t2-server.gemspec +4 -1
- data/test/helpers/fake-run.rb +47 -0
- data/test/helpers/test-cache.rb +49 -0
- data/test/helpers/test-xml.rb +36 -0
- data/test/helpers/timezone.rb +39 -0
- data/test/mocked-server-responses/.gitattributes +1 -0
- data/test/mocked-server-responses/get-admin.raw +6 -0
- data/test/mocked-server-responses/get-rest-policy-runlimit.raw +6 -0
- data/test/mocked-server-responses/get-rest-policy.raw +6 -0
- data/test/mocked-server-responses/get-rest-run-input-expected.raw +6 -0
- data/test/mocked-server-responses/get-rest-run-input.raw +6 -0
- data/test/mocked-server-responses/get-rest-run-interaction-feed-0.raw +11 -0
- data/test/mocked-server-responses/get-rest-run-interaction-feed-1.raw +92 -0
- data/test/mocked-server-responses/get-rest-run-interaction-feed-2.raw +80 -0
- data/test/mocked-server-responses/get-rest-run-name.raw +6 -0
- data/test/mocked-server-responses/get-rest-run-output-list-errors.raw +6 -0
- data/test/mocked-server-responses/get-rest-run-output.raw +6 -0
- data/test/mocked-server-responses/get-rest-run-security-permissions.raw +6 -0
- data/test/mocked-server-responses/get-rest-run-security.raw +6 -0
- data/test/mocked-server-responses/get-rest-run.raw +6 -0
- data/test/mocked-server-responses/get-rest-runs.raw +6 -0
- data/test/mocked-server-responses/get-rest.raw +6 -0
- data/test/mocked-server-responses/log.txt +1 -0
- data/test/mocked-server-responses/mocks.rb +107 -0
- data/test/mocked-server-responses/options-admin-allownew.raw +7 -0
- data/test/tc_admin.rb +52 -24
- data/test/tc_admin_live.rb +66 -0
- data/test/tc_connection.rb +87 -0
- data/test/tc_connection_exceptions.rb +86 -0
- data/test/tc_credentials.rb +73 -0
- data/test/tc_interaction.rb +182 -0
- data/test/{tc_misc.rb → tc_misc_live.rb} +3 -1
- data/test/tc_params.rb +82 -4
- data/test/tc_perms.rb +54 -101
- data/test/tc_perms_live.rb +150 -0
- data/test/tc_ports.rb +192 -0
- data/test/tc_run.rb +333 -350
- data/test/tc_run_live.rb +453 -0
- data/test/{tc_secure.rb → tc_secure_live.rb} +30 -29
- data/test/tc_server.rb +115 -42
- data/test/tc_server_live.rb +92 -0
- data/test/tc_server_version.rb +19 -0
- data/test/tc_xml_messages.rb +201 -0
- data/test/ts_t2server.rb +37 -43
- data/test/workflows/secure/heater-pk.pem +24 -18
- data/test/workflows/secure/user-cert.p12 +0 -0
- data/version.yml +1 -1
- metadata +136 -29
- data/lib/t2-server/xml/fragments.rb +0 -78
@@ -0,0 +1,86 @@
|
|
1
|
+
# Copyright (c) 2014 The University of Manchester, UK.
|
2
|
+
#
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# * Neither the names of The University of Manchester nor the names of its
|
16
|
+
# contributors may be used to endorse or promote products derived from this
|
17
|
+
# software without specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
23
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
24
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
#
|
31
|
+
# Author: Robert Haines
|
32
|
+
|
33
|
+
require 'mocked-server-responses/mocks'
|
34
|
+
require 't2-server'
|
35
|
+
|
36
|
+
class TestConnectionExceptions < Test::Unit::TestCase
|
37
|
+
include T2Server::Mocks
|
38
|
+
|
39
|
+
def test_get_404
|
40
|
+
mock("", :accept => "*/*", :status => 404)
|
41
|
+
connection = T2Server::ConnectionFactory.connect($uri, $conn_params)
|
42
|
+
|
43
|
+
assert_raise(T2Server::AttributeNotFoundError) do
|
44
|
+
connection.GET($uri, "*/*", nil, nil)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_put_403
|
49
|
+
mock("", :method => :put, :accept => "*/*", :status => 403)
|
50
|
+
|
51
|
+
connection = T2Server::ConnectionFactory.connect($uri, $conn_params)
|
52
|
+
|
53
|
+
assert_raise(T2Server::AccessForbiddenError) do
|
54
|
+
connection.PUT($uri, "", "*/*", nil)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_post_401
|
59
|
+
mock("", :method => :post, :accept => "*/*", :credentials => $userinfo,
|
60
|
+
:status => 401)
|
61
|
+
|
62
|
+
connection = T2Server::ConnectionFactory.connect($uri, $conn_params)
|
63
|
+
assert_raise(T2Server::AuthorizationError) do
|
64
|
+
connection.POST($uri, "", "*/*", $creds)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_options_500
|
69
|
+
mock("", :method => :options, :status => 500)
|
70
|
+
|
71
|
+
connection = T2Server::ConnectionFactory.connect($uri, $conn_params)
|
72
|
+
assert_raise(T2Server::UnexpectedServerResponse) do
|
73
|
+
connection.OPTIONS($uri, nil)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_network_timeout
|
78
|
+
mock("", :timeout => true)
|
79
|
+
|
80
|
+
connection = T2Server::ConnectionFactory.connect($uri, $conn_params)
|
81
|
+
assert_raise(T2Server::ConnectionError) do
|
82
|
+
connection.GET($uri, "*/*", nil, nil)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright (c) 2014 The University of Manchester, UK.
|
2
|
+
#
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# * Neither the names of The University of Manchester nor the names of its
|
16
|
+
# contributors may be used to endorse or promote products derived from this
|
17
|
+
# software without specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
23
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
24
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
#
|
31
|
+
# Author: Robert Haines
|
32
|
+
|
33
|
+
require 't2-server'
|
34
|
+
|
35
|
+
class TestCredentials < Test::Unit::TestCase
|
36
|
+
|
37
|
+
USERNAME = "username"
|
38
|
+
PASSWORD = "password"
|
39
|
+
USERINFO = "#{USERNAME}:#{PASSWORD}"
|
40
|
+
|
41
|
+
# This class is used to ensure that the password is set in the credentials.
|
42
|
+
class FakeRequest
|
43
|
+
def basic_auth(user, pass)
|
44
|
+
pass
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_no_password_exposure
|
49
|
+
creds = T2Server::HttpBasic.new(USERNAME, PASSWORD)
|
50
|
+
|
51
|
+
r_to_s = creds.to_s
|
52
|
+
r_inspect = creds.inspect
|
53
|
+
|
54
|
+
refute r_to_s.include?(PASSWORD)
|
55
|
+
refute r_inspect.include?(PASSWORD)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_create_basic
|
59
|
+
request = FakeRequest.new
|
60
|
+
creds = T2Server::HttpBasic.new(USERNAME, PASSWORD)
|
61
|
+
|
62
|
+
assert_equal USERNAME, creds.username
|
63
|
+
assert_equal PASSWORD, creds.authenticate(request)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_parse_basic
|
67
|
+
request = FakeRequest.new
|
68
|
+
creds = T2Server::HttpBasic.parse(USERINFO)
|
69
|
+
|
70
|
+
assert_equal USERNAME, creds.username
|
71
|
+
assert_equal PASSWORD, creds.authenticate(request)
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# Copyright (c) 2014 The University of Manchester, UK.
|
2
|
+
#
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# * Neither the names of The University of Manchester nor the names of its
|
16
|
+
# contributors may be used to endorse or promote products derived from this
|
17
|
+
# software without specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
23
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
24
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
#
|
31
|
+
# Author: Robert Haines
|
32
|
+
|
33
|
+
require 'mocked-server-responses/mocks'
|
34
|
+
require 't2-server'
|
35
|
+
|
36
|
+
class TestInteractions < Test::Unit::TestCase
|
37
|
+
include T2Server::Mocks
|
38
|
+
|
39
|
+
WKF_PASS = "test/workflows/pass_through.t2flow"
|
40
|
+
|
41
|
+
# Need to lock down the run UUID so recorded server responses make sense.
|
42
|
+
RUN_UUID = "a341b87f-25cc-4dfd-be36-f5b073a6ba74"
|
43
|
+
RUN_PATH = "/rest/runs/#{RUN_UUID}"
|
44
|
+
|
45
|
+
def setup
|
46
|
+
# Register common mocks.
|
47
|
+
mock("/rest/", :accept => "application/xml", :output => "get-rest.raw")
|
48
|
+
mock("/rest/policy", :accept => "application/xml",
|
49
|
+
:output => "get-rest-policy.raw")
|
50
|
+
mock("/rest/runs", :method => :post, :credentials => $userinfo,
|
51
|
+
:status => 201,
|
52
|
+
:location => "https://localhost/taverna#{RUN_PATH}")
|
53
|
+
mock(RUN_PATH, :accept => "application/xml", :credentials => $userinfo,
|
54
|
+
:output => "get-rest-run.raw")
|
55
|
+
mock("#{RUN_PATH}/input", :accept => "application/xml",
|
56
|
+
:credentials => $userinfo, :output => "get-rest-run-input.raw")
|
57
|
+
mock("#{RUN_PATH}/security", :accept => "application/xml",
|
58
|
+
:credentials => $userinfo, :output => "get-rest-run-security.raw")
|
59
|
+
|
60
|
+
@run = T2Server::Run.create($uri, WKF_PASS, $creds, $conn_params)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_empty_feed
|
64
|
+
mock("#{RUN_PATH}/interaction", :accept => "application/atom+xml",
|
65
|
+
:credentials => $userinfo,
|
66
|
+
:output => "get-rest-run-interaction-feed-0.raw")
|
67
|
+
assert_equal [], @run.notifications(:all)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_requests
|
71
|
+
mock("#{RUN_PATH}/interaction", :accept => "application/atom+xml",
|
72
|
+
:credentials => $userinfo,
|
73
|
+
:output => "get-rest-run-interaction-feed-1.raw")
|
74
|
+
|
75
|
+
entries = @run.notifications(:all)
|
76
|
+
requests = @run.notifications(:requests)
|
77
|
+
replies = @run.notifications(:replies)
|
78
|
+
|
79
|
+
assert_equal 2, entries.length
|
80
|
+
assert_equal 2, requests.length
|
81
|
+
assert_equal [], replies
|
82
|
+
|
83
|
+
# No new requests...
|
84
|
+
assert_equal [], @run.notifications
|
85
|
+
|
86
|
+
entries.each do |entry|
|
87
|
+
refute entry.is_reply?
|
88
|
+
refute entry.is_notification?
|
89
|
+
refute entry.has_reply?
|
90
|
+
assert_not_equal "", entry.serial
|
91
|
+
assert_not_nil entry.uri
|
92
|
+
assert_nil entry.reply_to
|
93
|
+
end
|
94
|
+
|
95
|
+
test_input_data = "{ \"test\" : \"value\"}"
|
96
|
+
mock("#{RUN_PATH}/wd/interactions/interaction#{entries[0].id}InputData.json",
|
97
|
+
:credentials => $userinfo, :body => test_input_data)
|
98
|
+
|
99
|
+
assert_equal test_input_data, entries[0].input_data
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_no_request_input_data
|
103
|
+
mock("#{RUN_PATH}/interaction", :accept => "application/atom+xml",
|
104
|
+
:credentials => $userinfo,
|
105
|
+
:output => "get-rest-run-interaction-feed-1.raw")
|
106
|
+
|
107
|
+
entries = @run.notifications
|
108
|
+
|
109
|
+
mock("#{RUN_PATH}/wd/interactions/interaction#{entries[0].id}InputData.json",
|
110
|
+
:credentials => $userinfo, :body => "", :status => 404)
|
111
|
+
|
112
|
+
assert_nothing_raised(T2Server::AttributeNotFoundError) do
|
113
|
+
assert_equal "", entries[0].input_data
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_reply
|
118
|
+
mock("#{RUN_PATH}/interaction", :accept => "application/atom+xml",
|
119
|
+
:credentials => $userinfo,
|
120
|
+
:output => "get-rest-run-interaction-feed-1.raw")
|
121
|
+
|
122
|
+
test_reply_data = "{ \"test\" : \"value\" }"
|
123
|
+
|
124
|
+
entries = @run.notifications
|
125
|
+
|
126
|
+
mock("#{RUN_PATH}/wd/interactions/interaction#{entries[0].id}OutputData.json",
|
127
|
+
:method => :put, :credentials => $userinfo, :body => test_reply_data)
|
128
|
+
|
129
|
+
# When mocking this POST it doesn't matter (at the moment) what the
|
130
|
+
# returned location is.
|
131
|
+
mock("#{RUN_PATH}/interaction", :method => :post, :status => 201,
|
132
|
+
:credentials => $userinfo, :location => "https://localhost/taverna")
|
133
|
+
|
134
|
+
entries[0].reply("OK", test_reply_data)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_replies
|
138
|
+
mock("#{RUN_PATH}/interaction", :accept => "application/atom+xml",
|
139
|
+
:credentials => $userinfo,
|
140
|
+
:output => "get-rest-run-interaction-feed-1.raw")
|
141
|
+
|
142
|
+
entries = @run.notifications(:all)
|
143
|
+
requests = @run.notifications(:requests)
|
144
|
+
replies = @run.notifications(:replies)
|
145
|
+
|
146
|
+
assert_equal 2, entries.length
|
147
|
+
assert_equal 2, requests.length
|
148
|
+
assert_equal [], replies
|
149
|
+
|
150
|
+
mock("#{RUN_PATH}/interaction", :accept => "application/atom+xml",
|
151
|
+
:credentials => $userinfo,
|
152
|
+
:output => "get-rest-run-interaction-feed-2.raw")
|
153
|
+
|
154
|
+
# No new requests...
|
155
|
+
assert_equal [], @run.notifications
|
156
|
+
|
157
|
+
# Refresh local lists.
|
158
|
+
entries = @run.notifications(:all)
|
159
|
+
requests = @run.notifications(:requests)
|
160
|
+
replies = @run.notifications(:replies)
|
161
|
+
|
162
|
+
# One more entry in total.
|
163
|
+
assert_equal 3, entries.length
|
164
|
+
|
165
|
+
# Should not lose a request.
|
166
|
+
assert_equal 2, requests.length
|
167
|
+
|
168
|
+
# Should gain a reply.
|
169
|
+
assert_equal 1, replies.length
|
170
|
+
|
171
|
+
# One request should have a reply.
|
172
|
+
assert requests[0].has_reply?
|
173
|
+
refute requests[1].has_reply?
|
174
|
+
|
175
|
+
refute replies[0].is_notification?
|
176
|
+
refute replies[0].has_reply?
|
177
|
+
assert replies[0].is_reply?
|
178
|
+
assert_equal requests[0].id, replies[0].reply_to
|
179
|
+
assert_equal "", replies[0].input_data
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
@@ -34,10 +34,12 @@ require 't2-server'
|
|
34
34
|
|
35
35
|
class TestMisc < Test::Unit::TestCase
|
36
36
|
|
37
|
+
WKF_MISS_O = "test/workflows/missing_outputs.t2flow"
|
38
|
+
|
37
39
|
# Test a run with the missing output data bug to check that the library can
|
38
40
|
# workaround it ok. Bug is: http://dev.mygrid.org.uk/issues/browse/T2-2100
|
39
41
|
def test_missing_ports
|
40
|
-
T2Server::Run.create($uri,
|
42
|
+
T2Server::Run.create($uri, WKF_MISS_O, $creds, $conn_params) do |run|
|
41
43
|
assert_nothing_raised { run.start }
|
42
44
|
assert(run.running?)
|
43
45
|
run.wait
|
data/test/tc_params.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2010
|
1
|
+
# Copyright (c) 2010-2014 The University of Manchester, UK.
|
2
2
|
#
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -34,13 +34,91 @@ require 't2-server'
|
|
34
34
|
|
35
35
|
class TestParams < Test::Unit::TestCase
|
36
36
|
|
37
|
-
|
37
|
+
CERT_DIR = "test/workflows/secure"
|
38
|
+
SERVER_PK = "#{CERT_DIR}/heater-pk.pem"
|
39
|
+
CLNT_CERT = "#{CERT_DIR}/user-cert.p12"
|
40
|
+
CLNT_PASS = "testcert"
|
41
|
+
|
42
|
+
def test_base_params
|
38
43
|
params = T2Server::ConnectionParameters.new
|
39
44
|
|
40
45
|
params[:verify_peer] = true
|
41
|
-
assert_not_nil
|
46
|
+
assert_not_nil params[:verify_peer]
|
42
47
|
|
43
48
|
params[:not_a_chance] = true
|
44
|
-
assert_nil
|
49
|
+
assert_nil params[:not_a_chance]
|
45
50
|
end
|
51
|
+
|
52
|
+
def test_insecure
|
53
|
+
params = T2Server::InsecureSSLConnectionParameters.new
|
54
|
+
|
55
|
+
assert_not_nil params[:verify_peer]
|
56
|
+
refute params[:verify_peer]
|
57
|
+
|
58
|
+
assert_nothing_raised do
|
59
|
+
T2Server::Server.new("#{$uri}/insecure", params)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_ssl3
|
64
|
+
params = T2Server::SSL3ConnectionParameters.new
|
65
|
+
|
66
|
+
assert_not_nil params[:verify_peer]
|
67
|
+
assert params[:verify_peer]
|
68
|
+
|
69
|
+
assert_not_nil params[:ssl_version]
|
70
|
+
assert_equal :SSLv3, params[:ssl_version]
|
71
|
+
|
72
|
+
assert_nothing_raised do
|
73
|
+
T2Server::Server.new("#{$uri}/ssl3", params)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_custom_ca
|
78
|
+
uri_suffix = 0
|
79
|
+
|
80
|
+
[CERT_DIR, SERVER_PK, Dir.new(CERT_DIR), File.new(SERVER_PK)].each do |c|
|
81
|
+
params = T2Server::CustomCASSLConnectionParameters.new(c)
|
82
|
+
|
83
|
+
assert_not_nil params[:verify_peer]
|
84
|
+
assert params[:verify_peer]
|
85
|
+
|
86
|
+
if c.instance_of?(Dir) || File.directory?(c)
|
87
|
+
assert_not_nil params[:ca_path]
|
88
|
+
assert_equal CERT_DIR, params[:ca_path]
|
89
|
+
else
|
90
|
+
assert_not_nil params[:ca_file]
|
91
|
+
assert_equal SERVER_PK, params[:ca_file]
|
92
|
+
end
|
93
|
+
|
94
|
+
assert_nothing_raised do
|
95
|
+
T2Server::Server.new("#{$uri}/ca/#{uri_suffix}", params)
|
96
|
+
end
|
97
|
+
|
98
|
+
uri_suffix += 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_client_cert
|
103
|
+
uri_suffix = 0
|
104
|
+
|
105
|
+
[CLNT_CERT, File.new(CLNT_CERT)].each do |c|
|
106
|
+
params = T2Server::ClientAuthSSLConnectionParameters.new(c, CLNT_PASS)
|
107
|
+
|
108
|
+
assert_not_nil params[:verify_peer]
|
109
|
+
assert params[:verify_peer]
|
110
|
+
|
111
|
+
assert_not_nil params[:client_certificate]
|
112
|
+
assert_equal CLNT_CERT, params[:client_certificate]
|
113
|
+
assert_not_nil params[:client_password]
|
114
|
+
assert_equal CLNT_PASS, params[:client_password]
|
115
|
+
|
116
|
+
assert_nothing_raised do
|
117
|
+
T2Server::Server.new("#{$uri}/client/#{uri_suffix}", params)
|
118
|
+
end
|
119
|
+
|
120
|
+
uri_suffix += 1
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
46
124
|
end
|