Skip to content

Commit 2826f59

Browse files
committed
More unit tests for AuthErrorHandler
1 parent ba8a27d commit 2826f59

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

FirebaseAdmin/FirebaseAdmin.Tests/Auth/AuthErrorHandlerTest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using System;
1516
using System.Collections.Generic;
1617
using System.Net;
1718
using System.Net.Http;
1819
using System.Text;
20+
using FirebaseAdmin.Util;
1921
using Xunit;
2022

2123
namespace FirebaseAdmin.Auth.Tests
@@ -190,5 +192,43 @@ public void NonJson()
190192
Assert.Same(resp, error.HttpResponse);
191193
Assert.Null(error.InnerException);
192194
}
195+
196+
[Fact]
197+
public void DeserializeException()
198+
{
199+
var text = "plain text";
200+
var resp = new HttpResponseMessage()
201+
{
202+
StatusCode = HttpStatusCode.ServiceUnavailable,
203+
Content = new StringContent(text, Encoding.UTF8, "text/plain"),
204+
};
205+
var inner = new Exception("Deserialization error");
206+
207+
var error = AuthErrorHandler.Instance.HandleDeserializeException(
208+
inner, new ResponseInfo(resp, text));
209+
210+
Assert.Equal(ErrorCode.Unknown, error.ErrorCode);
211+
Assert.Equal(
212+
$"Error while parsing Auth service response. Deserialization error: {text}",
213+
error.Message);
214+
Assert.Equal(AuthErrorCode.UnexpectedResponse, error.AuthErrorCode);
215+
Assert.Same(resp, error.HttpResponse);
216+
Assert.Same(inner, error.InnerException);
217+
}
218+
219+
[Fact]
220+
public void HttpRequestException()
221+
{
222+
var exception = new HttpRequestException("network error");
223+
224+
var error = AuthErrorHandler.Instance.HandleHttpRequestException(exception);
225+
226+
Assert.Equal(ErrorCode.Unknown, error.ErrorCode);
227+
Assert.Equal(
228+
"Unknown error while making a remote service call: network error", error.Message);
229+
Assert.Null(error.AuthErrorCode);
230+
Assert.Null(error.HttpResponse);
231+
Assert.Same(exception, error.InnerException);
232+
}
193233
}
194234
}

FirebaseAdmin/FirebaseAdmin.Tests/Auth/FirebaseUserManagerTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,11 @@ public async Task ListUsersNonJsonResponse()
733733

734734
Assert.Equal(ErrorCode.Unknown, exception.ErrorCode);
735735
Assert.Equal(AuthErrorCode.UnexpectedResponse, exception.AuthErrorCode);
736+
Assert.NotNull(exception.InnerException);
736737
Assert.Equal(
737-
"Error while parsing Auth service response: not json",
738+
$"Error while parsing Auth service response. {exception.InnerException.Message}: not json",
738739
exception.Message);
739740
Assert.NotNull(exception.HttpResponse);
740-
Assert.NotNull(exception.InnerException);
741741

742742
Assert.Single(handler.Requests);
743743
var query = this.ExtractQueryParams(handler.Requests[0]);

FirebaseAdmin/FirebaseAdmin/Auth/AuthErrorHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public FirebaseAuthException HandleDeserializeException(
8383
{
8484
return new FirebaseAuthException(
8585
ErrorCode.Unknown,
86-
$"Error while parsing Auth service response: {responseInfo.Body}",
86+
$"Error while parsing Auth service response. {exception.Message}: {responseInfo.Body}",
8787
AuthErrorCode.UnexpectedResponse,
8888
inner: exception,
8989
response: responseInfo.HttpResponse);

0 commit comments

Comments
 (0)