public void EscapeStringlistAsInFAQ()
 {
     Assert.AreEqual(@"Editors\\ Architects,Programmers\,Testers", UserExtensions.StringlistToEscapedStringForEnvVar(new List <string> {
         @"Editors\ Architects", "Programmers,Testers"
     }));
 }
 public void EscapeStringlistWithCustomSeparatorSingleChar()
 {
     Assert.AreEqual(@"Editors\\ Architects|Programmers\|Testers", UserExtensions.StringlistToEscapedStringForEnvVar(new List <string> {
         @"Editors\ Architects", "Programmers|Testers"
     }, "|"));
 }
Esempio n. 3
0
        public void ExecuteServiceByName(
            string correlationId,
            string repositoryName,
            string serviceName,
            ExecutionOptions options,
            Stream inStream,
            Stream outStream)
        {
            if (!_permittedServiceNames.Contains(serviceName))
            {
                throw new ArgumentException("Invalid service name", nameof(serviceName));
            }

            var args = serviceName + " --stateless-rpc";

            args += options.ToCommandLineArgs();
            args += " \"" + repoLocator.GetRepositoryDirectoryPath(repositoryName).FullName + "\"";

            var info = new ProcessStartInfo(gitPath, args)
            {
                CreateNoWindow         = true,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                WorkingDirectory       = Path.GetDirectoryName(repositoriesDirPath),
            };

            SetHomePath(info);

            var username    = serviceProvider.GetService <IHttpContextAccessor>().HttpContext.User.Username();
            var teamsstr    = "";
            var rolesstr    = "";
            var displayname = "";

            if (!string.IsNullOrEmpty(username))
            {
                ITeamRepository tr     = serviceProvider.GetService <ITeamRepository>();
                var             userId = serviceProvider.GetService <IHttpContextAccessor>().HttpContext.User.Id();
                var             teams  = tr.GetTeams(userId);
                teamsstr = UserExtensions.StringlistToEscapedStringForEnvVar(teams.Select(x => x.Name));

                IRoleProvider rp = serviceProvider.GetService <IRoleProvider>();
                rolesstr = UserExtensions.StringlistToEscapedStringForEnvVar(rp.GetRolesForUser(userId));

                IMembershipService ms = serviceProvider.GetService <IMembershipService>();
                displayname = ms.GetUserModel(userId).DisplayName;
            }
            // If anonymous option is set then these will always be empty
            info.EnvironmentVariables.Add("AUTH_USER", username);
            info.EnvironmentVariables.Add("REMOTE_USER", username);
            info.EnvironmentVariables.Add("AUTH_USER_TEAMS", teamsstr);
            info.EnvironmentVariables.Add("AUTH_USER_ROLES", rolesstr);
            info.EnvironmentVariables.Add("AUTH_USER_DISPLAYNAME", displayname);


            using (var process = Process.Start(info))
            {
                inStream.CopyTo(process.StandardInput.BaseStream);
                if (options.endStreamWithClose)
                {
                    process.StandardInput.Close();
                }
                else
                {
                    process.StandardInput.Write('\0');
                }

                process.StandardOutput.BaseStream.CopyTo(outStream);
                process.WaitForExit();
            }
        }