< Summary

Class:Azure.Identity.ScopeUtilities
Assembly:Azure.Identity
File(s):C:\Git\azure-sdk-for-net\sdk\identity\Azure.Identity\src\ScopeUtilities.cs
Covered lines:9
Uncovered lines:4
Coverable lines:13
Total lines:56
Line coverage:69.2% (9 of 13)
Covered branches:5
Total branches:8
Branch coverage:62.5% (5 of 8)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
ScopesToResource(...)-71.43%66.67%
ResourceToScopes(...)-0%100%
ValidateScope(...)-75%50%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using System.Text;
 8using System.Text.RegularExpressions;
 9using System.Threading.Tasks;
 10
 11namespace Azure.Identity
 12{
 13    internal static class ScopeUtilities
 14    {
 15        private const string DefaultSuffix = "/.default";
 16        private const string ScopePattern = "^[0-9a-zA-Z-.:/]+$";
 17
 18        private const string InvalidScopeMessage = "The specified scope is not in expected format. Only alphanumeric cha
 219        private static readonly Regex scopeRegex = new Regex(ScopePattern);
 20
 21        public static string ScopesToResource(string[] scopes)
 22        {
 19223            if (scopes == null)
 24            {
 025                throw new ArgumentNullException(nameof(scopes));
 26            }
 27
 19228            if (scopes.Length != 1)
 29            {
 030                throw new ArgumentException("To convert to a resource string the specified array must be exactly length 
 31            }
 32
 19233            if (!scopes[0].EndsWith(DefaultSuffix, StringComparison.Ordinal))
 34            {
 3635                return scopes[0];
 36            }
 37
 15638            return scopes[0].Remove(scopes[0].LastIndexOf(DefaultSuffix, StringComparison.Ordinal));
 39        }
 40
 41        public static string[] ResourceToScopes(string resource)
 42        {
 043            return new string[] { resource + "/.default" };
 44        }
 45
 46        public static void ValidateScope(string scope)
 47        {
 10448            bool isScopeMatch = scopeRegex.IsMatch(scope);
 49
 10450            if (!isScopeMatch)
 51            {
 052                throw new ArgumentException(InvalidScopeMessage, nameof(scope));
 53            }
 10454        }
 55    }
 56}