Skip to content

Commit

Permalink
Merge 2b450cb into 0cc3836
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Mar 22, 2016
2 parents 0cc3836 + 2b450cb commit c43cf86
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ matrix:
# Although there are two different things we're testing against here, they
# are orthogonal and any failures should be easily attributable to either
# Twisted version or Riak version without adding an additional build job.
# Twisted 13.2 requires PyCrypto for twisted.conch.ssh support.
- python: "2.7"
env: TWISTED_VERSION="Twisted==13.2.0" RIAK_VERSION="2.1.1"
env: TWISTED_VERSION="Twisted==13.2.0" RIAK_VERSION="2.1.1" PYCRYPTO_VERSION="PyCrypto==2.6.1"
# Test on pypy without coverage, because it's unnecessary and very slow.
# Also, we hit an obscure GC bug in pypy<=2.6.0 so we need at least 2.6.1.
- python: "pypy"
Expand All @@ -40,6 +41,8 @@ install:
# Travis seems to have pip 6.x, which doesn't build and cache wheels.
- "pip install 'pip>=7.1.0'"
- "pip install ${TWISTED_VERSION}"
# If requested, install PyCrypto
- if [ ! -z "$PYCRYPTO_VERSION" ]; then pip install "$PYCRYPTO_VERSION"; fi
- "pip install -r requirements.pip"
- "pip install coveralls"

Expand Down
7 changes: 2 additions & 5 deletions vumi/middleware/manhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
from vumi.middleware.base import BaseMiddlewareConfig
from vumi.config import ConfigServerEndpoint

from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from twisted.cred import portal
from twisted.conch import manhole_ssh, manhole_tap
from twisted.conch.checkers import SSHPublicKeyDatabase
from twisted.python.filepath import FilePath
from twisted.internet.endpoints import serverFromString


class ManholeMiddlewareConfig(BaseMiddlewareConfig):
twisted_endpoint = ConfigServerEndpoint(
"Twisted endpoint to listen on", default="tcp:0", static=True)
autorized_keys = ConfigList(
authorized_keys = ConfigList(
"List of absolute paths to `authorized_keys` files containing SSH "
"public keys that are allowed access.", default=None, static=True)

Expand Down Expand Up @@ -73,8 +71,7 @@ def setup_middleware(self):
})
ssh_portal = portal.Portal(ssh_realm, [checker])
factory = manhole_ssh.ConchFactory(ssh_portal)
endpoint = serverFromString(reactor, self.twisted_endpoint)
self.socket = yield endpoint.listen(factory)
self.socket = yield self.twisted_endpoint.listen(factory)

def teardown_middleware(self):
return self.socket.stopListening()
4 changes: 2 additions & 2 deletions vumi/middleware/manhole_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def getPassword(self, prompt=None):
return

def getPublicKey(self):
return public_key.blob()
return public_key

def getPrivateKey(self):
return defer.succeed(private_key.keyObject)
return defer.succeed(private_key)


class ClientConnection(connection.SSHConnection):
Expand Down
19 changes: 8 additions & 11 deletions vumi/middleware/tests/test_manhole.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from twisted.trial.unittest import SkipTest

from twisted.internet import defer, protocol, reactor
from twisted.internet.defer import inlineCallbacks
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.endpoints import TCP4ClientEndpoint

from vumi.tests.helpers import VumiTestCase
Expand Down Expand Up @@ -29,6 +29,7 @@ class DummyWorker(object):

class TestManholeMiddleware(VumiTestCase):

@inlineCallbacks
def setUp(self):
if not ssh:
raise SkipTest('Crypto requirements missing. Skipping Test.')
Expand All @@ -38,10 +39,7 @@ def setUp(self):
self.pub_key_file.write(public_key.toString('OPENSSH'))
self.pub_key_file.flush()

self._middlewares = []
self._client_sockets = []

self.mw = self.get_middleware({
self.mw = yield self.get_middleware({
'authorized_keys': [self.pub_key_file.name]
})

Expand All @@ -53,17 +51,17 @@ def open_shell(self, middleware):
factory.channelConnected = defer.Deferred()

endpoint = TCP4ClientEndpoint(reactor, host.host, host.port)
proto = yield endpoint.connect(factory)
transport = yield endpoint.connect(factory)

channel = yield factory.channelConnected
conn = channel.conn
term = session.packRequest_pty_req("vt100", (0, 0, 0, 0), '')
yield conn.sendRequest(channel, 'pty-req', term, wantReply=1)
yield conn.sendRequest(channel, 'shell', '', wantReply=1)
self._client_sockets.append(proto)
self.add_cleanup(proto.loseConnection)
self.add_cleanup(transport.loseConnection)
defer.returnValue(channel)

@inlineCallbacks
def get_middleware(self, config={}):
config = dict({
'port': '0',
Expand All @@ -73,10 +71,9 @@ def get_middleware(self, config={}):
worker.transport_name = 'foo'

mw = ManholeMiddleware("test_manhole_mw", config, worker)
mw.setup_middleware()
self._middlewares.append(mw)
yield mw.setup_middleware()
self.add_cleanup(mw.teardown_middleware)
return mw
returnValue(mw)

@inlineCallbacks
def test_mw(self):
Expand Down

0 comments on commit c43cf86

Please sign in to comment.