@@ -157,7 +157,7 @@ void testAddBackendWithTags()
157157 JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager (dataStoreConfig ());
158158 HaGatewayManager haGatewayManager = new HaGatewayManager (connectionManager .getJdbi (), new RoutingConfiguration (), new DatabaseCacheConfiguration ());
159159
160- var backend = new ProxyBackendConfiguration ();
160+ ProxyBackendConfiguration backend = new ProxyBackendConfiguration ();
161161 backend .setName ("tagged-backend" );
162162 backend .setRoutingGroup ("adhoc" );
163163 backend .setProxyTo ("tagged.trino.gateway.io" );
@@ -167,7 +167,7 @@ void testAddBackendWithTags()
167167
168168 haGatewayManager .addBackend (backend );
169169
170- var retrieved = haGatewayManager .getBackendByName ("tagged-backend" ).orElseThrow ();
170+ ProxyBackendConfiguration retrieved = haGatewayManager .getBackendByName ("tagged-backend" ).orElseThrow ();
171171 assertThat (retrieved .getTags ()).containsExactly ("prod" , "us-east-1" );
172172 }
173173
@@ -176,7 +176,7 @@ void testAddBackendWithoutTagsReturnsEmptyList()
176176 {
177177 JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager (dataStoreConfig ());
178178 HaGatewayManager haGatewayManager = new HaGatewayManager (connectionManager .getJdbi (), new RoutingConfiguration (), new DatabaseCacheConfiguration ());
179- var backend = new ProxyBackendConfiguration ();
179+ ProxyBackendConfiguration backend = new ProxyBackendConfiguration ();
180180 backend .setName ("untagged-backend" );
181181 backend .setRoutingGroup ("adhoc" );
182182 backend .setProxyTo ("untagged.trino.gateway.io" );
@@ -186,7 +186,7 @@ void testAddBackendWithoutTagsReturnsEmptyList()
186186
187187 haGatewayManager .addBackend (backend );
188188
189- var retrieved = haGatewayManager .getBackendByName ("untagged-backend" ).orElseThrow ();
189+ ProxyBackendConfiguration retrieved = haGatewayManager .getBackendByName ("untagged-backend" ).orElseThrow ();
190190 assertThat (retrieved .getTags ()).isEmpty ();
191191 }
192192
@@ -195,7 +195,7 @@ void testUpdateBackendTags()
195195 {
196196 JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager (dataStoreConfig ());
197197 HaGatewayManager haGatewayManager = new HaGatewayManager (connectionManager .getJdbi (), new RoutingConfiguration (), new DatabaseCacheConfiguration ());
198- var backend = new ProxyBackendConfiguration ();
198+ ProxyBackendConfiguration backend = new ProxyBackendConfiguration ();
199199 backend .setName ("update-tags-backend" );
200200 backend .setRoutingGroup ("adhoc" );
201201 backend .setProxyTo ("update-tags.trino.gateway.io" );
@@ -207,7 +207,7 @@ void testUpdateBackendTags()
207207 backend .setTags (List .of ("prod" , "critical" ));
208208 haGatewayManager .updateBackend (backend );
209209
210- var retrieved = haGatewayManager .getBackendByName ("update-tags-backend" ).orElseThrow ();
210+ ProxyBackendConfiguration retrieved = haGatewayManager .getBackendByName ("update-tags-backend" ).orElseThrow ();
211211 assertThat (retrieved .getTags ()).containsExactly ("prod" , "critical" );
212212 }
213213
@@ -216,7 +216,7 @@ void testClearBackendTags()
216216 {
217217 JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager (dataStoreConfig ());
218218 HaGatewayManager haGatewayManager = new HaGatewayManager (connectionManager .getJdbi (), new RoutingConfiguration (), new DatabaseCacheConfiguration ());
219- var backend = new ProxyBackendConfiguration ();
219+ ProxyBackendConfiguration backend = new ProxyBackendConfiguration ();
220220 backend .setName ("clear-tags-backend" );
221221 backend .setRoutingGroup ("adhoc" );
222222 backend .setProxyTo ("clear-tags.trino.gateway.io" );
@@ -228,7 +228,7 @@ void testClearBackendTags()
228228 backend .setTags (List .of ());
229229 haGatewayManager .updateBackend (backend );
230230
231- var retrieved = haGatewayManager .getBackendByName ("clear-tags-backend" ).orElseThrow ();
231+ ProxyBackendConfiguration retrieved = haGatewayManager .getBackendByName ("clear-tags-backend" ).orElseThrow ();
232232 assertThat (retrieved .getTags ()).isEmpty ();
233233 }
234234
@@ -237,7 +237,7 @@ void testTagsAreIncludedInGetAllBackends()
237237 {
238238 JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager (dataStoreConfig ());
239239 HaGatewayManager haGatewayManager = new HaGatewayManager (connectionManager .getJdbi (), new RoutingConfiguration (), new DatabaseCacheConfiguration ());
240- var backend = new ProxyBackendConfiguration ();
240+ ProxyBackendConfiguration backend = new ProxyBackendConfiguration ();
241241 backend .setName ("all-backends-tags-backend" );
242242 backend .setRoutingGroup ("adhoc" );
243243 backend .setProxyTo ("all-backends-tags.trino.gateway.io" );
@@ -246,14 +246,71 @@ void testTagsAreIncludedInGetAllBackends()
246246 backend .setTags (List .of ("env:prod" , "region:us-west-2" ));
247247 haGatewayManager .addBackend (backend );
248248
249- var allBackends = haGatewayManager .getAllBackends ();
250- var match = allBackends .stream ()
249+ List < ProxyBackendConfiguration > allBackends = haGatewayManager .getAllBackends ();
250+ ProxyBackendConfiguration match = allBackends .stream ()
251251 .filter (b -> b .getName ().equals ("all-backends-tags-backend" ))
252252 .findFirst ()
253253 .orElseThrow ();
254254 assertThat (match .getTags ()).containsExactly ("env:prod" , "region:us-west-2" );
255255 }
256256
257+ @ Test
258+ void testAddBackendRejectsTagWithComma ()
259+ {
260+ JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager (dataStoreConfig ());
261+ HaGatewayManager haGatewayManager = new HaGatewayManager (connectionManager .getJdbi (), new RoutingConfiguration (), new DatabaseCacheConfiguration ());
262+ ProxyBackendConfiguration backend = new ProxyBackendConfiguration ();
263+ backend .setName ("comma-tag-backend" );
264+ backend .setRoutingGroup ("adhoc" );
265+ backend .setProxyTo ("comma-tag.trino.gateway.io" );
266+ backend .setExternalUrl ("comma-tag.trino.gateway.io" );
267+ backend .setActive (true );
268+ backend .setTags (List .of ("version - 480,475" ));
269+
270+ assertThatThrownBy (() -> haGatewayManager .addBackend (backend ))
271+ .isInstanceOf (IllegalArgumentException .class )
272+ .hasMessageContaining ("Backend tag cannot contain ',' character" )
273+ .hasMessageContaining ("version - 480,475" );
274+ }
275+
276+ @ Test
277+ void testAddBackendRejectsBlankTag ()
278+ {
279+ JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager (dataStoreConfig ());
280+ HaGatewayManager haGatewayManager = new HaGatewayManager (connectionManager .getJdbi (), new RoutingConfiguration (), new DatabaseCacheConfiguration ());
281+ ProxyBackendConfiguration backend = new ProxyBackendConfiguration ();
282+ backend .setName ("blank-tag-backend" );
283+ backend .setRoutingGroup ("adhoc" );
284+ backend .setProxyTo ("blank-tag.trino.gateway.io" );
285+ backend .setExternalUrl ("blank-tag.trino.gateway.io" );
286+ backend .setActive (true );
287+ backend .setTags (List .of ("env:prod" , " " ));
288+
289+ assertThatThrownBy (() -> haGatewayManager .addBackend (backend ))
290+ .isInstanceOf (IllegalArgumentException .class )
291+ .hasMessage ("Backend tag cannot be null or blank" );
292+ }
293+
294+ @ Test
295+ void testUpdateBackendRejectsTagWithComma ()
296+ {
297+ JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager (dataStoreConfig ());
298+ HaGatewayManager haGatewayManager = new HaGatewayManager (connectionManager .getJdbi (), new RoutingConfiguration (), new DatabaseCacheConfiguration ());
299+ ProxyBackendConfiguration backend = new ProxyBackendConfiguration ();
300+ backend .setName ("update-comma-tag-backend" );
301+ backend .setRoutingGroup ("adhoc" );
302+ backend .setProxyTo ("update-comma-tag.trino.gateway.io" );
303+ backend .setExternalUrl ("update-comma-tag.trino.gateway.io" );
304+ backend .setActive (true );
305+ backend .setTags (List .of ("env:prod" ));
306+ haGatewayManager .addBackend (backend );
307+
308+ backend .setTags (List .of ("a,b" ));
309+ assertThatThrownBy (() -> haGatewayManager .updateBackend (backend ))
310+ .isInstanceOf (IllegalArgumentException .class )
311+ .hasMessageContaining ("Backend tag cannot contain ',' character" );
312+ }
313+
257314 @ Test
258315 void testRemoveTrailingSlashInUrl ()
259316 {
0 commit comments