def test_save(self): """Setup the test cases""" SecureString.create(MY_STRING, NAME).save() with self.assertRaises(Exception): SecureString.create(unencrypted="", name=NAME).save() with self.assertRaises(Exception): SecureString(encrypted_string='something', name=NAME).save()
def test_save(self): """Setup the test cases""" SecureString.create(MY_STRING, NAME).save() with self.assertRaises(Exception): SecureString.create(name=NAME).save() with self.assertRaises(Exception): SecureString(encrypted_string='something', name=NAME).save()
def save(self, *args, **kwargs): """Override the default save behavior to also include the secure secret""" password = kwargs.pop('password', '') super(ThermoFisherCloudAccount, self).save(*args, **kwargs) if password: secret = SecureString.create(password, self.ampliseq_secret_name) secret.save()
def obj_create(self, bundle, request=None, **kwargs): """Custom create method to override the default post""" try: params = bundle.data # sanity check on the input parameters if 'encrypted_string' in params: del params['encrypted_string'] if 'unencrypted' not in params: return HttpApplicationError("API creation of SecureString requires \'unencrypted\' parameter") if 'name' not in params: return HttpApplicationError("API creation of SecureString requires \'name\' parameter") # create and save the new object try: secured = SecureString.objects.get(name=params['name']) secured.encrypt(params['unencrypted']) secured.save() except SecureString.DoesNotExist: secured = SecureString.create(params['unencrypted'], params['name']) secured.save() return bundle except Exception as exc: logger.debug(str(exc)) return HttpApplicationError("Error creating secure string: " + str(exc))
def obj_create(self, bundle, request=None, **kwargs): """Custom create method to override the default post""" try: params = bundle.data # sanity check on the input parameters if 'encrypted_string' in params: del params['encrypted_string'] if 'unencrypted' not in params: return HttpApplicationError( "API creation of SecureString requires \'unencrypted\' parameter" ) if 'name' not in params: return HttpApplicationError( "API creation of SecureString requires \'name\' parameter") # create and save the new object try: secured = SecureString.objects.get(name=params['name']) secured.encrypt(params['unencrypted']) secured.save() except SecureString.DoesNotExist: secured = SecureString.create(params['unencrypted'], params['name']) secured.save() return bundle except Exception as exc: logger.debug(str(exc)) return HttpApplicationError("Error creating secure string: " + str(exc))
def test_create(self): """test the objects create method""" self.assertIsNotNone(SecureString.create(unencrypted=MY_STRING, name=NAME)) with self.assertRaises(Exception): SecureString.objects.create(name=NAME) with self.assertRaises(TypeError): SecureString.objects.create(password=MY_STRING, name=NAME)
def test_created(self): SecureString.create(MY_STRING, NAME).save() self.assertIsNotNone(SecureString.objects.get(name=NAME).created)
def test_decrypt(self): """tests the get method""" SecureString.create(MY_STRING, NAME).save() sp = SecureString.objects.get(name=NAME) self.assertEqual(sp.decrypted, MY_STRING)
def test_get(self): """tests the get method""" SecureString.create(MY_STRING, NAME).save() self.assertIsNotNone(SecureString.objects.get(name=NAME))