1
# Copyright (c) 2009 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Tests for L{twisted.conch.tap}.
9
import Crypto.Cipher.DES3
19
from twisted.conch import unix
23
if Crypto and pyasn1 and unix:
24
from twisted.conch import tap
25
from twisted.conch.openssh_compat.factory import OpenSSHFactory
27
from twisted.python.compat import set
28
from twisted.application.internet import TCPServer
29
from twisted.cred.credentials import IPluggableAuthenticationModules
30
from twisted.cred.credentials import ISSHPrivateKey
31
from twisted.cred.credentials import IUsernamePassword
33
from twisted.trial.unittest import TestCase
37
class MakeServiceTest(TestCase):
39
Tests for L{tap.makeService}.
43
skip = "can't run w/o PyCrypto"
46
skip = "can't run w/o PyASN1"
49
skip = "can't run on non-posix computers"
53
L{tap.makeService} returns a L{TCPServer} instance running on port 22,
54
and the linked protocol factory is an instance of L{OpenSSHFactory}.
56
config = tap.Options()
57
service = tap.makeService(config)
58
self.assertIsInstance(service, TCPServer)
59
self.assertEquals(service.args[0], 22)
60
factory = service.args[1]
61
self.assertIsInstance(factory, OpenSSHFactory)
64
def test_checkersPamAuth(self):
66
The L{OpenSSHFactory} built by L{tap.makeService} has a portal with
67
L{IPluggableAuthenticationModules}, L{ISSHPrivateKey} and
68
L{IUsernamePassword} interfaces registered as checkers if C{pamauth} is
71
# Fake the presence of pamauth, even if PyPAM is not installed
72
self.patch(tap, "pamauth", object())
73
config = tap.Options()
74
service = tap.makeService(config)
75
portal = service.args[1].portal
77
set(portal.checkers.keys()),
78
set([IPluggableAuthenticationModules, ISSHPrivateKey,
82
def test_checkersWithoutPamAuth(self):
84
The L{OpenSSHFactory} built by L{tap.makeService} has a portal with
85
L{ISSHPrivateKey} and L{IUsernamePassword} interfaces registered as
86
checkers if C{pamauth} is not available.
88
# Fake the absence of pamauth, even if PyPAM is installed
89
self.patch(tap, "pamauth", None)
90
config = tap.Options()
91
service = tap.makeService(config)
92
portal = service.args[1].portal
94
set(portal.checkers.keys()),
95
set([ISSHPrivateKey, IUsernamePassword]))