def test_aes_key(self):
     temp_private = '242416858127415443985927051233248666254'
     test_result = (b"\xf8\x05\x98\xbb '\xeeM<=\xe2\x8eU\xf6E\xa1",
                    b';\xd1\xacR|:\xc2\xdd#t\x181\xad\x11d\x0b')
     test = password.PasswordCommands()
     self.assertEqual(test._compute_aes_key(temp_private), test_result,
                      'AES expected key was not expected value')
Ejemplo n.º 2
0
 def test_decode_password_base64_error(self):
     test = password.PasswordCommands()
     try:
         test._decode_password(password)
         assert False, 'Exception was not caught'
     except password.PasswordError as e:
         self.assertEqual(str(e), "500: Couldn't decode base64 data",
                          'Incorrect message received on exception')
 def test_compute_shared_key(self):
     temp_private = 242416858127415443985927051233248666254
     temp_public = 29146890515040234272807524713655
     test = password.PasswordCommands()
     self.assertEqual(
         test._dh_compute_shared_key(temp_private, temp_public),
         158481232637345256609879856716487,
         'Shared key does not match expected value')
Ejemplo n.º 4
0
 def test_change_password_string(self):
     test = password.PasswordCommands()
     test_password = '******'
     with mock.patch('novaagent.common.password.set_password'):
         try:
             test._change_password(test_password)
         except Exception:
             assert False, 'An error was generated when should not have'
 def test_wipe_aes_key_error(self):
     test = password.PasswordCommands()
     test._wipe_key()
     try:
         print(test.aes_key)
         assert False, 'AES key was not removed as expected'
     except:
         pass
Ejemplo n.º 6
0
 def test_password_cmd_invalid_password_data(self):
     test = password.PasswordCommands()
     test._aes_key = b"\xf8\x05\x98\xbb '\xeeM<=\xe2\x8eU\xf6E\xa1"
     test._aes_iv = b';\xd1\xacR|:\xc2\xdd#t\x181\xad\x11d\x0b'
     message = test.password_cmd(
         "6E6haX/YGRSEcR9X9+3nLOgD+ItDTv9/uOHms02Cos0sqI/k1uFIC3V/YNydHJOk")
     self.assertEqual(
         (500, 'Invalid password data received'), message,
         'Did not receive expected error on invalid password data')
 def test_password_commands_init(self):
     test = password.PasswordCommands(test='Test Data', test2='Test 2')
     self.assertEqual(test.prime, 162259276829213363391578010288127,
                      'Prime values do not match')
     self.assertEqual(test.base, 5, 'Base values do not match')
     self.assertEqual(test.kwargs.get('test'), 'Test Data',
                      "invalid key from kwargs")
     self.assertEqual(test.kwargs.get('test2'), 'Test 2',
                      "invalid key from kwargs")
Ejemplo n.º 8
0
 def test_aes_key(self):
     test = password.PasswordCommands()
     test._compute_aes_key()
     self.assertEqual(test._aes_key,
                      b'j\xdf\x97\xf8:\xcfdS\xd4\xa6\xa4\xb1\x07\x0f7T',
                      'AES key was not expected value')
     self.assertEqual(test._aes_iv,
                      b'#d\r\xec6\x8f\xbe\xf3\x03dp\xfcTe\xb8e',
                      'AES IV set was not expected value')
Ejemplo n.º 9
0
 def test_decode_password_no_key_exchange(self):
     temp_pass = base64.b64encode(b'this is a test')
     test = password.PasswordCommands()
     try:
         test._decode_password(temp_pass)
         assert False, 'Exception was not caught'
     except password.PasswordError as e:
         self.assertEqual(str(e), "500: Password without key exchange",
                          'Incorrect message received on AES error')
Ejemplo n.º 10
0
    def test_password_cmd_error(self):
        test = password.PasswordCommands()
        password_error = password.PasswordError((999, "Generate Exception"))
        with mock.patch(
                'novaagent.common.password.PasswordCommands._decode_password',
                side_effect=password_error):
            message = test.password_cmd('Test Pass')

        self.assertEqual(
            (999, "Generate Exception"), message,
            'Did not receive expected message on change password exception')
Ejemplo n.º 11
0
    def test_compute_shared_key(self):
        test = password.PasswordCommands()
        test._private = int("""
            23112120562215754241813840772170184083273863303098366811852003357
            72446841869122972713534217535689064137278608958579090107008875567
            5269543831650785847026033312
            46342023613076766721726""".replace('\n', '').replace(' ', ''))

        temp_public = 29146890515040234272807524713655
        test._compute_shared_key(temp_public)
        self.assertEqual(test._shared, 27234591073885988013566387861589,
                         'Shared key does not match expected value')
