< Summary

Class:Azure.Identity.MacosVisualStudioCodeAdapter
Assembly:Azure.Identity
File(s):C:\Git\azure-sdk-for-net\sdk\identity\Azure.Identity\src\MacosVisualStudioCodeAdapter.cs
Covered lines:0
Uncovered lines:14
Coverable lines:14
Total lines:45
Line coverage:0% (0 of 14)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-0%100%
GetUserSettingsPath()-0%100%
GetCredentials(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\identity\Azure.Identity\src\MacosVisualStudioCodeAdapter.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Globalization;
 6using System.IO;
 7using System.Runtime.InteropServices;
 8using System.Text;
 9using Azure.Core;
 10
 11namespace Azure.Identity
 12{
 13    internal sealed class MacosVisualStudioCodeAdapter : IVisualStudioCodeAdapter
 14    {
 015        private static readonly string s_userSettingsJsonPath = Path.Combine(Environment.GetFolderPath(Environment.Speci
 16
 017        public string GetUserSettingsPath() => s_userSettingsJsonPath;
 18
 19        public string GetCredentials(string serviceName, string accountName)
 20        {
 021            Argument.AssertNotNullOrEmpty(serviceName, nameof(serviceName));
 022            Argument.AssertNotNullOrEmpty(accountName, nameof(accountName));
 23
 024            IntPtr credentialsPtr = IntPtr.Zero;
 025            IntPtr itemRef = IntPtr.Zero;
 26
 27            try
 28            {
 029                MacosNativeMethods.SecKeychainFindGenericPassword(IntPtr.Zero, serviceName, accountName, out int passwor
 030                return passwordLength > 0 ? Marshal.PtrToStringAnsi(credentialsPtr, passwordLength) : throw new InvalidO
 31            }
 32            finally
 33            {
 34                try
 35                {
 036                    MacosNativeMethods.SecKeychainItemFreeContent(IntPtr.Zero, credentialsPtr);
 037                }
 38                finally
 39                {
 040                    MacosNativeMethods.CFRelease(itemRef);
 041                }
 042            }
 043        }
 44    }
 45}