/// <summary> /// The non-boilerplated test code of the APIs for managing the lifecycle of a given server's auditing policy. It is meant to be called with a name of an already existing server (and therefore already existing /// resource group). This test does not create these resources and does not remove them. /// </summary> private void TestServerAuditingAPIs(SqlManagementClient sqlClient, string resourceGroupName, Server server) { ServerAuditingPolicyGetResponse getDefaultServerPolicyResponse = sqlClient.AuditingPolicy.GetServerPolicy(resourceGroupName, server.Name); ServerAuditingPolicyProperties properties = getDefaultServerPolicyResponse.AuditingPolicy.Properties; // Verify that the initial Get request contains the default policy. TestUtilities.ValidateOperationResponse(getDefaultServerPolicyResponse, HttpStatusCode.OK); VerifyServerAuditingPolicyInformation(GetDefaultServerAuditProperties(), properties); // Modify the policy properties, send and receive, see it its still ok ChangeServerAuditPolicy(properties); ServerAuditingPolicyCreateOrUpdateParameters updateParams = new ServerAuditingPolicyCreateOrUpdateParameters { Properties = properties }; var updateResponse = sqlClient.AuditingPolicy.CreateOrUpdateServerPolicy(resourceGroupName, server.Name, updateParams); // Verify that the initial Get request of contains the default policy. TestUtilities.ValidateOperationResponse(updateResponse, HttpStatusCode.OK); ServerAuditingPolicyGetResponse getUpdatedPolicyResponse = sqlClient.AuditingPolicy.GetServerPolicy(resourceGroupName, server.Name); ServerAuditingPolicyProperties updatedProperties = getUpdatedPolicyResponse.AuditingPolicy.Properties; // Verify that the Get request contains the updated policy. TestUtilities.ValidateOperationResponse(getUpdatedPolicyResponse, HttpStatusCode.OK); VerifyServerAuditingPolicyInformation(properties, updatedProperties); }
/// <summary> /// Changes the server auditing policy with new values /// </summary> private void ChangeServerAuditPolicy(ServerAuditingPolicyProperties properties) { properties.AuditingState = "Disabled"; properties.EventTypesToAudit = "PlainSQL_Success"; properties.RetentionDays = "10"; properties.AuditLogsTableName = "TempHyrdraTestAuditLogsTableName"; }
/// <summary> /// Transforms the given server policy object to its cmdlet model representation /// </summary> private ServerAuditingPolicyModel ModelizeServerAuditPolicy(ServerAuditingPolicy policy) { ServerAuditingPolicyModel serverPolicyModel = new ServerAuditingPolicyModel(); ServerAuditingPolicyProperties properties = policy.Properties; serverPolicyModel.AuditState = ModelizeAuditState(properties.AuditingState); ModelizeStorageInfo(serverPolicyModel, properties.StorageAccountName, properties.StorageAccountKey, properties.StorageAccountSecondaryKey); ModelizeEventTypesInfo(serverPolicyModel, properties.EventTypesToAudit); return(serverPolicyModel); }
/// <summary> /// Verify that the received properties match their expected values /// </summary> /// <param name="expected">The expected value of the properties object</param> /// <param name="actual">The properties object that needs to be checked</param> private static void VerifyServerAuditingPolicyInformation(ServerAuditingPolicyProperties expected, ServerAuditingPolicyProperties actual) { Assert.Equal(expected.AuditingState, actual.AuditingState); Assert.Equal(expected.EventTypesToAudit, actual.EventTypesToAudit); Assert.Equal(expected.StorageAccountName, actual.StorageAccountName); Assert.Equal(expected.StorageAccountKey, actual.StorageAccountKey); Assert.Equal(expected.StorageAccountSecondaryKey, actual.StorageAccountSecondaryKey); Assert.Equal(expected.StorageAccountResourceGroupName, actual.StorageAccountResourceGroupName); Assert.Equal(expected.StorageTableEndpoint, actual.StorageTableEndpoint); Assert.Equal(expected.StorageAccountSubscriptionId, actual.StorageAccountSubscriptionId); Assert.Equal(expected.RetentionDays, actual.RetentionDays); }
/// <summary> /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint /// </summary> /// <param name="policy">The AuditingPolicy object</param> /// <returns>The communication model object</returns> private ServerAuditingPolicyCreateOrUpdateParameters PolicizeServerAuditingModel(ServerAuditingPolicyModel model) { ServerAuditingPolicyCreateOrUpdateParameters updateParameters = new ServerAuditingPolicyCreateOrUpdateParameters(); ServerAuditingPolicyProperties properties = new ServerAuditingPolicyProperties(); updateParameters.Properties = properties; properties.AuditingState = PolicizeAuditState(model.AuditState); properties.StorageAccountName = ExtractStorageAccountName(model); properties.StorageAccountResourceGroupName = ExtractStorageAccountResourceGroup(properties.StorageAccountName); properties.StorageAccountSubscriptionId = ExtractStorageAccountSubscriptionId(properties.StorageAccountName); properties.StorageTableEndpoint = ExtractStorageAccountTableEndpoint(properties.StorageAccountName); properties.StorageAccountKey = ExtractStorageAccountKey(properties.StorageAccountName, model, properties.StorageAccountResourceGroupName, StorageKeyKind.Primary); properties.StorageAccountSecondaryKey = ExtractStorageAccountKey(properties.StorageAccountName, model, properties.StorageAccountResourceGroupName, StorageKeyKind.Secondary); properties.EventTypesToAudit = ExtractEventTypes(model); return(updateParameters); }
/// <summary> /// Creates and returns a ServerAuditingPolicyProperties object that holds the default settings for a server auditing policy /// </summary> /// <returns>A ServerAuditingPolicyProperties object with the default audit policy settings</returns> private ServerAuditingPolicyProperties GetDefaultServerAuditProperties() { ServerAuditingPolicyProperties props = new ServerAuditingPolicyProperties { AuditingState = "New", EventTypesToAudit = c_DefualtEventTypesToAudit, StorageAccountName = null, StorageAccountKey = null, StorageAccountSecondaryKey = null, StorageAccountResourceGroupName = null, StorageAccountSubscriptionId = null, StorageTableEndpoint = null, RetentionDays = "0" }; return(props); }
/// <summary> /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint /// </summary> /// <param name="model">The AuditingPolicy model object</param> /// <returns>The communication model object</returns> private ServerAuditingPolicyCreateOrUpdateParameters PolicizeServerAuditingModel(ServerAuditingPolicyModel model, string storageEndpointSuffix) { ServerAuditingPolicyCreateOrUpdateParameters updateParameters = new ServerAuditingPolicyCreateOrUpdateParameters(); ServerAuditingPolicyProperties properties = new ServerAuditingPolicyProperties(); updateParameters.Properties = properties; properties.AuditingState = PolicizeAuditState(model.AuditState); properties.StorageAccountName = ExtractStorageAccountName(model); properties.StorageAccountResourceGroupName = ExtractStorageAccountResourceGroup(properties.StorageAccountName); properties.StorageAccountSubscriptionId = ExtractStorageAccountSubscriptionId(properties.StorageAccountName); properties.StorageTableEndpoint = ExtractStorageAccountTableEndpoint(properties.StorageAccountName, storageEndpointSuffix); properties.StorageAccountKey = ExtractStorageAccountKey(properties.StorageAccountName, model, properties.StorageAccountResourceGroupName, StorageKeyKind.Primary); properties.StorageAccountSecondaryKey = ExtractStorageAccountKey(properties.StorageAccountName, model, properties.StorageAccountResourceGroupName, StorageKeyKind.Secondary); properties.EventTypesToAudit = ExtractEventTypes(model); properties.RetentionDays = model.RetentionInDays.ToString(); properties.AuditLogsTableName = model.TableIdentifier; return updateParameters; }