-
Notifications
You must be signed in to change notification settings - Fork 1
894 lines (759 loc) · 33.1 KB
/
integration-test.yml
File metadata and controls
894 lines (759 loc) · 33.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
name: Integration Test
on:
workflow_dispatch:
inputs:
os:
description: "Platform to test"
required: true
type: choice
options:
- all
- windows-latest
- ubuntu-latest
- macos-latest
jobs:
build:
permissions:
contents: read
uses: ./.github/workflows/build.yml
with:
os_list: "${{ inputs.os == 'all' && '[''windows-latest'',''ubuntu-latest'',''macos-latest'']' || format('[{0}{1}{0}]', '''', inputs.os) }}"
cache: true
build-integration-test:
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: ${{ fromJson(inputs.os == 'all' && '[''windows-latest'',''ubuntu-latest'',''macos-latest'']' || format('[{0}{1}{0}]', '''', inputs.os)) }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Cache integration test build output
id: cache-build
uses: actions/cache@v5
with:
path: ./dist
key: build-it-${{ matrix.os }}-go1.24.0-${{ hashFiles('**/*.go', 'go.sum', 'go.mod') }}
- name: Setup go
if: steps.cache-build.outputs.cache-hit != 'true'
uses: actions/setup-go@v6
with:
go-version: "1.24.0"
cache: true
- name: Build integration test binary
if: steps.cache-build.outputs.cache-hit != 'true'
shell: pwsh
id: build
run: ./scripts/build_integration_test.ps1 | % { "binary_path=$_" } >> $env:GITHUB_OUTPUT
- name: Upload integration test binary
uses: actions/upload-artifact@v6
with:
name: it-${{ matrix.os }}
path: ${{ steps.build.outputs.binary_path || './dist/*' }}
test-ubuntu-latest:
permissions:
contents: read
needs: [build, build-integration-test]
if: inputs.os == 'ubuntu-latest' || inputs.os == 'all'
runs-on: ubuntu-latest
steps:
- name: Download compiled binary
uses: actions/download-artifact@v8
with:
name: ubuntu-latest
path: ./dist
- name: Download integration test binary
uses: actions/download-artifact@v8
with:
name: it-ubuntu-latest
path: ./dist
- name: Make binaries executable
run: |
chmod +x ./dist/rewst_agent_config.linux.bin
chmod +x ./dist/rewst_agent_config.linux.it.bin
- name: Install agent
id: install_agent
shell: bash
run: |
sudo ./dist/rewst_agent_config.linux.bin --config-url ${{ vars.IT_CONFIG_URL }} --config-secret ${{ secrets.IT_CONFIG_SECRET }} --org-id ${{ vars.IT_ORG_ID }}
echo "service=rewst_remote_agent_${{ vars.IT_ORG_ID }}" >> $GITHUB_OUTPUT
- name: Check service
shell: bash
run: |
systemctl status ${{ steps.install_agent.outputs.service }}
- name: Get device id
id: get_device_id
shell: bash
run: |
echo "value=$(cat /etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/config.json | jq -r '.device_id')" >> "$GITHUB_OUTPUT"
- name: Validate config.json fields
shell: bash
run: |
config="/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/config.json"
failed=false
for field in device_id rewst_org_id rewst_engine_host shared_access_key azure_iot_hub_host; do
val=$(jq -r ".$field" "$config")
if [ -z "$val" ] || [ "$val" = "null" ]; then
echo "ERROR: Config field '$field' is missing or empty"
failed=true
else
echo "OK: $field = $val"
fi
done
org_id=$(jq -r '.rewst_org_id' "$config")
if [ "$org_id" != "${{ vars.IT_ORG_ID }}" ]; then
echo "ERROR: rewst_org_id '$org_id' does not match expected '${{ vars.IT_ORG_ID }}'"
failed=true
fi
if [ "$failed" = true ]; then exit 1; fi
echo "All config.json fields validated"
- name: Send test command
shell: bash
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' \
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' \
--form 'commands="echo \"hello world\""'
- name: Check logs
shell: bash
run: |
logFile="/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
logContent=$(cat "$logFile")
echo "$logContent"
for pattern in "Command completed" "Sending postback" "Postback sent"; do
if ! echo "$logContent" | grep -qF "$pattern"; then
echo "ERROR: Expected log line not found: $pattern"
exit 1
fi
done
echo "All expected log lines found"
- name: Send failing command
shell: bash
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' \
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' \
--form 'commands="exit 1"'
- name: Check logs for error handling
shell: bash
run: |
sleep 15
logFile="/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
logContent=$(cat "$logFile")
echo "$logContent"
if ! echo "$logContent" | grep -qF "Command failed"; then
echo "ERROR: Expected 'Command failed' not found in logs"
exit 1
fi
echo "Error handling verified: failing command error was captured"
- name: Install integration test binary (old version)
shell: bash
run: |
sudo ./dist/rewst_agent_config.linux.it.bin --update --org-id ${{ vars.IT_ORG_ID }}
echo "Installed integration test binary (version 0.0.0-it)"
- name: Wait for auto updater to trigger and update
shell: bash
run: |
logFile="/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
echo "Waiting for auto updater to detect newer version and update..."
for i in $(seq 1 60); do
logContent=$(cat "$logFile" 2>/dev/null || true)
if echo "$logContent" | grep -qF "Updating agent"; then
echo "Auto update triggered after ${i}s"
break
fi
sleep 2
done
- name: Verify auto update completed
shell: bash
run: |
sleep 15
logFile="/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
logContent=$(cat "$logFile")
echo "$logContent"
for pattern in "Checking for updates" "Updating agent"; do
if ! echo "$logContent" | grep -qF "$pattern"; then
echo "ERROR: Expected auto update log line not found: $pattern"
exit 1
fi
done
if echo "$logContent" | grep -qF "version=0.0.0-it"; then
lastVersion=$(echo "$logContent" | grep "Agent Smith started" | tail -1)
if echo "$lastVersion" | grep -qF "version=0.0.0-it"; then
echo "ERROR: Agent is still running the integration test version after update"
exit 1
fi
fi
echo "Auto updater integration test passed"
- name: Update logging level to debug
shell: bash
run: |
sudo ./dist/rewst_agent_config.linux.bin --update --org-id ${{ vars.IT_ORG_ID }} --logging-level debug
echo "Logging level successfully updated to debug"
- name: Send test command
shell: bash
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' \
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' \
--form 'commands="echo \"hello world\""'
- name: Check logs for debug level
shell: bash
run: |
logFile="/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
logContent=$(cat "$logFile")
echo "$logContent"
if ! echo "$logContent" | grep -qF "DEBUG"; then
echo "ERROR: Expected log line not found: DEBUG"
exit 1
fi
echo "All expected log lines found"
- name: Stop service
shell: bash
run: |
sudo systemctl stop ${{ steps.install_agent.outputs.service }}
- name: Delete log file
shell: bash
run: |
sudo rm -f "/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
- name: Update agent
shell: bash
run: |
sudo ./dist/rewst_agent_config.linux.bin --update --org-id ${{ vars.IT_ORG_ID }} --no-auto-updates
- name: Check logs for no auto updater
shell: bash
run: |
logFile="/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
for i in $(seq 1 30); do
[ -f "$logFile" ] && break
echo "Waiting for log file to be created... ($i/30)"
sleep 1
done
logContent=$(cat "$logFile")
echo "$logContent"
if echo "$logContent" | grep -qF "Starting auto updater"; then
echo "ERROR: Unexpected log line found: Starting auto updater"
exit 1
fi
echo "Confirmed: no 'Starting auto updater' log line found"
- name: Update agent with syslog
shell: bash
run: |
sudo ./dist/rewst_agent_config.linux.bin --update --org-id ${{ vars.IT_ORG_ID }} --syslog
- name: Send test command
shell: bash
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' \
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' \
--form 'commands="echo \"hello world\""'
- name: Check syslog for command completed
shell: bash
run: |
sleep 15
entries=$(journalctl -t "rewst_remote_agent_${{ vars.IT_ORG_ID }}" --no-pager 2>/dev/null || sudo grep "rewst_remote_agent_${{ vars.IT_ORG_ID }}" /var/log/syslog 2>/dev/null || sudo grep "rewst_remote_agent_${{ vars.IT_ORG_ID }}" /var/log/messages 2>/dev/null || true)
echo "$entries"
if ! echo "$entries" | grep -qF "Command completed"; then
echo "ERROR: Expected 'Command completed' entry not found in syslog"
exit 1
fi
echo "Found 'Command completed' in syslog"
- name: Uninstall agent
shell: bash
run: |
sudo ./dist/rewst_agent_config.linux.bin --uninstall --org-id ${{ vars.IT_ORG_ID }}
- name: Check deleted directories
shell: pwsh
run: |
if (Test-Path -Path "/etc/rewst_remote_agent/${{ vars.IT_ORG_ID }}") { exit 1 }
if (Test-Path -Path "/usr/local/bin/rewst_remote_agent/${{ vars.IT_ORG_ID }}") { exit 1 }
if (Test-Path -Path "/tmp/rewst_remote_agent/scripts/${{ vars.IT_ORG_ID }}") { exit 1 }
echo "All directories have been deleted"
test-windows-latest:
permissions:
contents: read
needs: [build, build-integration-test]
if: inputs.os == 'windows-latest' || inputs.os == 'all'
runs-on: windows-latest
steps:
- name: Download compiled binary
uses: actions/download-artifact@v8
with:
name: windows-latest
path: ./dist
- name: Download integration test binary
uses: actions/download-artifact@v8
with:
name: it-windows-latest
path: ./dist
- name: Install agent
id: install_agent
shell: pwsh
run: |
./dist/rewst_agent_config.win.exe --config-url ${{ vars.IT_CONFIG_URL }} --config-secret ${{ secrets.IT_CONFIG_SECRET }} --org-id ${{ vars.IT_ORG_ID }}
Write-Output "service=RewstRemoteAgent_${{ vars.IT_ORG_ID }}" >> $env:GITHUB_OUTPUT
- name: Check service
shell: pwsh
run: |
sc.exe query ${{ steps.install_agent.outputs.service }}
- name: Get device id
id: get_device_id
shell: pwsh
run: |
(Get-Content C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\config.json | ConvertFrom-Json).device_id | % { "value=$_" } >> $env:GITHUB_OUTPUT
- name: Validate config.json fields
shell: pwsh
run: |
$config = Get-Content C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\config.json | ConvertFrom-Json
$requiredFields = @(
@{ Name = "device_id"; Value = $config.device_id },
@{ Name = "rewst_org_id"; Value = $config.rewst_org_id },
@{ Name = "rewst_engine_host"; Value = $config.rewst_engine_host },
@{ Name = "shared_access_key"; Value = $config.shared_access_key },
@{ Name = "azure_iot_hub_host"; Value = $config.azure_iot_hub_host }
)
$failed = $false
foreach ($field in $requiredFields) {
if ([string]::IsNullOrWhiteSpace($field.Value)) {
Write-Error "Config field '$($field.Name)' is missing or empty"
$failed = $true
} else {
Write-Output "OK: $($field.Name) = $($field.Value)"
}
}
if ($config.rewst_org_id -ne "${{ vars.IT_ORG_ID }}") {
Write-Error "rewst_org_id '$($config.rewst_org_id)' does not match expected '${{ vars.IT_ORG_ID }}'"
$failed = $true
}
if ($failed) { exit 1 }
Write-Output "All config.json fields validated"
- name: Send test command
shell: pwsh
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' `
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' `
--form 'commands="[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$PS_Results = New-Object -TypeName psobject
# Start of typed powershell
$PS_Results | Add-Member -MemberType NoteProperty -Name \"error\" -Value \"\"
$PS_Results | Add-Member -MemberType NoteProperty -Name \"output\" -Value \"hello world`n\"
# Post results back to Rewst
$postData = $PS_Results | ConvertTo-Json
Invoke-RestMethod -Method \"Post\" -Uri $post_url -Body $postData -ContentType \"application/json\""'
- name: Check logs
shell: pwsh
run: |
$logFile = "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\rewst_agent.log"
$logContent = Get-Content $logFile -Raw
Write-Output $logContent
$expectedPatterns = @(
"Command completed",
"Sending postback",
"Postback already sent"
)
foreach ($pattern in $expectedPatterns) {
if ($logContent -notmatch [regex]::Escape($pattern)) {
Write-Error "Expected log line not found: $pattern"
exit 1
}
}
Write-Output "All expected log lines found"
- name: Send failing command
shell: pwsh
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' `
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' `
--form 'commands="[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$PS_Results = New-Object -TypeName psobject
# Start of typed powershell
throw \"this is a test error\"
# Post results back to Rewst
$postData = $PS_Results | ConvertTo-Json
Invoke-RestMethod -Method \"Post\" -Uri $post_url -Body $postData -ContentType \"application/json\""'
- name: Check logs for error handling
shell: pwsh
run: |
Start-Sleep -Seconds 15
$logFile = "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\rewst_agent.log"
$logContent = Get-Content $logFile -Raw
Write-Output $logContent
if ($logContent -notmatch "Command failed") {
Write-Error "Expected error message 'Command failed' not found in logs"
exit 1
}
Write-Output "Error handling verified: failing command error was captured"
- name: Install integration test binary (old version)
shell: pwsh
run: |
./dist/rewst_agent_config.win.it.exe --update --org-id ${{ vars.IT_ORG_ID }}
Write-Output "Installed integration test binary (version 0.0.0-it)"
- name: Wait for auto updater to trigger and update
shell: pwsh
run: |
$logFile = "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\rewst_agent.log"
Write-Output "Waiting for auto updater to detect newer version and update..."
for ($i = 1; $i -le 60; $i++) {
$logContent = Get-Content $logFile -Raw -ErrorAction SilentlyContinue
if ($logContent -match [regex]::Escape("Updating agent")) {
Write-Output "Auto update triggered after ${i}s"
break
}
Start-Sleep -Seconds 2
}
- name: Verify auto update completed
shell: pwsh
run: |
Start-Sleep -Seconds 15
$logFile = "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\rewst_agent.log"
$logContent = Get-Content $logFile -Raw
Write-Output $logContent
foreach ($pattern in @("Checking for updates", "Updating agent")) {
if ($logContent -notmatch [regex]::Escape($pattern)) {
Write-Error "Expected auto update log line not found: $pattern"
exit 1
}
}
$lastStartLine = ($logContent -split "`n" | Where-Object { $_ -match "Agent Smith started" } | Select-Object -Last 1)
if ($lastStartLine -match [regex]::Escape("version=0.0.0-it")) {
Write-Error "Agent is still running the integration test version after update"
exit 1
}
Write-Output "Auto updater integration test passed"
- name: Update logging level to debug
shell: pwsh
run: |
./dist/rewst_agent_config.win.exe --update --org-id ${{ vars.IT_ORG_ID }} --logging-level debug
Write-Output "Logging level successfully updated to debug"
- name: Send test command
shell: pwsh
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' `
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' `
--form 'commands="[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$PS_Results = New-Object -TypeName psobject
# Start of typed powershell
$PS_Results | Add-Member -MemberType NoteProperty -Name \"error\" -Value \"\"
$PS_Results | Add-Member -MemberType NoteProperty -Name \"output\" -Value \"hello world`n\"
# Post results back to Rewst
$postData = $PS_Results | ConvertTo-Json
Invoke-RestMethod -Method \"Post\" -Uri $post_url -Body $postData -ContentType \"application/json\""'
- name: Check logs
shell: pwsh
run: |
$logFile = "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\rewst_agent.log"
$logContent = Get-Content $logFile -Raw
Write-Output $logContent
if ($logContent -notmatch [regex]::Escape("DEBUG")) {
Write-Error "Expected log line not found: DEBUG"
}
Write-Output "All expected log lines found"
- name: Stop service
shell: pwsh
run: |
sc.exe stop ${{ steps.install_agent.outputs.service }}
- name: Delete log file
shell: pwsh
run: |
Remove-Item -Force "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\rewst_agent.log"
- name: Update agent
shell: pwsh
run: |
./dist/rewst_agent_config.win.exe --update --org-id ${{ vars.IT_ORG_ID }} --no-auto-updates --disable-agent-postback
- name: Check logs for no auto updater
shell: pwsh
run: |
$logFile = "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\rewst_agent.log"
for ($i = 1; $i -le 30; $i++) {
if (Test-Path $logFile) { break }
Write-Output "Waiting for log file to be created... ($i/30)"
Start-Sleep -Seconds 1
}
$logContent = Get-Content $logFile -Raw
Write-Output $logContent
if ($logContent -match [regex]::Escape("Starting auto updater")) {
Write-Error "Unexpected log line found: Starting auto updater"
exit 1
}
Write-Output "Confirmed: no 'Starting auto updater' log line found"
- name: Send test command
shell: pwsh
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' `
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' `
--form 'commands="[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$PS_Results = New-Object -TypeName psobject
# Start of typed powershell
$PS_Results | Add-Member -MemberType NoteProperty -Name \"error\" -Value \"\"
$PS_Results | Add-Member -MemberType NoteProperty -Name \"output\" -Value \"hello world`n\"
# Post results back to Rewst
$postData = $PS_Results | ConvertTo-Json
Invoke-RestMethod -Method \"Post\" -Uri $post_url -Body $postData -ContentType \"application/json\""'
- name: Check logs for command received
shell: pwsh
run: |
$logFile = "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}\rewst_agent.log"
$logContent = Get-Content $logFile -Raw
Write-Output $logContent
if ($logContent -notmatch [regex]::Escape("Command completed")) {
Write-Error "Expected log line not found: Command completed"
exit 1
}
if ($logContent -match [regex]::Escape("Postback already sent")) {
Write-Error "Unexpected log line found: Postback already sent"
exit 1
}
Write-Output "All log checks passed"
- name: Update agent with syslog
shell: pwsh
run: |
./dist/rewst_agent_config.win.exe --update --org-id ${{ vars.IT_ORG_ID }} --syslog
- name: Send test command
shell: pwsh
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' `
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' `
--form 'commands="[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$PS_Results = New-Object -TypeName psobject
# Start of typed powershell
$PS_Results | Add-Member -MemberType NoteProperty -Name \"error\" -Value \"\"
$PS_Results | Add-Member -MemberType NoteProperty -Name \"output\" -Value \"hello world`n\"
# Post results back to Rewst
$postData = $PS_Results | ConvertTo-Json
Invoke-RestMethod -Method \"Post\" -Uri $post_url -Body $postData -ContentType \"application/json\""'
- name: Check Windows Event Log for command completed
shell: pwsh
run: |
$events = Get-WinEvent -LogName Application -FilterXPath "*[System[Provider[@Name='RewstRemoteAgent_${{ vars.IT_ORG_ID }}']]]"
Write-Output "Found $($events.Count) event(s)"
$events | ForEach-Object { Write-Output $_.Message }
$matched = $events | Where-Object { $_.Message -match "Command completed" }
if (-not $matched) {
Write-Error "Expected 'Command completed' entry not found in Windows Event Log"
exit 1
}
Write-Output "Found 'Command completed' in Windows Event Log"
- name: Uninstall agent
shell: pwsh
run: |
./dist/rewst_agent_config.win.exe --uninstall --org-id ${{ vars.IT_ORG_ID }}
- name: Check deleted directories
shell: pwsh
run: |
if (Test-Path -Path "C:\ProgramData\RewstRemoteAgent\${{ vars.IT_ORG_ID }}") { exit 1 }
if (Test-Path -Path "C:\Program Files\RewstRemoteAgent\${{ vars.IT_ORG_ID }}") { exit 1 }
if (Test-Path -Path "C:\RewstRemoteAgent\scripts\${{ vars.IT_ORG_ID }}") { exit 1 }
echo "All directories have been deleted"
test-macos-latest:
permissions:
contents: read
needs: [build, build-integration-test]
if: inputs.os == 'macos-latest' || inputs.os == 'all'
runs-on: macos-latest
steps:
- name: Download compiled binary
uses: actions/download-artifact@v8
with:
name: macos-latest
path: ./dist
- name: Download integration test binary
uses: actions/download-artifact@v8
with:
name: it-macos-latest
path: ./dist
- name: Make binaries executable
run: |
chmod +x ./dist/rewst_agent_config.mac-os.bin
chmod +x ./dist/rewst_agent_config.mac-os.it.bin
- name: Install agent
id: install_agent
shell: bash
run: |
sudo ./dist/rewst_agent_config.mac-os.bin --config-url ${{ vars.IT_CONFIG_URL }} --config-secret ${{ secrets.IT_CONFIG_SECRET }} --org-id ${{ vars.IT_ORG_ID }}
echo "service=io.rewst.remote_agent_${{ vars.IT_ORG_ID }}" >> $GITHUB_OUTPUT
- name: Check service
shell: bash
run: |
sudo launchctl print system/${{ steps.install_agent.outputs.service }}
- name: Get device id
id: get_device_id
shell: bash
run: |
echo "value=$(cat "/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/config.json" | jq -r '.device_id')" >> "$GITHUB_OUTPUT"
- name: Validate config.json fields
shell: bash
run: |
config="/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/config.json"
failed=false
for field in device_id rewst_org_id rewst_engine_host shared_access_key azure_iot_hub_host; do
val=$(jq -r ".$field" "$config")
if [ -z "$val" ] || [ "$val" = "null" ]; then
echo "ERROR: Config field '$field' is missing or empty"
failed=true
else
echo "OK: $field = $val"
fi
done
org_id=$(jq -r '.rewst_org_id' "$config")
if [ "$org_id" != "${{ vars.IT_ORG_ID }}" ]; then
echo "ERROR: rewst_org_id '$org_id' does not match expected '${{ vars.IT_ORG_ID }}'"
failed=true
fi
if [ "$failed" = true ]; then exit 1; fi
echo "All config.json fields validated"
- name: Send test command
shell: bash
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' \
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' \
--form 'commands="echo \"hello world\""'
- name: Check logs
shell: bash
run: |
logFile="/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
logContent=$(cat "$logFile")
echo "$logContent"
for pattern in "Command completed" "Sending postback" "Postback sent"; do
if ! echo "$logContent" | grep -qF "$pattern"; then
echo "ERROR: Expected log line not found: $pattern"
exit 1
fi
done
echo "All expected log lines found"
- name: Send failing command
shell: bash
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' \
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' \
--form 'commands="exit 1"'
- name: Check logs for error handling
shell: bash
run: |
sleep 15
logFile="/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
logContent=$(cat "$logFile")
echo "$logContent"
if ! echo "$logContent" | grep -qF "Command failed"; then
echo "ERROR: Expected 'Command failed' not found in logs"
exit 1
fi
echo "Error handling verified: failing command error was captured"
- name: Install integration test binary (old version)
shell: bash
run: |
sudo ./dist/rewst_agent_config.mac-os.it.bin --update --org-id ${{ vars.IT_ORG_ID }}
echo "Installed integration test binary (version 0.0.0-it)"
- name: Wait for auto updater to trigger and update
shell: bash
run: |
logFile="/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
echo "Waiting for auto updater to detect newer version and update..."
for i in $(seq 1 60); do
logContent=$(cat "$logFile" 2>/dev/null || true)
if echo "$logContent" | grep -qF "Updating agent"; then
echo "Auto update triggered after ${i}s"
break
fi
sleep 2
done
- name: Verify auto update completed
shell: bash
run: |
sleep 15
logFile="/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
logContent=$(cat "$logFile")
echo "$logContent"
for pattern in "Checking for updates" "Updating agent"; do
if ! echo "$logContent" | grep -qF "$pattern"; then
echo "ERROR: Expected auto update log line not found: $pattern"
exit 1
fi
done
lastVersion=$(echo "$logContent" | grep "Agent Smith started" | tail -1)
if echo "$lastVersion" | grep -qF "version=0.0.0-it"; then
echo "ERROR: Agent is still running the integration test version after update"
exit 1
fi
echo "Auto updater integration test passed"
- name: Update logging level to debug
shell: bash
run: |
sudo ./dist/rewst_agent_config.mac-os.bin --update --org-id ${{ vars.IT_ORG_ID }} --logging-level debug
echo "Logging level successfully updated to debug"
- name: Send test command
shell: bash
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' \
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' \
--form 'commands="echo \"hello world\""'
- name: Check logs for debug level
shell: bash
run: |
logFile="/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
logContent=$(cat "$logFile")
echo "$logContent"
if ! echo "$logContent" | grep -qF "DEBUG"; then
echo "ERROR: Expected log line not found: DEBUG"
exit 1
fi
echo "All expected log lines found"
- name: Stop service
shell: bash
run: |
sudo launchctl stop system/${{ steps.install_agent.outputs.service }} || true
- name: Delete log file
shell: bash
run: |
sudo rm -f "/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
- name: Update agent
shell: bash
run: |
sudo ./dist/rewst_agent_config.mac-os.bin --update --org-id ${{ vars.IT_ORG_ID }} --no-auto-updates
- name: Check logs for no auto updater
shell: bash
run: |
logFile="/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}/rewst_agent.log"
for i in $(seq 1 30); do
[ -f "$logFile" ] && break
echo "Waiting for log file to be created... ($i/30)"
sleep 1
done
logContent=$(cat "$logFile")
echo "$logContent"
if echo "$logContent" | grep -qF "Starting auto updater"; then
echo "ERROR: Unexpected log line found: Starting auto updater"
exit 1
fi
echo "Confirmed: no 'Starting auto updater' log line found"
- name: Update agent with syslog
shell: bash
run: |
sudo ./dist/rewst_agent_config.mac-os.bin --update --org-id ${{ vars.IT_ORG_ID }} --syslog
- name: Send test command
shell: bash
run: |
curl --location '${{ vars.IT_SEND_COMMAND_TRIGGER_URL }}' \
--form 'device_id="${{ steps.get_device_id.outputs.value }}"' \
--form 'commands="echo \"hello world\""'
- name: Check syslog for command completed
shell: bash
run: |
sleep 15
entries=$(log show --predicate 'processImagePath contains "logger"' --info --last 5m 2>/dev/null || true)
echo "$entries"
if ! echo "$entries" | grep -qF "Command completed"; then
echo "ERROR: Expected 'Command completed' entry not found in syslog"
exit 1
fi
echo "Found 'Command completed' in syslog"
- name: Uninstall agent
shell: bash
run: |
sudo ./dist/rewst_agent_config.mac-os.bin --uninstall --org-id ${{ vars.IT_ORG_ID }}
- name: Check deleted directories
shell: pwsh
run: |
if (Test-Path -Path "/Library/Application Support/rewst_remote_agent/${{ vars.IT_ORG_ID }}") { exit 1 }
if (Test-Path -Path "/usr/local/bin/rewst_remote_agent/${{ vars.IT_ORG_ID }}") { exit 1 }
if (Test-Path -Path "$env:TMPDIR/rewst_remote_agent/scripts/${{ vars.IT_ORG_ID }}") { exit 1 }
echo "All directories have been deleted"