OpenCyber Academy
Rapid course · Lesson 6 · English
Course code: OCA-019Lesson 06: OCA-019-A006

Exclusion is the first branch

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Lesson map

Lesson 06. Map, example, EX052.

flowchart TD
  A["ip_address of this string"] --> B{"In the excluded set?"}
  B -->|Yes| E["EXCLUDED - do not test"]
  B -->|No| C{"Inside 192.0.2.0/25?"}
  C -->|Yes| I["in scope"]
  C -->|No| O["OUT OF SCOPE - do not test"]

The set test runs before the network test. .10 never reaches the second test.

Logical drawing

192.0.2.10 is inside the /25
and inside the excluded set
first true branch
  EXCLUDED - do not test
the elif is not evaluated

Learning outcomes

After this chapter, you should be able to:

  1. Say which test runs first.
  2. Explain why membership in the /25 does not save .10.
  3. Refuse a reading that calls the exclusion a script bug.

6.1 if then elif. The first true branch wins.

The excluded object is a set with one member, 192.0.2.10. The allowed object is a list with one network, 192.0.2.0/25. For each string, ip_address builds an address, then the if asks whether that address is in the set. Only if that test is false does the elif ask whether the address sits in any network in the list.

192.0.2.10 makes the set test true. Python skips the elif. The network object still contains that address; the branch structure is what keeps the verdict at EXCLUDED - do not test. Reversing the two tests would be a different program. This file does not reverse them.

Lesson table; scroll horizontally to read all columns →

Address In the set? In the /25? Branch that runs
192.0.2.5 No Yes elif → in scope
192.0.2.10 Yes Yes, unused if → EXCLUDED
192.0.2.130 No No else
198.51.100.7 No No else

6.2 Worked example

Lesson table; scroll horizontally to read all columns →

Offered claim What the branch does Decision
"Payroll is excluded because the owner said so, and the if encodes that." Set test first Keep
".10 is in the range, so the range line should win." The elif does not run Refuse
"The set removes .10 from the network object." The network is unchanged Refuse

Synthetic case. The payroll server is a label in a comment. The set holds the address.

Errors and limits

Do not treat "inside the range" as permission when the set test is true.

Apply

  • EX052 — First branch. 192.0.2.10 is inside 192.0.2.0/25 and inside the excluded set. Which test decides the printed verdict, and does the other test still get evaluated?
    Show marking criteria
    Rubric: 3 = the set test is first and true; the elif is skipped; the verdict is EXCLUDED - do not test;; 2 = exclusion wins and the range does not override it;; 1 = one fact;; 0 = none.
Worked answers

EX052. The set test is first and true, so the elif does not run. The verdict is EXCLUDED - do not test. The network object still contains the address.