Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update-NexposeScanEnginePool: 4 misc fixes #28

Open
NetherSmash opened this issue Apr 24, 2024 · 12 comments
Open

Update-NexposeScanEnginePool: 4 misc fixes #28

NetherSmash opened this issue Apr 24, 2024 · 12 comments

Comments

@NetherSmash
Copy link

While (re)testing more of this function, I discovered a few bugs:

  1. line 54
    If ([string]::IsNullOrEmpty($NewName) -and [string]::IsNullOrEmpty($ScanEngine)) {
    is missing checking for sites. I'm not sure if this is intentional
    If ([string]::IsNullOrEmpty($NewName) -and [string]::IsNullOrEmpty($ScanEngine) -and [string]::IsNullOrEmpty($Site)) {

  2. line 67
    ForEach ($seId In $ScanEngineIds) {
    should be
    ForEach ($seId In $ScanEngine) {

  3. line 83
    ForEach ($sId In $SiteIds) {
    should be
    ForEach ($sId In $Site) {

  4. line 85
    $ScanEngineIds += $sId
    should be
    $SiteIds += $sId

@NetherSmash
Copy link
Author

My unit test for NEWNAME

$EnginePoolId = 7
$NewName = "Secondary Scanners"

# get existing
$OriginalPool = Get-NexposeScanEnginePool -Id $EnginePoolId
$OriginalName = $OriginalPool.name
$link = Update-NexposeScanEnginePool -Id $EnginePoolId -NewName $NewName
$UpdatedPool = Get-NexposeScanEnginePool -Id $EnginePoolId
Write-Host "Changed ID $EnginePoolId Name from '$($OriginalPool.name)' to '$($UpdatedPool.Name)'"

# change back to original 
$link = Update-NexposeScanEnginePool -Id $EnginePoolId -NewName $OriginalName
Write-Host "Changed ID $EnginePoolId Name from '$($UpdatedPool.name)' to '$((Get-NexposeScanEnginePool -Id $EnginePoolId).Name)'"

Output:
Changed ID 7 Name from 'Prime Scanners' to 'Secondary Scanners'
Changed ID 7 Name from 'Secondary Scanners' to 'Prime Scanners'

@NetherSmash
Copy link
Author

My unit test for SCANENGINE

$EnginePoolId = 7
$EngineIdToAdd = 42

# get existing
$OriginalPool = Get-NexposeScanEnginePool -Id $EnginePoolId
$OriginalEngines = $OriginalPool.engines

# add new engine
$NewEngines = $OriginalEngines + $EngineIdToAdd
$link = Update-NexposeScanEnginePool -Id $EnginePoolId -ScanEngine $NewEngines
$UpdatedPool = Get-NexposeScanEnginePool -Id $EnginePoolId
Write-Host "Changed ID $EnginePoolId from $($OriginalPool.engines.Count) engines to $($UpdatedPool.engines.Count)"
Compare-Object ($OriginalPool.engines) ($UpdatedPool.engines)

# replace engines with orginal list
$link = Update-NexposeScanEnginePool -Id $EnginePoolId -ScanEngine $OriginalEngines
Write-Host "Changed ID $EnginePoolId from $($UpdatedPool.engines.Count) engines to $((Get-NexposeScanEnginePool -Id $EnginePoolId).engines.Count)"
Compare-Object ($UpdatedPool.engines) ((Get-NexposeScanEnginePool -Id $EnginePoolId).engines)

Output
Changed ID 7 from 10 engines to 11

Changed ID 7 from 11 engines to 10
InputObject SideIndicator
42 =>
42 <=

@NetherSmash
Copy link
Author

My unit test for SITE

$EnginePoolId = 7
$SiteIdToAdd = 471

# get existing
$OriginalPool = Get-NexposeScanEnginePool -Id $EnginePoolId
$OriginalSites = $OriginalPool.sites

# add new site
$NewSites = $OriginalSites + $SiteIdToAdd
$link = Update-NexposeScanEnginePool -Id $EnginePoolId -Site $NewSites
$UpdatedPool = Get-NexposeScanEnginePool -Id $EnginePoolId
Write-Host "Changed ID $EnginePoolId from $($OriginalPool.sites.Count) sites to $($UpdatedPool.sites.Count)"
Compare-Object ($OriginalPool.sites) ($UpdatedPool.sites)

# replace sites with orginal list
$link = Update-NexposeScanEnginePool -Id $EnginePoolId -Site $OriginalSites
Write-Host "Changed ID $EnginePoolId from $($UpdatedPool.sites.Count) sites to $((Get-NexposeScanEnginePool -Id $EnginePoolId).sites.Count)"
Compare-Object ($UpdatedPool.sites) ((Get-NexposeScanEnginePool -Id $EnginePoolId).sites)

Output
Changed ID 7 from 16 sites to 16
Changed ID 7 from 16 sites to 16

@NetherSmash
Copy link
Author

You can see from the output that changing the name works, as well as adding an engine (and replacing back with the original list)

However, adding a site does not seem to work. I've thrown on -debug and the updated list appears to be passed correctly to Invoke-NexposeRestMethod. I'm interested to know if it works for you, or if you can find what I've missed.

as always, thanks!

@My-Random-Thoughts
Copy link
Owner

Thank you again for these bug reports, I really appreciate it.

I can't test the scan engine code very well as I am using the 30-day trial licence that only allows the single built-in scan engine, however the code fixes you posted are correct.

@NetherSmash
Copy link
Author

Did you get a chance to test updating the sites?

@My-Random-Thoughts
Copy link
Owner

Ah sorry, missed that bit.

@My-Random-Thoughts
Copy link
Owner

Can you send me the ApiQuery data shown with the -Debug please.
It should match something like the example shown here [PUT] Engine Pool

@NetherSmash
Copy link
Author

Add an engine (this works)

  1. Confirm initial state
PS C:\WINDOWS\system32>> $OriginalPool = Get-NexposeScanEnginePool -Id $EnginePoolId -Debug; $OriginalPool
DEBUG: {
    "engines":  [
                    24,
                    23,
                    26,
                    25
                ],
    "id":  47,
    "name":  "R7-Mgmt-Pool",
    "sites":  [
                  498,
                  499,
                  500,
                  502,
                  377
              ]
}

engines          id name         sites                  
-------          -- ----         -----                  
{24, 23, 26, 25} 47 R7-Mgmt-Pool {498, 499, 500, 502...}
  1. Add an engine
PS C:\WINDOWS\system32>> $link = Update-NexposeScanEnginePool -Id $EnginePoolId -ScanEngine ($OriginalEngines + 42) -Debug
DEBUG: {
    "engines":  [
                    24,
                    23,
                    26,
                    25
                ],
    "id":  47,
    "name":  "R7-Mgmt-Pool",
    "sites":  [
                  498,
                  499,
                  500,
                  502,
                  377
              ]
}
DEBUG: ApiQuery:
{
    "engines":  [
                    24,
                    23,
                    26,
                    25,
                    42
                ],
    "name":  "R7-Mgmt-Pool",
    "id":  "47",
    "sites":  [
                  498,
                  499,
                  500,
                  502,
                  377
              ]
}
  1. Confirm addition
PS C:\WINDOWS\system32>> Get-NexposeScanEnginePool -Id $EnginePoolId -Debug
DEBUG: {
    "engines":  [
                    24,
                    23,
                    26,
                    25,
                    42
                ],
    "id":  47,
    "name":  "R7-Mgmt-Pool",
    "sites":  [
                  498,
                  499,
                  500,
                  502,
                  377
              ]
}

engines             id name         sites                  
-------             -- ----         -----                  
{24, 23, 26, 25...} 47 R7-Mgmt-Pool {498, 499, 500, 502...}

@NetherSmash
Copy link
Author

Add a site (this doesn't work)

  1. Confirm initial state
PS C:\WINDOWS\system32>> $OriginalPool = Get-NexposeScanEnginePool -Id $EnginePoolId -Debug; $OriginalPool
DEBUG: {
    "engines":  [
                    24,
                    23,
                    26,
                    25
                ],
    "id":  47,
    "name":  "R7-Mgmt-Pool",
    "sites":  [
                  498,
                  499,
                  500,
                  502,
                  377
              ]
}

engines          id name         sites                  
-------          -- ----         -----                  
{24, 23, 26, 25} 47 R7-Mgmt-Pool {498, 499, 500, 502...}
  1. Add a site
PS C:\WINDOWS\system32>> $link = Update-NexposeScanEnginePool -Id $EnginePoolId -Site ($OriginalSites + 505) -Debug
DEBUG: {
    "engines":  [
                    24,
                    23,
                    26,
                    25
                ],
    "id":  47,
    "name":  "R7-Mgmt-Pool",
    "sites":  [
                  498,
                  499,
                  500,
                  502,
                  377
              ]
}
DEBUG: ApiQuery:
{
    "engines":  [
                    24,
                    23,
                    26,
                    25
                ],
    "name":  "R7-Mgmt-Pool",
    "id":  "47",
    "sites":  [
                  498,
                  499,
                  500,
                  502,
                  377,
                  505
              ]
}
  1. Confirm addition
PS C:\WINDOWS\system32>> Get-NexposeScanEnginePool -Id $EnginePoolId -Debug
DEBUG: {
    "engines":  [
                    24,
                    23,
                    26,
                    25
                ],
    "id":  47,
    "name":  "R7-Mgmt-Pool",
    "sites":  [
                  498,
                  499,
                  500,
                  502,
                  377
              ]
}

engines          id name         sites                  
-------          -- ----         -----                  
{24, 23, 26, 25} 47 R7-Mgmt-Pool {498, 499, 500, 502...}

@NetherSmash
Copy link
Author

I'm just writing some code to test directly against the API and confirm functionality, and will post that when complete

@My-Random-Thoughts
Copy link
Owner

Thank you very much for that, it does look like the ApiQuery is valid for the call.
Please let me know how how your test go, it may be a bug with R7 - I have logged so many when writing this module :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants