Software Development

“Forget me” and Tests

Your users have profiles on your web application. And normally you should give them a way to delete their profiles (at least that’s what the European Court has decided).

That “simply” means you need to have a /forget-me endpoint which deletes every piece of data for the current user. From the database, from the file storage, from the search engine, etc. Apart from giving your users at least partial control over their own data (whether you can have it or not is their decision), it is also a benefit for developers.

Apart from your isolated unit tests, containing a lot of mocks, you have other sorts of tests – integration test, acceptance tests, Selenim tests. All of these need a way to leave the database in the same state that it was before they were executed. In some cases you can use read-only transactions (e.g. with spring-test you get that automatically), or you can use an in-memory database and hope it will work the same way as your production one, or you can drop the database and recreate it on each run. But these are partial solutions with some additional complexity.

The best way, I think, is to just reuse the “forget me” functionality. From your acceptance/selenium tests you can call the /forget-me endpoint at the end of the test (tearDown), and for your integration tests y. If you distribute client-side APIs (or a third-party is building them against a test deployments of your system), you can again call the forget-me endpoint.

That, of course, doesn’t cover non-user-related data that you need in the database. If you have such data (apart from enumarations and data that should be always there), you have to take care of it separately.

Doesn’t that bring some additional complexity as well, and the constant need to update your forget-me functionality? Isn’t having read-only transactions, or a shell script that recreates the database after each run, simpler to support? Assuming that you need to have a properly working forget-me functionality anyway – no. It’s better to reuse it. That would also make sure the endpoint is indeed working properly, and your users can be fully forgotten.

Reference: “Forget me” and Tests from our JCG partner Bozhidar Bozhanov at the Bozho’s tech blog blog.

Bozhidar Bozhanov

Senior Java developer, one of the top stackoverflow users, fluent with Java and Java technology stacks - Spring, JPA, JavaEE, as well as Android, Scala and any framework you throw at him. creator of Computoser - an algorithmic music composer. Worked on telecom projects, e-government and large-scale online recruitment and navigation platforms.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button