Ejemplo n.º 1
0
        public static Mock <IKeyEncryptionKey> GetIKeyEncryptionKey(
            this RecordedTestBase testBase,
            CancellationToken?expectedCancellationToken,
            byte[] userKeyBytes    = default,
            string keyId           = default,
            TimeSpan optionalDelay = default)
        {
            if (userKeyBytes == default)
            {
                const int keySizeBits = 256;
                var       bytes       = new byte[keySizeBits >> 3];
                testBase.Recording.Random.NextBytes(bytes);
                userKeyBytes = bytes;
            }
            keyId ??= testBase.Recording.Random.NewGuid().ToString();

            var keyMock = new Mock <IKeyEncryptionKey>(MockBehavior.Strict);

            keyMock.SetupGet(k => k.KeyId).Returns(keyId);
            if (testBase.IsAsync)
            {
                keyMock.Setup(k => k.WrapKeyAsync(s_algorithmName, It.IsNotNull <ReadOnlyMemory <byte> >(), expectedCancellationToken ?? It.IsAny <CancellationToken>()))
                .Returns <string, ReadOnlyMemory <byte>, CancellationToken>(async(algorithm, key, cancellationToken) =>
                {
                    await Task.Delay(optionalDelay);
                    // TODO develop transformative function that can work with different size keys. no-op is fine for now
                    //return Xor(userKeyBytes, key.ToArray());
                    return(key.ToArray());
                });
                keyMock.Setup(k => k.UnwrapKeyAsync(s_algorithmName, It.IsNotNull <ReadOnlyMemory <byte> >(), expectedCancellationToken ?? It.IsAny <CancellationToken>()))
                .Returns <string, ReadOnlyMemory <byte>, CancellationToken>(async(algorithm, wrappedKey, cancellationToken) =>
                {
                    await Task.Delay(optionalDelay);
                    //return Xor(userKeyBytes, wrappedKey.ToArray());
                    return(wrappedKey.ToArray());
                });
            }
            else
            {
                keyMock.Setup(k => k.WrapKey(s_algorithmName, It.IsNotNull <ReadOnlyMemory <byte> >(), expectedCancellationToken ?? It.IsAny <CancellationToken>()))
                .Returns <string, ReadOnlyMemory <byte>, CancellationToken>((algorithm, key, cancellationToken) =>
                {
                    Thread.Sleep(optionalDelay);
                    //return Xor(userKeyBytes, key.ToArray());
                    return(key.ToArray());
                });
                keyMock.Setup(k => k.UnwrapKey(s_algorithmName, It.IsNotNull <ReadOnlyMemory <byte> >(), It.IsAny <CancellationToken>()))
                .Returns <string, ReadOnlyMemory <byte>, CancellationToken>((algorithm, wrappedKey, cancellationToken) =>
                {
                    Thread.Sleep(optionalDelay);
                    //return Xor(userKeyBytes, wrappedKey.ToArray());
                    return(wrappedKey.ToArray());
                });
            }

            return(keyMock);
        }
Ejemplo n.º 2
0
        public MetricsTestData(RecordedTestBase <MonitorQueryClientTestEnvironment> test)
        {
            _testEnvironment = test.TestEnvironment;

            var recordingUtcNow = test.Recording.UtcNow;

            // Snap to 15 minute intervals
            StartTime = recordingUtcNow.AddTicks(-Duration.Ticks - recordingUtcNow.Ticks % Duration.Ticks);

            MetricName      = "CowsHappiness";
            MetricNamespace = "Cows";
        }
Ejemplo n.º 3
0
        public LogsTestData(RecordedTestBase <MonitorQueryTestEnvironment> test)
        {
            _testEnvironment = test.TestEnvironment;

            var recordingUtcNow = DateTime.SpecifyKind(test.Recording.UtcNow.Date, DateTimeKind.Utc);

            RetentionWindowStart = recordingUtcNow.AddDays(DayOfWeek.Monday - recordingUtcNow.DayOfWeek - 7);

            TableA = new()
            {
                new()
                {
                    { IntColumnNameSent, 1 },
                    { StringColumnNameSent, "a" },
                    { BoolColumnNameSent, false },
Ejemplo n.º 4
0
        public static Mock <IKeyEncryptionKeyResolver> GetIKeyEncryptionKeyResolver(
            this RecordedTestBase testBase,
            CancellationToken?expectedCancellationToken,
            params IKeyEncryptionKey[] keys)
        {
            IKeyEncryptionKey Resolve(string keyId, CancellationToken cancellationToken)
            => keys.FirstOrDefault(k => k.KeyId == keyId) ?? throw new Exception("Mock resolver couldn't resolve key id.");

            var resolverMock = new Mock <IKeyEncryptionKeyResolver>(MockBehavior.Strict);

            if (testBase.IsAsync)
            {
                resolverMock.Setup(r => r.ResolveAsync(It.IsNotNull <string>(), expectedCancellationToken ?? It.IsAny <CancellationToken>()))
                .Returns <string, CancellationToken>((keyId, cancellationToken) => Task.FromResult(Resolve(keyId, cancellationToken)));
            }
            else
            {
                resolverMock.Setup(r => r.Resolve(It.IsNotNull <string>(), expectedCancellationToken ?? It.IsAny <CancellationToken>()))
                .Returns <string, CancellationToken>(Resolve);
                ;
            }

            return(resolverMock);
        }
 public DataLakeAccessConditionConfigs(RecordedTestBase recordedTestBase)
     : base(recordedTestBase)
 {
 }
 public BlobAccessConditionConfigs(RecordedTestBase recordedTestBase)
     : base(recordedTestBase)
 {
 }
Ejemplo n.º 7
0
 public static void AddPurviewSanitizers(this RecordedTestBase testBase)
 {
     testBase.JsonPathSanitizers.Add("$..atlasKafkaPrimaryEndpoint");
     testBase.JsonPathSanitizers.Add("$..atlasKafkaSecondaryEndpoint");
 }
 public TenantConfigurationBuilder(RecordedTestBase recordedTestBase)
 {
     AzureCoreRecordedTestBase = recordedTestBase;
 }
Ejemplo n.º 9
0
 public InstrumentedTableClientProvider(RecordedTestBase recording, IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger <TableServiceClient> logger) : base(configuration, componentFactory, logForwarder, logger)
 {
     _recording = recording;
 }
Ejemplo n.º 10
0
 public AccessConditionConfigs(RecordedTestBase recordedTestBase)
 {
     _azureCoreRecordedTestBase = recordedTestBase;
 }