Friday, October 15, 2004

Sites for testing

When writing code that needs to test against DNS or writing documentation that needs to point to a URL as an example, whose domain name do you use? The marketing department might suggest that these are opportunities to drive traffic to some of your sites and that real sites should always be used in testing and documentation. It sounds good but in practice could invalidate tests or could result in inappropriate documentation as domain names change purpose.

Fortunately the fine thinkers that helped lay out the structure of the Internet considered just this scenerio in 1999 with RFC 2606. The RFC mentions the following as one of the reasons not to follow your marketing departments advice:

For example, without guidance, a site might set up some local additional unused top level domains for testing of its local DNS code and configuration. Later, these TLDs might come into actual use on the global Internet. As a result, local attempts to reference the real data in these zones could be thwarted by the local test versions.


A Top Level Domain (TLD) is the final letters of the URL after the last period but before the first slash. com is the most widely known TLD. Four other largely unknown TLDs were established by RFC 2606 to accommodate testing and documentation. These are:
.test       For example: http://www.spyjournal.test
.example       For example: http://www.spyjournal.example
.invalid       For example: http://www.spyjournal.invalid
.localhost       For example: http://www.spyjournal.localhost


RFC 2606 defines each of these four TLDs as:
".test" is recommended for use in testing of current or new DNS related code.
".example" is recommended for use in documentation or as examples.
".invalid" is intended for use in online construction of domain names that are sure to be invalid and which it is obvious at a glance are invalid.
The ".localhost" TLD has traditionally been statically defined in host DNS implementations as having an A record pointing to the loop back IP address and is reserved for such use. Any other use would conflict with widely deployed code which assumes this use.


A second level domain is the part of the URL just before the last period. We commonly expect this to be the company name. In this well known URL http://www.google.com/ google is the second level domain while com is the top level domain. Naturally www is the third level domain.

RFC 2606 establishes example.com, example.net, and example.org as permanent urls that can be used for documentation purposes.

Use of these established domains for testing and documentation will prevent errors and sometimes embarrassment. Make it part of your best practices!