Skip to main content

Crate fritz_sim

Crate fritz_sim 

Source
Expand description

Stateful fake TR-064 server, built from recorded fixtures. Used by tests only: every write test runs against it, never against a real device.

Sim::start serves a Fixture on the loopback interface: the device description and the service descriptions without authentication, and the action calls with HTTP Digest authentication.

  • Calls are checked against the service description: an unknown action fails with UPnP error 401, missing or unknown arguments with 402, and values that don’t fit the data type or the allowed values with 600. Like the devices, it doesn’t check the allowed range.
  • Getters answer as recorded. Getters with an index answer the recorded entry, or 713 if there is none.
  • Every argument refers to a state variable. Calls of other actions, like SetEnable, write their input arguments into these variables, and the getters that read the same variables answer with the new values. Nothing else changes: the simulator does not know which settings a device changes along with them, like the options of a feature it turns off. Tests inject such side effects themselves.
  • Paths to list documents, like the one X_AVM-DE_GetHostListPath returns, hold a session ID, and the documents are served for it.
  • The web interface has a session login, /login_sid.lua, with a PBKDF2 challenge, and serves the documents of the REST API, like /api/v0/smarthome/overview, the pages of /data.lua, like ecoStat, and the statistics of Smart Home devices of /webservices/homeautoswitch.lua, for the open session. Like the device, the page log remembers the category of its last field filter and lists only its entries, see Sim::log_filter.
  • Tests can inject UPnP errors, delays, discarded writes, side effects of writes, counters that grow, a locked login, calls that break off, restarts and pages that fail, and read the requests the server got.
  • CallMonitor replays scripted lines of the call monitor, drops the connection between sessions and sends lines that are not valid.
use fritz_sim::{Fixture, Injection, Sim};

let sim = Sim::start(Fixture::bundled("fritzbox-7690/8.25")?).await?;
let client = sim.client().build()?;
let description = client.description().await?;
let wlan = description.service("WLANConfiguration1")?;
client.call(wlan, "SetEnable", &[("NewEnable", "0")]).await?;
assert_eq!(sim.state("WLANConfiguration1", "Enable").as_deref(), Some("0"));

sim.inject(Injection::fault("WLANConfiguration1", "SetEnable", 866));
assert!(client.call(wlan, "SetEnable", &[("NewEnable", "1")]).await.is_err());

Modules§

dns
A small DNS server on the loopback interface, for tests of DNS clients: it answers A and AAAA queries from a table of names and addresses, and every other name with NXDOMAIN.

Structs§

CallMonitor
A running call monitor. It stops when dropped.
Fixture
A device as recorded in a fixture directory:
Options
How the simulator listens and whom it lets in.
Request
A request the simulator got.
Sim
A running simulator. It stops when dropped.

Enums§

Answer
A recorded answer to an action call.
Error
Why a fixture cannot be loaded.
Injection
A change to how the simulator behaves, until cleared.

Constants§

PASSWORD
The password the simulator accepts by default.
USERNAME
The user name the simulator accepts by default.