-
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.
- Loading branch information
1 parent
7e1060c
commit 0fd4856
Showing
4 changed files
with
154 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2024 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
|
||
using Newtonsoft.Json; | ||
using Snowflake.Data.Core; | ||
using Snowflake.Data.Core.Authenticator; | ||
using System; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Snowflake.Data.Tests.Mock | ||
{ | ||
|
||
class MockOktaRetryMaxTimeout : RestRequester, IMockRestRequester | ||
{ | ||
internal bool _forceTimeoutForNonLoginRequestsOnly = false; | ||
internal int _maxRetryCount; | ||
internal int _maxRetryTimeout; | ||
|
||
public MockOktaRetryMaxTimeout(int maxRetryCount, int maxRetryTimeout) : base(null) | ||
{ | ||
_maxRetryCount = maxRetryCount; | ||
_maxRetryTimeout = maxRetryTimeout; | ||
} | ||
|
||
public void setHttpClient(HttpClient httpClient) | ||
{ | ||
_HttpClient = httpClient; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage message, | ||
TimeSpan restTimeout, | ||
CancellationToken externalCancellationToken, | ||
string sid = "") | ||
{ | ||
if (HttpUtil.IsOktaSSORequest(message.RequestUri.Host, message.RequestUri.AbsolutePath)) | ||
{ | ||
var mockContent = new StringContent(JsonConvert.SerializeObject("<form=error}"), Encoding.UTF8, "application/json"); | ||
mockContent.Headers.Add(OktaAuthenticator.RetryCountHeader, _maxRetryCount.ToString()); | ||
mockContent.Headers.Add(OktaAuthenticator.TimeoutElapsedHeader, _maxRetryTimeout.ToString()); | ||
|
||
return new HttpResponseMessage | ||
{ | ||
StatusCode = System.Net.HttpStatusCode.OK, | ||
Content = mockContent | ||
}; | ||
} | ||
|
||
return await base.SendAsync(message, restTimeout, externalCancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} |
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