Skip to topic
    ← Back to course topics

    Robust and secure programming — AQA GCSE Computer Science

    Robust and secure programming involves designing software that handles unexpected user inputs and runtime conditions without crashing, alongside protecting code against vulnerabilities. In AQA GCSE Computer Science, this centres on defensive design techniques including input validation, sanitisation, authentication, maintainability, and structured testing.

    Robust and secure programming explained

    To select suitable test data, first identify the input requirements and any validation rules from the problem.

    Read the full explanation

    Then choose data that covers three categories: normal data (valid, expected values), boundary data (values at the edges of valid ranges, such as the minimum, maximum, and just inside/outside limits), and erroneous data (invalid values that should be rejected). For example, if a program accepts an integer between 1 and 100, normal data could be 50, boundary data could be 1, 100, 0, and 101, and erroneous data could be 'abc' or -5. Justify each choice by explaining what it tests: normal data checks typical processing, boundary data checks the limits of validation, and erroneous data checks error handling. The justification should link the data to the specific rule or requirement it verifies, demonstrating understanding of robust programming.

    Your focus

    1. Identify the input requirements and validation rules for a given problem.
    2. Select appropriate normal, boundary, and erroneous test data.
    3. Justify the choice of each test data item by linking it to the problem's requirements.

    Robust and secure programming exam tips

    Topic Overview

    Robust and secure programming focuses on designing software that anticipates misuse, mitigates runtime faults, and guards against malicious attacks. Students learn how defensive design practices ensure programs fail gracefully or reject improper data rather than crashing.

    This topic connects algorithmic problem-solving to real-world software engineering across AQA Paper 1. Understanding validation, sanitisation, authentication, maintainability, and rigorous testing equips students with the foundational skills needed to build dependable software architectures.

    Key Concepts
    • →Defensive design: Anticipating every route of user error, accidental misuse, and malicious exploit before writing functional logic.
    • →Validation vs Sanitisation: Validation checks data against rules (e.g., presence, length, range, format, type); sanitisation cleans or strips unwanted characters before processing.
    • →Authentication: Verifying the identity of a user before granting access to resources (e.g., passwords, biometric checks, multi-factor authentication).
    • →Code maintainability: Techniques that make code readable and modifiable, such as meaningful variable names, code comments, modular subroutines, and consistent indentation.
    • →Test strategies: Differentiating between iterative testing (conducted during development) and final/terminal testing (conducted at the end of development against original requirements).
    Marking Points
    • Select normal data that is valid and within the expected range to test typical processing.
    • Select boundary data at the lower and upper limits of valid input, and just outside those limits, to test validation edges.
    • Select erroneous data that is invalid, such as wrong data type or out-of-range values, to test error handling.
    • Justify each test data choice by explaining which requirement or validation rule it checks.
    • Ensure the test data covers all relevant input conditions for the given problem.
    • Use the problem's specification to determine appropriate values, rather than choosing arbitrary data.
    Examiner Tips
    • 💡Read the problem carefully to identify all input constraints, such as ranges, data types, and required formats.
    • 💡Use a table to organise test data with columns for data, type (normal/boundary/erroneous), and justification.
    • 💡For boundary data, include values just inside and just outside the valid range, as these are most likely to reveal off-by-one errors.
    • 💡When justifying, state what the program should do with that data, e.g., accept it, reject it, or produce a specific output.
    • 💡When naming validation checks, use the exact standard curriculum terms: range check, length check, type check, format check, presence check, or lookup check.
    • 💡In test table questions, always provide an expected result alongside your sample input (e.g., Input: 12, Expected: Error message displayed).
    • 💡When explaining maintainability, state both the method (e.g., modularisation) and the direct human impact (e.g., makes debugging faster because code blocks can be tested independently).
    Common Mistakes
    • Selecting only normal data and ignoring boundary and erroneous cases, which leaves validation untested.
    • Choosing boundary data that is not actually at the limit, such as using 10 when the range is 1-100.
    • Failing to justify the choice, or giving a justification that does not link the data to a specific rule or expected outcome.
    • Believing authentication and validation are the same: Validation confirms data conforms to structural rules; authentication verifies that a user actually is who they claim to be.
    • Assuming boundary data means extreme values: Students often provide massive values like 999999 instead of values sitting directly on the valid/invalid boundary edges (e.g., 0 and 1 for min limit 1).
    • Thinking comments and indentation affect machine execution speed: Comments and whitespace are stripped during compilation or interpretation and have no bearing on machine run-time efficiency, but are vital for human maintainability.
    Revision Plan
    1. 1Day 1-2: Master defensive design theory; create flashcards defining the six validation check types and input sanitisation.
    2. 2Day 3-4: Practice writing Python or pseudocode scripts implementing `try...except` exception handling and validation loops.
    3. 3Day 5: Revise test plans by drawing test tables and populating them with normal, boundary, and erroneous data for past paper prompts.
    4. 4Day 6-7: Complete timed AQA Paper 1 past paper questions focused on code maintainability and defensive programming.
    Exam Question Types
    • 📋Test Data Tables: Completing a 4-column table (Test Type, Test Data, Purpose, Expected Result) for a given algorithm snippet.
    • 📋Code Correction/Refactoring: Identifying why an unvalidated script would crash and rewriting it to handle bad input robustly.
    • 📋Maintainability Evaluations: Explaining two or three ways a poorly written script can be made easier for a team of developers to maintain.
    Command Word Expectations (AQA)
    Explain

    Set out the causes, reasons, or mechanisms clearly. Mention the technique and link it directly to why it prevents failure or aids developers (e.g., 'Technique X does Y, which means Z happens').

    State / Give

    Provide a factual name or brief term without detailed narrative. For example, naming 'Range check' or providing a valid test value like '18'.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing input validation with input sanitisation.
    ❌ Weak Answer (Loses Marks):Input validation is when the computer removes spaces or dangerous characters from what the user typed in.
    Example improved answer:Input validation checks whether user input meets predefined criteria (such as range, length, type, format, or presence) before processing it, rejecting invalid data. In contrast, input sanitisation modifies the input by removing unwanted or potentially harmful characters, such as SQL injection tags or leading/trailing whitespace, without necessarily rejecting the entry.
    Examiner Tip: Always specify the mechanism: validation checks and accepts or rejects, whereas sanitisation actively strips or cleans data before execution.
    Pitfall: Describing boundary test data as simply extreme numbers.
    ❌ Weak Answer (Loses Marks):Boundary data is using really big numbers or negative numbers to push the program to its limits.
    Example improved answer:Boundary data tests values at the exact limits of allowable input ranges, specifically testing the edges where valid data transitions to invalid data. For example, for an acceptable range of 1 to 10 inclusive, boundary test data includes 0 and 1, as well as 10 and 11.
    Examiner Tip: When asked for boundary test data in AQA exams, provide paired values spanning the exact threshold: one value directly on the boundary edge and one value just outside it.
    Step-by-Step Worked Solutions

    Question: A program asks a user to enter their age to join an online gaming club. The age must be an integer between 13 and 18 inclusive. State two validation checks that should be applied to this input, and provide an example of normal, boundary, and erroneous test data for this system.

    1. 1.Step 1: Identify required validation checks suitable for the input criteria. The input must be a whole number, so a type check is required. The value must fall between 13 and 18, so a range check is required.
    2. 2.Step 2: Define normal test data. Normal data is valid data within the allowed range that tests standard execution. Suitable example: 15.
    3. 3.Step 3: Define boundary test data. Boundary data sits at the extreme ends of the accepted limits. Suitable examples: 13 (lower boundary) or 18 (upper boundary).
    4. 4.Step 4: Define erroneous (invalid) test data. Erroneous data violates the validation rules and should be rejected. Suitable examples: 12 (below range), 19 (above range), or 'fourteen' (incorrect data type).
    Final Answer: Validation checks: Type check (must be an integer) and Range check (must be between 13 and 18 inclusive). Normal data: 15; Boundary data: 13 (or 18); Erroneous data: 12 (or 'fifteen').

    Question: Explain two programming practices that improve the maintainability of source code for future developers.

    1. 1.Step 1: Identify the first programming practice that aids human readability and comprehension. Meaningful identifier names for variables, constants, and subroutines.
    2. 2.Step 2: Explain the direct benefit of meaningful identifiers. Using descriptive names like 'totalScore' instead of 'x' allows future programmers to understand the purpose of each variable without reverse-engineering the code.
    3. 3.Step 3: Identify the second programming practice. Modularisation through subroutines (functions and procedures) or indentation/comments.
    4. 4.Step 4: Explain the benefit of subroutines/comments. Comments explain complex logic, while subroutines break code into self-contained blocks, making individual components easier to test, update, and reuse without unintended side effects.
    Final Answer: 1. Meaningful identifiers: Descriptive variable names (e.g., 'studentAge' rather than 's') clarify variable intent and reduce maintenance errors. 2. Subroutines and comments: Breaking code into modular subroutines and adding comments documents the logic, allowing developers to isolate and update specific features quickly.
    Active Recall Memory Test
    What are the five main types of validation checks examined in GCSE Computer Science?
    Key Fact: Range check, length check, type check, presence check, and format check (lookup check is also accepted).
    What is the primary difference between iterative testing and final/terminal testing?
    Key Fact: Iterative testing occurs continuously during module development; final testing occurs once development is complete to test the whole integrated system against user requirements.
    Name three defensive design practices that ensure source code maintainability.
    Key Fact: Using meaningful variable names, incorporating clear comments, and using modular subroutines (functions/procedures).
    How does input sanitisation prevent SQL injection attacks?
    Key Fact: It strips out or escapes malicious control characters (such as apostrophes or SQL commands like DROP TABLE) from raw user input before database execution.
    Frequently Asked Questions
    What is the difference between input validation and input sanitisation?
    Input validation inspects data against a set of predefined criteria and rejects the input if it fails those rules, often triggering an error message. Input sanitisation actively cleans or alters the input before the program uses it, such as removing special SQL command characters or trimming unnecessary spaces. Validation checks correctness; sanitisation cleans up unsafe content.
    Why do programmers need to use boundary test data?
    Boundary test data targets the exact limits where acceptable input switches to unacceptable input. Programmers frequently make off-by-one errors in conditional logic (such as using '<' instead of '<='). Testing both sides of the boundary edge confirms that the program's relational operators are strictly correct.
    What does defensive design mean in AQA GCSE Computer Science?
    Defensive design is an approach to software engineering where developers write code anticipating that errors, incorrect inputs, and malicious actions will occur. It incorporates input validation, input sanitisation, exception handling, and access authentication so that the program fails gracefully without crashing or creating security vulnerabilities.
    What is the difference between syntax errors and logic errors?
    A syntax error is a grammatical violation of the programming language rules (such as a missing bracket, typo in a keyword, or incorrect indentation), which stops the code from compiling or executing. A logic error occurs when the code runs without crashing, but produces incorrect, unintended, or unexpected output due to a flaw in the underlying algorithm.