Beispiel #1
0
 def test_generate_secret_file(self, mock_context, mock_create_aws,
                               mock_file_open, mock_json, mock_dump):
     """Test generate_secret_file and ensure encrypt is called with the correct parameters"""
     context = ef_password.EFPWContext()
     context.env, context.service = self.env, self.service
     context.secret_file = self.secret_file
     context.match = 'password'
     mock_context.return_value = context
     mock_create_aws.return_value = {"kms": self.mock_kms}
     mock_json.return_value = {
         "params": {
             "test": {
                 "password": "******"
             }
         }
     }
     ef_password.main()
     self.mock_kms.decrypt.assert_not_called()
     self.mock_kms.encrypt.assert_called_once_with(
         KeyId='alias/{}-{}'.format(self.env, self.service),
         Plaintext="mock_secret1".encode())
     mock_file_open.assert_called_with(self.secret_file, 'w')
     handle = mock_file_open()
     mock_dump.assert_called_once_with(
         {
             'params': {
                 'test': {
                     'password': '******'
                 }
             }
         },
         handle,
         indent=2,
         separators=(',', ': '))
     handle.write.assert_called_with('\n')
Beispiel #2
0
 def test_main_decrypt(self, mock_context, mock_create_aws, mock_gen):
     """Test valid main() call with service, env, and --decrypt.
 Ensure decrypt is called with the correct parameters"""
     context = ef_password.EFPWContext()
     context.env, context.service, context.decrypt = self.env, self.service, base64.b64encode(
         self.secret)
     mock_context.return_value = context
     mock_create_aws.return_value = {"kms": self.mock_kms}
     ef_password.main()
     mock_gen.assert_not_called()
     self.mock_kms.encrypt.assert_not_called()
     self.mock_kms.decrypt.assert_called_once_with(
         CiphertextBlob=self.secret)
Beispiel #3
0
 def test_main_plaintext(self, mock_context, mock_create_aws, mock_gen):
     """Test valid main() call with service, env, and --plaintext.
 Ensure generate_password and encrypt are called with the correct parameters"""
     context = ef_password.EFPWContext()
     context.env, context.service, context.plaintext = self.env, self.service, self.secret
     mock_context.return_value = context
     mock_create_aws.return_value = {"kms": self.mock_kms}
     ef_password.main()
     mock_gen.assert_not_called()
     self.mock_kms.decrypt.assert_not_called()
     self.mock_kms.encrypt.assert_called_once_with(
         KeyId='alias/{}-{}'.format(self.env, self.service),
         Plaintext=self.secret.encode())
Beispiel #4
0
 def test_main_secret_file_parameters(self, mock_context, mock_create_aws,
                                      mock_gen):
     """Test valid main() call with service, env, --secret_file, and --match.
 Ensure generate_secret_file is called with the correct parameters"""
     context = ef_password.EFPWContext()
     context.env, context.service = self.env, self.service
     context.secret_file = self.secret_file
     context.match = 'password'
     mock_context.return_value = context
     mock_create_aws.return_value = {"kms": self.mock_kms}
     ef_password.main()
     mock_gen.assert_called_once_with(context.secret_file, context.match,
                                      context.service, context.env,
                                      mock_create_aws.return_value)