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

SQL Ledger Cmdlets #14997

Merged
merged 86 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
dbdcfc0
ledger changes + changes for new SDK version
rewongmicrosoft May 13, 2021
af01912
adding tests, updating cmdlets
rewongmicrosoft May 13, 2021
9b02401
adding tests, fixing cmdlets
rewongmicrosoft May 14, 2021
5dc5c66
adding comments to locations model
rewongmicrosoft May 14, 2021
7b3d2db
adding to changelog.md
rewongmicrosoft May 14, 2021
6225512
adding markdowe help files
rewongmicrosoft May 14, 2021
801da5e
fixing merge problems with backup restore resources
rewongmicrosoft May 14, 2021
4a6b843
updating help file for new-azsqldatabase
rewongmicrosoft May 14, 2021
b24ecb7
rerecording tests
rewongmicrosoft May 14, 2021
efef183
removing EnableLedger from Set-AzureSqlDatabase
rewongmicrosoft May 14, 2021
ca33bc4
removing extra parameter
rewongmicrosoft May 14, 2021
c71933f
adding whatif text
rewongmicrosoft May 14, 2021
2e76d33
upgrading Microsoft.Azure.Management.Sql to 1.52
rewongmicrosoft May 14, 2021
0276433
fixing online version link
rewongmicrosoft May 14, 2021
05c8a6e
adding audit action group for ledger
rewongmicrosoft May 15, 2021
7b01c3d
adding default parameter set
rewongmicrosoft May 15, 2021
b732ead
adding default parameter set
rewongmicrosoft May 15, 2021
033f2cf
adding -EnableLedger description to new-azsqldatabase help file
rewongmicrosoft May 15, 2021
2f1d5b1
adding ResourceIdentityWithUserAssignedIdentities to breaking changes…
rewongmicrosoft May 15, 2021
cf9a296
adding breaking change message
rewongmicrosoft May 16, 2021
0bebc05
fixing type name
rewongmicrosoft May 16, 2021
ea33943
adding using directive
rewongmicrosoft May 16, 2021
fa97167
updating breaking changes message
rewongmicrosoft May 16, 2021
14b7295
testing updating TestDatabaseDataMaskingPrivilegedUsersChanges test
rewongmicrosoft May 16, 2021
547499a
adding first batch of test re-records
rewongmicrosoft May 17, 2021
510d4c4
adding more re-recordings
rewongmicrosoft May 17, 2021
dabf2b9
more changes for re-recording
rewongmicrosoft May 17, 2021
0633b81
adding re-recordings, adding ignore api version to some tests
rewongmicrosoft May 17, 2021
f0591fd
adding ignore API version to instance pools test
rewongmicrosoft May 18, 2021
dfd0f0c
removing ignore API version from Auditing
rewongmicrosoft May 18, 2021
7599efa
adding auditing tests, removing database override from vulnerability …
rewongmicrosoft May 18, 2021
4640b3e
addding test re-recordings
rewongmicrosoft May 19, 2021
94ecd76
updating version to newest SDK, removing breaking change warnings
rewongmicrosoft May 19, 2021
3641573
adding server crud test re-records, instance pool crud tests to ignor…
rewongmicrosoft May 19, 2021
fc7a898
adding skip to managed instance tests
rewongmicrosoft May 20, 2021
cd90d0d
Commenting out instance pool, adding vulnerability assessment tests
rewongmicrosoft May 20, 2021
5b12258
Adding more test rescordings, skipping tests
rewongmicrosoft May 20, 2021
c79598f
reverting unneeded file changes
rewongmicrosoft May 20, 2021
830d876
Merge branch 'master' into sqlledger
rewongmicrosoft May 25, 2021
fb8838f
Update ChangeLog.md
wyunchi-ms May 25, 2021
8b09bcb
rerecording test
rewongmicrosoft May 25, 2021
3763528
Merge branch 'sqlledger' of https://github.com/rewongmicrosoft/azure-…
rewongmicrosoft May 25, 2021
8a43525
update changelog
rewongmicrosoft May 25, 2021
785a61e
ledger changes + changes for new SDK version
rewongmicrosoft May 13, 2021
74767bf
adding tests, updating cmdlets
rewongmicrosoft May 13, 2021
8dd0b33
adding tests, fixing cmdlets
rewongmicrosoft May 14, 2021
f107957
adding comments to locations model
rewongmicrosoft May 14, 2021
3f51814
adding to changelog.md
rewongmicrosoft May 14, 2021
12db9b2
adding markdowe help files
rewongmicrosoft May 14, 2021
6e73321
fixing merge problems with backup restore resources
rewongmicrosoft May 14, 2021
5430b6b
updating help file for new-azsqldatabase
rewongmicrosoft May 14, 2021
32fc76f
rerecording tests
rewongmicrosoft May 14, 2021
f13328c
removing EnableLedger from Set-AzureSqlDatabase
rewongmicrosoft May 14, 2021
003a6d8
removing extra parameter
rewongmicrosoft May 14, 2021
d1b451c
adding whatif text
rewongmicrosoft May 14, 2021
a8eda69
upgrading Microsoft.Azure.Management.Sql to 1.52
rewongmicrosoft May 14, 2021
f4c7b84
fixing online version link
rewongmicrosoft May 14, 2021
d76b84c
adding audit action group for ledger
rewongmicrosoft May 15, 2021
6fb3579
adding default parameter set
rewongmicrosoft May 15, 2021
acff20a
adding default parameter set
rewongmicrosoft May 15, 2021
a8129ad
adding -EnableLedger description to new-azsqldatabase help file
rewongmicrosoft May 15, 2021
c7a5413
adding ResourceIdentityWithUserAssignedIdentities to breaking changes…
rewongmicrosoft May 15, 2021
a580359
adding breaking change message
rewongmicrosoft May 16, 2021
1a851dd
fixing type name
rewongmicrosoft May 16, 2021
8c1471c
adding using directive
rewongmicrosoft May 16, 2021
9585886
updating breaking changes message
rewongmicrosoft May 16, 2021
481b086
testing updating TestDatabaseDataMaskingPrivilegedUsersChanges test
rewongmicrosoft May 16, 2021
9686c98
adding first batch of test re-records
rewongmicrosoft May 17, 2021
89a17c1
adding more re-recordings
rewongmicrosoft May 17, 2021
6e33b2e
more changes for re-recording
rewongmicrosoft May 17, 2021
f422f37
adding re-recordings, adding ignore api version to some tests
rewongmicrosoft May 17, 2021
94f1627
adding ignore API version to instance pools test
rewongmicrosoft May 18, 2021
fda30bf
removing ignore API version from Auditing
rewongmicrosoft May 18, 2021
c67c789
adding auditing tests, removing database override from vulnerability …
rewongmicrosoft May 18, 2021
87b1a74
addding test re-recordings
rewongmicrosoft May 19, 2021
af1c19c
updating version to newest SDK, removing breaking change warnings
rewongmicrosoft May 19, 2021
e248b32
adding server crud test re-records, instance pool crud tests to ignor…
rewongmicrosoft May 19, 2021
12e0f35
adding skip to managed instance tests
rewongmicrosoft May 20, 2021
d22d599
Commenting out instance pool, adding vulnerability assessment tests
rewongmicrosoft May 20, 2021
d95f104
Adding more test rescordings, skipping tests
rewongmicrosoft May 20, 2021
78a9386
reverting unneeded file changes
rewongmicrosoft May 20, 2021
8a3afed
rerecording test
rewongmicrosoft May 25, 2021
13f56e7
Update ChangeLog.md
wyunchi-ms May 25, 2021
227dc72
update changelog
rewongmicrosoft May 25, 2021
cb1a3ca
Merge branch 'sqlledger' of https://github.com/rewongmicrosoft/azure-…
rewongmicrosoft May 26, 2021
5bffdde
re-recording named secondary test after rebase
rewongmicrosoft May 26, 2021
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
41 changes: 41 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,47 @@ function Create-BasicTestEnvironmentWithParams ($params, $location, $serverVersi
New-AzSqlDatabase -DatabaseName $params.databaseName -ResourceGroupName $params.rgname -ServerName $params.serverName -Edition Basic -Force
}

