[Internal] Visibility: Adds new Portal Backend to Microsoft.Azure.Cosmos InternalsVisibleTo (#4529)

Co-authored-by: Asier Isayas <aisayas@microsoft.com>
This commit is contained in:
Asier Isayas 2024-06-05 15:50:01 -04:00 коммит произвёл GitHub
Родитель 18a677ace9
Коммит 087ed73fa9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 48 добавлений и 2 удалений

Просмотреть файл

@ -23,6 +23,8 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Table.Tests" + AssemblyKeys.TestPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Performance.Tests" + AssemblyKeys.ProductPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Performance.Tests" + AssemblyKeys.TestPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Portal.Services.Backend" + AssemblyKeys.ProductPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Portal.Services.Backend" + AssemblyKeys.TestPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Tests" + AssemblyKeys.ProductPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Tests" + AssemblyKeys.TestPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.EmulatorTests" + AssemblyKeys.ProductPublicKey)]

Просмотреть файл

@ -5,10 +5,11 @@ namespace Microsoft.Azure.Cosmos.Contracts
{
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;
using Microsoft.Azure.Documents;
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Azure.Documents;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class ContractTests
@ -43,6 +44,49 @@ namespace Microsoft.Azure.Cosmos.Contracts
ContractTests.NamespaceCountTest(typeof(CosmosClient), expected);
}
[TestMethod]
public void GenerateKeyAuthorizationSignatureContractTest()
{
Assembly clientAssembly = typeof(AuthorizationHelper).GetAssembly();
object[] internals = clientAssembly.GetCustomAttributes(typeof(InternalsVisibleToAttribute), false);
bool foundPortalBackend = internals.Cast<InternalsVisibleToAttribute>()
.Any(x => x.AssemblyName.Contains("Microsoft.Azure.Cosmos.Portal.Services.Backend"));
if (foundPortalBackend)
{
// Test GenerateKeyAuthorizationSignature method still exists
string[] generateKeyAuthorizationSignatureArgs = new string[] {
"http://localhost.sql:8901/dbs/92dc837c73484349852a2c8f05777565/colls/ea9ebd7de6aa46d8bc0aa7e29b89236c",
"dbs/92dc837c73484349852a2c8f05777565/colls/ea9ebd7de6aa46d8bc0aa7e29b89236c",
"GET",
"colls",
"Tue, 21 Jul 2020 17:55:37 GMT",
"" };
string key = "VGhpcyBpcyBhIHNhbXBsZSBzdHJpbmc=";
Documents.Collections.RequestNameValueCollection headers = new()
{
{ HttpConstants.HttpHeaders.XDate, generateKeyAuthorizationSignatureArgs[4] }
};
string keyAuthorizationSignature = AuthorizationHelper.GenerateKeyAuthorizationSignature(
verb: generateKeyAuthorizationSignatureArgs[2],
resourceId: generateKeyAuthorizationSignatureArgs[1],
resourceType: generateKeyAuthorizationSignatureArgs[3],
headers: headers,
key: key);
AuthorizationHelper.ParseAuthorizationToken(keyAuthorizationSignature, out ReadOnlyMemory<char> typeOutput1, out ReadOnlyMemory<char> versionoutput1, out ReadOnlyMemory<char> tokenOutput1);
Assert.AreEqual("master", typeOutput1.ToString());
Assert.IsTrue(AuthorizationHelper.CheckPayloadUsingKey(
tokenOutput1,
generateKeyAuthorizationSignatureArgs[2],
generateKeyAuthorizationSignatureArgs[1],
generateKeyAuthorizationSignatureArgs[3],
headers,
key));
}
}
private static void NamespaceCountTest(Type input, int expected)
{
Assembly clientAssembly = input.GetAssembly();