fix(iroh-dns-server): inverted validation logic in DoH JSON response handler (#3737)

## Description

Fix inverted validation logic in the DNS-over-HTTPS (DoH) JSON response
handler. Previously, JSON DoH queries (`accept: application/dns-json`)
failed with a 500 error:

```json
{"status": "500", "detail": "Expected message type to be response"}
```

## Changes made
Corrected three ensure_any! validation checks from != to ==: 

  message_type() == Response
  query_count() == queries().len()
  answer_count() == answers().len()

## Testing
Tested locally with iroh-dns-server v0.95.1:

  Before fix:
```sh
  curl --header "accept: application/dns-json" \
    "http://localhost:8080/dns-query?name=_iroh.<id>&type=TXT"
  # {"status":"500","detail":"Expected message type to be response"}
```

  After fix:
```sh
  {
    "Status": 0,
    "Answer": [{
      "name": "_iroh.nskwmm4rh...",
      "type": 16,
      "TTL": 30,
      "data": "relay=https://..."
    }]
  }
```

## Notes
Only affects JSON DoH responses.
The binary POST format worked fine in my tests

Co-authored-by: Franz Heinzmann <frando@unbiskant.org>
This commit is contained in:
Dorian González
2025-12-08 12:36:53 +00:00
committed by GitHub
co-authored by Franz Heinzmann
parent dd280b81ea
commit 2efbff6a21
+3 -3
View File
@@ -48,17 +48,17 @@ impl DnsResponse {
/// Create a new JSON response from a DNS message
pub fn from_message(message: proto::op::Message) -> Result<Self> {
ensure_any!(
message.message_type() != proto::op::MessageType::Response,
message.message_type() == proto::op::MessageType::Response,
"Expected message type to be response"
);
ensure_any!(
message.query_count() != message.queries().len() as u16,
message.query_count() == message.queries().len() as u16,
"Query count mismatch"
);
ensure_any!(
message.answer_count() != message.answers().len() as u16,
message.answer_count() == message.answers().len() as u16,
"Answer count mismatch"
);