1010package org .elasticsearch .entitlement .qa .test ;
1111
1212import org .elasticsearch .core .CheckedConsumer ;
13+ import org .elasticsearch .entitlement .qa .entitled .EntitledActions ;
1314
1415import java .io .IOException ;
1516import java .io .InputStream ;
@@ -64,7 +65,7 @@ public InputStream getInputStream() throws IOException {
6465 }
6566
6667 private static void withJdkHttpConnection (CheckedConsumer <HttpURLConnection , Exception > connectionConsumer ) throws Exception {
67- var conn = URI . create ( "http://127.0.0.1:12345/" ). toURL (). openConnection ();
68+ var conn = EntitledActions . createHttpURLConnection ();
6869 // Be sure we got the connection implementation we want
6970 assert HttpURLConnection .class .isAssignableFrom (conn .getClass ());
7071 try {
@@ -75,62 +76,102 @@ private static void withJdkHttpConnection(CheckedConsumer<HttpURLConnection, Exc
7576 }
7677
7778 @ EntitlementTest (expectedAccess = PLUGINS )
78- static void urlConnectionGetContentLength () throws Exception {
79+ static void baseUrlConnectionGetContentLength () throws Exception {
7980 withPlainNetworkConnection (URLConnection ::getContentLength );
81+ }
82+
83+ @ EntitlementTest (expectedAccess = PLUGINS )
84+ static void sunHttpConnectionGetContentLength () throws Exception {
8085 withJdkHttpConnection (URLConnection ::getContentLength );
8186 }
8287
8388 @ EntitlementTest (expectedAccess = PLUGINS )
84- static void urlConnectionGetContentType () throws Exception {
89+ static void baseUrlConnectionGetContentType () throws Exception {
8590 withPlainNetworkConnection (URLConnection ::getContentType );
91+ }
92+
93+ @ EntitlementTest (expectedAccess = PLUGINS )
94+ static void sunHttpConnectionGetContentType () throws Exception {
8695 withJdkHttpConnection (URLConnection ::getContentType );
8796 }
8897
8998 @ EntitlementTest (expectedAccess = PLUGINS )
90- static void urlConnectionGetContentEncoding () throws Exception {
99+ static void baseUrlConnectionGetContentEncoding () throws Exception {
91100 withPlainNetworkConnection (URLConnection ::getContentEncoding );
101+ }
102+
103+ @ EntitlementTest (expectedAccess = PLUGINS )
104+ static void sunHttpConnectionGetContentEncoding () throws Exception {
92105 withJdkHttpConnection (URLConnection ::getContentEncoding );
93106 }
94107
95108 @ EntitlementTest (expectedAccess = PLUGINS )
96- static void urlConnectionGetExpiration () throws Exception {
109+ static void baseUrlConnectionGetExpiration () throws Exception {
97110 withPlainNetworkConnection (URLConnection ::getExpiration );
111+ }
112+
113+ @ EntitlementTest (expectedAccess = PLUGINS )
114+ static void sunHttpConnectionGetExpiration () throws Exception {
98115 withJdkHttpConnection (URLConnection ::getExpiration );
99116 }
100117
101118 @ EntitlementTest (expectedAccess = PLUGINS )
102- static void urlConnectionGetDate () throws Exception {
119+ static void baseUrlConnectionGetDate () throws Exception {
103120 withPlainNetworkConnection (URLConnection ::getDate );
121+ }
122+
123+ @ EntitlementTest (expectedAccess = PLUGINS )
124+ static void sunHttpConnectionGetDate () throws Exception {
104125 withJdkHttpConnection (URLConnection ::getDate );
105126 }
106127
107128 @ EntitlementTest (expectedAccess = PLUGINS )
108- static void urlConnectionGetLastModified () throws Exception {
129+ static void baseUrlConnectionGetLastModified () throws Exception {
109130 withPlainNetworkConnection (URLConnection ::getLastModified );
131+ }
132+
133+ @ EntitlementTest (expectedAccess = PLUGINS )
134+ static void sunHttpConnectionGetLastModified () throws Exception {
110135 withJdkHttpConnection (URLConnection ::getLastModified );
111136 }
112137
113138 @ EntitlementTest (expectedAccess = PLUGINS )
114- static void urlConnectionGetHeaderFieldInt () throws Exception {
139+ static void baseUrlConnectionGetHeaderFieldInt () throws Exception {
115140 withPlainNetworkConnection (conn -> conn .getHeaderFieldInt ("field" , 0 ));
141+ }
142+
143+ @ EntitlementTest (expectedAccess = PLUGINS )
144+ static void sunHttpConnectionGetHeaderFieldInt () throws Exception {
116145 withJdkHttpConnection (conn -> conn .getHeaderFieldInt ("field" , 0 ));
117146 }
118147
119148 @ EntitlementTest (expectedAccess = PLUGINS )
120- static void urlConnectionGetHeaderFieldLong () throws Exception {
149+ static void baseUrlConnectionGetHeaderFieldLong () throws Exception {
121150 withPlainNetworkConnection (conn -> conn .getHeaderFieldLong ("field" , 0 ));
151+ }
152+
153+ @ EntitlementTest (expectedAccess = PLUGINS )
154+ static void sunHttpConnectionGetHeaderFieldLong () throws Exception {
122155 withJdkHttpConnection (conn -> conn .getHeaderFieldLong ("field" , 0 ));
123156 }
124157
125158 @ EntitlementTest (expectedAccess = PLUGINS )
126- static void urlConnectionGetContent () throws Exception {
159+ static void baseUrlConnectionGetContent () throws Exception {
127160 withPlainNetworkConnection (URLConnection ::getContent );
161+ }
162+
163+ @ EntitlementTest (expectedAccess = PLUGINS )
164+ static void sunHttpConnectionGetContent () throws Exception {
128165 withJdkHttpConnection (URLConnection ::getContent );
129166 }
130167
131168 @ EntitlementTest (expectedAccess = PLUGINS )
132- static void urlConnectionGetContentWithClasses () throws Exception {
169+ static void baseUrlConnectionGetContentWithClasses () throws Exception {
133170 withPlainNetworkConnection (conn -> conn .getContent (new Class <?>[] { String .class }));
171+ }
172+
173+ @ EntitlementTest (expectedAccess = PLUGINS )
174+ static void sunHttpConnectionGetContentWithClasses () throws Exception {
134175 withJdkHttpConnection (conn -> conn .getContent (new Class <?>[] { String .class }));
135176 }
136177}
0 commit comments