Unit Test Goals
What is the main goal of writing unit tests for user input validation?
- To ensure the input behaves as expected and blocks malicious data
- To increase the number of commits in the repository
- To randomly test some of the code for fun
- To make the UI look more attractive
- To reduce code performance
SQL Injection Prevention
Which unit test case best helps prevent SQL injection vulnerabilities?
- Testing the input with typical SQL code such as: ' OR '1'='1
- Testing input with a valid email address
- Testing input with only letters
- Testing input with random numbers
- Testing input using double quotes only
XSS Defense Scenario
Suppose you are testing a function that renders user comments. What input is important to include in your unit test to check for Cross-Site Scripting (XSS) vulnerabilities?
- u003Cscriptu003Ealert('XSS')u003C/scriptu003E
- helloWorld123
- u003Cscrptu003Ealert('XSS')u003C/scrptu003E
- select * from users;
- u003Cdivu003Ecommentu003C/divu003E
Validating Input Length
Why should you test that a username input does not exceed a specified maximum length?
- To prevent buffer overflow and related security issues
- To prevent typos in usernames
- To ensure better graphics rendering
- To increase database size limits
- To allow users unlimited creativity
Typos in Test Inputs
Why is it helpful to include common typos in your input unit tests?
- To ensure the validation handles real-world mistakes
- To check for better database connections
- To speed up frontend performance
- To confuse automated test runners
- To allow for extra punctuation marks
Parameterized Queries
Which test scenario best validates the use of parameterized queries?
- Sending user input containing SQL keywords and ensuring the query doesn't break
- Testing input that is always empty
- Testing input with large images
- Providing input with extra spaces only
- Changing the parameter names in the backend only
Valid and Invalid Email Inputs
A unit test for an email field should check which of the following scenarios?
- Valid email, invalid email, SQL payload, XSS payload, and empty string
- Only valid emails
- Only invalid emails
- Only uppercase email addresses
- Only emails ending with .com
Mitigating Script Injection
You are testing a web application for script injection flaws. Which user input should you unit test for?
- Input that includes u003Cscriptu003E tags
- Input that includes only blanks
- Input that includes special characters like ! and @
- Input using emojis
- Input written in all caps
Acceptable Username Example
Which value is most likely to be considered a safe, valid username in a typical unit test?
- john_doe99
- drop table users;
- u003Ch1u003Eadminu003C/h1u003E
- admin’ OR ‘1’=‘1
- jo hn doe
Testing Required Input
Why should unit tests specifically check for missing required fields in user input?
- To ensure the application doesn't accept incomplete data and handles errors gracefully
- To allow valid users to skip required fields
- To let invalid data into the database
- To crash the testing framework
- To hide errors from developers