Ejemplo n.º 12
0
 def test_clear_data(self):
     test = password.PasswordCommands()
     test._generate_private_key()
     test._compute_public_key()
     test._aes_key = 'Test AES'
     test._aes_iv = 'Test AES IV'
     test._wipe_keys()
     self.assertEqual(test._aes_key, None, "AES key is not None")
     self.assertEqual(test._aes_iv, None, "AES IV is not None")
     self.assertEqual(test._private, None, "Private is not None")
     self.assertEqual(test._public, None, "Public key is not None")
     self.assertEqual(test._shared, None, "Shared key is not None")
Ejemplo n.º 13
0
 def test_password_commands_init(self):
     test = password.PasswordCommands()
     self.assertEqual(test.prime, 162259276829213363391578010288127,
                      'Prime values do not match')
     self.assertEqual(test.base, 5, 'Base values do not match')
     self.assertEqual(test.min_key_length, 540,
                      "Invalid key length on init")
     self.assertEqual(test._public, None, "Public is not none")
     self.assertEqual(test._private, None, "Private is not none")
     self.assertEqual(test._shared, None, "Shared is not none")
     self.assertEqual(test._aes_key, None, "AES key is not none")
     self.assertEqual(test._aes_iv, None, "AES IV is not none")
    def test_key_init(self):
        test = password.PasswordCommands()
        try:
            keyinit = test.keyinit_cmd(242416858127415443985927051233248666254)
        except:
            assert False, 'Key init caused an error'

        self.assertEqual(len(keyinit), 2, 'Invalid length of return')
        self.assertEqual(keyinit[0], 'D0', 'Unexpected first value of tuple')
        self.assertEqual(
            type(keyinit[1]), str,
            'Unexpected type on second value of tuple should be string')
Ejemplo n.º 15
0
 def test_decode_password_password_error_length(self):
     temp_pass = base64.b64encode(b'this is a test')
     test = password.PasswordCommands()
     test._aes_key = b"\xf8\x05\x98\xbb '\xeeM<=\xe2\x8eU\xf6E\xa1"
     test._aes_iv = b';\xd1\xacR|:\xc2\xdd#t\x181\xad\x11d\x0b'
     try:
         test._decode_password(temp_pass)
         assert False, 'Exception was not caught'
     except password.PasswordError as e:
         self.assertEqual(
             '500: The length of the provided data is not a multiple '
             'of the block length.', str(e),
             'Incorrect message received generic password error')
Ejemplo n.º 16
0
 def test_make_private_key(self):
     test = password.PasswordCommands()
     test._generate_private_key()
     self.assertEqual(type(test._private), long,
                      'Invalid return type from make key')
     try:
         self.assertGreaterEqual(test._private.bit_length(),
                                 test.min_key_length,
                                 'Incorrect bit length in private key')
     except AttributeError:
         self.assertGreaterEqual(
             len(bin(test._private)) - 2, test.min_key_length,
             'Incorrect bit length in private key')
Ejemplo n.º 17
0
 def test_decode_password_password_error_length(self):
     temp_pass = base64.b64encode(b'this is a test')
     test = password.PasswordCommands()
     test._aes_key = b"\xf8\x05\x98\xbb '\xeeM<=\xe2\x8eU\xf6E\xa1"
     test._aes_iv = b';\xd1\xacR|:\xc2\xdd#t\x181\xad\x11d\x0b'
     try:
         test._decode_password(temp_pass)
         assert False, 'Exception was not caught'
     except password.PasswordError as e:
         self.assertEqual(
             str(e),
             "500: Input strings must be a multiple of 16 in length",
             'Incorrect message received generic password error')
    def test_password_cmd_success(self):
        test = password.PasswordCommands(testmode=True)
        test.aes_key = (b"\xf8\x05\x98\xbb '\xeeM<=\xe2\x8eU\xf6E\xa1",
                        b';\xd1\xacR|:\xc2\xdd#t\x181\xad\x11d\x0b')
        with mock.patch(
                'novaagent.common.password.PasswordCommands._decode_password'):
            with mock.patch(
                    'novaagent.common.password.PasswordCommands._change_password'
            ):
                message = test.password_cmd('6E6haX/YGRSEcR9X9+3nLOgD+ItDTv9/'
                                            'uOHms02Cos0sqI/k1uFIC3V/YNydHJOk')

        self.assertEqual(("0", ""), message,
                         'Did not receive expected message on change password')
