private RRset makeNameServerSet(DomainResource domain) { RRset nameServerSet = new RRset(); for (String hostName : domain.loadNameserverFullyQualifiedHostNames()) { NSRecord record = new NSRecord( toAbsoluteName(domain.getFullyQualifiedDomainName()), DClass.IN, dnsDefaultNsTtl.getStandardSeconds(), toAbsoluteName(hostName)); nameServerSet.addRR(record); } return nameServerSet; }
@Test public void canResolveRecord() throws Exception { AcceptanceTestRunner runner = new AcceptanceTestRunner(); runner.runUngarded(new AcceptanceScenario() { public void run(WebDriver driver, String deployedURL) throws Exception { int id = new SecureRandom().nextInt(); final String systemTestBase = "system-tests.onomate.test"; final String soaBase = "soa-" + id +"."+ systemTestBase; final String ns = "ns." + soaBase; final String contactName = "admin." + soaBase; final String aTestRecordHost = "record."+soaBase; final String aTestRecordNS = "ns.test"; OnomateAssembly assembly = new OnomateAssembly(driver, deployedURL); OnomateAssembly.Dashboard board = assembly.gotoLanding().authenticate().newAuthority(soaBase, ns, contactName); board.authorityByZone(soaBase).details().createRecord(aTestRecordHost, OnomateAssembly.RecordType.NS, aTestRecordNS); Options.set("verbose"); SimpleResolver resolver = new SimpleResolver(); resolver.setAddress(InetAddress.getLocalHost()); resolver.setPort(9101); Record query = Record.newRecord(Name.fromString(aTestRecordHost + "."), Type.NS, DClass.IN); Message question = Message.newQuery(query); Message response = resolver.send(question); Record responses[] = response.getSectionArray(Section.AUTHORITY); NSRecord record = ((NSRecord) responses[0]); assertEquals(record.getName().toString(), aTestRecordHost+ "."); assertEquals(record.getTarget().toString(), aTestRecordNS + "."); } }); }
private Message lookup(Set<Name> stack, String[] addresses, Message query) throws IOException { Message msg = getCached(query); if (msg != null) return msg; if (addresses == null) return null; Resolver resolver = createResolver(addresses); try { msg = resolver.send(query); } catch (IOException e) { return null; } if (msg == null) return null; // Found the authoritative answer if (msg.getHeader().getFlag(Flags.AA)) return msg; Record[] authority = msg.getSectionArray(Section.AUTHORITY); for (Record record : authority) { if (Type.NS == record.getType()) { Name nameserver = ((NSRecord)record).getTarget(); // Try to find glue for the record first Record[] additional = msg.getSectionArray(Section.ADDITIONAL); addresses = findAddresses(nameserver, additional); if (stack.contains(nameserver)) // Loop - cannot go there continue; stack.add(nameserver); if (stack.size() > MAX_RECURSION_STACK) // Prevent recursion spinning out of control return null; // No glue found - lookup target recursively if (addresses == null) addresses = findAddressesRecursive(stack, nameserver); // Chase down to the next level Message resp = lookup(stack, addresses, query); if (resp != null) { addCached(resp); return resp; } } } return null; // Just couldn't do it }
/** {@inheritDoc} */ @Override public void beforeTestMethod(final TestContext testContext) throws Exception { super.beforeTestMethod(testContext); final JUnitDNSServer config = findTestAnnotation(JUnitDNSServer.class, testContext); if (config == null) { return; } LogUtils.infof(this, "initializing DNS on port %d", config.port()); m_server = new DNSServer(); m_server.addPort(config.port()); for (final DNSZone dnsZone : config.zones()) { String name = dnsZone.name(); if (!name.endsWith(".")) { name = name + "."; } final Name zoneName = Name.fromString(name, Name.root); LogUtils.debugf(this, "zoneName = %s", zoneName); final Zone zone = new Zone(zoneName, new Record[] { new SOARecord(zoneName, DClass.IN, DEFAULT_TTL, zoneName, Name.fromString("admin." + name), 1, DEFAULT_TTL, DEFAULT_TTL, DEFAULT_TTL, DEFAULT_TTL), new NSRecord(zoneName, DClass.IN, DEFAULT_TTL, Name.fromString("resolver1.opendns.com.")), new NSRecord(zoneName, DClass.IN, DEFAULT_TTL, Name.fromString("resolver2.opendns.com.")), new ARecord(zoneName, DClass.IN, DEFAULT_TTL, InetAddressUtils.addr(dnsZone.v4address())), new AAAARecord(zoneName, DClass.IN, DEFAULT_TTL, InetAddressUtils.addr(dnsZone.v6address())) }); LogUtils.debugf(this, "zone = %s", zone); for (final DNSEntry entry : dnsZone.entries()) { LogUtils.debugf(this, "adding entry: %s", entry); String hostname = entry.hostname(); final Name recordName = Name.fromString(hostname, zoneName); LogUtils.debugf(this, "name = %s", recordName); if (entry.ipv6()) { zone.addRecord(new AAAARecord(recordName, DClass.IN, DEFAULT_TTL, InetAddressUtils.addr(entry.address()))); } else { zone.addRecord(new ARecord(recordName, DClass.IN, DEFAULT_TTL, InetAddressUtils.addr(entry.address()))); } } m_server.addZone(zone); } LogUtils.debugf(this, "starting DNS server"); m_server.start(); try { Thread.sleep(50); } catch (final InterruptedException e) { LogUtils.debugf(this, e, "interrupted while waiting for server to come up"); Thread.currentThread().interrupt(); } }
public static NSRecord getNSRecord(String domainName) { return null; }
public NSRecord getNSRecord(String domainName) { return null; }