Fake DNS query result inside a test (original) (raw)

Weijun Wang weijun.wang at oracle.com
Wed Nov 7 15:15:12 UTC 2012


Hi Vinnie

As you know, krb5 can read KDC info from DNS and I want to write a regression test on it. However, the test must be independent and it should not access any server not inside the test suite.

Java uses those 2 lines to read the KDC info. Surely it would work if I write my own DNS server and embed it into the test, but as you said, that's too complicated. So I was thinking about how to trick it to return something without querying a real server.

My current solution is to provide my own javax.naming.spi.NamingManager and make sure it shadows the original one by setting the path to -Xbootclasspath/p:. It is quite ugly and I feel shame to go this way.

Thanks Max

On 11/07/2012 08:51 PM, Vincent Ryan wrote:

Are you suggesting to run a local DNS server? If so then it is easy to access that via a JNDI context.

If you're proposing developing a basic JNDI service provider then that would be more effort.

On 7 Nov 2012, at 01:05, Weijun Wang wrote: Hi Vinnie

I want to write a regression test so that Context ctx = NamingManager.getURLContext("dns", new Hashtable<>(0)); Attributes attrs =((DirContext)ctx).getAttributes( "kerberos.udp.ASDF.COM.", SRVRRATTR); can return some entries without querying a real external server. Is this possible by registering a local name server provider or else? Thanks Max



More information about the core-libs-dev mailing list