Skip to content

Commit 58d775b

Browse files
committed
test: cover windows native network sandbox path
1 parent 1813003 commit 58d775b

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

tests/AgentPowerShell.IntegrationTests/SmokeTests.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,69 @@ await File.WriteAllTextAsync(Path.Combine(root, "default-policy.yml"), """
6666
}
6767
}
6868

69+
[Fact]
70+
public async Task Cli_Exec_Runs_Native_Network_Client_In_AppContainer_When_Network_Is_Denied()
71+
{
72+
if (!OperatingSystem.IsWindows())
73+
{
74+
return;
75+
}
76+
77+
var curlExecutable = TryGetCurlExecutable();
78+
if (curlExecutable is null)
79+
{
80+
return;
81+
}
82+
83+
var root = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}-cli-native-network-appcontainer");
84+
Directory.CreateDirectory(root);
85+
var originalDirectory = Environment.CurrentDirectory;
86+
var originalOut = Console.Out;
87+
88+
try
89+
{
90+
Environment.CurrentDirectory = root;
91+
await File.WriteAllTextAsync(Path.Combine(root, "default-policy.yml"), """
92+
command_rules:
93+
- name: allow-all
94+
pattern: "*"
95+
decision: allow
96+
network_rules:
97+
- name: deny-all
98+
domain: "*"
99+
ports: ["1-65535"]
100+
decision: deny
101+
""");
102+
103+
using var writer = new StringWriter();
104+
Console.SetOut(writer);
105+
106+
var exitCode = CliApp.Run([
107+
"exec",
108+
"session-native-appcontainer",
109+
curlExecutable,
110+
"https://example.com",
111+
"--output",
112+
"json"
113+
]);
114+
115+
var payload = writer.ToString();
116+
Assert.NotEqual(0, exitCode);
117+
Assert.Contains("\"policyDecision\":\"allow\"", payload, StringComparison.Ordinal);
118+
Assert.Contains("\"exitCode\":", payload, StringComparison.Ordinal);
119+
Assert.DoesNotContain("No matching network rule.", payload, StringComparison.Ordinal);
120+
}
121+
finally
122+
{
123+
Console.SetOut(originalOut);
124+
Environment.CurrentDirectory = originalDirectory;
125+
if (Directory.Exists(root))
126+
{
127+
Directory.Delete(root, recursive: true);
128+
}
129+
}
130+
}
131+
69132
[Fact]
70133
public async Task ShimProcessor_Runs_PowerShell_Command()
71134
{
@@ -133,4 +196,20 @@ await File.WriteAllTextAsync(Path.Combine(root, "default-policy.yml"), """
133196
}
134197
}
135198
}
199+
200+
private static string? TryGetCurlExecutable()
201+
{
202+
if (!OperatingSystem.IsWindows())
203+
{
204+
return null;
205+
}
206+
207+
var candidates = new[]
208+
{
209+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "curl.exe"),
210+
@"C:\Program Files\Git\mingw64\bin\curl.exe"
211+
};
212+
213+
return candidates.FirstOrDefault(File.Exists);
214+
}
136215
}

0 commit comments

Comments
 (0)