Beispiel #1
0
        bool ICaptureService.GetCapturedData(ICapturedDataFilter filter, out object capturedData)
        {
            if (GetCapturedData(filter, out CapturedGuiData guiData))
            {
                capturedData = guiData;
                return(true);
            }

            capturedData = null;
            return(false);
        }
Beispiel #2
0
        internal void GetCapturedData(ICapturedDataFilter filter, out List <string> capturedData)
        {
            if (filter is null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            var buffers = new List <string>(_buffers.Count);

            foreach (var buffer in _buffers)
            {
                var encodedBuffer = Convert.ToBase64String(buffer);

                buffers.Add(encodedBuffer);
            }

            capturedData = buffers;
        }
Beispiel #3
0
        internal bool GetCapturedData(ICapturedDataFilter filter, out CapturedAdalData capturedData)
        {
            if (filter is null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            var operations = new List <CapturedAdalOperation>(_captures.Count);

            foreach (var capture in _captures)
            {
                var operation = new CapturedAdalOperation
                {
                    AuthorityUrl = filter.ApplyFilter(capture.AuthorityUrl),
                    Error        = new CapturedAdalException
                    {
                        Message = filter.ApplyFilter(capture.Error.Message),
                    },
                    Input = new CapturedAdalInput
                    {
                        ClientId             = filter.ApplyFilter(capture.Input.ClientId),
                        ExtraQueryParameters = filter.ApplyFilter(capture.Input.ExtraQueryParameters),
                        RedirectUrl          = filter.ApplyFilter(capture.Input.RedirectUrl),
                        Resource             = filter.ApplyFilter(capture.Input.Resource),
                    },
                    Result = new CapturedAdalResult
                    {
                        AccessToken = capture.Result.AccessToken is null ? null : CapturedAdalAccessToken,
                        Authority   = filter.ApplyFilter(capture.Result.Authority),
                        TenantId    = capture.Result.TenantId,
                        TokenType   = capture.Result.TokenType,
                    },
                };

                operations.Add(operation);
            }

            capturedData = new CapturedAdalData
            {
                Operations = operations,
            };

            return(true);
        }
Beispiel #4
0
        internal bool GetCapturedData(ICapturedDataFilter filter, out CapturedGuiData capturedData)
        {
            if (filter is null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            lock (_syncpoint)
            {
                capturedData = new CapturedGuiData
                {
                    Operations = new List <CapturedGuiOperation>(_captured.Count),
                };

                foreach (var item in _captured)
                {
                    var operation = new CapturedGuiOperation
                    {
                        Output = new CapturedGuiOutput
                        {
                            AuthenticationCode = item.Output.AuthenticationCode,
                            IsValid            = item.Output.IsValid,
                            Login = item.Output.Login != null
                                ? FauxUsername
                                : null,
                            Password = item.Output.Password != null
                                ? FauxPassword
                                : null,
                            Result  = item.Output.Result,
                            Success = item.Output.Success,
                        },
                        DialogType = item.DialogType,
                    };

                    capturedData.Operations.Add(operation);
                }
            }

            return(true);
        }
Beispiel #5
0
 bool ICaptureService <CapturedGuiData> .GetCapturedData(ICapturedDataFilter filter, out CapturedGuiData capturedData)
 => GetCapturedData(filter, out capturedData);
Beispiel #6
0
        internal bool GetCapturedData(ICapturedDataFilter filter, out CapturedSettingsData capturedData)
        {
            if (filter is null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            lock (_syncpoint)
            {
                _captured.EnvironmentVariables = new List <CapturedSettingsEnvironmentVariables>(3);

                // Ensure the special GCM_DEBUG environment variable is set.
                if (!_variables[EnvironmentVariableTarget.Process].ContainsKey("GCM_DEBUG"))
                {
                    _variables[EnvironmentVariableTarget.Process].Add("GCM_DEBUG", null);
                }

                foreach (var target in _variables.Keys)
                {
                    var variables = new CapturedSettingsEnvironmentVariables
                    {
                        Target = (int)target,
                        Values = new List <CapturedSettingsEnvironmentVariable>(),
                    };

                    foreach (var kvp in _variables[target])
                    {
                        if (kvp.Key is null)
                        {
                            continue;
                        }

                        if (OrdinalIgnoreCase.Equals("PATH", kvp.Key))
                        {
                            var items = kvp.Value?.Split(';');
                            var keeps = new List <string>(items.Length);

                            for (int i = 0; i < items.Length; i += 1)
                            {
                                foreach (var legal in AllowedCapturedPathValues)
                                {
                                    if (legal.IsMatch(items[i]))
                                    {
                                        keeps.Add(items[i]);
                                        break;
                                    }
                                }
                            }

                            if (keeps.Count > 0)
                            {
                                var name     = kvp.Key;
                                var variable = string.Join(";", keeps);

                                var entry = new CapturedSettingsEnvironmentVariable
                                {
                                    Name     = name,
                                    Variable = variable,
                                };

                                variables.Values.Add(entry);
                            }
                        }
                        else if (AllowedCapturedVariables.TryGetValue(kvp.Key, out string variable))
                        {
                            var name = kvp.Key;

                            var entry = new CapturedSettingsEnvironmentVariable
                            {
                                Name     = name,
                                Variable = variable,
                            };

                            variables.Values.Add(entry);
                        }
                        else
                        {
                            var name = kvp.Key;
                            variable = kvp.Value;

                            foreach (var allowed in AllowedCapturedVariableNames)
                            {
                                if (allowed.IsMatch(name))
                                {
                                    variable = filter.ApplyFilter(variable);

                                    var entry = new CapturedSettingsEnvironmentVariable
                                    {
                                        Name     = name,
                                        Variable = variable,
                                    };

                                    variables.Values.Add(entry);

                                    break;
                                }
                            }
                        }
                    }

                    _captured.EnvironmentVariables.Add(variables);
                }

                _captured.ExpandVariables = new List <CapturedSettingsExpandVariable>();

                foreach (var kvp in _expandedVariables)
                {
                    if (kvp.Key is null)
                    {
                        continue;
                    }

                    var expanded = kvp.Value;
                    var original = kvp.Key;

                    expanded = filter.ApplyFilter(expanded);
                    original = filter.ApplyFilter(original);

                    var query = new CapturedSettingsExpandVariable
                    {
                        Expanded = expanded,
                        Original = original,
                    };

                    _captured.ExpandVariables.Add(query);
                }

                _captured.SpecialFolders = new List <CapturedSettingsSpecialFolder>();

                foreach (var kvp in _specialFolders)
                {
                    if (kvp.Value is null)
                    {
                        continue;
                    }

                    var path = kvp.Value;

                    path = filter.ApplyFilter(path);

                    var folder = new CapturedSettingsSpecialFolder
                    {
                        SpecialFolder = (int)kvp.Key,
                        Path          = path,
                    };

                    _captured.SpecialFolders.Add(folder);
                }

                _captured.CurrentDirectory = filter.ApplyFilter(_captured.CurrentDirectory);

                capturedData = _captured;
                return(true);
            }
        }
Beispiel #7
0
        public override void WriteTestData(Stream writableStream)
        {
            if (writableStream is null)
            {
                throw new ArgumentNullException(nameof(writableStream));
            }
            if (!writableStream.CanWrite)
            {
                var inner = new InvalidDataException($"Method `{nameof(WriteTestData)}` requires `{nameof(writableStream)}` to be writable.");
                throw new ArgumentException(inner.Message, nameof(writableStream), inner);
            }

            if (_data is null)
            {
                return;
            }

            using (var writer = new StreamWriter(writableStream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)))
            {
                string[] HeaderComment = new[]
                {
                    @"/**** Git Process Management Library ****",
                    @" *",
                    @" * Copyright (c) Microsoft Corporation",
                    @" * All rights reserved.",
                    @" *",
                    @" * MIT License",
                    @" *",
                    @" * Permission is hereby granted, free of charge, to any person obtaining a copy",
                    @" * of this software and associated documentation files (the ""Software""), to deal",
                    @" * in the Software without restriction, including without limitation the rights to",
                    @" * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of",
                    @" * the Software, and to permit persons to whom the Software is furnished to do so,",
                    @" * subject to the following conditions:",
                    @" *",
                    @" * The above copyright notice and this permission notice shall be included in all",
                    @" * copies or substantial portions of the Software.",
                    @" *",
                    @" * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR",
                    @" * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS",
                    @" * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR",
                    @" * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN",
                    @" * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION",
                    @" * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
                    @"**/",
                    @"",
                    @"// Use `Formatting.Indented` to ease review readability.",
                };

                for (int i = 0; i < HeaderComment.Length; i += 1)
                {
                    writer.WriteLine(HeaderComment[i]);
                }

                var data       = _data;
                var dataFilter = new CapturedDataFilter(typeof(ICaptureService));

                foreach (var kvp in _storageFilters)
                {
                    Regex filter = BuildFilter(kvp.Key);

                    dataFilter.AddFilter(filter, kvp.Value);
                }

                var separaterFilter = new Regex(@"[/\\]+", RegexOptions.Compiled | RegexOptions.CultureInvariant);

                var testResultPath   = separaterFilter.Replace(data.ResultPath, PathSeparator);
                var testResultFilter = BuildFilter(testResultPath);
                dataFilter.AddFilter(testResultFilter, _options.FauxResultPath);

                var slnRootPath = _options.SolutionDirectory;
                slnRootPath = separaterFilter.Replace(slnRootPath, PathSeparator);
                var slnRootFilter = BuildFilter(slnRootPath);
                dataFilter.AddFilter(slnRootFilter, _options.FauxPrefixPath);

                var testRootPath   = _options.SolutionDirectory;
                var testRootFilter = BuildFilter(testRootPath);
                dataFilter.AddFilter(testRootFilter, _options.FauxPrefixPath);

                var userHomePath = _context.Settings.GetEnvironmentVariable("HOME")
                                   ?? _context.Settings.GetEnvironmentVariable("USERPROFILE");
                var userHomeFilter = BuildFilter(userHomePath);
                dataFilter.AddFilter(userHomeFilter, _options.FauxHomePath);

                foreach (var runtimeService in EnumeratorServices())
                {
                    if (runtimeService is ICaptureService captureService)
                    {
                        ICapturedDataFilter filter = dataFilter.SupportsService(runtimeService.GetType())
                            ? dataFilter
                            : CapturedDataFilter.Null;

                        if (captureService.GetCapturedData(dataFilter, out object capturedData))
                        {
                            data.Services.Add(captureService.ServiceName, capturedData);
                        }
                    }
                }

                var jsonSettings = new JsonSerializerSettings()
                {
                    Converters           = CustomJsonConverters,
                    Culture              = System.Globalization.CultureInfo.InvariantCulture,
                    Formatting           = Formatting.Indented,
                    NullValueHandling    = NullValueHandling.Ignore,
                    StringEscapeHandling = StringEscapeHandling.Default,
                };

                string serializedData = JsonConvert.SerializeObject(data, jsonSettings);

                writer.Write(serializedData);
            }
        }