-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ps1
More file actions
177 lines (151 loc) · 5.94 KB
/
Copy pathtest.ps1
File metadata and controls
177 lines (151 loc) · 5.94 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
# Test script for acllock
# Run this to verify installation and basic functionality
$ErrorActionPreference = "Continue"
Write-Host ""
Write-Host "==================================" -ForegroundColor Cyan
Write-Host " acllock Test Suite" -ForegroundColor Cyan
Write-Host "==================================" -ForegroundColor Cyan
Write-Host ""
# Test 1: Check PowerShell version
Write-Host "[TEST 1] PowerShell Version Check" -ForegroundColor Yellow
$psVersion = $PSVersionTable.PSVersion
Write-Host " Version: $psVersion"
if ($psVersion.Major -ge 7) {
Write-Host " ✓ PASS" -ForegroundColor Green
} else {
Write-Host " ✗ FAIL - PowerShell 7+ required" -ForegroundColor Red
}
Write-Host ""
# Test 2: Check admin privileges
Write-Host "[TEST 2] Administrator Privileges" -ForegroundColor Yellow
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ($isAdmin) {
Write-Host " ✓ PASS - Running as Administrator" -ForegroundColor Green
} else {
Write-Host " ⚠ WARNING - Not running as Administrator" -ForegroundColor Yellow
Write-Host " Some tests will be skipped" -ForegroundColor Gray
}
Write-Host ""
# Test 3: Check acllock files
Write-Host "[TEST 3] File Structure" -ForegroundColor Yellow
$requiredFiles = @(
"acllock.ps1",
"acllock.cmd",
"core\acl.ps1",
"core\validate.ps1",
"core\state.ps1",
"core\backup.ps1",
"core\logger.ps1",
"ui\tui.ps1",
"ui\draw.ps1"
)
$allFilesExist = $true
foreach ($file in $requiredFiles) {
$path = Join-Path $PSScriptRoot $file
if (Test-Path $path) {
Write-Host " ✓ $file" -ForegroundColor Green
} else {
Write-Host " ✗ $file MISSING" -ForegroundColor Red
$allFilesExist = $false
}
}
if ($allFilesExist) {
Write-Host " ✓ PASS - All files present" -ForegroundColor Green
} else {
Write-Host " ✗ FAIL - Missing files" -ForegroundColor Red
}
Write-Host ""
# Test 4: Module loading
Write-Host "[TEST 4] Module Loading" -ForegroundColor Yellow
try {
. "$PSScriptRoot\core\logger.ps1"
. "$PSScriptRoot\core\validate.ps1"
. "$PSScriptRoot\core\state.ps1"
. "$PSScriptRoot\core\backup.ps1"
. "$PSScriptRoot\core\acl.ps1"
Write-Host " ✓ PASS - All modules loaded" -ForegroundColor Green
} catch {
Write-Host " ✗ FAIL - Module loading error: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 5: Help command
Write-Host "[TEST 5] Help Command" -ForegroundColor Yellow
try {
$helpOutput = & "$PSScriptRoot\acllock.ps1" help 2>&1
if ($helpOutput -match "acllock") {
Write-Host " ✓ PASS - Help command works" -ForegroundColor Green
} else {
Write-Host " ✗ FAIL - Help output unexpected" -ForegroundColor Red
}
} catch {
Write-Host " ✗ FAIL - Help command error: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 6: Version command
Write-Host "[TEST 6] Version Command" -ForegroundColor Yellow
try {
$versionOutput = & "$PSScriptRoot\acllock.ps1" version 2>&1
if ($versionOutput -match "acllock v\d+\.\d+\.\d+") {
Write-Host " ✓ PASS - Version command works" -ForegroundColor Green
Write-Host " $versionOutput" -ForegroundColor Gray
} else {
Write-Host " ✗ FAIL - Version output unexpected" -ForegroundColor Red
}
} catch {
Write-Host " ✗ FAIL - Version command error: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 7: Functional test (only if admin)
if ($isAdmin) {
Write-Host "[TEST 7] Functional Test" -ForegroundColor Yellow
# Create test directory
$testDir = Join-Path $env:TEMP "acllock-test-$(Get-Random)"
try {
New-Item -ItemType Directory -Path $testDir -Force | Out-Null
New-Item -ItemType File -Path "$testDir\test.txt" -Force | Out-Null
Set-Content -Path "$testDir\test.txt" -Value "Test content"
Write-Host " Created test directory: $testDir" -ForegroundColor Gray
# Test lock
Write-Host " Testing lock..." -ForegroundColor Gray
& "$PSScriptRoot\acllock.ps1" lock $testDir -Force -Note "Test lock" | Out-Null
$status = & "$PSScriptRoot\acllock.ps1" status $testDir -Json | ConvertFrom-Json
if ($status.isLocked) {
Write-Host " ✓ Lock successful" -ForegroundColor Green
} else {
Write-Host " ✗ Lock failed" -ForegroundColor Red
}
# Test unlock
Write-Host " Testing unlock..." -ForegroundColor Gray
& "$PSScriptRoot\acllock.ps1" unlock $testDir -Force | Out-Null
$status = & "$PSScriptRoot\acllock.ps1" status $testDir -Json | ConvertFrom-Json
if (-not $status.isLocked) {
Write-Host " ✓ Unlock successful" -ForegroundColor Green
} else {
Write-Host " ✗ Unlock failed" -ForegroundColor Red
}
Write-Host " ✓ PASS - Functional test complete" -ForegroundColor Green
} catch {
Write-Host " ✗ FAIL - Functional test error: $($_.Exception.Message)" -ForegroundColor Red
} finally {
# Cleanup
if (Test-Path $testDir) {
Remove-Item -Path $testDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
Write-Host ""
} else {
Write-Host "[TEST 7] Functional Test - SKIPPED (requires admin)" -ForegroundColor Yellow
Write-Host ""
}
# Summary
Write-Host "==================================" -ForegroundColor Cyan
Write-Host " Test Suite Complete" -ForegroundColor Cyan
Write-Host "==================================" -ForegroundColor Cyan
Write-Host ""
if ($isAdmin) {
Write-Host "All tests completed successfully!" -ForegroundColor Green
} else {
Write-Host "Basic tests passed. Run as Administrator for full test suite." -ForegroundColor Yellow
}
Write-Host ""