Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SNOW-1050418] OktaAuthenticator refactor part1 #858

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

using System.Data.Common;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.IntegrationTests
{
Expand Down
1 change: 1 addition & 0 deletions Snowflake.Data.Tests/Mock/MockOkta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Snowflake.Data.Core.Authenticator.Okta.Models;

namespace Snowflake.Data.Tests.Mock
{
Expand Down
1 change: 1 addition & 0 deletions Snowflake.Data.Tests/Mock/MockSnowflakeDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.Mock
{
Expand Down
1 change: 1 addition & 0 deletions Snowflake.Data.Tests/UnitTests/ArrowResultSetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Apache.Arrow.Ipc;
using NUnit.Framework;
using Snowflake.Data.Core;
using Snowflake.Data.Core.Session;
using Snowflake.Data.Tests.Util;

namespace Snowflake.Data.Tests.UnitTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright (c) 2023 Snowflake Computing Inc. All rights reserved.
*/

using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests
{
using NUnit.Framework;
Expand Down
33 changes: 17 additions & 16 deletions Snowflake.Data.Tests/UnitTests/ChunkStreamingParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
* Copyright (c) 2023 Snowflake Computing Inc. All rights reserved.
*/

using Snowflake.Data.Core;

namespace Snowflake.Data.Tests.UnitTests
{
using NUnit.Framework;
using Snowflake.Data.Client;
using Client;
using Snowflake.Data.Configuration;
using Snowflake.Data.Core;
using System;
using System.IO;
using System.Text;
Expand All @@ -31,19 +32,12 @@ public void AfterTest()
SFConfiguration.Instance().ChunkParserVersion = _chunkParserVersionDefault; // Return to default version
}

public IChunkParser getParser(string data)
{
byte[] bytes = Encoding.UTF8.GetBytes(data);
Stream stream = new MemoryStream(bytes);
return ChunkParserFactory.Instance.GetParser(ResultFormat.JSON, stream);
}

[Test]
public async Task TestParsingEmptyChunk()
{
// Create sample data for parser
string data = "[ ]";
IChunkParser parser = getParser(data);
IChunkParser parser = GetParser(data);

SFResultChunk chunk = new SFResultChunk(new string[0, 0]);

Expand All @@ -60,7 +54,7 @@ public async Task TestParsingEmptyArraysInChunk()
{
// Create sample data for parser
string data = "[ [], [] ]";
IChunkParser parser = getParser(data);
IChunkParser parser = GetParser(data);

SFResultChunk chunk = new SFResultChunk(new string[2, 0]);

Expand All @@ -77,7 +71,7 @@ public async Task TestParsingNonJsonArrayChunk()
{
// Create a sample data using data not contained in an array
string data = "[ \"1\", \"1.234\", \"abcde\" ]";
IChunkParser parser = getParser(data);
IChunkParser parser = GetParser(data);

SFResultChunk chunk = new SFResultChunk(new string[1, 3]);

Expand All @@ -95,7 +89,7 @@ public void TestThrowingExceptionOnUsupportedNestedJsonArrays()
{
// Create a sample data using non-array data and an array
string data = "[ \"1\", \"1.234\", \"abcde\", [\"2\", \"5.678\", \"fghi\"] ]";
IChunkParser parser = getParser(data);
IChunkParser parser = GetParser(data);

SFResultChunk chunk = new SFResultChunk(new string[1, 3]);

Expand All @@ -108,7 +102,7 @@ public void TestThrowingExceptionForJsonObjectElementsInAnArray()
{
// Create a sample data using JSON objects instead
string data = "[ {\"1\", \"1.234\", \"abcde\"}, {\"2\", \"5.678\", \"fghi\"} ]";
IChunkParser parser = getParser(data);
IChunkParser parser = GetParser(data);

SFResultChunk chunk = new SFResultChunk(new string[2, 3]);

Expand All @@ -122,7 +116,7 @@ public async Task TestParsingSimpleChunk()
{
// Create sample data for parser
string data = "[ [\"1\", \"1.234\", \"abcde\"], [\"2\", \"5.678\", \"fghi\"] ]";
IChunkParser parser = getParser(data);
IChunkParser parser = GetParser(data);

SFResultChunk chunk = new SFResultChunk(new string[2, 3]);

Expand All @@ -144,7 +138,7 @@ public async Task TestParsingChunkWithNullValue()
{
// Create sample data that contain null values
string data = "[ [null, \"1.234\", null], [\"2\", null, \"fghi\"] ]";
IChunkParser parser = getParser(data);
IChunkParser parser = GetParser(data);

SFResultChunk chunk = new SFResultChunk(new string[2, 3]);

Expand All @@ -160,5 +154,12 @@ public async Task TestParsingChunkWithNullValue()
Assert.AreEqual(null, chunk.ExtractCell(1).SafeToString());
Assert.AreEqual("fghi", chunk.ExtractCell(2).SafeToString());
}

private static IChunkParser GetParser(string data)
{
byte[] bytes = Encoding.UTF8.GetBytes(data);
Stream stream = new MemoryStream(bytes);
return ChunkParserFactory.Instance.GetParser(ResultFormat.JSON, stream);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Security;
using NUnit.Framework;
using Snowflake.Data.Core.Authenticator.Okta;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests.Core.Authenticator.Okta
{
public class IdpTokenRestRequestFactoryTests
{
private IdpTokenRestRequestFactory _idpTokenRestRequestFactory;

[SetUp]
public void SetUp()
{
_idpTokenRestRequestFactory = new IdpTokenRestRequestFactory();
}

[Test]
public void TestIfCreateCorrectRequest()
{
// arrange
var tokenUrl = new Uri("https://test.com/");
var session = new SFSession("ACCOUNT=account;USER=username1;", new SecureString());

// act
var actual = _idpTokenRestRequestFactory.Create(tokenUrl, session);

// assert
Assert.AreEqual(tokenUrl, actual.Url);
Assert.AreEqual(session.connectionTimeout, actual.RestTimeout);
Assert.AreEqual(TimeSpan.FromSeconds(16), actual.HttpTimeout);
Assert.AreEqual("username1", actual.JsonBody.Username);
Assert.AreEqual("", actual.JsonBody.Password);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Threading;
using NUnit.Framework;
using Snowflake.Data.Core.Authenticator.Okta;

namespace Snowflake.Data.Tests.UnitTests.Core.Authenticator.Okta
{
public class SamlRestRequestFactoryTests
{
private ISamlRestRequestFactory _samlRestRequestFactory;

[SetUp]
public void SetUp()
{
_samlRestRequestFactory = new SamlRestRequestFactory();
}

[Test]
public void TestIfCorrectSamlRestRequestIsCreated()
{
// arrange
var uri = new Uri("https://test.com");
var onetimeToken = Guid.NewGuid().ToString();
var timeout = TimeSpan.Parse("00:10:00");

// act
var actual = _samlRestRequestFactory.Create(uri, onetimeToken, timeout);

// assert
Assert.AreEqual(uri, actual.Url);
Assert.AreEqual(timeout, actual.RestTimeout);
Assert.AreEqual(Timeout.InfiniteTimeSpan, actual.HttpTimeout);
Assert.AreEqual(onetimeToken, actual.OnetimeToken);
}
}
}
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/UnitTests/FastMemoryStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Snowflake.Data.Tests.UnitTests
[TestFixture]
class FastMemoryStreamTest
{
FastMemoryStream _fastMemoryStream;
private FastMemoryStream _fastMemoryStream;

[SetUp]
public void BeforeTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using NUnit.Framework;
using Snowflake.Data.Core.FileTransfer;

namespace Snowflake.Data.Tests
namespace Snowflake.Data.Tests.UnitTests
{
public class FileBackedOutputStreamTest
{
Expand Down
7 changes: 3 additions & 4 deletions Snowflake.Data.Tests/UnitTests/Logger/SFLoggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* Copyright (c) 2023 Snowflake Computing Inc. All rights reserved.
*/

using NUnit.Framework;
using Snowflake.Data.Configuration;
using Snowflake.Data.Log;

namespace Snowflake.Data.Tests.UnitTests
namespace Snowflake.Data.Tests.UnitTests.Logger
{
using NUnit.Framework;
using Snowflake.Data.Log;

[TestFixture, NonParallelizable]
class SFLoggerTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

using Snowflake.Data.Core.Authenticator.Okta;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests
{
using NUnit.Framework;
Expand All @@ -25,7 +28,7 @@ private IAuthenticator GetAuthenticator(string authenticatorName, string extraPa
[Test]
public void TestGetAuthenticatorBasic()
{
_authenticator = GetAuthenticator(BasicAuthenticator.AUTH_NAME);
_authenticator = GetAuthenticator(BasicAuthenticator.AuthName);
Assert.IsInstanceOf<BasicAuthenticator>(_authenticator);
}

Expand Down
15 changes: 8 additions & 7 deletions Snowflake.Data.Tests/UnitTests/SFDbParameterCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

namespace Snowflake.Data.Tests
using System;
using System.Collections;
using NUnit.Framework;
using Snowflake.Data.Client;
using Snowflake.Data.Core;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests
{
using NUnit.Framework;
using Snowflake.Data.Client;
using Snowflake.Data.Core;
using System;
using System.Collections;

[TestFixture]
class SFDbParameterCollectionTest
{
Expand Down
13 changes: 7 additions & 6 deletions Snowflake.Data.Tests/UnitTests/SFDbParameterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

namespace Snowflake.Data.Tests
{
using NUnit.Framework;
using Snowflake.Data.Client;
using Snowflake.Data.Core;
using System.Data;
using System.Data;
using NUnit.Framework;
using Snowflake.Data.Client;
using Snowflake.Data.Core;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests
{
[TestFixture]
class SFDbParameterTest
{
Expand Down
3 changes: 3 additions & 0 deletions Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

using Snowflake.Data.Core.FileTransfer.StorageClient;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests
{
using NUnit.Framework;
Expand Down
1 change: 1 addition & 0 deletions Snowflake.Data.Tests/UnitTests/SFOktaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Snowflake.Data.Client;
using Snowflake.Data.Core;
using System.Net.Http;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests
{
Expand Down
1 change: 1 addition & 0 deletions Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

using System;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests
{
Expand Down
7 changes: 4 additions & 3 deletions Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NUnit.Framework;
using Snowflake.Data.Client;
using Snowflake.Data.Core.Authenticator;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Tests.UnitTests
{
Expand All @@ -18,7 +19,7 @@ class SFSessionPropertyTest
public void TestThatPropertiesAreParsed(TestCase testcase)
{
// act
var properties = SFSessionProperties.parseConnectionString(
var properties = SFSessionProperties.ParseConnectionString(
testcase.ConnectionString,
testcase.SecurePassword);

Expand All @@ -36,7 +37,7 @@ public void TestThatItFailsForWrongConnectionParameter(string connectionString,
{
// act
var exception = Assert.Throws<SnowflakeDbException>(
() => SFSessionProperties.parseConnectionString(connectionString, null)
() => SFSessionProperties.ParseConnectionString(connectionString, null)
);

// assert
Expand All @@ -51,7 +52,7 @@ public void TestThatItFailsIfNoAccountSpecified(string connectionString)
{
// act
var exception = Assert.Throws<SnowflakeDbException>(
() => SFSessionProperties.parseConnectionString(connectionString, null)
() => SFSessionProperties.ParseConnectionString(connectionString, null)
);

// assert
Expand Down
3 changes: 2 additions & 1 deletion Snowflake.Data.Tests/UnitTests/SFSessionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

using Snowflake.Data.Configuration;
using Snowflake.Data.Core.Session;
using Snowflake.Data.Log;

namespace Snowflake.Data.Tests.UnitTests
Expand All @@ -20,7 +21,7 @@ public void TestSessionGoneWhenClose()
Mock.MockCloseSessionGone restRequester = new Mock.MockCloseSessionGone();
SFSession sfSession = new SFSession("account=test;user=test;password=test", null, restRequester);
sfSession.Open();
sfSession.close(); // no exception is raised.
sfSession.Close(); // no exception is raised.
}

[Test]
Expand Down
Loading
Loading