summaryrefslogtreecommitdiffstats
path: root/Monitoring/MonitoringService/Credential/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'Monitoring/MonitoringService/Credential/test.py')
-rw-r--r--Monitoring/MonitoringService/Credential/test.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/Monitoring/MonitoringService/Credential/test.py b/Monitoring/MonitoringService/Credential/test.py
new file mode 100644
index 0000000..04a59f3
--- /dev/null
+++ b/Monitoring/MonitoringService/Credential/test.py
@@ -0,0 +1,46 @@
+'''
+Created on Aug 10, 2011
+
+@author: steger
+'''
+import unittest
+from os import close, unlink
+from tempfile import mkstemp
+from subprocess import Popen, PIPE
+from SshKeygen import SshKeygen
+
+class Test(unittest.TestCase):
+ sshkeygen = '/usr/bin/ssh-keygen'
+
+ def test_sshkeygen(self):
+ # generate a pair of RSA keys
+ self.key = SshKeygen()
+
+ # save keys in a file
+ fid, fn = mkstemp(suffix = "_rsa")
+ close(fid)
+ unlink(fn)
+ self.fn_private = fn
+ self.fn_public = "%s.pub" % fn
+ self.key.save_private_key(self.fn_private)
+ self.key.save_public_key(self.fn_public)
+
+ # Test the base64 format of the public key.
+ # convert and compare private key using ssh-keygen
+ proc = Popen(args = [self.sshkeygen, '-y', '-f', self.fn_private], stdout = PIPE)
+ converted = str(proc.communicate(input = None)[0])
+ expected = "ssh-rsa %s\n" % self.key.public
+ self.assertEqual(expected, converted, "Base64 encoded public RSA key differs from the one generated by %s" % self.sshkeygen)
+
+ # Test SshKeygen objects convert_key_from_file method.
+ expected = self.key.public
+ converted = SshKeygen.convert_key_from_file(self.fn_private)
+ self.assertEqual(expected, converted, "Base64 encoded public RSA key generated from file %s differs from expected" % self.fn_private)
+
+ # remove generated files
+ unlink(self.fn_private)
+ unlink(self.fn_public)
+
+if __name__ == "__main__":
+ #import sys;sys.argv = ['', 'Test.test_sshkeygen']
+ unittest.main() \ No newline at end of file