Test cleanup

This commit is contained in:
femsci 2023-10-19 18:25:22 +02:00
parent 359c370b49
commit 6c5e9b8716
Signed by: femsci
GPG key ID: 08F7911F0E650C67
3 changed files with 20 additions and 19 deletions

View file

@ -8,8 +8,7 @@ public class Host : IBindable
{
[Key]
public required string Id { get; set; }
[MaxLength(16)]
public byte[] Duid { get; set; } = default!;
public Int128 Duid { get; set; }
public HostType HostType { get; set; }
public required IPAddressCollection Addresses { get; set; }
public required MacAddress Mac { get; set; }

View file

@ -2,11 +2,20 @@ using System.ComponentModel.DataAnnotations;
namespace IPMeow.Lib.Host;
public enum HostInterfaceType
{
Ethernet,
Infiniband,
Wireless,
Virtual
}
public class HostInterface
{
[Key]
public required string Id { get; set; }
public byte[] IAID { get; set; } = default!;
public HostInterfaceType InterfaceType { get; set; }
public DateTime LastPinged { get; set; }
public DateTime LastAssignment { get; set; }

View file

@ -13,6 +13,9 @@ public class DnsTest
[Fact]
public async Task TestDns()
{
using UdpClient udp = new UdpClient(AddressFamily.InterNetwork);
udp.Connect(IPAddress.Parse("1.1.1.1"), 53);
DnsMessage msg = new()
{
IsRecursionDesired = true,
@ -32,24 +35,14 @@ public class DnsTest
ResponseCode = 0,
};
await Send(msg);
Console.WriteLine("sendt");
msg.IsRecursionDesired = false;
msg.IsAuthoritative = false;
msg.MessageType = DnsMessageType.Reply;
msg.Opcode = DnsMessageOpcode.Status;
msg.ResponseCode = DnsResponseCode.NxDomain;
await Send(msg);
}
private async Task Send(DnsMessage msg)
{
var data = msg.Serialize();
using UdpClient udp = new UdpClient(AddressFamily.InterNetwork);
udp.Connect(IPAddress.Parse("1.1.1.1"), 53);
await udp.SendAsync(data);
var rec = await udp.ReceiveAsync();
var res = DnsMessage.Deserialize(rec.Buffer);
Assert.Equal(DnsMessageType.Reply, res.MessageType);
Assert.Equal(0xbabe, res.MessageId);
}
}