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

Manage SQL Information Protection Policy #11558

Merged
merged 11 commits into from
Apr 22, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// ----------------------------------------------------------------------------------
//
// 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 SqlInformationProtectionPolicyTests
{
public SqlInformationProtectionPolicyTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
TestExecutionHelpers.SetUpSessionAndProfile();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestErrorWhenInformationTypeAndSensitivityLabelShareSameId()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ErrorWhenInformationTypeAndSensitivityLabelShareSameId");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestErrorWhenInformationTypeAndSensitivityLabelShareSameDisplayName()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ErrorWhenInformationTypeAndSensitivityLabelShareSameDisplayName");

}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestErrorWhenInformationTypesShareSameDisplayName()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ErrorWhenInformationTypesShareSameDisplayName");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestErrorWhenSensitivityLabelsShareSameDisplayName()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ErrorWhenSensitivityLabelsShareSameDisplayName");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestErrorWhenRankIsInvalid()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ErrorWhenRankIsInvalid");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestErrorWhenRankIsMissing()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ErrorWhenRankIsMissing");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestErrorWhenSettingAnEmptyPolicy()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ErrorWhenSettingAnEmptyPolicy");
}

private readonly XunitTracingInterceptor _logger;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# ----------------------------------------------------------------------------------
#
# 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
Tests an error is raised when setting an empty policy
#>
function Test-ErrorWhenSettingAnEmptyPolicy
{
$message = "The provided policy definition is empty."
Assert-Throws {Set-AzSqlInformationProtectionPolicy -FilePath "SqlInformationProtectionPolicies\Empty.json" } $message
}

<#
.SYNOPSIS
Tests an error is raised when setting a policy containing a label and an information type sharing same id.
#>
function Test-ErrorWhenInformationTypeAndSensitivityLabelShareSameId
{
$message = "Ids should be unique. Please eliminate duplication of these ids: '50e58766-ab53-4846-be8a-35e0bb87723e'."
Assert-Throws {Set-AzSqlInformationProtectionPolicy -FilePath "SqlInformationProtectionPolicies\InformationTypeAndSensitivityLabelSharingSameId.json" } $message
}

<#
.SYNOPSIS
Tests an error is raised when setting a policy containing information types sharing same display name.
#>
function Test-ErrorWhenInformationTypesShareSameDisplayName
{
$message = "Display names should be unique. Please eliminate duplication of these names: 'Health'."
Assert-Throws {Set-AzSqlInformationProtectionPolicy -FilePath "SqlInformationProtectionPolicies\InformationTypesSharingSameDisplayName.json" } $message
}

<#
.SYNOPSIS
Tests an error is raised when setting a policy containing sensitivity labels sharing same display name.
#>
function Test-ErrorWhenSensitivityLabelsShareSameDisplayName
{
$message = "Display names should be unique. Please eliminate duplication of these names: 'Public'."
Assert-Throws {Set-AzSqlInformationProtectionPolicy -FilePath "SqlInformationProtectionPolicies\SensitivityLabelsSharingSameDisplayName.json" } $message
}

<#
.SYNOPSIS
Tests an error is raised when setting a policy containing information type and sensitivity label sharing same display name.
#>
function Test-ErrorWhenInformationTypeAndSensitivityLabelShareSameDisplayName
{
$message = "Display names should be unique. Please eliminate duplication of these names: 'Public'."
Assert-Throws {Set-AzSqlInformationProtectionPolicy -FilePath "SqlInformationProtectionPolicies\SensitivityLabelsSharingSameDisplayName.json" } $message
}

<#
.SYNOPSIS
Tests an error is raised when setting a policy containing an invalid rank.
#>
function Test-ErrorWhenRankIsInvalid
{
$message = "Error converting value ""Non"" to type 'System.Nullable``1[Microsoft.Azure.Commands.SecurityCenter.Models.SqlInformationProtectionPolicy.PSSqlInformationProtectionRank]'. Path 'Labels.50e58766-ab53-4846-be8a-35e0bb87723e.Rank', line 6, position 19."
Assert-Throws {Set-AzSqlInformationProtectionPolicy -FilePath "SqlInformationProtectionPolicies\InvalidRank.json" } $message
}

<#
.SYNOPSIS
Tests an error is raised when setting a policy containing missing rank.
#>
function Test-ErrorWhenRankIsMissing
{
$message = "Required property 'Rank' not found in JSON. Path 'Labels.50e58766-ab53-4846-be8a-35e0bb87723e', line 8, position 5."
Assert-Throws {Set-AzSqlInformationProtectionPolicy -FilePath "SqlInformationProtectionPolicies\MissingRank.json" } $message
}
28 changes: 26 additions & 2 deletions src/Security/Security.Test/Security.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,31 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.SecurityCenter" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Management.SecurityCenter" Version="1.1.3" />
</ItemGroup>


