-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Support Advanced Threat Protection policy management #8523
Changes from 7 commits
2aaa7da
2a8763d
6ed9fd9
2d77c74
2d7777c
d272955
8f4621e
eef4981
5442cea
680df5e
3979f20
57a2dbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.ScenarioTest; | ||
using Microsoft.Azure.ServiceManagement.Common.Models; | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Commands.Security.Test.ScenarioTests | ||
{ | ||
public class SecurityAdvancedThreatProtectionTests | ||
{ | ||
private readonly XunitTracingInterceptor _logger; | ||
|
||
public SecurityAdvancedThreatProtectionTests(Xunit.Abstractions.ITestOutputHelper output) | ||
{ | ||
_logger = new XunitTracingInterceptor(output); | ||
XunitTracingInterceptor.AddToContext(_logger); | ||
TestExecutionHelpers.SetUpSessionAndProfile(); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void GetResourceId() | ||
{ | ||
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzSecurityThreatProtection-ResourceId"); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# Copyright Microsoft Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ---------------------------------------------------------------------------------- | ||
|
||
<# | ||
.SYNOPSIS | ||
Get a security contact by resource ID | ||
#> | ||
function Test-AzSecurityThreatProtection-ResourceId | ||
{ | ||
# Setup | ||
$testSuffix = "pstest" | ||
$testParams = Get-AdvancedThreatProtectionTestEnvironmentParameters $testSuffix | ||
$resourceId = "/subscriptions/" + $testParams.subscriptionId + "/resourceGroups/" + $testParams.rgName + "/providers/Microsoft.Storage/storageAccounts/" + $testParams.accountName | ||
Create-TestEnvironmentWithParams $testParams | ||
|
||
#Enable | ||
$policy = Set-AzSecurityThreatProtection -ResourceId $resourceId -Enable | ||
$fetchedPolicy = Get-AzSecurityThreatProtection -ResourceId $resourceId | ||
Assert-AreEqual $policy.IsEnabled $True | ||
Assert-AreEqual $True $fetchedPolicy.IsEnabled | ||
|
||
#Disable | ||
$policy = Set-AzSecurityThreatProtection -ResourceId $resourceId -Disable | ||
$fetchedPolicy = Get-AzSecurityThreatProtection -ResourceId $resourceId | ||
Assert-AreEqual $policy.IsEnabled $False | ||
Assert-AreEqual $False $fetchedPolicy.IsEnabled | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Gets the values of the parameters used at the tests | ||
#> | ||
function Get-AdvancedThreatProtectionTestEnvironmentParameters ($testSuffix) | ||
{ | ||
return @{ subscriptionId = (Get-AzContext).Subscription.Id; | ||
rgName = "storage-atp-cmdlet-test-rg" +$testSuffix; | ||
accountName = "storage" +$testSuffix; | ||
storageSku = "Standard_GRS"; | ||
location = "West Central US" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Creates the basic test environment needed to perform the threat protection tests - resource group and storage account | ||
#> | ||
function Create-TestEnvironmentWithParams ($testParams) | ||
{ | ||
# Create a new resource group. | ||
New-AzResourceGroup -Name $testParams.rgName -Location $testParams.location | ||
|
||
# Create the storage account. | ||
$storageAccount = New-AzStorageAccount -ResourceGroupName $testParams.rgName -AccountName $testParams.accountName -Location $testParams.location -SkuName $testParams.storageSku | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -12,26 +12,26 @@ | |||||||
// limitations under the License. | ||||||||
// ---------------------------------------------------------------------------------- | ||||||||
|
||||||||
using System; | ||||||||
using System.Collections.Generic; | ||||||||
using System.Diagnostics; | ||||||||
using System.IO; | ||||||||
using System.Linq; | ||||||||
using Microsoft.Azure.Commands.Common.Authentication; | ||||||||
using Microsoft.Azure.Management.ResourceManager; | ||||||||
using Microsoft.Azure.Management.Security; | ||||||||
using Microsoft.Azure.Management.Storage; | ||||||||
using Microsoft.Azure.Test.HttpRecorder; | ||||||||
using Microsoft.Rest.ClientRuntime.Azure.TestFramework; | ||||||||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||||||||
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; | ||||||||
using System; | ||||||||
using System.Collections.Generic; | ||||||||
using System.Diagnostics; | ||||||||
using System.IO; | ||||||||
using System.Linq; | ||||||||
|
||||||||
namespace Microsoft.Azure.Commands.Security.Test.ScenarioTests | ||||||||
{ | ||||||||
public class TestController : RMTestBase | ||||||||
{ | ||||||||
private readonly EnvironmentSetupHelper _helper; | ||||||||
|
||||||||
public SecurityCenterClient SecurityCenterClient { get; private set; } | ||||||||
|
||||||||
public static TestController NewInstance => new TestController(); | ||||||||
|
||||||||
protected TestController() | ||||||||
|
@@ -63,21 +63,33 @@ public void RunPowerShellTest(ServiceManagement.Common.Models.XunitTracingInterc | |||||||
_helper.RMProfileModule, | ||||||||
_helper.GetRMModulePath(@"AzureRM.Security.psd1"), | ||||||||
"ScenarioTests\\Common.ps1", | ||||||||
"ScenarioTests\\" + callingClassName + ".ps1"); | ||||||||
"ScenarioTests\\" + callingClassName + ".ps1", | ||||||||
_helper.GetRMModulePath(@"AzureRM.Resources"), | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using the Resources and Storage modules, please use our internal version of these cmdlets. This is just changing this import to the two ps1 files: azure-powershell/src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/TestsBase.cs Line 145 in d99d9f8
azure-powershell/src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/TestsBase.cs Line 32 in d99d9f8
azure-powershell/src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/TestsBase.cs Line 29 in d99d9f8
|
||||||||
_helper.GetRMModulePath(@"Az.Storage.psd1")); | ||||||||
|
||||||||
_helper.RunPowerShellTest(scripts); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
protected void SetupManagementClients(MockContext context) | ||||||||
{ | ||||||||
SecurityCenterClient = GetSecurityCenterClient(context); | ||||||||
_helper.SetupManagementClients(SecurityCenterClient); | ||||||||
var resourcesClient = GetResourcesClient(context); | ||||||||
var securityCenterClient = GetSecurityCenterClient(context); | ||||||||
var storageClient = GetStorageManagementClient(context); | ||||||||
_helper.SetupManagementClients(securityCenterClient, resourcesClient, storageClient); | ||||||||
} | ||||||||
|
||||||||
private static SecurityCenterClient GetSecurityCenterClient(MockContext context) | ||||||||
{ | ||||||||
return context.GetServiceClient<SecurityCenterClient>(TestEnvironmentFactory.GetTestEnvironment()); | ||||||||
} | ||||||||
private static ResourceManagementClient GetResourcesClient(MockContext context) | ||||||||
{ | ||||||||
return context.GetServiceClient<ResourceManagementClient>(TestEnvironmentFactory.GetTestEnvironment()); | ||||||||
} | ||||||||
private static StorageManagementClient GetStorageManagementClient(MockContext context) | ||||||||
{ | ||||||||
return context.GetServiceClient<StorageManagementClient>(TestEnvironmentFactory.GetTestEnvironment()); | ||||||||
} | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Azure.Management.SecurityCenter" Version="0.10.0-preview" /> | ||
<PackageReference Include="Microsoft.Azure.Management.SecurityCenter" Version="0.11.0-preview" /> | ||
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="9.1.0-preview" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this once you update to the common client. |
||
</ItemGroup> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use "getAssetName" to add an element of randomness to your resource name generation.