2 import qualified Data.ByteString.Lazy as LBS
4 import Network.DNS.Message
5 import Network.Socket.IsString ()
9 messages :: [([Word8], Message)]
10 messages = [ ( [ 0x22, 0x79, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00
11 , 0x00, 0x00, 0x00, 0x00, 0x04, 0x6D, 0x61, 0x69
12 , 0x6C, 0x0A, 0x63, 0x69, 0x65, 0x6C, 0x6F, 0x6E
13 , 0x65, 0x67, 0x72, 0x6F, 0x03, 0x6F, 0x72, 0x67
14 , 0x00, 0x00, 0x05, 0x00, 0x01
19 , hdMessageType = Query
20 , hdOpcode = StandardQuery
21 , hdIsAuthoritativeAnswer = False
22 , hdIsTruncated = False
23 , hdIsRecursionDesired = True
24 , hdIsRecursionAvailable = False
25 , hdResponseCode = NoError
27 , msgQuestions = [ wrapQuestion $
29 qName = "mail.cielonegro.org."
39 , ( [ 0x22, 0x79, 0x85, 0x00, 0x00, 0x01, 0x00, 0x01
40 , 0x00, 0x01, 0x00, 0x01, 0x04, 0x6D, 0x61, 0x69
41 , 0x6C, 0x0A, 0x63, 0x69, 0x65, 0x6C, 0x6F, 0x6E
42 , 0x65, 0x67, 0x72, 0x6F, 0x03, 0x6F, 0x72, 0x67
43 , 0x00, 0x00, 0x05, 0x00, 0x01, 0xC0, 0x0C, 0x00
44 , 0x05, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00
45 , 0x06, 0x03, 0x6E, 0x65, 0x6D, 0xC0, 0x11, 0xC0
46 , 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0E
47 , 0x10, 0x00, 0x02, 0xC0, 0x31, 0xC0, 0x31, 0x00
48 , 0x01, 0x00, 0x01, 0x00, 0x00, 0x0E, 0x10, 0x00
49 , 0x04, 0xDB, 0x5E, 0x82, 0x8B
54 , hdMessageType = Response
55 , hdOpcode = StandardQuery
56 , hdIsAuthoritativeAnswer = True
57 , hdIsTruncated = False
58 , hdIsRecursionDesired = True
59 , hdIsRecursionAvailable = False
60 , hdResponseCode = NoError
62 , msgQuestions = [ wrapQuestion $
64 qName = "mail.cielonegro.org."
69 , msgAnswers = [ wrapRecord $
71 rrName = "mail.cielonegro.org."
75 , rrData = "nem.cielonegro.org."
78 , msgAuthorities = [ wrapRecord $
80 rrName = "cielonegro.org."
84 , rrData = "nem.cielonegro.org."
87 , msgAdditionals = [ wrapRecord $
89 rrName = "nem.cielonegro.org."
93 , rrData = "219.94.130.139"
98 , ( [ 0xED, 0x68, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00
99 , 0x00, 0x00, 0x00, 0x00, 0x0A, 0x63, 0x69, 0x65
100 , 0x6C, 0x6F, 0x6E, 0x65, 0x67, 0x72, 0x6F, 0x03
101 , 0x6F, 0x72, 0x67, 0x00, 0x00, 0x06, 0x00, 0x01
106 , hdMessageType = Query
107 , hdOpcode = StandardQuery
108 , hdIsAuthoritativeAnswer = False
109 , hdIsTruncated = False
110 , hdIsRecursionDesired = True
111 , hdIsRecursionAvailable = False
112 , hdResponseCode = NoError
114 , msgQuestions = [ wrapQuestion $
116 qName = "cielonegro.org."
122 , msgAuthorities = []
123 , msgAdditionals = []
126 , ( [ 0xED, 0x68, 0x85, 0x00, 0x00, 0x01, 0x00, 0x01
127 , 0x00, 0x01, 0x00, 0x01, 0x0A, 0x63, 0x69, 0x65
128 , 0x6C, 0x6F, 0x6E, 0x65, 0x67, 0x72, 0x6F, 0x03
129 , 0x6F, 0x72, 0x67, 0x00, 0x00, 0x06, 0x00, 0x01
130 , 0xC0, 0x0C, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00
131 , 0x0E, 0x10, 0x00, 0x21, 0x03, 0x6E, 0x65, 0x6D
132 , 0xC0, 0x0C, 0x04, 0x72, 0x6F, 0x6F, 0x74, 0xC0
133 , 0x2C, 0x77, 0xAF, 0xFC, 0x84, 0x00, 0x00, 0x0E
134 , 0x10, 0x00, 0x00, 0x03, 0x84, 0x00, 0x36, 0xEE
135 , 0x80, 0x00, 0x00, 0x0E, 0x10, 0xC0, 0x0C, 0x00
136 , 0x02, 0x00, 0x01, 0x00, 0x00, 0x0E, 0x10, 0x00
137 , 0x02, 0xC0, 0x2C, 0xC0, 0x2C, 0x00, 0x01, 0x00
138 , 0x01, 0x00, 0x00, 0x0E, 0x10, 0x00, 0x04, 0xDB
144 , hdMessageType = Response
145 , hdOpcode = StandardQuery
146 , hdIsAuthoritativeAnswer = True
147 , hdIsTruncated = False
148 , hdIsRecursionDesired = True
149 , hdIsRecursionAvailable = False
150 , hdResponseCode = NoError
152 , msgQuestions = [ wrapQuestion $
154 qName = "cielonegro.org."
159 , msgAnswers = [ wrapRecord $
161 rrName = "cielonegro.org."
165 , rrData = SOAFields {
166 soaMasterNameServer = "nem.cielonegro.org."
167 , soaResponsibleMailbox = "root.nem.cielonegro.org."
168 , soaSerialNumber = 2008022148
169 , soaRefreshInterval = 3600
170 , soaRetryInterval = 900
171 , soaExpirationLimit = 3600000
172 , soaMinimumTTL = 3600
176 , msgAuthorities = [ wrapRecord $
178 rrName = "cielonegro.org."
182 , rrData = "nem.cielonegro.org."
185 , msgAdditionals = [ wrapRecord $
187 rrName = "nem.cielonegro.org."
191 , rrData = "219.94.130.139"
198 packMsg :: Message -> [Word8]
199 packMsg = LBS.unpack . encode
201 unpackMsg :: [Word8] -> Message
202 unpackMsg = decode . LBS.pack
205 testData = map mkPackTest messages
207 map mkUnpackTest messages
209 mkPackTest :: ([Word8], Message) -> Test
210 mkPackTest (bin, msg) = packMsg msg ~?= bin
212 mkUnpackTest :: ([Word8], Message) -> Test
213 mkUnpackTest (bin, msg) = unpackMsg bin ~?= msg
216 main = runTestTT (test testData) >> return ()