version mise à jour par claude , à tester
This commit is contained in:
+186
@@ -0,0 +1,186 @@
|
||||
# AD API Testing Script
|
||||
# Tests each Application Dictionary element type endpoint
|
||||
|
||||
# Configuration
|
||||
$baseUrl = "https://localhost"
|
||||
$tokenUrl = "$baseUrl/EasySTS/OAuth/Token"
|
||||
$adApiBase = "$baseUrl/AD/api"
|
||||
$auth = "Basic R05BOklFNGU3aXFoZHQ="
|
||||
$username = "mecalux"
|
||||
$password = "ANDREZmlx6"
|
||||
$tenant = "AD"
|
||||
$application = "EasyWMS"
|
||||
|
||||
# Skip SSL certificate validation (self-signed cert)
|
||||
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
|
||||
Add-Type @"
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
public class TrustAllCertsPolicy : ICertificatePolicy {
|
||||
public bool CheckValidationResult(
|
||||
ServicePoint srvPoint, X509Certificate certificate,
|
||||
WebRequest request, int certificateProblem) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"@
|
||||
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
|
||||
|
||||
Write-Host "`n=== Getting OAuth Token ===" -ForegroundColor Cyan
|
||||
|
||||
# Get OAuth token
|
||||
$tokenBody = @{
|
||||
grant_type = "password"
|
||||
tenant_code = $tenant
|
||||
username = $username
|
||||
password = $password
|
||||
}
|
||||
|
||||
try {
|
||||
$tokenResponse = Invoke-RestMethod -Uri $tokenUrl -Method Post -Headers @{
|
||||
"Authorization" = $auth
|
||||
"Content-Type" = "application/x-www-form-urlencoded"
|
||||
} -Body $tokenBody
|
||||
|
||||
$token = $tokenResponse.access_token
|
||||
Write-Host "[OK] Token obtained successfully" -ForegroundColor Green
|
||||
Write-Host " Token: $($token.Substring(0, 50))..." -ForegroundColor Gray
|
||||
}
|
||||
catch {
|
||||
Write-Host "[FAIL] Failed to get token: $($_.Exception.Message)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Element types to test (only non-zero counts from screenshot)
|
||||
$elementTypes = @(
|
||||
@{Name="Command"; Count=1872},
|
||||
@{Name="Dialog"; Count=734},
|
||||
@{Name="Entity"; Count=331},
|
||||
@{Name="Event"; Count=1980},
|
||||
@{Name="FieldType"; Count=320},
|
||||
@{Name="Hook"; Count=60},
|
||||
@{Name="List"; Count=243},
|
||||
@{Name="Query"; Count=2016},
|
||||
@{Name="Record"; Count=337},
|
||||
@{Name="Relationship"; Count=49},
|
||||
@{Name="Report"; Count=67},
|
||||
@{Name="Resource"; Count=29374},
|
||||
@{Name="Subscription"; Count=500},
|
||||
@{Name="Validator"; Count=17},
|
||||
@{Name="ViewGroup"; Count=180},
|
||||
@{Name="View"; Count=373},
|
||||
@{Name="WorkflowAction"; Count=47},
|
||||
@{Name="Workflow"; Count=3712},
|
||||
@{Name="WritingModel"; Count=226}
|
||||
)
|
||||
|
||||
Write-Host "`n=== Testing AD API Endpoints ===" -ForegroundColor Cyan
|
||||
Write-Host "Testing $($elementTypes.Count) element types`n" -ForegroundColor Gray
|
||||
|
||||
$results = @()
|
||||
|
||||
foreach ($type in $elementTypes) {
|
||||
$typeName = $type.Name
|
||||
$expectedCount = $type.Count
|
||||
|
||||
Write-Host "Testing $typeName (expected: $expectedCount)..." -ForegroundColor Yellow -NoNewline
|
||||
|
||||
$endpoint = "$adApiBase/$typeName/GetByApplication"
|
||||
$body = @($application, $tenant, 10, 0) | ConvertTo-Json -Compress
|
||||
|
||||
try {
|
||||
$response = Invoke-RestMethod -Uri $endpoint -Method Post -Headers @{
|
||||
"Authorization" = "Bearer $token"
|
||||
"Content-Type" = "application/json"
|
||||
} -Body $body -TimeoutSec 30
|
||||
|
||||
$entities = $response.entities
|
||||
$count = if ($entities) { $entities.Count } else { 0 }
|
||||
|
||||
if ($count -gt 0) {
|
||||
Write-Host " SUCCESS ($count elements)" -ForegroundColor Green
|
||||
|
||||
# Show first element details
|
||||
$firstElement = $entities[0]
|
||||
$elementId = if ($firstElement.Id) { $firstElement.Id } else { $firstElement.id }
|
||||
$elementName = if ($firstElement.Name) { $firstElement.Name } else { $firstElement.name }
|
||||
$elementCode = if ($firstElement.Code) { $firstElement.Code } else { $firstElement.code }
|
||||
|
||||
Write-Host " First element: ID=$elementId, Name=$elementName, Code=$elementCode" -ForegroundColor Gray
|
||||
|
||||
$results += @{
|
||||
Type = $typeName
|
||||
Status = "SUCCESS"
|
||||
Count = $count
|
||||
Expected = $expectedCount
|
||||
FirstElement = @{
|
||||
Id = $elementId
|
||||
Name = $elementName
|
||||
Code = $elementCode
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host " No entities returned" -ForegroundColor DarkYellow
|
||||
$results += @{
|
||||
Type = $typeName
|
||||
Status = "EMPTY"
|
||||
Count = 0
|
||||
Expected = $expectedCount
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host " FAILED" -ForegroundColor Red
|
||||
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor DarkRed
|
||||
$results += @{
|
||||
Type = $typeName
|
||||
Status = "FAILED"
|
||||
Error = $_.Exception.Message
|
||||
Expected = $expectedCount
|
||||
}
|
||||
}
|
||||
|
||||
Start-Sleep -Milliseconds 200
|
||||
}
|
||||
|
||||
# Summary
|
||||
Write-Host "`n=== Test Summary ===" -ForegroundColor Cyan
|
||||
$successful = ($results | Where-Object { $_.Status -eq "SUCCESS" }).Count
|
||||
$failed = ($results | Where-Object { $_.Status -eq "FAILED" }).Count
|
||||
$empty = ($results | Where-Object { $_.Status -eq "EMPTY" }).Count
|
||||
|
||||
Write-Host "Total tested: $($elementTypes.Count)" -ForegroundColor White
|
||||
Write-Host "[OK] Successful: $successful" -ForegroundColor Green
|
||||
Write-Host "[WARN] Empty: $empty" -ForegroundColor DarkYellow
|
||||
Write-Host "[FAIL] Failed: $failed" -ForegroundColor Red
|
||||
|
||||
# Detailed results
|
||||
Write-Host "`n=== Detailed Results ===" -ForegroundColor Cyan
|
||||
foreach ($result in $results) {
|
||||
$status = switch ($result.Status) {
|
||||
"SUCCESS" { "[OK]" }
|
||||
"EMPTY" { "[WARN]" }
|
||||
"FAILED" { "[FAIL]" }
|
||||
}
|
||||
|
||||
$color = switch ($result.Status) {
|
||||
"SUCCESS" { "Green" }
|
||||
"EMPTY" { "DarkYellow" }
|
||||
"FAILED" { "Red" }
|
||||
}
|
||||
|
||||
Write-Host "$status $($result.Type): " -ForegroundColor $color -NoNewline
|
||||
|
||||
if ($result.Status -eq "SUCCESS") {
|
||||
Write-Host "$($result.Count) elements (expected: $($result.Expected))" -ForegroundColor Gray
|
||||
}
|
||||
elseif ($result.Status -eq "EMPTY") {
|
||||
Write-Host "No data (expected: $($result.Expected))" -ForegroundColor Gray
|
||||
}
|
||||
else {
|
||||
Write-Host "$($result.Error)" -ForegroundColor DarkRed
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`nTest completed.`n" -ForegroundColor Cyan
|
||||
Reference in New Issue
Block a user