dns-mock-server

Latest version: 0.1.6 registry icon
Maintenance score
40
Safety score
100
Popularity score
70
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.1.6 0 0 0 0 0
0.1.5 0 0 0 0 0
0.1.4 0 0 0 0 0
0.1.3 0 0 0 0 0
0.1.2 0 0 0 0 0
0.1.1 0 0 0 0 0
0.1.0 0 0 0 0 0

Stability
Latest release:

0.1.6 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

Apache-2.0   -   Apache License 2.0

Not a wildcard

Not proprietary

OSI Compliant


MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



dns-mock-server

Implementation of a DNS mock server for use in tests, based on hickory-server.

Usage

The following example shows the basic usage for the library, where we create a new server, add some records and then spawn it on a background task.

use std::net::{IpAddr, Ipv4Addr, SocketAddrV4};

use dns_mock_server::Server;
use tokio::net::UdpSocket;

type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[tokio::test]
async fn check_something() -> Result<()> {
    let mut server = Server::default();

    let records = vec![IpAddr::V4(Ipv4Addr::LOCALHOST)];
    server.add_records("example.com", records)?

    let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0);
    let socket = UdpSocket::bind(&addr).await?;
    let local_addr = socket.local_addr()?;

    tokio::spawn(async move {
        server.start(socket).await.unwrap();
    });

    // Point your DNS handling at `local_addr` and make requests

    Ok(())
}