Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/Microsoft.PowerShell.Security/security/CatalogCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,27 @@ protected override void ProcessRecord()
{
foreach (PathInfo tempPath in SessionState.Path.GetResolvedPSPathFromPSPath(p))
{
paths.Add(tempPath.ProviderPath);
if (ShouldProcess(tempPath.ProviderPath))
{
paths.Add(tempPath.ProviderPath);
}
}
}
}

string drive = null;

// resolve catalog destination Path
if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath))
// We add 'paths.Count > 0' to support 'ShouldProcess()'
if (paths.Count > 0 )
{
catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath);
}
string drive = null;

// resolve catalog destination Path
if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath))
{
catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath);
}

PerformAction(paths, catalogFilePath);
PerformAction(paths, catalogFilePath);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ Describe "Test suite for NewFileCatalogAndTestFileCatalogCmdlets" -Tags "CI" {

Context "NewAndTestCatalogTests PositiveTestCases when validation Succeeds" {

It "NewFileCatalogWithSingleFile with WhatIf" {

$sourcePath = Join-Path $testDataPath '\CatalogTestFile1.mof'
# use existant Path for the directory when .cat file name is not specified
$catalogPath = $testDataPath
$catalogFile = $catalogPath + "\catalog.cat"

try
{
$null = New-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath -WhatIf
$result = Test-Path -Path $catalogFile
}
finally
{
Remove-Item $catalogFile -Force -ErrorAction SilentlyContinue
}

# Validate result properties
$result | Should Be $false
}

It "NewFileCatalogFolder" {

$sourcePath = Join-Path $testDataPath 'UserConfigProv\DSCResources\scriptdsc'
Expand Down