|
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"); |
|
57 } |
|
58 |
|
59 public static void main(String[] args) throws Exception { |
|
60 new GetNonstandard().run(args); |
|
61 } |
|
62 |
|
63 @Override public void runTest() throws Exception { |
|
64 initContext(); |
|
65 Attributes retAttrs = getAttributes(); |
|
66 verifyAttributes(retAttrs); |
|
67 verifyLoc(retAttrs); |
|
68 } |
|
69 |
|
70 /* |
|
71 * Tests that we can get an attribute that has a nonstandard name from |
|
72 * a DNS entry. |
|
73 */ |
|
74 @Override public Attributes getAttributes() throws Exception { |
|
75 return context().getAttributes(getKey(), getMandatoryAttrs()); |
|
76 } |
|
77 |
|
78 private void verifyLoc(Attributes retAttrs) throws NamingException { |
|
79 Attribute loc = retAttrs.get(getMandatoryAttrs()[0]); |
|
80 byte[] val = (byte[]) loc.get(0); |
|
81 |
|
82 String expected = Arrays.toString(EXPECTED_VALUE); |
|
83 String actual = Arrays.toString(val); |
|
84 DNSTestUtils.debug("Expected: " + expected); |
|
85 DNSTestUtils.debug("Actual: " + actual); |
|
86 |
|
87 if (!Arrays.equals(val, EXPECTED_VALUE)) { |
|
88 throw new RuntimeException(String.format( |
|
89 "Failed: values not match, expected: %s, actual: %s", |
|
90 expected, actual)); |
|
91 } |
|
92 } |
|
93 } |