Skip to content

Commit f49d8ae

Browse files
FLOW-11254 Snowflake connector: improve server instance URL validation (#4212)
* NO-FLOW Fix build warnings (#19) * FLOW-11254 Validate configure URL is a Snowflake domain --------- Co-authored-by: Piotr Zalas <127133187+sfc-gh-pzalas@users.noreply.github.com>
1 parent 6b63460 commit f49d8ae

5 files changed

Lines changed: 12 additions & 6 deletions

File tree

certified-connectors/Snowflake v2/SnowflakeTestApp.Tests/Sql/SqlEndpointIntegrationTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ public async Task CancelStatementEndpoint_WithAuth_ReturnsBadRequest()
246246
}
247247

248248
/// <summary>
249-
/// Test cancellation of already completed SQL statement - should return 422
249+
/// Test cancellation of already completed SQL statement - Snowflake returns 200
250250
/// </summary>
251251
[TestMethod]
252-
public async Task SqlExecutionFlow_CancelCompletedStatement_Returns422()
252+
public async Task SqlExecutionFlow_CancelCompletedStatement_Returns200()
253253
{
254254
var testToken = GetTestToken();
255255
HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {testToken}");
@@ -281,11 +281,11 @@ public async Task SqlExecutionFlow_CancelCompletedStatement_Returns422()
281281
string statementHandle = executeResult["Metadata"]["StatementHandle"].ToString();
282282
Assert.IsFalse(string.IsNullOrEmpty(statementHandle), "Statement handle should be present in response");
283283

284-
// Try to cancel already completed statement - should return 422
284+
// Try to cancel already completed statement - Snowflake returns 200
285285
var cancelContent = new StringContent("{}", Encoding.UTF8, "application/json");
286286
var cancelResponse = await HttpClient.PostAsync($"{BaseUrl}/sql/{statementHandle}/cancel", cancelContent);
287287

288-
Assert.AreEqual(422, (int)cancelResponse.StatusCode, "Cancel should return 422 for already completed statement");
288+
Assert.AreEqual(HttpStatusCode.OK, cancelResponse.StatusCode, "Cancel of completed statement should return 200");
289289
}
290290
}
291291
}

certified-connectors/Snowflake v2/SnowflakeTestApp/Mocks/ConnectionParametersProviderMock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ public TokenMock(string token)
160160

161161
public DateTime TokenAcquireTime => DateTime.UtcNow.AddMinutes(-1);
162162
}
163-
}
163+
}

certified-connectors/Snowflake v2/SnowflakeV2CoreLogic/Controllers/SnowflakeSQLController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ private static void ValidateInstanceUrl(
182182
{
183183
throw new ArgumentException($"The Instance parameter cannot contain a trailing slash. Please remove it and try again.");
184184
}
185+
186+
// Validate that the instance belongs to a valid Snowflake domain
187+
instanceUrl.EnsureValidSnowflakeUrl("Instance");
185188
}
186189
}
187190
}

certified-connectors/Snowflake v2/SnowflakeV2CoreLogic/SnowflakeV2CoreLogic.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<ItemGroup>
1212
<None Include="SnowflakeV2RuleSet.ruleset" />
1313
</ItemGroup>
14+
<ItemGroup>
15+
<InternalsVisibleTo Include="SnowflakeV2CoreLogic.Tests" />
16+
</ItemGroup>
1417
<ItemGroup>
1518
<PackageReference Include="Microsoft.AspNet.OData" Version="5.11.0" />
1619
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />

certified-connectors/Snowflake v2/SnowflakeV2CoreLogic/Utilities/EnsureExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal static class EnsureExtensions
2121
private static readonly Regex IdentifierRegexPattern = new Regex(IdentifierFullRegex, RegexOptions.Compiled);
2222

2323
// Setup the regex for the snowflake URL
24-
private static readonly string UrlFullRegex = @"[a-zA-Z0-9-_.]+\.snowflakecomputing\.com|[a-zA-Z0-9-_.]+\.privatelink\.snowflakecomputing\.com";
24+
private static readonly string UrlFullRegex = @"^([a-zA-Z0-9-_.]+\.snowflakecomputing\.com|[a-zA-Z0-9-_.]+\.privatelink\.snowflakecomputing\.com)$";
2525
private static readonly Regex UrlRegexPattern = new Regex(UrlFullRegex, RegexOptions.Compiled);
2626

2727
/// <summary>

0 commit comments

Comments
 (0)