added test_compression_strategy from dev

This commit is contained in:
Frederick Sell 2023-01-16 11:03:22 -05:00 committed by GitHub
parent 57e19c2d4c
commit f759e9c938
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ import os
import pytest
import tempfile
import dns.resolver
import actions.tree
import actions.drop
import actions.tamper
@ -24,3 +25,17 @@ def test_compression_strategy(logger):
with engine.Engine(53, "[UDP:dport:53]-tamper{DNS:qd:compress}-|", server_side=False, environment_id="compress_test", output_directory=actions.utils.RUN_DIRECTORY, log_level=actions.utils.CONSOLE_LOG_LEVEL):
os.system("dig @8.8.8.8 google.com")
def test_compression_strategy(logger):
"""
Tests dns compression strategy.
"""
with engine.Engine(53, "[UDP:dport:53]-tamper{DNS:qd:compress}-|", server_side=False, environment_id="compress_test", output_directory=actions.utils.RUN_DIRECTORY, log_level=actions.utils.CONSOLE_LOG_LEVEL):
resolver = dns.resolver.Resolver()
resolver.nameservers = ["8.8.8.8"]
resolver.lifetime = 3
answer = resolver.query("google.com", "A")
assert answer, "Resolver query returned None"
assert len(answer) > 0, "No answers"
assert answer[0], "No answer to DNS query"
print("Got answer: %s" % str(answer[0]))