Files
Libation/Source/_Tests/AudibleUtilities.Tests/FindAuthenticationRequiredTests.cs
T
Cursor Agentandrmcrackan 0f4cfac3b0 Name the account and the real cause when auto-scan pauses for a login
Ported from #1949. The reporter's log paused auto-scan on a second account that
had never been logged in, while the dialog blamed an expired session and named no
account, so there was nothing to act on.

AccountCredentialStatus tells a never-registered account apart from one holding an
expired access token, by looking for a refresh token to renew from. AutoScanRunner
now hands the AuthenticationRequiredException to the notification so the prompt can
name the account, which means digging that exception back out of the wrappers the
scan adds on the way up. Same distinction in the log line and in the exception
message ApiExtended throws when interactive login is unavailable, which is what the
CLI and Docker users see.

Co-authored-by: rmcrackan <rmcrackan@gmail.com>
2026-08-16 16:55:46 +00:00

47 lines
1.6 KiB
C#

using AssertionHelper;
using AudibleUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace AudibleUtilities.Tests;
/// <summary>
/// The scan wraps failures on the way up, so the exception that knows which account needs a login has to be dug
/// back out before the auto-scan dialog can name it.
/// </summary>
[TestClass]
public class FindAuthenticationRequiredTests
{
[TestMethod]
public void the_exception_itself_is_returned()
{
var auth = new AuthenticationRequiredException(new Account("user@example.com"));
AuthenticationExceptionHelper.FindAuthenticationRequired(auth).Should().BeSameAs(auth);
}
[TestMethod]
public void a_wrapped_exception_is_found()
{
var auth = new AuthenticationRequiredException(new Account("user@example.com"), "need login");
var wrapped = new Exception("Error importing library", new Exception("inner", auth));
AuthenticationExceptionHelper.FindAuthenticationRequired(wrapped).Should().BeSameAs(auth);
}
/// <summary>Scanning several accounts at once surfaces failures as an AggregateException.</summary>
[TestMethod]
public void an_aggregated_exception_is_found()
{
var auth = new AuthenticationRequiredException(new Account("user@example.com"), "need login");
var aggregate = new AggregateException(new InvalidOperationException("unrelated"), auth);
AuthenticationExceptionHelper.FindAuthenticationRequired(aggregate).Should().BeSameAs(auth);
}
[TestMethod]
public void an_unrelated_exception_yields_nothing()
=> AuthenticationExceptionHelper.FindAuthenticationRequired(new InvalidOperationException("unrelated"))
.Should().BeNull();
}