<#
.SYNOPSIS
Gets the values of the parameters used for ledger digest upload tests
#>
function Get-LedgerTestEnvironmentParameters ($testSuffix)
{
return @{ subscriptionId = (Get-AzContext).Subscription.Id;
rgname = "ledger-cmdlet-test-rg" + $testSuffix;
serverName = "ledger-cmdlet-server" + $testSuffix;
databaseName = "ledger-cmdlet-db" + $testSuffix;
}
}

<#
.SYNOPSIS
Creates the basic test environment used for the ledger tests - creates resource group, server, and database
#>
function Create-LedgerTestEnvironment ($params)
{
$location = "eastus2euap"
$serverVersion = "12.0"
New-AzResourceGroup -Name $params.rgname -Location $location
$serverName = $params.serverName
$serverLogin = "testusername"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$serverPassword = "t357ingP@s5w0rd!ledger"
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
New-AzSqlServer -ResourceGroupName $params.rgname -ServerName $params.serverName -Location $location -ServerVersion $serverVersion -SqlAdministratorCredentials $credentials
New-AzSqlDatabase -DatabaseName $params.databaseName -ResourceGroupName $params.rgname -ServerName $params.serverName -Edition Basic
}

<#
.SYNOPSIS
Removes the test environment that was needed to perform the ledger digest upload tests
#>
function Remove-LedgerTestEnvironment ($testSuffix)
{
$params = Get-LedgerTestEnvironmentParameters $testSuffix
Remove-AzResourceGroup -Name $params.rgname -Force
}

