1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-01-02 06:31:51 +02:00

Fixed: Prevent exception for seed configuration provider with invalid indexer ID

This commit is contained in:
Bogdan 2024-12-21 13:52:27 +02:00 committed by Mark McDowall
parent ce7d8a175e
commit f7b54f9d6b
2 changed files with 39 additions and 6 deletions

View File

@ -22,7 +22,7 @@ public void should_not_return_config_for_non_existent_indexer()
var result = Subject.GetSeedConfiguration(new RemoteEpisode
{
Release = new ReleaseInfo()
Release = new ReleaseInfo
{
DownloadProtocol = DownloadProtocol.Torrent,
IndexerId = 0
@ -32,6 +32,29 @@ public void should_not_return_config_for_non_existent_indexer()
result.Should().BeNull();
}
[Test]
public void should_not_return_config_for_invalid_indexer()
{
Mocker.GetMock<ICachedIndexerSettingsProvider>()
.Setup(v => v.GetSettings(It.IsAny<int>()))
.Returns<CachedIndexerSettings>(null);
var result = Subject.GetSeedConfiguration(new RemoteEpisode
{
Release = new ReleaseInfo
{
DownloadProtocol = DownloadProtocol.Torrent,
IndexerId = 1
},
ParsedEpisodeInfo = new ParsedEpisodeInfo
{
FullSeason = true
}
});
result.Should().BeNull();
}
[Test]
public void should_return_season_time_for_season_packs()
{
@ -48,7 +71,7 @@ public void should_return_season_time_for_season_packs()
var result = Subject.GetSeedConfiguration(new RemoteEpisode
{
Release = new ReleaseInfo()
Release = new ReleaseInfo
{
DownloadProtocol = DownloadProtocol.Torrent,
IndexerId = 1

View File

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.ThingiProvider.Events;
@ -12,8 +14,10 @@ public interface ICachedIndexerSettingsProvider
CachedIndexerSettings GetSettings(int indexerId);
}
public class CachedIndexerSettingsProvider : ICachedIndexerSettingsProvider, IHandle<ProviderUpdatedEvent<IIndexer>>
public class CachedIndexerSettingsProvider : ICachedIndexerSettingsProvider, IHandle<ProviderUpdatedEvent<IIndexer>>, IHandle<ProviderDeletedEvent<IIndexer>>
{
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(CachedIndexerSettingsProvider));
private readonly IIndexerFactory _indexerFactory;
private readonly ICached<CachedIndexerSettings> _cache;
@ -35,11 +39,12 @@ public CachedIndexerSettings GetSettings(int indexerId)
private CachedIndexerSettings FetchIndexerSettings(int indexerId)
{
var indexer = _indexerFactory.Get(indexerId);
var indexerSettings = indexer.Settings as IIndexerSettings;
var indexer = _indexerFactory.Find(indexerId);
if (indexerSettings == null)
if (indexer?.Settings is not IIndexerSettings indexerSettings)
{
Logger.Trace("Could not load settings for indexer ID: {0}", indexerId);
return null;
}
@ -60,6 +65,11 @@ public void Handle(ProviderUpdatedEvent<IIndexer> message)
{
_cache.Clear();
}
public void Handle(ProviderDeletedEvent<IIndexer> message)
{
_cache.Clear();
}
}
public class CachedIndexerSettings