001: // -*- Java -*-
002: //
003: // Copyright (c) 2005, Matthew J. Rutherford <rutherfo@cs.colorado.edu>
004: // Copyright (c) 2005, University of Colorado at Boulder
005: // All rights reserved.
006: //
007: // Redistribution and use in source and binary forms, with or without
008: // modification, are permitted provided that the following conditions are
009: // met:
010: //
011: // * Redistributions of source code must retain the above copyright
012: // notice, this list of conditions and the following disclaimer.
013: //
014: // * Redistributions in binary form must reproduce the above copyright
015: // notice, this list of conditions and the following disclaimer in the
016: // documentation and/or other materials provided with the distribution.
017: //
018: // * Neither the name of the University of Colorado at Boulder nor the
019: // names of its contributors may be used to endorse or promote
020: // products derived from this software without specific prior written
021: // permission.
022: //
023: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
024: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
025: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
026: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
027: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
028: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
029: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
030: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
031: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
032: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
033: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
034: //
035: package org.xbill.DNS;
036:
037: import java.io.IOException;
038: import java.net.InetAddress;
039: import java.net.UnknownHostException;
040: import java.util.Arrays;
041: import junit.framework.TestCase;
042:
043: public class DNSKEYRecordTest extends TestCase {
044: public void test_ctor_0arg() throws UnknownHostException {
045: DNSKEYRecord ar = new DNSKEYRecord();
046: assertNull(ar.getName());
047: assertEquals(0, ar.getType());
048: assertEquals(0, ar.getDClass());
049: assertEquals(0, ar.getTTL());
050: assertEquals(0, ar.getAlgorithm());
051: assertEquals(0, ar.getFlags());
052: assertEquals(0, ar.getFootprint());
053: assertEquals(0, ar.getProtocol());
054: assertNull(ar.getKey());
055: }
056:
057: public void test_getObject() {
058: DNSKEYRecord ar = new DNSKEYRecord();
059: Record r = ar.getObject();
060: assertTrue(r instanceof DNSKEYRecord);
061: }
062:
063: public void test_ctor_7arg() throws TextParseException {
064: Name n = Name.fromString("My.Absolute.Name.");
065: Name r = Name.fromString("My.Relative.Name");
066: byte[] key = new byte[] { 0, 1, 3, 5, 7, 9 };
067:
068: DNSKEYRecord kr = new DNSKEYRecord(n, DClass.IN, 0x24AC,
069: 0x9832, 0x12, 0x67, key);
070: assertEquals(n, kr.getName());
071: assertEquals(Type.DNSKEY, kr.getType());
072: assertEquals(DClass.IN, kr.getDClass());
073: assertEquals(0x24AC, kr.getTTL());
074: assertEquals(0x9832, kr.getFlags());
075: assertEquals(0x12, kr.getProtocol());
076: assertEquals(0x67, kr.getAlgorithm());
077: assertTrue(Arrays.equals(key, kr.getKey()));
078:
079: // a relative name
080: try {
081: new DNSKEYRecord(r, DClass.IN, 0x24AC, 0x9832, 0x12, 0x67,
082: key);
083: fail("RelativeNameException not thrown");
084: } catch (RelativeNameException e) {
085: }
086: }
087:
088: public void test_rdataFromString() throws IOException,
089: TextParseException {
090: // basic
091: DNSKEYRecord kr = new DNSKEYRecord();
092: Tokenizer st = new Tokenizer(0xABCD + " " + 0x81
093: + " RSASHA1 AQIDBAUGBwgJ");
094: kr.rdataFromString(st, null);
095: assertEquals(0xABCD, kr.getFlags());
096: assertEquals(0x81, kr.getProtocol());
097: assertEquals(DNSSEC.Algorithm.RSASHA1, kr.getAlgorithm());
098: assertTrue(Arrays.equals(
099: new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, kr.getKey()));
100:
101: // invalid algorithm
102: kr = new DNSKEYRecord();
103: st = new Tokenizer(0x1212 + " " + 0xAA + " ZONE AQIDBAUGBwgJ");
104: try {
105: kr.rdataFromString(st, null);
106: fail("TextParseException not thrown");
107: } catch (TextParseException e) {
108: }
109: }
110: }
|