Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/SFBaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2012-2021 Snowflake Computing Inc. All rights reserved.
*/

Expand Down
85 changes: 70 additions & 15 deletions Snowflake.Data.Tests/UnitTests/HttpUtilTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
*/

using System.Net.Http;
using NUnit.Framework;
using Snowflake.Data.Core;
using RichardSzalay.MockHttp;
using System.Threading.Tasks;
using System.Net;
using System;

namespace Snowflake.Data.Tests.UnitTests
{
using NUnit.Framework;
using Snowflake.Data.Core;
using RichardSzalay.MockHttp;
using System.Threading.Tasks;
using System.Net;
using System;

[TestFixture]
class HttpUtilTest
{
Expand Down Expand Up @@ -102,48 +101,104 @@ public void TestGetJitter(int seconds)
}

[Test]
public void ShouldCreateHttpClientHandlerWithProxy()
public void TestCreateHttpClientHandlerWithExplicitProxy([Values] bool allowEmptyProxy)
{
// given
var config = new HttpClientConfig(
true,
allowEmptyProxy,
true,
"snowflake.com",
"123",
"testUser",
"proxyPassword",
"localhost",
"localhost",
false,
false,
7
);

// when
var handler = (HttpClientHandler) HttpUtil.Instance.SetupCustomHttpHandler(config);

// then
Assert.IsTrue(handler.UseProxy);
Assert.IsNotNull(handler.Proxy);
}

[Test]
public void ShouldCreateHttpClientHandlerWithoutProxy()
public void TestCreateHttpClientHandlerWithImplicitProxy()
{
// given
var config = new HttpClientConfig(
true,
true,
true,
null,
null,
null,
null,
null,
false,
false,
7
);

// when
var handler = (HttpClientHandler) HttpUtil.Instance.SetupCustomHttpHandler(config);

// then
Assert.IsTrue(handler.UseProxy);
Assert.IsNull(handler.Proxy);
}

[Test]
public void TestDoNotCreateHttpClientHandlerWithImplicitProxyWhenEmptyProxyNotAllowed()
{
// given
var config = new HttpClientConfig(
true,
false,
true,
null,
null,
null,
null,
null,
null,
false,
false,
7
);

// when
var handler = (HttpClientHandler) HttpUtil.Instance.SetupCustomHttpHandler(config);

// then
Assert.IsFalse(handler.UseProxy);
Assert.IsNull(handler.Proxy);
}

[Test]
public void ShouldCreateHttpClientHandlerWithoutProxy([Values] bool allowEmptyProxy)
{
// given
var config = new HttpClientConfig(
false,
allowEmptyProxy,
false,
null,
null,
null,
null,
null,
false,
false,
0
);

// when
var handler = (HttpClientHandler) HttpUtil.Instance.SetupCustomHttpHandler(config);

// then
Assert.IsFalse(handler.UseProxy);
Assert.IsNull(handler.Proxy);
Expand Down
49 changes: 37 additions & 12 deletions Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ public void TestResolveConnectionArea(string host, string expectedMessage)
Assert.AreEqual(expectedMessage, message);
}

[Test]
[TestCase("ACCOUNT=account;USER=test;PASSWORD=test;ALLOWEMPTYPROXY=false", "false")]
[TestCase("ACCOUNT=account;USER=test;PASSWORD=test;ALLOWEMPTYPROXY=true", "true")]
[TestCase("ACCOUNT=account;USER=test;PASSWORD=test", "false")]
public void TestParseAllowEmptyProxy(string connectionString, string expectedAllowEmptyProxy)
{
// act
var properties = SFSessionProperties.ParseConnectionString(connectionString, null);

// assert
Assert.AreEqual(expectedAllowEmptyProxy, properties[SFSessionProperty.ALLOWEMPTYPROXY]);
}

public static IEnumerable<TestCase> ConnectionStringTestCases()
{
string defAccount = "testaccount";
Expand Down Expand Up @@ -222,7 +235,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
}
};

Expand Down Expand Up @@ -258,7 +272,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
}
};
var testCaseWithProxySettings = new TestCase()
Expand Down Expand Up @@ -296,7 +311,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
},
ConnectionString =
$"ACCOUNT={defAccount};USER={defUser};PASSWORD={defPassword};useProxy=true;proxyHost=proxy.com;proxyPort=1234;nonProxyHosts=localhost"
Expand Down Expand Up @@ -336,7 +352,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
},
ConnectionString =
$"ACCOUNT={defAccount};USER={defUser};PASSWORD={defPassword};proxyHost=proxy.com;proxyPort=1234;nonProxyHosts=localhost"
Expand Down Expand Up @@ -375,7 +392,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
}
};
var testCaseWithIncludeRetryReason = new TestCase()
Expand Down Expand Up @@ -411,7 +429,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
}
};
var testCaseWithDisableQueryContextCache = new TestCase()
Expand Down Expand Up @@ -446,7 +465,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
},
ConnectionString =
$"ACCOUNT={defAccount};USER={defUser};PASSWORD={defPassword};DISABLEQUERYCONTEXTCACHE=true"
Expand Down Expand Up @@ -483,7 +503,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
},
ConnectionString =
$"ACCOUNT={defAccount};USER={defUser};PASSWORD={defPassword};DISABLE_CONSOLE_LOGIN=false"
Expand Down Expand Up @@ -522,7 +543,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
}
};
var testCaseUnderscoredAccountName = new TestCase()
Expand Down Expand Up @@ -558,7 +580,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
}
};
var testCaseUnderscoredAccountNameWithEnabledAllowUnderscores = new TestCase()
Expand Down Expand Up @@ -594,7 +617,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
}
};
var testQueryTag = "Test QUERY_TAG 12345";
Expand Down Expand Up @@ -632,7 +656,8 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
{ SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT, DefaultValue(SFSessionProperty.WAITINGFORIDLESESSIONTIMEOUT) },
{ SFSessionProperty.EXPIRATIONTIMEOUT, DefaultValue(SFSessionProperty.EXPIRATIONTIMEOUT) },
{ SFSessionProperty.POOLINGENABLED, DefaultValue(SFSessionProperty.POOLINGENABLED) },
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) }
{ SFSessionProperty.DISABLE_SAML_URL_CHECK, DefaultValue(SFSessionProperty.DISABLE_SAML_URL_CHECK) },
{ SFSessionProperty.ALLOWEMPTYPROXY, DefaultValue(SFSessionProperty.ALLOWEMPTYPROXY) }
}
};

Expand Down
Loading