Home / Learn / 17 Information flow
17.7 Testing it
Page 8 of 11
17.7.1 Examples of the policy
The examples are those of section 12.6, with one change: the first one expects the masked address, r***@example.invalid, which is what notify now returns. Two more examples, at the end of the file, test the policy itself:
example "the log shows the first letter and the domain of an address"
do masked_email("tomas@example.invalid")
expect result == "t***@example.invalid"
example "an address the mask cannot read is hidden"
do masked_email("no address")
expect result == "(hidden)"A policy can be called like a function, so its examples need no fakes. Test the release the way a reviewer would read it: what an ordinary value becomes, and what an unexpected one becomes. A mask that showed a whole malformed address would pass the type checker, since labels are not checked inside via, so this example is the check that it does not.
17.7.2 Examples can observe a secret
An expect line compares a value whatever its label, and a do line is checked like ordinary code: an example can observe a secret, but cannot send it anywhere the program itself could not (Examples are not sinks). So chapter 12's example of notice still passes: its result is now a secret[PII] Text, and its expect line compares it with the text of the notice.
17.7.3 The failure paths and their fakes
The examples of the failure paths are chapter 12's, with its fakes: directory_down for the directory that does not answer, and mail_down. The examples of UnknownCustomer, OptedOut and DirectoryDown install mail_down on purpose, as A failure that comes first explains: had notify sent any mail before it failed, the example would see MailDown. Labels do not alter which paths exist or how a fake reaches them. (Chapter 14 gives a more direct way to say that no mail went out, expect not performed; this chapter keeps chapter 12's examples, so that only the labels change.) The fakes outbox and mail_down are handlers of Mailer, which now accepts secret[PII]. They pass the check because they do nothing with what they receive. A fake mail service that printed each message, as printed in chapter 12 did, would be U4003: what it prints could reveal the notice (A handler is checked for its most sensitive caller).
17.7.4 Running the examples
una test . prints:
example notices "a customer who wants notices gets one" ... ok
example notices "an unknown customer is rejected before any mail is sent" ... ok
example notices "a customer who asked for no notices is rejected before any mail is sent" ... ok
example notices "a directory that does not answer is DirectoryDown, before any mail is sent" ... ok
example notices "a mail service that does not answer is MailDown" ... ok
example notices "the notice names the customer, the order and the carrier" ... ok
example notices "a skipped shipment says why in the log" ... ok
example notices "the log shows the first letter and the domain of an address" ... ok
example notices "an address the mask cannot read is hidden" ... ok
9 examples: 9 passed, 0 failedNext:17.8 Common mistakes