<#
.SYNOPSIS
Creates the basic test environment needed to perform the Sql data security tests - resource group, managed instance and managed database
Expand Down
7 changes: 7 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/DatabaseCrudTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,12 @@ public void TestDatabaseGetWithBackupStorageRedundancy()
{
RunPowerShellTest("Test-GetDatabaseWithBackupStorageRedundancy");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDatabaseCreateWithLedgerEnabled()
{
RunPowerShellTest("Test-DatabaseCreateWithLedgerEnabled");
}
}
}
23 changes: 23 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/DatabaseCrudTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,29 @@ function Test-GetDatabaseWithMaintenanceConfigurationId
}
}

<#
.SYNOPSIS
Tests creating a database with ledger enabled
#>
function Test-DatabaseCreateWithLedgerEnabled ($location = "eastus2euap")
{
# Setup
$rg = Create-ResourceGroupForTest
$server = Create-ServerForTest $rg $location

# Create with ledger enabled
$databaseName = Get-DatabaseName
$db1 = New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -EnableLedger -Force
Assert-AreEqual $db1.DatabaseName $databaseName
Assert-AreEqual "True" $db1.EnableLedger

# Validate Get-AzSqlDatabase returns ledger property
$databaseFromGet = Get-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName
Assert-AreEqual "True" $databaseFromGet.EnableLedger

Remove-ResourceGroupForTest $rg
}

