Skip to content

Commit

Permalink
Fixed failing test for authcallback returning tokenrequest or tokende…
Browse files Browse the repository at this point in the history
…tails
  • Loading branch information
sacOO7 committed Apr 16, 2024
1 parent c7b99f3 commit 29bb790
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -815,18 +815,18 @@ await Assert.ThrowsAsync<AblyException>(() =>
}

[Fact]
public async Task WhenCallbackReturnsAnObjectThatIsNotTokenRequestOrTokenDetails_ThrowsAblyException()
public async Task WhenAuthCallbackReturnsAnObjectThatIsNotTokenRequestOrTokenDetails_ThrowsAblyException()
{
var signedTokenRequest = await new AblyRest("fake.key:fakeid").Auth.CreateTokenRequestAsync();
// do not throw exceptions
var objects = new object[] { new TokenDetails(), new TokenRequest() };
string serializedTokenRequest = await new AblyRest("fake.key:fakeid").Auth.CreateTokenRequestAsync();
// do not throw exceptions for valid values in authCallback
var objects = new object[] { new TokenDetails(), new TokenRequest(), serializedTokenRequest };
foreach (var obj in objects)
{
var exception = await Record.ExceptionAsync(async () => await GetClient(_ => Task.FromResult<object>(obj)).StatsAsync());
var exception = await Record.ExceptionAsync(async () => await GetClient(_ => Task.FromResult(obj)).StatsAsync());
Assert.Null(exception);
}

// throw exceptions
// throw exceptions for invalid values in authCallback
objects = new[] { new object(), string.Empty, new Uri("http://test"), "jwtToken" };
foreach (var obj in objects)
{
Expand All @@ -846,7 +846,10 @@ private static AblyRest GetClient(Func<TokenParams, Task<object>> authCallback)
};

var rest = new AblyRest(options);
rest.ExecuteHttpRequest = delegate { return "[{}]".ToAblyResponse(); };
rest.ExecuteHttpRequest = arg => arg.Url.Contains("requestToken") ?
JsonHelper.Serialize(new TokenDetails()).ToAblyResponse() :
"[{}]".ToAblyResponse();

return rest;
}
}
Expand Down

0 comments on commit 29bb790

Please sign in to comment.