def setUp(self): """ Create an in-memory L{Store} with a L{SecureShellConfiguration} in it. """ self.store = Store() self.shell = SecureShellConfiguration(store=self.store, hostKey=self._hostKey) installOn(self.shell, self.store)
def test_keyGeneration(self): """ L{SecureShellConfiguration} generates its own key pair if one is not supplied to C{__init__}. """ store = Store() shell = SecureShellConfiguration(store=store) installOn(shell, store) factory = shell.getFactory() self.assertHostKey(shell, factory)
def setUp(self): """ Create an in-memory L{Store} with a L{SecureShellConfiguration} in it. """ self.store = Store() self.shell = SecureShellConfiguration( store=self.store, hostKey=self._hostKey) installOn(self.shell, self.store)
class SecureShellConfigurationTests(TestCase): """ Tests for L{xmantissa.shell.SecureShellConfiguration} which defines how to create an SSH server. """ _hostKey = ( "-----BEGIN RSA PRIVATE KEY-----\n" "MIIByAIBAAJhAM/dftm59mJJ1JVy0bsq8J7fp4WUecgaJukRyf637d76ywxRYGdw\n" "47hkBiJaDYgaE9HMlh2eSow3b2YCyom4FLlh/7Buq58A9IofR7ZiNVYv0ZDppbDg\n" "FN+Gl2ZFLFB3dwIBIwJgC+DFa4b4It+lv2Wllaquqf4m1G7iYzSxxCzm+JzLw5lN\n" "bmsM0rX+Yk7bx3LcM6m34vyvhY6p/kQyjHo7/CkpaSQg4bnpOcqEq3oMf8E0c0lp\n" "TQ1TdtfnKKrZZPTaVr7rAjEA7O19/tSLK6by1BpE1cb6W07GK1WcafYLxQLT64o+\n" "GKxbrlsossc8gWJ8GDRjE2S5AjEA4JkYfYkgfucH941r9yDFrhr6FuOdwbLXDESZ\n" "DyLhW/7DHiVIXlaLFnY+51PcTwWvAjBzFESDFsdBFpMz0j6w+j8WaBccXMhQuVYs\n" "fbdjxs20NnWsdWuKCQAhljxGRVSxpfMCMBmrGL3jyTMTFtp2j/78bl0KZbl5GVf3\n" "LoUPJ29xs1r4i1PnAPTWsM9d+I93TGDNcwIxAMRz4KO02tiLXG2igwDw/WWszrkr\n" "r4ggaFDlt4QqoNz0l4tayqzbDV1XceLgP4cXcQ==\n" "-----END RSA PRIVATE KEY-----\n") def setUp(self): """ Create an in-memory L{Store} with a L{SecureShellConfiguration} in it. """ self.store = Store() self.shell = SecureShellConfiguration( store=self.store, hostKey=self._hostKey) installOn(self.shell, self.store) def test_interfaces(self): """ L{SecureShellConfiguration} implements L{IProtocolFactoryFactory}. """ self.assertTrue(verifyObject(IProtocolFactoryFactory, self.shell)) def test_powerup(self): """ L{installOn} powers up the target for L{IProtocolFactoryFactory} with L{SecureShellConfiguration}. """ self.assertIn( self.shell, list(self.store.powerupsFor(IProtocolFactoryFactory))) def test_repr(self): """ The result of C{repr} on a L{SecureShellConfiguration} instance includes only a fingerprint of the private key, not the entire value. """ self.assertEqual( repr(self.shell), "SecureShellConfiguration(storeID=%d, " % (self.shell.storeID,) + "hostKeyFingerprint='68cc7060bb6394060672467e7c4d8f3b')") def assertHostKey(self, shell, factory): """ Assert that the public and private keys provided by C{factory} match those specified by C{shell} and that they are L{Key} instances. """ privateKey = Key.fromString(shell.hostKey) self.assertEqual( factory.publicKeys, {'ssh-rsa': privateKey.public()}) self.assertEqual(factory.privateKeys, {'ssh-rsa': privateKey}) def test_getFactory(self): """ L{SecureShellConfiguration.getFactory} returns an L{SSHFactory} with keys from L{SecureShellConfiguration.hostKey}. """ factory = self.shell.getFactory() self.assertHostKey(self.shell, factory) def test_keyGeneration(self): """ L{SecureShellConfiguration} generates its own key pair if one is not supplied to C{__init__}. """ store = Store() shell = SecureShellConfiguration(store=store) installOn(shell, store) factory = shell.getFactory() self.assertHostKey(shell, factory) def test_portal(self): """ The factory returned by L{SecureShellConfiguration.getFactory} has a C{portal} attribute which allows logins authenticated in the usual L{axiom.userbase} manner. """ localpart = u'foo bar' domain = u'example.com' password = u'baz quux' loginSystem = self.store.findUnique(LoginSystem) account = loginSystem.addAccount( localpart, domain, password, internal=True) subStore = account.avatars.open() avatar = object() subStore.inMemoryPowerUp(avatar, IConchUser) factory = self.shell.getFactory() login = factory.portal.login( UsernamePassword( '%s@%s' % (localpart.encode('ascii'), domain.encode('ascii')), password), None, IConchUser) def cbLoggedIn(result): self.assertIdentical(IConchUser, result[0]) self.assertIdentical(avatar, result[1]) login.addCallback(cbLoggedIn) return login
class SecureShellConfigurationTests(TestCase): """ Tests for L{xmantissa.shell.SecureShellConfiguration} which defines how to create an SSH server. """ _hostKey = ( "-----BEGIN RSA PRIVATE KEY-----\n" "MIIByAIBAAJhAM/dftm59mJJ1JVy0bsq8J7fp4WUecgaJukRyf637d76ywxRYGdw\n" "47hkBiJaDYgaE9HMlh2eSow3b2YCyom4FLlh/7Buq58A9IofR7ZiNVYv0ZDppbDg\n" "FN+Gl2ZFLFB3dwIBIwJgC+DFa4b4It+lv2Wllaquqf4m1G7iYzSxxCzm+JzLw5lN\n" "bmsM0rX+Yk7bx3LcM6m34vyvhY6p/kQyjHo7/CkpaSQg4bnpOcqEq3oMf8E0c0lp\n" "TQ1TdtfnKKrZZPTaVr7rAjEA7O19/tSLK6by1BpE1cb6W07GK1WcafYLxQLT64o+\n" "GKxbrlsossc8gWJ8GDRjE2S5AjEA4JkYfYkgfucH941r9yDFrhr6FuOdwbLXDESZ\n" "DyLhW/7DHiVIXlaLFnY+51PcTwWvAjBzFESDFsdBFpMz0j6w+j8WaBccXMhQuVYs\n" "fbdjxs20NnWsdWuKCQAhljxGRVSxpfMCMBmrGL3jyTMTFtp2j/78bl0KZbl5GVf3\n" "LoUPJ29xs1r4i1PnAPTWsM9d+I93TGDNcwIxAMRz4KO02tiLXG2igwDw/WWszrkr\n" "r4ggaFDlt4QqoNz0l4tayqzbDV1XceLgP4cXcQ==\n" "-----END RSA PRIVATE KEY-----\n") def setUp(self): """ Create an in-memory L{Store} with a L{SecureShellConfiguration} in it. """ self.store = Store() self.shell = SecureShellConfiguration(store=self.store, hostKey=self._hostKey) installOn(self.shell, self.store) def test_interfaces(self): """ L{SecureShellConfiguration} implements L{IProtocolFactoryFactory}. """ self.assertTrue(verifyObject(IProtocolFactoryFactory, self.shell)) def test_powerup(self): """ L{installOn} powers up the target for L{IProtocolFactoryFactory} with L{SecureShellConfiguration}. """ self.assertIn(self.shell, list(self.store.powerupsFor(IProtocolFactoryFactory))) def test_repr(self): """ The result of C{repr} on a L{SecureShellConfiguration} instance includes only a fingerprint of the private key, not the entire value. """ self.assertEqual( repr(self.shell), "SecureShellConfiguration(storeID=%d, " % (self.shell.storeID, ) + "hostKeyFingerprint='68cc7060bb6394060672467e7c4d8f3b')") def assertHostKey(self, shell, factory): """ Assert that the public and private keys provided by C{factory} match those specified by C{shell} and that they are L{Key} instances. """ privateKey = Key.fromString(shell.hostKey) self.assertEqual(factory.publicKeys, {'ssh-rsa': privateKey.public()}) self.assertEqual(factory.privateKeys, {'ssh-rsa': privateKey}) def test_getFactory(self): """ L{SecureShellConfiguration.getFactory} returns an L{SSHFactory} with keys from L{SecureShellConfiguration.hostKey}. """ factory = self.shell.getFactory() self.assertHostKey(self.shell, factory) def test_keyGeneration(self): """ L{SecureShellConfiguration} generates its own key pair if one is not supplied to C{__init__}. """ store = Store() shell = SecureShellConfiguration(store=store) installOn(shell, store) factory = shell.getFactory() self.assertHostKey(shell, factory) def test_keyRotation(self): """ L{SecureShellConfiguration.rotate} generates a new key pair replacing the old one. """ oldKey = self.shell.hostKey self.shell.rotate() newKey = self.shell.hostKey self.assertNotEqual(oldKey, newKey) factory = self.shell.getFactory() self.assertHostKey(self.shell, factory) def test_portal(self): """ The factory returned by L{SecureShellConfiguration.getFactory} has a C{portal} attribute which allows logins authenticated in the usual L{axiom.userbase} manner. """ localpart = u'foo bar' domain = u'example.com' password = u'baz quux' loginSystem = self.store.findUnique(LoginSystem) account = loginSystem.addAccount(localpart, domain, password, internal=True) subStore = account.avatars.open() avatar = object() subStore.inMemoryPowerUp(avatar, IConchUser) factory = self.shell.getFactory() login = factory.portal.login( UsernamePassword( '%s@%s' % (localpart.encode('ascii'), domain.encode('ascii')), password), None, IConchUser) def cbLoggedIn(result): self.assertIdentical(IConchUser, result[0]) self.assertIdentical(avatar, result[1]) login.addCallback(cbLoggedIn) return login