From the course: Securing Django Applications

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unit testing per-field encryption

Unit testing per-field encryption - Django Tutorial

From the course: Securing Django Applications

Start my 1-month free trial

Unit testing per-field encryption

- [Tutor] We're going to test the per field encryption by storing the secret code ABC123. So our secret code goes here, and a payment is made by the user, and the password confirmation code is our secret code right here. We are going to make sure that the payment passport confirmation is equal to the secret code, and this field is in memory, so it's unencrypted, and then we're going to be using the database connection cursor, so that we can make a direct SQL query from the model and select that field and make sure it is encrypted. And then we get the result of this query using fetch one. We can print the encrypted string, and then we can make sure that it's not equal to our secret code, because it is encrypted, and we also in to test the deserialization, and for that we get the object from the database through Djangos ORM. Again comparing it. That way, and now we can run the tests, so we open up the…

Contents