예제 #1
0
파일: dns.cpp 프로젝트: Temptationx/libtins
TEST_F(DNSTest, ItAintGonnaCorrupt) {
    DNS dns(dns_response1, sizeof(dns_response1));
    EXPECT_EQ(dns.questions_count(), 1);
    EXPECT_EQ(dns.answers_count(), 5);

    const char *domain = "carlos.example.com";
    dns.add_additional(
        DNS::Resource("www.example.com", domain, DNS::CNAME, DNS::IN, 0x762)
    );
    dns.add_authority(
        DNS::Resource("www.example.com", domain, DNS::CNAME, DNS::IN, 0x762)
    );
    dns.add_query(DNS::Query("google.com", DNS::A, DNS::IN));

    DNS::queries_type queries(dns.queries());
    for(DNS::queries_type::const_iterator it = queries.begin(); it != queries.end(); ++it) {
        EXPECT_EQ("google.com", it->dname());
        EXPECT_TRUE(it->type() == DNS::MX || it->type() == DNS::A);
        EXPECT_EQ(it->query_class(), DNS::IN);
    }
    
    // Check answers
    DNS::resources_type resources = dns.answers();
    for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
        EXPECT_EQ("google.com", it->dname());
        EXPECT_EQ(DNS::MX, it->type());
        EXPECT_EQ(DNS::IN, it->query_class());
        EXPECT_TRUE(
            it->data() == "alt1.aspmx.l.google.com" ||
            it->data() == "alt2.aspmx.l.google.com" ||
            it->data() == "alt3.aspmx.l.google.com" ||
            it->data() == "alt4.aspmx.l.google.com" ||
            it->data() == "alt5.aspmx.l.google.com" ||
            it->data() == "aspmx.l.google.com"
        );
    }
    
    // Check authority records
    resources = dns.authority();
    EXPECT_EQ(1, resources.size());
    for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
        EXPECT_EQ("www.example.com", it->dname());
        EXPECT_EQ(it->type(), DNS::CNAME);
        EXPECT_EQ(it->ttl(), 0x762U);
        EXPECT_EQ(it->data(), domain);
        EXPECT_EQ(it->query_class(), DNS::IN);
    }
    
        
    // Check additional records
    resources = dns.additional();
    EXPECT_EQ(1, resources.size());
    for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
        EXPECT_EQ("www.example.com", it->dname());
        EXPECT_EQ(it->type(), DNS::CNAME);
        EXPECT_EQ(it->ttl(), 0x762U);
        EXPECT_EQ(it->data(), domain);
        EXPECT_EQ(it->query_class(), DNS::IN);
    }
}
예제 #2
0
파일: dns.cpp 프로젝트: Temptationx/libtins
TEST_F(DNSTest, Answers) {
    DNS dns;
    dns.add_answer(
        DNS::Resource("www.example.com", "127.0.0.1", DNS::A, DNS::IN, 0x762)
    );
    dns.add_answer(
        DNS::Resource("www.example2.com", "mail.example.com", DNS::MX, DNS::IN, 0x762)
    );
    
    ASSERT_EQ(dns.answers_count(), 2);
    
    DNS::resources_type resources = dns.answers();
    for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
        EXPECT_TRUE(it->dname() == "www.example.com" || it->dname() == "www.example2.com");
        if(it->dname() == "www.example.com") {
            EXPECT_EQ(it->type(), DNS::A);
            EXPECT_EQ(it->ttl(), 0x762U);
            EXPECT_EQ(it->data(), "127.0.0.1");
            EXPECT_EQ(it->query_class(), DNS::IN);
        }
        else if(it->dname() == "www.example2.com") {
            EXPECT_EQ(it->type(), DNS::MX);
            EXPECT_EQ(it->ttl(), 0x762U);
            EXPECT_EQ(it->data(), "mail.example.com");
            EXPECT_EQ(it->query_class(), DNS::IN);
        }
    }
}
예제 #3
0
파일: dns.cpp 프로젝트: jalons/libtins
TEST_F(DNSTest, AnswersWithSameName) {
    DNS dns;
    dns.add_answer("www.example.com", DNS::make_info(DNS::A, DNS::IN, 0x762), IPv4Address("127.0.0.1"));
    dns.add_answer("www.example.com", DNS::make_info(DNS::A, DNS::IN, 0x762), IPv4Address("127.0.0.2"));
    ASSERT_EQ(dns.answers_count(), 2);
    DNS::resources_type resources = dns.answers();
    for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
        EXPECT_TRUE(it->data() == "127.0.0.1" || it->data() == "127.0.0.2");
        EXPECT_EQ(it->dname(), "www.example.com");
        EXPECT_EQ(it->type(), DNS::A);
        EXPECT_EQ(it->ttl(), 0x762U);
        EXPECT_EQ(it->query_class(), DNS::IN);
    }
}
예제 #4
0
파일: dns.cpp 프로젝트: jalons/libtins
TEST_F(DNSTest, AnswersV6) {
    DNS dns;
    dns.add_answer("www.example.com", DNS::make_info(DNS::AAAA, DNS::IN, 0x762), IPv6Address("f9a8:239::1:1"));
    dns.add_answer("www.example.com", DNS::make_info(DNS::AAAA, DNS::IN, 0x762), IPv6Address("f9a8:239::1:1"));
    ASSERT_EQ(dns.answers_count(), 2);
    
    DNS::resources_type resources = dns.answers();
    for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
        EXPECT_EQ(it->dname(), "www.example.com");
        EXPECT_EQ(it->type(), DNS::AAAA);
        EXPECT_EQ(it->ttl(), 0x762U);
        EXPECT_EQ(it->data(), "f9a8:239::1:1");
        EXPECT_EQ(it->query_class(), DNS::IN);
    }
}
예제 #5
0
파일: dns.cpp 프로젝트: Temptationx/libtins
TEST_F(DNSTest, Additional) {
    DNS dns;
    
    const char *domain = "carlos.example.com";
    dns.add_additional(
        DNS::Resource("www.example.com", domain, DNS::CNAME, DNS::IN, 0x762)
    );
    dns.add_additional(
        DNS::Resource("www.example.com", domain, DNS::CNAME, DNS::IN, 0x762)
    );
    
    ASSERT_EQ(dns.additional_count(), 2);
    
    DNS::resources_type resources = dns.additional();
    for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
        EXPECT_EQ("www.example.com", it->dname());
        EXPECT_EQ(it->type(), DNS::CNAME);
        EXPECT_EQ(it->ttl(), 0x762U);
        EXPECT_EQ(it->data(), domain);
        EXPECT_EQ(it->query_class(), DNS::IN);
    }
}
예제 #6
0
파일: dns.cpp 프로젝트: Temptationx/libtins
TEST_F(DNSTest, ConstructorFromBuffer2) {
    DNS dns(dns_response1, sizeof(dns_response1));
    EXPECT_EQ(dns.questions_count(), 1);
    EXPECT_EQ(dns.answers_count(), 5);
    
    for(size_t i = 0; i < 2; ++i) {   
        DNS::queries_type queries(dns.queries());
        for(DNS::queries_type::const_iterator it = queries.begin(); it != queries.end(); ++it) {
            EXPECT_EQ("google.com", it->dname());
            EXPECT_TRUE(it->type() == DNS::MX || it->type() == DNS::A);
            EXPECT_EQ(it->query_class(), DNS::IN);
        }
         
        DNS::resources_type resources = dns.answers();
        for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
            EXPECT_EQ("google.com", it->dname());
            EXPECT_EQ(DNS::MX, it->type());
            EXPECT_EQ(DNS::IN, it->query_class());
            EXPECT_TRUE(
                it->data() == "alt1.aspmx.l.google.com" ||
                it->data() == "alt2.aspmx.l.google.com" ||
                it->data() == "alt3.aspmx.l.google.com" ||
                it->data() == "alt4.aspmx.l.google.com" ||
                it->data() == "alt5.aspmx.l.google.com" ||
                it->data() == "aspmx.l.google.com"
            );
        }
        // Add some stuff and see if something gets broken
        if(i == 0) {
            dns.add_query(DNS::Query("google.com", DNS::A, DNS::IN));
            dns.add_query(DNS::Query("google.com", DNS::MX, DNS::IN));
            dns.add_answer(
                DNS::Resource("google.com", "alt5.aspmx.l.google.com", DNS::MX, DNS::IN, 0x762)
            );
        }
    }
}