Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ bool permitted(const LabDevicePolicy& policy, const LabDeviceIdentity& device){
return false;
}

// Capture IDs are allowlisted as hex; show the readable ID beside it so a
// refusal names the device the settings selected.
std::string readable_capture_id(const std::string& hex){
const bool is_hex = hex.size() % 2 == 0 && std::ranges::all_of(hex, [](char c){
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
});
if (!is_hex){
return hex;
}
const QByteArray bytes = QByteArray::fromHex(QByteArray(hex.data(), (qsizetype)hex.size()));
return bytes.toStdString() + " (allowlist ID " + hex + ")";
}

std::string describe(const LabDeviceIdentity& device){
switch (device.kind){
case LabDeviceKind::SERIAL: return "Serial device " + device.id;
case LabDeviceKind::VIDEO: return "Video input " + readable_capture_id(device.id);
case LabDeviceKind::AUDIO: return "Audio input " + readable_capture_id(device.id);
case LabDeviceKind::PROFILE: return "Profile " + device.id;
}
return device.id;
}

std::string normalize_serial_path(std::string_view path){
if (path.starts_with("/dev/tty.")){
return "/dev/cu." + std::string(path.substr(9));
Expand Down Expand Up @@ -119,7 +142,7 @@ std::unique_ptr<LabDeviceLease> acquire_lab_device(
const LabDevicePolicy& policy, std::string_view directory, const LabDeviceIdentity& device
){
if (!permitted(policy, device)){
throw std::runtime_error("Device is not allowlisted for profile " + policy.profile + ". Nothing was opened.");
throw std::runtime_error(describe(device) + " is not allowlisted for profile " + policy.profile + ". Nothing was opened.");
}
if (!QDir().mkpath(text(directory))){
throw std::runtime_error("Cannot create shared device lease directory. Nothing was opened.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct PolicyInput{

struct PolicyExpectation{
int opens = 0;
std::string_view refusal = {}; // The refusal message starts with this.
};

struct PolicyCase{
Expand Down Expand Up @@ -75,9 +76,11 @@ std::string check_serial(const SerialCase& test){

const PolicyCase POLICY_CASES[] = {
{.input = {.name = "matching serial", .json = R"({"schema":1,"profile":"lab-B","serial":["10c4:ea60:B"],"video":[],"audio":[]})", .requested = {LabDeviceKind::SERIAL, "10c4:ea60:B"}}, .expectation = {.opens = 1}},
{.input = {.name = "wrong console serial", .json = R"({"schema":1,"profile":"lab-B","serial":["10c4:ea60:B"],"video":[],"audio":[]})", .requested = {LabDeviceKind::SERIAL, "10c4:ea60:A"}}, .expectation = {}},
{.input = {.name = "wrong console serial", .json = R"({"schema":1,"profile":"lab-B","serial":["10c4:ea60:B"],"video":[],"audio":[]})", .requested = {LabDeviceKind::SERIAL, "10c4:ea60:A"}}, .expectation = {.refusal = "Serial device 10c4:ea60:A is not allowlisted for profile lab-B."}},
{.input = {.name = "camera allowed", .json = R"({"schema":1,"profile":"lab-B","serial":[],"video":["766964656f42"],"audio":[]})", .requested = {LabDeviceKind::VIDEO, "766964656f42"}}, .expectation = {.opens = 1}},
{.input = {.name = "audio allowed", .json = R"({"schema":1,"profile":"lab-B","serial":[],"video":[],"audio":["617564696f42"]})", .requested = {LabDeviceKind::AUDIO, "617564696f42"}}, .expectation = {.opens = 1}},
// lab-B, 2026-11-08: a panel selected console A's audio input, and the refusal didn't say which device it was.
{.input = {.name = "wrong console audio", .json = R"({"schema":1,"profile":"lab-B","serial":[],"video":[],"audio":["617564696f42"]})", .requested = {LabDeviceKind::AUDIO, "617564696f41"}}, .expectation = {.refusal = "Audio input audioA (allowlist ID 617564696f41) is not allowlisted for profile lab-B."}},
{.input = {.name = "camera not audio", .json = R"({"schema":1,"profile":"lab-B","serial":[],"video":["same-id"],"audio":[]})", .requested = {LabDeviceKind::AUDIO, "same-id"}}, .expectation = {}},
{.input = {.name = "mismatched profile", .json = R"({"schema":1,"profile":"lab-A","serial":["port"],"video":[],"audio":[]})", .requested = {LabDeviceKind::SERIAL, "port"}}, .expectation = {}},
{.input = {.name = "missing policy", .json = "", .requested = {LabDeviceKind::SERIAL, "port"}}, .expectation = {}},
Expand All @@ -95,14 +98,20 @@ std::string check_policy(const PolicyCase& test){
return "Cannot create temporary lease directory.";
}
int opens = 0;
std::string refusal;
try{
const auto policy = parse_lab_device_policy(test.input.json, "lab-B");
auto lease = acquire_lab_device(policy, directory.path().toStdString(), test.input.requested);
opens++; // Scripted native open: no real port, camera or microphone exists.
}catch (const std::runtime_error&){}
}catch (const std::runtime_error& error){
refusal = error.what();
}
if (opens != test.expectation.opens){
return "Expected opens " + std::to_string(test.expectation.opens) + "; read " + std::to_string(opens);
}
if (!refusal.starts_with(test.expectation.refusal)){
return "Expected a refusal starting \"" + std::string(test.expectation.refusal) + "\"; read \"" + refusal + "\"";
}
return {};
}

Expand Down
7 changes: 7 additions & 0 deletions devtools/lab/DEVICE_OWNERSHIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ the corresponding original device ID; it does not use the hex string as a device
selector. Do not use capture descriptions, friendly names or list positions.
Audio output to speakers is outside this input-device policy.

A refusal names the kind and ID of the device the panel selected, e.g.
`Audio input AppleUSBAudioEngine:...:1112100:3 (allowlist ID 4170...) is not
allowlisted for profile lab-B`. That usually means the panel's settings pick the
other console's input, not that the allowlist is wrong: both capture cards are
listed as "USB Digital Audio", and only the ID tells them apart. Select the
other entry in that panel's audio dropdown.

This PR does not generate a policy from the currently selected panel: that could
approve the very wrong-console binding we are preventing. Identity collection
and confirming A/B assignments remain a deliberate setup step. Existing profiles,
Expand Down
Loading