From 20242c64c1c1d8f28b8e9d785ec71e7267251d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Hofman?= Date: Thu, 5 Sep 2024 20:21:06 +0200 Subject: [PATCH] SNOW-1651983 authenticated proxy on azure --- parent-pom.xml | 2 +- .../java/net/snowflake/client/core/HttpUtil.java | 14 ++++++++++---- .../client/core/CoreUtilsMiscellaneousTest.java | 2 ++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/parent-pom.xml b/parent-pom.xml index 28412d161..9fecf4ea3 100644 --- a/parent-pom.xml +++ b/parent-pom.xml @@ -24,7 +24,7 @@ 1.8.1 4.2.0 1.12.655 - 5.0.0 + 8.6.6 1.74 1.0.2.4 1.0.5 diff --git a/src/main/java/net/snowflake/client/core/HttpUtil.java b/src/main/java/net/snowflake/client/core/HttpUtil.java index 166bd7e0a..537c692c3 100644 --- a/src/main/java/net/snowflake/client/core/HttpUtil.java +++ b/src/main/java/net/snowflake/client/core/HttpUtil.java @@ -225,11 +225,17 @@ public static void setSessionlessProxyForAzure( */ public static void setProxyForAzure(HttpClientSettingsKey key, OperationContext opContext) { if (key != null && key.usesProxy()) { - Proxy azProxy = - new Proxy(Proxy.Type.HTTP, new InetSocketAddress(key.getProxyHost(), key.getProxyPort())); - logger.debug( - "Setting Azure proxy. Host: {}, port: {}", key.getProxyHost(), key.getProxyPort()); + Proxy azProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(key.getProxyHost(), key.getProxyPort())); opContext.setProxy(azProxy); + boolean setProxyUser = !Strings.isNullOrEmpty(key.getProxyUser()) && !Strings.isNullOrEmpty(key.getProxyPassword()); + logger.debug("Setting Azure proxy {} user. Host: {}, port: {}", + setProxyUser ? "with" : "without", + key.getProxyHost(), + key.getProxyPort()); + if (setProxyUser) { + opContext.setProxyUsername(key.getProxyUser()); + opContext.setProxyPassword(key.getProxyPassword()); + } } else { logger.debug("Omitting Azure proxy setup"); } diff --git a/src/test/java/net/snowflake/client/core/CoreUtilsMiscellaneousTest.java b/src/test/java/net/snowflake/client/core/CoreUtilsMiscellaneousTest.java index f11614c8b..87df6c659 100644 --- a/src/test/java/net/snowflake/client/core/CoreUtilsMiscellaneousTest.java +++ b/src/test/java/net/snowflake/client/core/CoreUtilsMiscellaneousTest.java @@ -162,6 +162,8 @@ public void testSetProxyForAzure() { false); HttpUtil.setProxyForAzure(testKey, op); Proxy proxy = op.getProxy(); + assertEquals("testuser", op.getProxyUsername()); + assertEquals("pw", op.getProxyPassword()); assertEquals(Proxy.Type.HTTP, proxy.type()); assertEquals(new InetSocketAddress("snowflakecomputing.com", 443), proxy.address()); }