< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.PreStartupRoutines.CreateNetworkConfiguration
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 28
Coverable lines: 28
Total lines: 131
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/27) Branch coverage: 0% (0/8) Total lines: 12911/13/2026 - 12:19:51 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/8) Total lines: 131 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/27) Branch coverage: 0% (0/8) Total lines: 12911/13/2026 - 12:19:51 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/8) Total lines: 131

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
PerformAsync(...)0%620%
.ctor()100%210%
get_BaseUrl()100%210%
set_BaseUrl(...)0%4260%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Threading;
 4using System.Threading.Tasks;
 5using System.Xml;
 6using System.Xml.Serialization;
 7using Emby.Server.Implementations;
 8using Microsoft.Extensions.Logging;
 9
 10namespace Jellyfin.Server.Migrations.PreStartupRoutines;
 11
 12/// <inheritdoc />
 13[JellyfinMigration("2025-04-20T00:00:00", nameof(CreateNetworkConfiguration), "9B354818-94D5-4B68-AC49-E35CB85F9D84", St
 14public class CreateNetworkConfiguration : IAsyncMigrationRoutine
 15{
 16    private readonly ServerApplicationPaths _applicationPaths;
 17    private readonly ILogger<CreateNetworkConfiguration> _logger;
 18
 19    /// <summary>
 20    /// Initializes a new instance of the <see cref="CreateNetworkConfiguration"/> class.
 21    /// </summary>
 22    /// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
 23    /// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
 24    public CreateNetworkConfiguration(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
 25    {
 026        _applicationPaths = applicationPaths;
 027        _logger = loggerFactory.CreateLogger<CreateNetworkConfiguration>();
 028    }
 29
 30    /// <inheritdoc />
 31    public Task PerformAsync(CancellationToken cancellationToken)
 32    {
 033        string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "network.xml");
 034        if (File.Exists(path))
 35        {
 036            _logger.LogDebug("Network configuration file already exists, skipping");
 037            return Task.CompletedTask;
 38        }
 39
 040        var serverConfigSerializer = new XmlSerializer(typeof(OldNetworkConfiguration), new XmlRootAttribute("ServerConf
 041        using var xmlReader = XmlReader.Create(_applicationPaths.SystemConfigurationFilePath);
 042        var networkSettings = serverConfigSerializer.Deserialize(xmlReader);
 43
 044        var networkConfigSerializer = new XmlSerializer(typeof(OldNetworkConfiguration), new XmlRootAttribute("NetworkCo
 045        var xmlWriterSettings = new XmlWriterSettings { Indent = true };
 046        using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
 047        networkConfigSerializer.Serialize(xmlWriter, networkSettings);
 48
 049        return Task.CompletedTask;
 050    }
 51
 52#pragma warning disable
 53    public sealed class OldNetworkConfiguration
 54    {
 55        public const int DefaultHttpPort = 8096;
 56
 57        public const int DefaultHttpsPort = 8920;
 58
 059        private string _baseUrl = string.Empty;
 60
 61        public bool RequireHttps { get; set; }
 62
 63        public string CertificatePath { get; set; } = string.Empty;
 64
 65        public string CertificatePassword { get; set; } = string.Empty;
 66
 67        public string BaseUrl
 68        {
 069            get => _baseUrl;
 70            set
 71            {
 72                // Normalize the start of the string
 073                if (string.IsNullOrWhiteSpace(value))
 74                {
 75                    // If baseUrl is empty, set an empty prefix string
 076                    _baseUrl = string.Empty;
 077                    return;
 78                }
 79
 080                if (value[0] != '/')
 81                {
 82                    // If baseUrl was not configured with a leading slash, append one for consistency
 083                    value = "/" + value;
 84                }
 85
 86                // Normalize the end of the string
 087                if (value[^1] == '/')
 88                {
 89                    // If baseUrl was configured with a trailing slash, remove it for consistency
 090                    value = value.Remove(value.Length - 1);
 91                }
 92
 093                _baseUrl = value;
 094            }
 95        }
 96
 97        public int PublicHttpsPort { get; set; } = DefaultHttpsPort;
 98
 99        public int HttpServerPortNumber { get; set; } = DefaultHttpPort;
 100
 101        public int HttpsPortNumber { get; set; } = DefaultHttpsPort;
 102
 103        public bool EnableHttps { get; set; }
 104
 105        public int PublicPort { get; set; } = DefaultHttpPort;
 106
 107        public bool EnableIPV6 { get; set; }
 108
 109        public bool EnableIPV4 { get; set; } = true;
 110
 111        public bool IgnoreVirtualInterfaces { get; set; } = true;
 112
 0113        public string[] VirtualInterfaceNames { get; set; } = new string[] { "veth" };
 114
 115        public string[] PublishedServerUriBySubnet { get; set; } = Array.Empty<string>();
 116
 117        public string[] RemoteIPFilter { get; set; } = Array.Empty<string>();
 118
 119        public bool IsRemoteIPFilterBlacklist { get; set; }
 120
 121        public bool EnableUPnP { get; set; }
 122
 123        public bool EnableRemoteAccess { get; set; } = true;
 124
 125        public string[] LocalNetworkSubnets { get; set; } = Array.Empty<string>();
 126
 127        public string[] LocalNetworkAddresses { get; set; } = Array.Empty<string>();
 128
 129        public string[] KnownProxies { get; set; } = Array.Empty<string>();
 130    }
 131}