예제 #1
0
    def test_encrypt_password(self):
        self.assertIsNotNone(self.session.password)
        self.assertIsNone(self.session.encrypted_password)

        # Encrypt the password
        self.session.encrypt_password(self.router.platform)
        self.assertIsNotNone(self.session.encrypted_password)
        self.assertTrue(junos_is_encrypted(self.session.encrypted_password))
        self.assertEqual(self.session.password,
                         junos_decrypt(self.session.encrypted_password))

        # Change router platform and re-encrypt
        self.router.platform = PLATFORM_IOSXR
        self.session.encrypt_password(self.router.platform)
        self.assertIsNotNone(self.session.encrypted_password)
        self.assertTrue(cisco_is_encrypted(self.session.encrypted_password))
        self.assertEqual(self.session.password,
                         cisco_decrypt(self.session.encrypted_password))

        # Change router platform to an unsupported one
        self.router.platform = PLATFORM_NONE
        self.session.encrypt_password(self.router.platform)
        self.assertIsNone(self.session.encrypted_password)

        # Change password to None and
        self.session.password = None
        self.router.platform = PLATFORM_JUNOS
        self.session.encrypt_password(self.router.platform)
        self.assertIsNone(self.session.encrypted_password)
예제 #2
0
    def test_encrypt_password(self):
        self.assertIsNotNone(self.session.password)
        self.assertIsNone(self.session.encrypted_password)

        # Encrypt the password
        self.session.encrypt_password(self.router.platform)
        self.assertIsNotNone(self.session.encrypted_password)
        self.assertTrue(junos_is_encrypted(self.session.encrypted_password))
        self.assertEqual(
            self.session.password, junos_decrypt(self.session.encrypted_password)
        )

        # Change router platform and re-encrypt
        self.router.platform = Platform.IOSXR
        self.session.encrypt_password(self.router.platform)
        self.assertIsNotNone(self.session.encrypted_password)
        self.assertTrue(cisco_is_encrypted(self.session.encrypted_password))
        self.assertEqual(
            self.session.password, cisco_decrypt(self.session.encrypted_password)
        )

        # Change router platform to an unsupported one
        self.router.platform = Platform.NONE
        self.session.encrypt_password(self.router.platform)
        self.assertIsNone(self.session.encrypted_password)

        # Change password to None
        self.session.password = None
        self.router.platform = Platform.JUNOS
        self.session.encrypt_password(self.router.platform)
        self.assertIsNone(self.session.encrypted_password)

        # Change the password to a new one and make sure it changes the encrypted one
        self.session.password = "******"
        self.session.encrypt_password(self.router.platform)
        self.assertEqual(
            self.session.password, junos_decrypt(self.session.encrypted_password)
        )
        self.session.password = "******"
        self.session.encrypt_password(self.router.platform)
        self.assertEqual(
            self.session.password, junos_decrypt(self.session.encrypted_password)
        )
예제 #3
0
    def decrypt_string(self, string):
        """
        Returns a decrypted version of a given string based on the router platform.

        If no crypto module can be found for the router platform, the returned string
        will be the same as the one passed as argument to this function.
        """
        if self.platform == PLATFORM_JUNOS:
            return junos_decrypt(string)
        if self.platform in [PLATFORM_EOS, PLATFORM_IOS, PLATFORM_IOSXR, PLATFORM_NXOS]:
            return cisco_decrypt(string)

        return string
예제 #4
0
    def test_encrypt_password(self):
        autonomous_system = AutonomousSystem.objects.create(asn=64500, name="Test")
        router = Router.objects.create(
            name="Test", hostname="test.example.com", platform=PLATFORM_JUNOS
        )
        internet_exchange = InternetExchange.objects.create(
            name="Test", slug="test", router=router
        )
        peering_session = InternetExchangePeeringSession.objects.create(
            autonomous_system=autonomous_system,
            internet_exchange=internet_exchange,
            ip_address="2001:db8::1",
            password="******",
        )
        self.assertIsNotNone(peering_session.password)
        self.assertIsNone(peering_session.encrypted_password)

        # Encrypt the password
        peering_session.encrypt_password(router.platform)
        self.assertIsNotNone(peering_session.encrypted_password)
        self.assertTrue(junos_is_encrypted(peering_session.encrypted_password))
        self.assertEqual(
            peering_session.password, junos_decrypt(peering_session.encrypted_password)
        )

        # Change router platform and re-encrypt
        router.platform = PLATFORM_IOSXR
        peering_session.encrypt_password(router.platform)
        self.assertIsNotNone(peering_session.encrypted_password)
        self.assertTrue(cisco_is_encrypted(peering_session.encrypted_password))
        self.assertEqual(
            peering_session.password, cisco_decrypt(peering_session.encrypted_password)
        )

        # Change router platform to an unsupported one
        router.platform = PLATFORM_NONE
        peering_session.encrypt_password(router.platform)
        self.assertIsNone(peering_session.encrypted_password)

        # Change password to None and
        peering_session.password = None
        router.platform = PLATFORM_JUNOS
        peering_session.encrypt_password(router.platform)
        self.assertIsNone(peering_session.encrypted_password)