File tree Expand file tree Collapse file tree 6 files changed +68
-5
lines changed
VirtualClient.Dependencies.UnitTests
VirtualClient.Dependencies
VirtualClient.Monitors.UnitTests Expand file tree Collapse file tree 6 files changed +68
-5
lines changed Original file line number Diff line number Diff line change 1
- 2.1.14
1
+ 2.1.15
Original file line number Diff line number Diff line change @@ -103,6 +103,36 @@ public async Task ExecuteCommandSupportsCommandChainingOnUnixSystems(string full
103
103
}
104
104
}
105
105
106
+ [ Test ]
107
+ [ TestCase (
108
+ "sudo dmesg && sudo lsblk && sudo mount && sudo df -h && sudo find /sys -name scheduler -print" ,
109
+ "sudo dmesg;sudo lsblk;sudo mount;sudo df -h;sudo find /sys -name scheduler -print" ) ]
110
+ public async Task ExecuteCommandSupportsCommandChainingOnUnixSystems_Bug_1 ( string fullCommand , string expectedCommandExecuted )
111
+ {
112
+ // Bug Scenario:
113
+ // Spaces (whitespace) in the commands due to the chaining SHOULD NOT cause
114
+ // parsing issues.
115
+ //
116
+ // e.g.
117
+ // "sudo dmesg && sudo lsblk " resulting in the command being identified as "sudo o lsblk"
118
+
119
+ this . SetupDefaults ( PlatformID . Unix ) ;
120
+
121
+ using ( TestExecuteCommand command = new TestExecuteCommand ( this . mockFixture ) )
122
+ {
123
+ command . Parameters [ nameof ( ExecuteCommand . Command ) ] = fullCommand ;
124
+ List < string > expectedCommands = new List < string > ( expectedCommandExecuted . Split ( ';' ) ) ;
125
+
126
+ this . mockFixture . ProcessManager . OnProcessCreated = ( process ) =>
127
+ {
128
+ expectedCommands . Remove ( process . FullCommand ( ) ) ;
129
+ } ;
130
+
131
+ await command . ExecuteAsync ( CancellationToken . None ) ;
132
+ Assert . IsEmpty ( expectedCommands ) ;
133
+ }
134
+ }
135
+
106
136
[ Test ]
107
137
[ TestCase ( "C:\\ \\ Users\\ User\\ anycommand&&C:\\ \\ home\\ user\\ anyothercommand" , "C:\\ \\ Users\\ User\\ anycommand;C:\\ \\ home\\ user\\ anyothercommand" ) ]
108
138
[ TestCase ( "C:\\ \\ Users\\ User\\ anycommand --argument=1&&C:\\ \\ home\\ user\\ anyothercommand --argument=2" , "C:\\ \\ Users\\ User\\ anycommand --argument=1;C:\\ \\ home\\ user\\ anyothercommand --argument=2" ) ]
Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ private IEnumerable<string> GetCommandsToExecute()
188
188
List < string > commandsToExecute = new List < string > ( ) ;
189
189
bool sudo = this . Command . StartsWith ( "sudo" , StringComparison . OrdinalIgnoreCase ) ;
190
190
191
- IEnumerable < string > commands = this . Command . Split ( "&&" , StringSplitOptions . RemoveEmptyEntries & StringSplitOptions . TrimEntries ) ;
191
+ IEnumerable < string > commands = this . Command . Split ( "&&" , StringSplitOptions . RemoveEmptyEntries ) ? . Select ( cmd => cmd . Trim ( ) ) ;
192
192
193
193
foreach ( string fullCommand in commands )
194
194
{
Original file line number Diff line number Diff line change @@ -427,8 +427,11 @@ protected async Task<EnvironmentLayout> ReadEnvironmentLayoutAsync(IServiceColle
427
427
$ "Invalid path specified. An environment layout file does not exist at path '{ layoutFullPath } '.") ;
428
428
}
429
429
430
- string layoutContent = await systemManagement . FileSystem . File . ReadAllTextAsync ( layoutFullPath )
431
- . ConfigureAwait ( false ) ;
430
+ string layoutContent = await RetryPolicies . FileOperations
431
+ . ExecuteAsync ( ( ) =>
432
+ {
433
+ return systemManagement . FileSystem . File . ReadAllTextAsync ( layoutFullPath ) ;
434
+ } ) ;
432
435
433
436
layout = layoutContent . FromJson < EnvironmentLayout > ( ) ;
434
437
}
Original file line number Diff line number Diff line change @@ -103,6 +103,36 @@ public async Task ExecuteCommandMonitorSupportsCommandChaining(string originalCo
103
103
}
104
104
}
105
105
106
+ [ Test ]
107
+ [ TestCase (
108
+ "sudo dmesg && sudo lsblk && sudo mount && sudo df -h && sudo find /sys -name scheduler -print" ,
109
+ "sudo dmesg;sudo lsblk;sudo mount;sudo df -h;sudo find /sys -name scheduler -print" ) ]
110
+ public async Task ExecuteCommandMonitorSupportsCommandChainingOnUnixSystems_Bug_1 ( string fullCommand , string expectedCommandExecuted )
111
+ {
112
+ // Bug Scenario:
113
+ // Spaces (whitespace) in the commands due to the chaining SHOULD NOT cause
114
+ // parsing issues.
115
+ //
116
+ // e.g.
117
+ // "sudo dmesg && sudo lsblk " resulting in the command being identified as "sudo o lsblk"
118
+
119
+ this . SetupDefaults ( PlatformID . Unix ) ;
120
+ List < string > commandsExecuted = new List < string > ( expectedCommandExecuted . Split ( ";" ) ) ;
121
+
122
+ using ( TestExecuteCommandMonitor monitor = new TestExecuteCommandMonitor ( this ) )
123
+ {
124
+ monitor . Parameters [ nameof ( ExecuteCommandMonitor . Command ) ] = fullCommand ;
125
+
126
+ this . ProcessManager . OnProcessCreated = ( process ) =>
127
+ {
128
+ commandsExecuted . Remove ( process . FullCommand ( ) ) ;
129
+ } ;
130
+
131
+ await monitor . ExecuteCommandAsync ( EventContext . None , CancellationToken . None ) ;
132
+ Assert . IsEmpty ( commandsExecuted ) ;
133
+ }
134
+ }
135
+
106
136
[ Test ]
107
137
[ TestCase ( "C:\\ \\ Users\\ User\\ anycommand&&C:\\ \\ home\\ user\\ anyothercommand" , "C:\\ \\ Users\\ User\\ anycommand;C:\\ \\ home\\ user\\ anyothercommand" ) ]
108
138
[ TestCase ( "C:\\ \\ Users\\ User\\ anycommand --argument=1&&C:\\ \\ home\\ user\\ anyothercommand --argument=2" , "C:\\ \\ Users\\ User\\ anycommand --argument=1;C:\\ \\ home\\ user\\ anyothercommand --argument=2" ) ]
Original file line number Diff line number Diff line change @@ -357,7 +357,7 @@ private IEnumerable<string> GetCommandsToExecute()
357
357
List < string > commandsToExecute = new List < string > ( ) ;
358
358
bool sudo = this . Command . StartsWith ( "sudo" , StringComparison . OrdinalIgnoreCase ) ;
359
359
360
- IEnumerable < string > commands = this . Command . Split ( "&&" , StringSplitOptions . RemoveEmptyEntries & StringSplitOptions . TrimEntries ) ;
360
+ IEnumerable < string > commands = this . Command . Split ( "&&" , StringSplitOptions . RemoveEmptyEntries ) ? . Select ( cmd => cmd . Trim ( ) ) ;
361
361
362
362
foreach ( string fullCommand in commands )
363
363
{
You can’t perform that action at this time.
0 commit comments