<ItemGroup>
<None Include="SqlInformationProtectionPolicies\Empty.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SqlInformationProtectionPolicies\InformationTypeAndSensitivityLabelSharingSameDisplayName.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SqlInformationProtectionPolicies\InformationTypeAndSensitivityLabelSharingSameId.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SqlInformationProtectionPolicies\InformationTypesSharingSameDisplayName.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SqlInformationProtectionPolicies\InvalidRank.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SqlInformationProtectionPolicies\MissingRank.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SqlInformationProtectionPolicies\SensitivityLabelsSharingSameDisplayName.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
"StatusCode": 200
},
{
"RequestUri": "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/resourceGroups/rg/providers/Microsoft.Security/locations/centralus/alerts/2518532788749999999_66276b36-db2a-4b2c-84ad-9676fe753a01/Activate?api-version=2019-01-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDg3YmI0ODUtYjViMC00NzFlLTljMGQtMTA3MTc2MTJmODY5L3Jlc291cmNlR3JvdXBzL3JnL3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvbG9jYXRpb25zL2NlbnRyYWx1cy9hbGVydHMvMjUxODUzMjc4ODc0OTk5OTk5OV82NjI3NmIzNi1kYjJhLTRiMmMtODRhZC05Njc2ZmU3NTNhMDEvQWN0aXZhdGU/YXBpLXZlcnNpb249MjAxOS0wMS0wMQ==",
"RequestUri": "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/resourceGroups/rg/providers/Microsoft.Security/locations/centralus/alerts/2518532788749999999_66276b36-db2a-4b2c-84ad-9676fe753a01/reactivate?api-version=2019-01-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDg3YmI0ODUtYjViMC00NzFlLTljMGQtMTA3MTc2MTJmODY5L3Jlc291cmNlR3JvdXBzL3JnL3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvbG9jYXRpb25zL2NlbnRyYWx1cy9hbGVydHMvMjUxODUzMjc4ODc0OTk5OTk5OV82NjI3NmIzNi1kYjJhLTRiMmMtODRhZC05Njc2ZmU3NTNhMDEvcmVhY3RpdmF0ZT9hcGktdmVyc2lvbj0yMDE5LTAxLTAx",
"RequestMethod": "POST",
"RequestBody": "",
"RequestHeaders": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
"StatusCode": 200
},
{
"RequestUri": "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/providers/Microsoft.Security/locations/centralus/alerts/2518532788749999999_66276b36-db2a-4b2c-84ad-9676fe753a01/Activate?api-version=2019-01-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDg3YmI0ODUtYjViMC00NzFlLTljMGQtMTA3MTc2MTJmODY5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvbG9jYXRpb25zL2NlbnRyYWx1cy9hbGVydHMvMjUxODUzMjc4ODc0OTk5OTk5OV82NjI3NmIzNi1kYjJhLTRiMmMtODRhZC05Njc2ZmU3NTNhMDEvQWN0aXZhdGU/YXBpLXZlcnNpb249MjAxOS0wMS0wMQ==",
"RequestUri": "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/providers/Microsoft.Security/locations/centralus/alerts/2518532788749999999_66276b36-db2a-4b2c-84ad-9676fe753a01/reactivate?api-version=2019-01-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDg3YmI0ODUtYjViMC00NzFlLTljMGQtMTA3MTc2MTJmODY5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvbG9jYXRpb25zL2NlbnRyYWx1cy9hbGVydHMvMjUxODUzMjc4ODc0OTk5OTk5OV82NjI3NmIzNi1kYjJhLTRiMmMtODRhZC05Njc2ZmU3NTNhMDEvcmVhY3RpdmF0ZT9hcGktdmVyc2lvbj0yMDE5LTAxLTAx",
"RequestMethod": "POST",
"RequestBody": "",
"RequestHeaders": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
"StatusCode": 200
},
{
"RequestUri": "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/providers/Microsoft.Security/locations/centralus/alerts/2518532788749999999_66276b36-db2a-4b2c-84ad-9676fe753a02/Activate?api-version=2019-01-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDg3YmI0ODUtYjViMC00NzFlLTljMGQtMTA3MTc2MTJmODY5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvbG9jYXRpb25zL2NlbnRyYWx1cy9hbGVydHMvMjUxODUzMjc4ODc0OTk5OTk5OV82NjI3NmIzNi1kYjJhLTRiMmMtODRhZC05Njc2ZmU3NTNhMDIvQWN0aXZhdGU/YXBpLXZlcnNpb249MjAxOS0wMS0wMQ==",
"RequestUri": "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/providers/Microsoft.Security/locations/centralus/alerts/2518532788749999999_66276b36-db2a-4b2c-84ad-9676fe753a02/reactivate?api-version=2019-01-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDg3YmI0ODUtYjViMC00NzFlLTljMGQtMTA3MTc2MTJmODY5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvbG9jYXRpb25zL2NlbnRyYWx1cy9hbGVydHMvMjUxODUzMjc4ODc0OTk5OTk5OV82NjI3NmIzNi1kYjJhLTRiMmMtODRhZC05Njc2ZmU3NTNhMDIvcmVhY3RpdmF0ZT9hcGktdmVyc2lvbj0yMDE5LTAxLTAx",
"RequestMethod": "POST",
"RequestBody": "",
"RequestHeaders": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Entries": [
],
"Names": {},
"Variables": {
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Entries": [
],
"Names": {},
"Variables": {
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Entries": [
],
"Names": {},
"Variables": {
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Entries": [
],
"Names": {},
"Variables": {
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Entries": [
],
"Names": {},
"Variables": {
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Entries": [
],
"Names": {},
"Variables": {
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Entries": [
],
"Names": {},
"Variables": {
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
}
}
Empty file.
Loading