< Summary

Information
Class: System.Net.Http.PreAuthCredentialCache
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\PreAuthCredentialCache.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 28
Coverable lines: 28
Total lines: 61
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Add(...)0%440%
Remove(...)0%440%
GetCredential(...)0%880%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\PreAuthCredentialCache.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections;
 5using System.Collections.Generic;
 6using System.Diagnostics;
 7using System.Diagnostics.CodeAnalysis;
 8using System.Globalization;
 9
 10namespace System.Net.Http
 11{
 12    internal sealed class PreAuthCredentialCache
 13    {
 14        private Dictionary<CredentialCacheKey, NetworkCredential>? _cache;
 15
 16        public void Add(Uri uriPrefix, string authType, NetworkCredential cred)
 017        {
 018            Debug.Assert(uriPrefix != null);
 019            Debug.Assert(authType != null);
 20
 021            var key = new CredentialCacheKey(uriPrefix, authType);
 22
 023            if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"Adding key:[{key}], cred:[{cred.Domain}],[{c
 24
 025            _cache ??= new Dictionary<CredentialCacheKey, NetworkCredential>();
 026            _cache.Add(key, cred);
 027        }
 28
 29        public void Remove(Uri uriPrefix, string authType)
 030        {
 031            Debug.Assert(uriPrefix != null);
 032            Debug.Assert(authType != null);
 33
 034            if (_cache == null)
 035            {
 036                return;
 37            }
 38
 039            var key = new CredentialCacheKey(uriPrefix, authType);
 040            if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"Removing key:[{key}]");
 041            _cache.Remove(key);
 042        }
 43
 44        public (Uri uriPrefix, NetworkCredential credential)? GetCredential(Uri uriPrefix, string authType)
 045        {
 046            Debug.Assert(uriPrefix != null);
 047            Debug.Assert(authType != null);
 48
 049            if (_cache == null)
 050            {
 051                return null;
 52            }
 53
 054            CredentialCacheHelper.TryGetCredential(_cache, uriPrefix, authType, out Uri? mostSpecificMatchUri, out Netwo
 55
 056            if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"Returning {(mostSpecificMatch == null ? "nul
 57
 058            return mostSpecificMatch == null ? null : (mostSpecificMatchUri!, mostSpecificMatch!);
 059        }
 60    }
 61}