Why security testing protects users in Testing Fundamentals - Automation Benefits in Action
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class TestSQLInjection(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') self.wait = WebDriverWait(self.driver, 10) def test_sql_injection_login(self): driver = self.driver wait = self.wait username_input = wait.until(EC.visibility_of_element_located((By.ID, 'username'))) password_input = driver.find_element(By.ID, 'password') login_button = driver.find_element(By.ID, 'loginBtn') username_input.clear() username_input.send_keys("admin' OR '1'='1") password_input.clear() password_input.send_keys('anyPassword') login_button.click() # Wait for error message to appear error_message = wait.until(EC.visibility_of_element_located((By.ID, 'errorMsg'))) # Assert error message is shown self.assertIn('Invalid username or password', error_message.text) # Assert URL did not change to dashboard self.assertNotIn('/dashboard', driver.current_url) # Assert no database error text is visible page_source = driver.page_source.lower() self.assertNotIn('sql syntax', page_source) self.assertNotIn('database error', page_source) def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
This test script uses Selenium with Python's unittest framework to automate the manual test case.
In setUp, it opens the browser and navigates to the login page.
The test test_sql_injection_login enters a common SQL injection string in the username field and any password, then clicks login.
It waits explicitly for the error message element to appear, then asserts the error message text is correct, ensuring the login was rejected.
It also checks the URL to confirm the user was not redirected to a logged-in page.
Finally, it checks the page source to ensure no database error messages are shown, which would be a security risk.
The tearDown method closes the browser after the test.
This structure follows best practices: explicit waits, clear locators by ID, and meaningful assertions.
Now add data-driven testing with 3 different SQL injection inputs to verify the login form rejects all.
Practice
Solution
Step 1: Understand the purpose of security testing
Security testing checks for weaknesses that attackers could use to steal or damage user data.Step 2: Identify the main benefit for users
Protecting user data from hackers keeps users safe and their information private.Final Answer:
It helps protect user data from hackers. -> Option BQuick Check:
Security testing protects data = A [OK]
- Confusing security testing with performance testing
- Thinking security testing adds features
- Believing it changes software design
Solution
Step 1: Define security testing
Security testing focuses on finding weak points or vulnerabilities in software that attackers might use.Step 2: Match the correct description
Only Testing software to find vulnerabilities attackers can exploit. correctly describes this focus on vulnerabilities and attacker risks.Final Answer:
Testing software to find vulnerabilities attackers can exploit. -> Option AQuick Check:
Security testing = find vulnerabilities [OK]
- Mixing security testing with performance or UI testing
- Thinking it improves documentation
- Confusing bugs with vulnerabilities
def check_password_strength(password):
if len(password) < 8:
return False
if not any(c.isdigit() for c in password):
return False
if not any(c.isalpha() for c in password):
return False
return True
print(check_password_strength('abc123'))
print(check_password_strength('abc12345'))What will be the output?
Solution
Step 1: Analyze first password 'abc123'
Length is 6, which is less than 8, so returns False immediately.Step 2: Analyze second password 'abc12345'
Length is 8, contains digits and letters, so returns True.Final Answer:
False\nTrue -> Option DQuick Check:
Short password False, valid password True [OK]
- Ignoring length check
- Assuming all passwords pass
- Confusing digit and letter checks
def is_input_safe(user_input):
if "'" in user_input or "--" in user_input:
return False
return True
print(is_input_safe("hello"))
print(is_input_safe("hello' OR 1=1 --"))What is the problem with this test?
Solution
Step 1: Understand the test logic
The function checks only for single quote and double dash but SQL injection can use other patterns too.Step 2: Identify limitation
Because it only checks two patterns, it may miss other injection attempts, so test is incomplete.Final Answer:
It does not check for all SQL injection patterns. -> Option CQuick Check:
Partial pattern check = incomplete test [OK]
- Thinking syntax is wrong
- Assuming it always returns True
- Believing it crashes on input
Solution
Step 1: Identify best security testing practice
Regular scanning finds new vulnerabilities as threats evolve, protecting user data continuously.Step 2: Evaluate other options
Adding animations, testing once, or ignoring security do not protect users effectively.Final Answer:
Regularly scan for vulnerabilities and fix data leaks promptly. -> Option AQuick Check:
Continuous testing protects users best [OK]
- Thinking security is a one-time task
- Confusing UI features with security
- Ignoring risks until attack happens
Ready to prove it?
Pass the test and this pattern moves unknown
