1 /* 2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8198882 27 * @summary Tests that we can get an attribute that has a nonstandard name from 28 * a DNS entry. 29 * @modules java.base/sun.security.util 30 * @library ../lib/ 31 * @run main GetNonstandard 32 */ 33 34 import javax.naming.NamingException; 35 import javax.naming.directory.Attribute; 36 import javax.naming.directory.Attributes; 37 import java.util.Arrays; 38 39 public class GetNonstandard extends GetAttrsBase { 40 // "40 2 0.373 N 105 17 23.528 W 1638m" 41 private static final byte[] EXPECTED_VALUE = { (byte) 0, // version 42 (byte) 18, // size 43 (byte) 22, // horiz pre 44 (byte) 19, // vert pre 45 (byte) -120, // latitude 1 46 (byte) -105, // latitude 2 47 (byte) 26, // longitude 1 48 (byte) 53, // longitude 2 49 (byte) 105, // altitude 1 50 (byte) 104, // altitude 2 51 (byte) 65, (byte) 56, (byte) 0, (byte) -101, (byte) 22, 52 (byte) 88, }; 53 54 public GetNonstandard() { 55 // set new test data instead of default value 56 setMandatoryAttrs("29" // LOC 57 ); 58 } 59 60 public static void main(String[] args) throws Exception { 61 new GetNonstandard().run(args); 62 } 63 64 @Override public void runTest() throws Exception { 65 initContext(); 66 Attributes retAttrs = getAttributes(); 67 verifyAttributes(retAttrs); 68 verifyLoc(retAttrs); 69 } 70 71 /* 72 * Tests that we can get an attribute that has a nonstandard name from 73 * a DNS entry. 74 */ 75 @Override public Attributes getAttributes() throws Exception { 76 return context().getAttributes(getKey(), getMandatoryAttrs()); 77 } 78 79 private void verifyLoc(Attributes retAttrs) throws NamingException { 80 Attribute loc = retAttrs.get(getMandatoryAttrs()[0]); 81 byte[] val = (byte[]) loc.get(0); 82 83 String expected = Arrays.toString(EXPECTED_VALUE); 84 String actual = Arrays.toString(val); 85 DNSTestUtils.debug("Expected: " + expected); 86 DNSTestUtils.debug("Actual: " + actual); 87 88 if (!Arrays.equals(val, EXPECTED_VALUE)) { 89 throw new RuntimeException(String.format( 90 "Failed: values not match, expected: %s, actual: %s", 91 expected, actual)); 92 } 93 } 94 }