Ejemplo n.º 19
0
 def test_decode_password_general_exception(self):
     temp_pass = base64.b64encode(b'this is a test')
     test = password.PasswordCommands()
     test._compute_aes_key()
     with mock.patch(
             'novaagent.common.password.PasswordCommands._decrypt_password',
             side_effect=ValueError('This is a test')):
         try:
             test._decode_password(temp_pass)
             assert False, 'A PasswordError should have occurred'
         except password.PasswordError:
             pass
         except Exception:
             assert False, 'A PasswordError should have been raised'
Ejemplo n.º 20
0
    def test_decode_password_success(self):
        temp_pass = base64.b64encode(b'this is a test')
        test = password.PasswordCommands()
        test._compute_aes_key()
        with mock.patch(
                'novaagent.common.password.PasswordCommands._decrypt_password',
        ) as decrypt:
            decrypt.return_value = 'test_password'
            try:
                returned_password = test._decode_password(temp_pass)
            except Exception:
                assert False, 'An exception occurred and should not have'

        self.assertEqual(returned_password, 'test_password',
                         'Password returned does not match')
Ejemplo n.º 21
0
 def test_decode_password_password_exception(self):
     temp_pass = base64.b64encode(b'this is a test')
     test = password.PasswordCommands()
     test._compute_aes_key()
     password_error = password.PasswordError((999, "Generate Exception"))
     with mock.patch(
             'novaagent.common.password.PasswordCommands._decrypt_password',
             side_effect=password_error):
         try:
             test._decode_password(temp_pass)
             assert False, 'A PasswordError exception shouldhave occurred'
         except password.PasswordError:
             pass
         except Exception:
             assert False, 'PasswordError exception was not triggered'
Ejemplo n.º 22
0
    def test_key_init(self):
        test = password.PasswordCommands()
        try:
            keyinit = test.keyinit_cmd(242416858127415443985927051233248666254)
        except Exception:
            assert False, 'Key init caused an error'

        self.assertNotEqual(test._private, None, 'Private is None')
        self.assertNotEqual(test._public, None, 'Public is None')
        self.assertNotEqual(test._shared, None, 'Shared is None')
        self.assertNotEqual(test._aes_key, None, 'AES key is None')
        self.assertNotEqual(test._aes_iv, None, 'AES IV is None')
        self.assertEqual(keyinit[0], 'D0', 'Unexpected first value of tuple')
        self.assertEqual(
            type(keyinit[1]), str,
            'Unexpected type on second value of tuple should be string')
Ejemplo n.º 23
0
    def test_password_cmd_success(self):
        test = password.PasswordCommands()
        test._aes_key = 'AES Key'
        test._aes_iv = 'AES IV'
        test._private = 'Private'
        test._shared = 'Shared'
        test._public = 'Public'
        with mock.patch(
                'novaagent.common.password.PasswordCommands._decode_password'
        ) as decode:
            decode.return_value = 'test'
            with mock.patch(
                    'novaagent.common.password.PasswordCommands._change_password'
            ):
                message = test.password_cmd('6E6haX/YGRSEcR9X9+3nLOgD+ItDTv9/'
                                            'uOHms02Cos0sqI/k1uFIC3V/YNydHJOk')

        self.assertEqual(test._aes_key, None, "AES key is not None")
        self.assertEqual(test._aes_iv, None, "AES IV is not None")
        self.assertEqual(test._private, None, "Private is not None")
        self.assertEqual(test._public, None, "Public key is not None")
        self.assertEqual(test._shared, None, "Shared key is not None")
        self.assertEqual(("0", ""), message,
                         'Did not receive expected message on change password')
Ejemplo n.º 24
0
 def test_compute_public_key(self):
     test = password.PasswordCommands()
     test._generate_private_key()
     test._compute_public_key()
     self.assertEqual(type(test._public), long,
                      'Invalid return type returned from compute public')
 def test_password_cmd_error(self):
     test = password.PasswordCommands(testmode=True)
     message = test.password_cmd('Test Pass')
     self.assertEqual((500, 'Password without key exchange'), message,
                      'Did not receive expected error on change password')
 def test_make_private_key(self):
     test = password.PasswordCommands()
     private_key = test._make_private_key()
     self.assertEqual(type(private_key), long,
                      'Invalid return type from make key')
 def test_compute_public_key(self):
     temp_private = 242416858127415443985927051233248666254
     test = password.PasswordCommands()
     public_key = test._dh_compute_public_key(temp_private)
     self.assertEqual(type(public_key), long,
                      'Invalid return type returned from compute public')
 def test_change_password_test_mode(self):
     test = password.PasswordCommands(testmode=True)
     self.assertEqual(test._change_password('test'), None,
                      'Return on change in test mode was not None')