Skip to content

Commit

Permalink
SNOW-916949: Refactor mock class and remove skip tag
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Feb 9, 2024
1 parent 5bed4df commit a572300
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 78 deletions.
38 changes: 24 additions & 14 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Snowflake.Data.Tests.IntegrationTests
using System.Diagnostics;
using Snowflake.Data.Tests.Mock;
using System.Runtime.InteropServices;
using System.Net.Http;

[TestFixture]
class SFConnectionIT : SFBaseTest
Expand Down Expand Up @@ -818,23 +819,28 @@ public void TestOktaConnection()
}

[Test]
[Ignore("This test requires manual setup and therefore cannot be run in CI")]
public void TestOktaConnectionUntilMaxTimeout()
{
var expectedMaxRetryCount = 15;
var expectedMaxConnectionTimeout = 450;
var mockRestRequester = new MockOktaRetryMaxTimeout(expectedMaxRetryCount, expectedMaxConnectionTimeout);
var oktaUrl = "https://test.okta.com";
var mockRestRequester = new MockOktaRestRequester()
{
TokenUrl = $"{oktaUrl}/api/v1/sessions?additionalFields=cookieToken",
SSOUrl = $"{oktaUrl}/app/testaccount/sso/saml",
ResponseContent = new StringContent("<form=error}"),
MaxRetryCount = expectedMaxRetryCount,
MaxRetryTimeout = expectedMaxConnectionTimeout
};
using (DbConnection conn = new MockSnowflakeDbConnection(mockRestRequester))
{
try
{
conn.ConnectionString
= ConnectionStringWithoutAuth
+ String.Format(
";authenticator={0};user={1};password={2};MAXHTTPRETRIES={3};RETRY_TIMEOUT={4};",
testConfig.oktaUrl,
testConfig.oktaUser,
testConfig.oktaPassword,
";authenticator={0};user=test;password=test;MAXHTTPRETRIES={1};RETRY_TIMEOUT={2};",
oktaUrl,
expectedMaxRetryCount,
expectedMaxConnectionTimeout);
conn.Open();
Expand Down Expand Up @@ -2094,27 +2100,31 @@ public void TestExplicitTransactionOperationsTracked()


[Test]
[Ignore("This test requires manual setup and therefore cannot be run in CI")]
public void TestAsyncOktaConnectionUntilMaxTimeout()
{
var expectedMaxRetryCount = 15;
var expectedMaxConnectionTimeout = 450;
var mockRestRequester = new MockOktaRetryMaxTimeout(expectedMaxRetryCount, expectedMaxConnectionTimeout);
var oktaUrl = "https://test.okta.com";
var mockRestRequester = new MockOktaRestRequester()
{
TokenUrl = $"{oktaUrl}/api/v1/sessions?additionalFields=cookieToken",
SSOUrl = $"{oktaUrl}/app/testaccount/sso/saml",
ResponseContent = new StringContent("<form=error}"),
MaxRetryCount = expectedMaxRetryCount,
MaxRetryTimeout = expectedMaxConnectionTimeout
};
using (DbConnection conn = new MockSnowflakeDbConnection(mockRestRequester))
{
Task connectTask = null;
try
{
conn.ConnectionString
= ConnectionStringWithoutAuth
+ String.Format(
";authenticator={0};user={1};password={2};MAXHTTPRETRIES={3};RETRY_TIMEOUT={4};",
testConfig.oktaUrl,
testConfig.oktaUser,
testConfig.oktaPassword,
";authenticator={0};user=test;password=test;MAXHTTPRETRIES={1};RETRY_TIMEOUT={2};",
oktaUrl,
expectedMaxRetryCount,
expectedMaxConnectionTimeout);
connectTask = conn.OpenAsync(CancellationToken.None);
Task connectTask = conn.OpenAsync(CancellationToken.None);
connectTask.Wait();
Assert.Fail();
}
Expand Down
4 changes: 4 additions & 0 deletions Snowflake.Data.Tests/Mock/MockOkta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class MockOktaRestRequester : IMockRestRequester
public string TokenUrl { get; set; }
public string SSOUrl { get; set; }
public StringContent ResponseContent { get; set; }
public int MaxRetryCount { get; set; }
public int MaxRetryTimeout { get; set; }

public T Get<T>(IRestRequest request)
{
Expand All @@ -31,6 +33,8 @@ public Task<HttpResponseMessage> GetAsync(IRestRequest request, CancellationToke
{
var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
response.Content = ResponseContent;
response.Content.Headers.Add(OktaAuthenticator.RetryCountHeader, MaxRetryCount.ToString());
response.Content.Headers.Add(OktaAuthenticator.TimeoutElapsedHeader, MaxRetryTimeout.ToString());
return Task.FromResult(response);
}

Expand Down
55 changes: 0 additions & 55 deletions Snowflake.Data.Tests/Mock/MockOktaRetryMaxTimeout.cs

This file was deleted.

Loading

0 comments on commit a572300

Please sign in to comment.