r2057 - in isis-fish/trunk/src/test: java/fr/ifremer/isisfish/util resources resources/ssh
Author: chatellier Date: 2009-04-01 14:56:28 +0000 (Wed, 01 Apr 2009) New Revision: 2057 Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/SSHUtils.java isis-fish/trunk/src/test/resources/ssh/ isis-fish/trunk/src/test/resources/ssh/isistestkey isis-fish/trunk/src/test/resources/ssh/isistestkey.pub isis-fish/trunk/src/test/resources/ssh/isistestkey.txt Log: Ajout d'un test unitaire pour tester la validite d'une passphrase. Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/SSHUtils.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/SSHUtils.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/SSHUtils.java 2009-04-01 14:56:28 UTC (rev 2057) @@ -0,0 +1,99 @@ +/* *##% + * Copyright (C) 2009 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package fr.ifremer.isisfish.util; + +import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; + +import junit.framework.Assert; + +import org.codelutin.util.Resource; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.KeyPair; + +/** + * Class de test créé pour tester et centraliser la gestion + * des clés SSH et leur passphrase dans Isis. + * + * @author chatellier + * @version $Revision: 1.0 $ + * + * Last update : $Date: 1 avr. 2009 $ + * By : $Author: chatellier $ + */ +public class SSHUtils { + + protected static File keyFile; + + /** + * Find ssh key file. + * + * @throws URISyntaxException + */ + @BeforeClass + public static void init() throws URISyntaxException { + keyFile = new File("src/test/resources/ssh/isistestkey"); + } + + /** + * Test que la clé existe. + */ + @Test + public void testKeyExist() { + Assert.assertNotNull(keyFile); + Assert.assertTrue(keyFile.isFile()); + } + + /** + * Test si une passphrase est valide pour une clé SSH. + * + * @throws JSchException + */ + @Test + public void testIsValidPassphrase() throws JSchException { + String passphrase = "isispassphrase"; + + JSch jsch=new JSch(); + KeyPair kpair=KeyPair.load(jsch, keyFile.getAbsolutePath()); + + Assert.assertTrue(kpair.isEncrypted()); // cle protegee + Assert.assertTrue(kpair.decrypt(passphrase)); // decodage fonctionne + + } + + /** + * Test qu'une passphrase n'est pas valide pour une clé. + * @throws JSchException + */ + @Test + public void testIsNotValidPassphrase() throws JSchException { + String passphrase = "passphare not good"; + + JSch jsch=new JSch(); + KeyPair kpair=KeyPair.load(jsch, keyFile.getAbsolutePath()); + + Assert.assertTrue(kpair.isEncrypted()); // cle protegee + Assert.assertFalse(kpair.decrypt(passphrase)); // decodage fonctionne + } +} Added: isis-fish/trunk/src/test/resources/ssh/isistestkey =================================================================== --- isis-fish/trunk/src/test/resources/ssh/isistestkey (rev 0) +++ isis-fish/trunk/src/test/resources/ssh/isistestkey 2009-04-01 14:56:28 UTC (rev 2057) @@ -0,0 +1,30 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,C78258F97D4516F9 + +31azf6UcEu1zvBpQE/nZuQLR7F97paRe3AvJcfHGlz8bqQd5JP8axRA0RzbKA22+ +C3p8Sk980/oNPDnceR7fGfRWrypzsSaGkV1BsDK2wkcWgpdJIomQVjEqKmNO1jkZ +wKHSE1rAQq1PtJLVoXEwOwpOnH2LRjuiExyIqZePciyMCd/QJ5orU+i4mCZErx3F +1Pdz8VeDLEZRmsfbZh/OKqrZ7z9zRMtpIS9oXgw1sRH303AmU9/2hBflnhFddQFx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X2Dl9S2PU27w2n0woFHI7C1siO8jfHcYrUJWnfTng+/wY0jC +W+qdSsBjjbOzSwalZV7r+xUSjoVe6MemhwYM4Tg7Z/kVGIWt7F2q3GiOHLiYPNdw +9lWQtn8yTZcLUIbwWPWkPZ0vNYUPQcd7z86ysiUtEEZDWVA98fkA8nRWP1qKbO3D +7V9G1YD3KUx8l88kFCKAgt8N+pB9Co8L1P58FioxsXMXbSBlnrf4za80IK5CZ2IR +C2aU6FimsuTnP19cVSj4sUdHr7zYdqJ0JQHlYn/FGb1cp+wPWNvJOw== +-----END RSA PRIVATE KEY----- Added: isis-fish/trunk/src/test/resources/ssh/isistestkey.pub =================================================================== --- isis-fish/trunk/src/test/resources/ssh/isistestkey.pub (rev 0) +++ isis-fish/trunk/src/test/resources/ssh/isistestkey.pub 2009-04-01 14:56:28 UTC (rev 2057) @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzQdBma9PwFdIx+GZg/bOlgjFINc9+iv5pe7HmD+v+RuJ7Miw7MBnttpB2mg7Q+p1V/2V2h9QX1QiRC78/JQptkQrqItpnifQduwL7p53oLC57DQXdLdg5waeqp6yhifFosTpvkhNmhni8A8GoJpd8YIAdExttOe2vboBB4NBjlj6ujqXBBwIGNQuGJ+yCN9wiitwawzCPtAn7HXfGSjWSH+vxo75DcT6BaLi2Rwni7CjHQZUoNQMK1aTL0Wn5EvqOW/vHaWQ4ARKxuuVOCwlYMaJxk3orWl90ZZuOtEHkwxTeXEnBS2JnHbiVFTj3R63rr23UofSC32tsz3+YiFTFQ== chatellier at genux Added: isis-fish/trunk/src/test/resources/ssh/isistestkey.txt =================================================================== --- isis-fish/trunk/src/test/resources/ssh/isistestkey.txt (rev 0) +++ isis-fish/trunk/src/test/resources/ssh/isistestkey.txt 2009-04-01 14:56:28 UTC (rev 2057) @@ -0,0 +1,3 @@ +Clé ssh pour les tests unitaire de ISIS. + +La passphrase est "isispassphrase".
participants (1)
-
chatellier@users.labs.libre-entreprise.org