public void ShouldCallHelloWithSensitiveVariable() { var variablesFile = Path.GetTempFileName(); var variables = new VariableDictionary(); variables.Set("Name", "NameToEncrypt"); variables.SaveEncrypted("5XETGOgqYR2bRhlfhDruEg==", variablesFile); var(output, _) = RunScript("HelloWithVariable.ps1", new Dictionary <string, string>() { ["Name"] = "NameToEncrypt" }, sensitiveVariablesPassword: "******"); output.AssertSuccess(); output.AssertOutput("Hello NameToEncrypt"); }
public void ShouldCallHelloWithSensitiveVariable() { var variablesFile = Path.GetTempFileName(); var variables = new VariableDictionary(); variables.Set("Name", "NameToEncrypt"); variables.SaveEncrypted("5XETGOgqYR2bRhlfhDruEg==", variablesFile); using (new TemporaryFile(variablesFile)) { var output = Invoke(Calamari() .Action("run-script") .Argument("script", GetFixtureResouce("Scripts", "Hello.csx")) .Argument("sensitiveVariables", variablesFile) .Argument("sensitiveVariablesPassword", "5XETGOgqYR2bRhlfhDruEg==")); output.AssertSuccess(); output.AssertOutput("Hello NameToEncrypt"); } }
protected (CalamariResult result, VariableDictionary variables) RunScript(string scriptName, Dictionary <string, string> additionalVariables = null, Dictionary <string, string> additionalParameters = null, string sensitiveVariablesPassword = null) { var variablesFile = Path.GetTempFileName(); var variables = new VariableDictionary(); variables.Set(SpecialVariables.Action.Script.ScriptFileName, scriptName); variables.Set(SpecialVariables.Action.Script.ScriptBody, File.ReadAllText(GetFixtureResouce("Scripts", scriptName))); variables.Set(SpecialVariables.Action.Script.Syntax, ScriptTypeExtensions.FileNameToScriptType(scriptName).ToString()); additionalVariables?.ToList().ForEach(v => variables[v.Key] = v.Value); using (new TemporaryFile(variablesFile)) { var cmdBase = Calamari() .Action("run-script"); if (sensitiveVariablesPassword == null) { variables.Save(variablesFile); cmdBase = cmdBase.Argument("variables", variablesFile); } else { variables.SaveEncrypted(sensitiveVariablesPassword, variablesFile); cmdBase = cmdBase.Argument("sensitiveVariables", variablesFile) .Argument("sensitiveVariablesPassword", sensitiveVariablesPassword); } cmdBase = (additionalParameters ?? new Dictionary <string, string>()).Aggregate(cmdBase, (cmd, param) => cmd.Argument(param.Key, param.Value)); var output = Invoke(cmdBase, variables); return(output, variables); } }