Skip to content

Commit

Permalink
chore: add disposable token testing (#495)
Browse files Browse the repository at this point in the history
* chore: add disposable token testing

* fix: remove stray comment
  • Loading branch information
pgautier404 authored Sep 20, 2023
1 parent c99391f commit d257585
Show file tree
Hide file tree
Showing 4 changed files with 919 additions and 31 deletions.
26 changes: 20 additions & 6 deletions src/Momento.Sdk/Internal/ScsTokenClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ScsTokenClient(IAuthConfiguration config, string authToken, string endpoi
this._exceptionMapper = new CacheExceptionMapper(config.LoggerFactory);
}

protected DateTime CalculateDeadline()
private DateTime CalculateDeadline()
{
return DateTime.UtcNow.Add(authClientOperationTimeout);
}
Expand All @@ -39,14 +39,28 @@ protected DateTime CalculateDeadline()
public async Task<GenerateDisposableTokenResponse> GenerateDisposableToken(
DisposableTokenScope scope, ExpiresIn expiresIn
) {
_GenerateDisposableTokenRequest request = new _GenerateDisposableTokenRequest
Permissions permissions;
try
{
permissions = PermissionsFromDisposableTokenScope(scope);
}
catch (ArgumentNullException e)
{
Expires = new _GenerateDisposableTokenRequest.Types.Expires() { ValidForSeconds = (uint)expiresIn.Seconds() },
AuthToken = this.authToken,
Permissions = PermissionsFromDisposableTokenScope(scope)
};
return _logger.LogTraceAuthRequestError(RequestTypeAuthGenerateDisposableToken,
new GenerateDisposableTokenResponse.Error(
new InvalidArgumentException("Permissions parameters may not be null", null, e)
)
);
}

try
{
_GenerateDisposableTokenRequest request = new _GenerateDisposableTokenRequest
{
Expires = new _GenerateDisposableTokenRequest.Types.Expires() { ValidForSeconds = (uint)expiresIn.Seconds() },
AuthToken = this.authToken,
Permissions = permissions
};
_logger.LogTraceExecutingAuthRequest(RequestTypeAuthGenerateDisposableToken);
var response = await grpcManager.Client.generateDisposableToken(
request, new CallOptions(deadline: CalculateDeadline())
Expand Down
Loading

0 comments on commit d257585

Please sign in to comment.