From the course: Secure Coding in Java

Unlock the full course today

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

Solution: Refactor Java code susceptible to injection attacks

Solution: Refactor Java code susceptible to injection attacks - Java Tutorial

From the course: Secure Coding in Java

Start my 1-month free trial

Solution: Refactor Java code susceptible to injection attacks

(upbeat music) - [Tutor] Now it's time to show you my solution. But before we get there, I want to chat a little bit about the testing strategies that I used, because I think it's a very good one. Now, first and foremost, I'm a big fan of writing tests. I especially like to spend time on negative and boundary conditions. I guess a lot of this comes from my entry into this industry as a software tester. Now I'm going to assume that you're using TDD or some similar process. And if so, the first thing you're going to do is write your happy path test. Now you should write a test that implements an injection attack, and you saw that in my example. You should do this for every single data access method that accepts input. And if you have multiple inputs, you should write a test that injects into each one of those. There's a valid reason for doing this. It lets you test each of those conditions separately, and now you're going…

Contents