Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
* next:
  Fix the client authentication connection settings.
  Don't need to detect connection errors in mocked tests.
  Cache a run's finished state when it has finished.
  • Loading branch information
hainesr committed Jun 12, 2014
2 parents 32e493f + 72742b1 commit ad73e4d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
8 changes: 4 additions & 4 deletions lib/t2-server/net/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ def set_peer_verification

def set_client_authentication
if @params[:client_certificate]
pem = File.read(@params[:client_certificate])
@http.certificate = OpenSSL::X509::Certificate.new(pem)
@http.private_key = OpenSSL::PKey::RSA.new(pem,
@params[:client_password])
cert = File.read(@params[:client_certificate])
pkcs12 = OpenSSL::PKCS12.new(cert, @params[:client_password])
@http.certificate = pkcs12.certificate
@http.private_key = pkcs12.key
end
end

Expand Down
11 changes: 10 additions & 1 deletion lib/t2-server/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def initialize(server, uri, credentials = nil)

@credentials = credentials

# Has this Run finished executing on the server?
@finished = false

# Has this Run object been deleted from the server?
@deleted = false

Expand Down Expand Up @@ -320,7 +323,13 @@ def workflow
# :running or :finished.
def status
return :deleted if @deleted
Status.to_sym(@server.read(links[:status], "text/plain", @credentials))
return :finished if @finished

state = Status.to_sym(@server.read(links[:status], "text/plain",
@credentials))

@finished = (state == :finished)
state
end

# :call-seq:
Expand Down
24 changes: 24 additions & 0 deletions test/tc_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class TestParams < Test::Unit::TestCase

CERT_DIR = "test/workflows/secure"
SERVER_PK = "#{CERT_DIR}/heater-pk.pem"
CLNT_CERT = "#{CERT_DIR}/user-cert.p12"
CLNT_PASS = "testcert"

def test_base_params
params = T2Server::ConnectionParameters.new
Expand Down Expand Up @@ -97,4 +99,26 @@ def test_custom_ca
end
end

def test_client_cert
uri_suffix = 0

[CLNT_CERT, File.new(CLNT_CERT)].each do |c|
params = T2Server::ClientAuthSSLConnectionParameters.new(c, CLNT_PASS)

assert_not_nil params[:verify_peer]
assert params[:verify_peer]

assert_not_nil params[:client_certificate]
assert_equal CLNT_CERT, params[:client_certificate]
assert_not_nil params[:client_password]
assert_equal CLNT_PASS, params[:client_password]

assert_nothing_raised do
T2Server::Server.new("#{$uri}/client/#{uri_suffix}", params)
end

uri_suffix += 1
end
end

end
30 changes: 17 additions & 13 deletions test/tc_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,23 @@ def setup
# Test run connection
def test_run_create_and_delete
status = mock("#{RUN_PATH}/status", :accept => "text/plain",
:credentials => $userinfo, :body => "Initialized")
:credentials => $userinfo, :body => "Finished")
del = mock(RUN_PATH, :method => :delete, :status => [204, 404, 404],
:credentials => $userinfo)

assert_nothing_raised(T2Server::ConnectionError) do
assert @run.initialized?
assert @run.delete
assert @run.deleted?
assert_nothing_raised(T2Server::AttributeNotFoundError) do
assert @run.delete # Should still return true, not raise 404
end
assert @run.delete # Should still return true
assert @run.finished?
refute @run.deleted?

assert @run.delete
assert @run.deleted?
refute @run.finished?
assert_nothing_raised(T2Server::AttributeNotFoundError) do
assert @run.delete # Should still return true, not raise 404
end
assert @run.delete # Should still return true

assert_equal :deleted, @run.status
assert_not_equal :finished, @run.status

assert_requested status, :times => 1
assert_requested del, :times => 3
Expand Down Expand Up @@ -243,7 +247,7 @@ def test_full_run
assert_nil @run.output_port("wrong!")
end

assert_requested status, :times => 12
assert_requested status, :times => 6
assert_requested in_exp, :times => 1
assert_requested out, :times => 1
end
Expand All @@ -261,7 +265,7 @@ def test_output_no_errors
# Status :finished
refute @run.error?

assert_requested status, :times => 3
assert_requested status, :times => 2
assert_requested out, :times => 1
end

Expand All @@ -279,7 +283,7 @@ def test_output_with_errors
# Status :finished
assert @run.error?

assert_requested status, :times => 3
assert_requested status, :times => 2
assert_requested out, :times => 1
end

Expand Down Expand Up @@ -375,7 +379,7 @@ def test_output_list
assert_equal output_4_value.size, output[4].stream_value(output_4_stream)
assert_equal output_4_value, output_4_stream.data

assert_requested status, :times => 2
assert_requested status, :times => 1
assert_requested out, :times => 1
end

Expand Down

0 comments on commit ad73e4d

Please sign in to comment.