-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-715504: MFA token cache support (#988)
Co-authored-by: Krzysztof Nozderko <[email protected]>
- Loading branch information
1 parent
27b0ae4
commit c45f1ad
Showing
61 changed files
with
2,745 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Snowflake.Data.Tests/Mock/MockLoginMFATokenCacheRestRequester.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Snowflake.Data.Core; | ||
|
||
namespace Snowflake.Data.Tests.Mock | ||
{ | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
class MockLoginMFATokenCacheRestRequester: IMockRestRequester | ||
{ | ||
internal Queue<LoginRequest> LoginRequests { get; } = new(); | ||
|
||
internal Queue<LoginResponseData> LoginResponses { get; } = new(); | ||
|
||
public T Get<T>(IRestRequest request) | ||
{ | ||
return Task.Run(async () => await (GetAsync<T>(request, CancellationToken.None)).ConfigureAwait(false)).Result; | ||
} | ||
|
||
public Task<T> GetAsync<T>(IRestRequest request, CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<T>((T)(object)null); | ||
} | ||
|
||
public Task<HttpResponseMessage> GetAsync(IRestRequest request, CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<HttpResponseMessage>(null); | ||
} | ||
|
||
public HttpResponseMessage Get(IRestRequest request) | ||
{ | ||
return null; | ||
} | ||
|
||
public T Post<T>(IRestRequest postRequest) | ||
{ | ||
return Task.Run(async () => await (PostAsync<T>(postRequest, CancellationToken.None)).ConfigureAwait(false)).Result; | ||
} | ||
|
||
public Task<T> PostAsync<T>(IRestRequest postRequest, CancellationToken cancellationToken) | ||
{ | ||
SFRestRequest sfRequest = (SFRestRequest)postRequest; | ||
if (sfRequest.jsonBody is LoginRequest) | ||
{ | ||
LoginRequests.Enqueue((LoginRequest) sfRequest.jsonBody); | ||
var responseData = this.LoginResponses.IsNullOrEmpty() ? new LoginResponseData() | ||
{ | ||
token = "session_token", | ||
masterToken = "master_token", | ||
authResponseSessionInfo = new SessionInfo(), | ||
nameValueParameter = new List<NameValueParameter>() | ||
} : this.LoginResponses.Dequeue(); | ||
var authnResponse = new LoginResponse | ||
{ | ||
data = responseData, | ||
success = true | ||
}; | ||
|
||
// login request return success | ||
return Task.FromResult<T>((T)(object)authnResponse); | ||
} | ||
else if (sfRequest.jsonBody is CloseResponse) | ||
{ | ||
var authnResponse = new CloseResponse() | ||
{ | ||
success = true | ||
}; | ||
|
||
// login request return success | ||
return Task.FromResult<T>((T)(object)authnResponse); | ||
} | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void setHttpClient(HttpClient httpClient) | ||
{ | ||
// Nothing to do | ||
} | ||
|
||
public void Reset() | ||
{ | ||
LoginRequests.Clear(); | ||
LoginResponses.Clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.