<#
.SYNOPSIS
Tests Deleting a database
Expand Down
60 changes: 60 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/LedgerDigestUploadTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// ----------------------------------------------------------------------------------
//
// 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.SqlTests;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
{
public class LedgerDigestUploadTests : SqlTestsBase
{
public LedgerDigestUploadTests(ITestOutputHelper output) : base(output)
{
base.resourceTypesToIgnoreApiVersion = new string[] {
"Microsoft.Sql/servers"
};
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetDefaultLedgerDigestUpload()
{
RunPowerShellTest("Test-GetDefaultLedgerDigestUpload");
rewongmicrosoft marked this conversation as resolved.
Show resolved Hide resolved
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSetLedgerDigestUploadByName()
{
RunPowerShellTest("Test-SetLedgerDigestUploadByName");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSetLedgerDigestUploadByDatabaseObject()
{
RunPowerShellTest("Test-SetLedgerDigestUploadByDatabaseObject");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSetLedgerDigestUploadByResourceId()
{
RunPowerShellTest("Test-SetLedgerDigestUploadByResourceId");
}
}
}
194 changes: 194 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/LedgerDigestUploadTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# ----------------------------------------------------------------------------------
#
# 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 getting default ledger digest upload configuration
#>
function Test-GetDefaultLedgerDigestUpload
{
# Setup
$testSuffix = getAssetName
$params = Get-LedgerTestEnvironmentParameters $testSuffix
Create-LedgerTestEnvironment $params

$databaseResourceId = "/subscriptions/" + $params.subscriptionId + "/resourceGroups/" + $params.rgname + "/providers/Microsoft.Sql/servers/" + $params.serverName + "/databases/" + $params.databaseName
$databaseObject = Get-AzSqlDatabase -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName

try
{
# Test
$ledgerDigestUpload = Get-AzSqlDatabaseLedgerDigestUpload -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName

# Assert
Assert-AreEqual $ledgerDigestUpload.State "Disabled"
rewongmicrosoft marked this conversation as resolved.
Show resolved Hide resolved

# Test
$ledgerDigestUploadByResourceId = Get-AzSqlDatabaseLedgerDigestUpload -ResourceId $databaseResourceId

# Assert
Assert-AreEqual $ledgerDigestUploadByResourceId.State "Disabled"

# Test
$ledgerDigestUploadByDatabase = Get-AzSqlDatabaseLedgerDigestUpload -InputObject $databaseObject

# Assert
Assert-AreEqual $ledgerDigestUploadByDatabase.State "Disabled"
}
finally
{
# Cleanup
Remove-LedgerTestEnvironment $testSuffix
}
}

<#
.SYNOPSIS
Tests enabling and disabling ledger digest uploading using named parameters
#>
function Test-SetLedgerDigestUploadByName
{
# Setup
$testSuffix = getAssetName
$params = Get-LedgerTestEnvironmentParameters $testSuffix
Create-LedgerTestEnvironment $params
$endpoint = "https://test.confidential-ledger.azure.com"

try
{
# Test enabling
$ledgerDigestUploadEnable = Enable-AzSqlDatabaseLedgerDigestUpload -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -Endpoint $endpoint

# Assert
Assert-AreEqual $ledgerDigestUploadEnable.State "Enabled"
Assert-AreEqual $ledgerDigestUploadEnable.Endpoint $endpoint

# Test get enabled settings
$ledgerDigestUploadEnabledGet = Get-AzSqlDatabaseLedgerDigestUpload -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName

# Assert
Assert-AreEqual $ledgerDigestUploadEnabledGet.State "Enabled"
rewongmicrosoft marked this conversation as resolved.
Show resolved Hide resolved

# Test disabling
$ledgerDigestUploadDisable = Disable-AzSqlDatabaseLedgerDigestUpload -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName

# Assert
Assert-AreEqual $ledgerDigestUploadDisable.State "Disabled"

# Test get disabled settings
$ledgerDigestUploadDisabledGet = Get-AzSqlDatabaseLedgerDigestUpload -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName

# Assert
Assert-AreEqual $ledgerDigestUploadDisabledGet.State "Disabled"
}
finally
{
# Cleanup
Remove-LedgerTestEnvironment $testSuffix
}
}

<#
.SYNOPSIS
Tests enabling and disabling ledger digest uploading using the database object
#>
function Test-SetLedgerDigestUploadByDatabaseObject
{
# Setup
$testSuffix = getAssetName
$params = Get-LedgerTestEnvironmentParameters $testSuffix
Create-LedgerTestEnvironment $params
$endpoint = "https://test.confidential-ledger.azure.com"
$databaseObject = Get-AzSqlDatabase -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName

try
{
# Test enabling
$ledgerDigestUploadEnable = Enable-AzSqlDatabaseLedgerDigestUpload -InputObject $databaseObject -Endpoint $endpoint

# Assert
Assert-AreEqual $ledgerDigestUploadEnable.State "Enabled"
Assert-AreEqual $ledgerDigestUploadEnable.Endpoint $endpoint

# Test get enabled settings
$ledgerDigestUploadEnabledGet = Get-AzSqlDatabaseLedgerDigestUpload -InputObject $databaseObject

# Assert
Assert-AreEqual $ledgerDigestUploadEnabledGet.State "Enabled"

# Test disabling
$ledgerDigestUploadDisable = Disable-AzSqlDatabaseLedgerDigestUpload -InputObject $databaseObject

# Assert
Assert-AreEqual $ledgerDigestUploadDisable.State "Disabled"

# Test get disabled settings
$ledgerDigestUploadDisabledGet = Get-AzSqlDatabaseLedgerDigestUpload -InputObject $databaseObject

# Assert
Assert-AreEqual $ledgerDigestUploadDisabledGet.State "Disabled"
}
finally
{
# Cleanup
Remove-LedgerTestEnvironment $testSuffix
}
}

<#
.SYNOPSIS
Tests enabling and disabling ledger digest uploading using the resource ID
#>
function Test-SetLedgerDigestUploadByResourceId
{
# Setup
$testSuffix = getAssetName
$params = Get-LedgerTestEnvironmentParameters $testSuffix
Create-LedgerTestEnvironment $params
$endpoint = "https://test.confidential-ledger.azure.com"
$databaseResourceId = "/subscriptions/" + $params.subscriptionId + "/resourceGroups/" + $params.rgname + "/providers/Microsoft.Sql/servers/" + $params.serverName + "/databases/" + $params.databaseName

try
{
# Test enabling
$ledgerDigestUploadEnable = Enable-AzSqlDatabaseLedgerDigestUpload -ResourceId $databaseResourceId -Endpoint $endpoint

# Assert
Assert-AreEqual $ledgerDigestUploadEnable.State "Enabled"
Assert-AreEqual $ledgerDigestUploadEnable.Endpoint $endpoint

# Test get enabled settings
$ledgerDigestUploadEnabledGet = Get-AzSqlDatabaseLedgerDigestUpload -ResourceId $databaseResourceId

# Assert
Assert-AreEqual $ledgerDigestUploadEnabledGet.State "Enabled"

# Test disabling
$ledgerDigestUploadDisable = Disable-AzSqlDatabaseLedgerDigestUpload -ResourceId $databaseResourceId

# Assert
Assert-AreEqual $ledgerDigestUploadDisable.State "Disabled"

# Test get disabled settings
$ledgerDigestUploadDisabledGet = Get-AzSqlDatabaseLedgerDigestUpload -ResourceId $databaseResourceId

# Assert
Assert-AreEqual $ledgerDigestUploadDisabledGet.State "Disabled"
}
finally
{
# Cleanup
Remove-LedgerTestEnvironment $testSuffix
}
}
Loading