|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using Azure.ResourceManager.SecurityInsights.Models; |
| 6 | +using Azure.ResourceManager.Models; |
| 7 | +using Azure.ResourceManager.Resources.Models; |
| 8 | +using NUnit.Framework; |
| 9 | +using Azure.Core; |
| 10 | +using System; |
| 11 | +using System.Text; |
| 12 | +using Azure.ResourceManager.Resources; |
| 13 | +using System.Threading.Tasks; |
| 14 | +using NUnit.Framework.Internal; |
| 15 | +using System.IO; |
| 16 | + |
| 17 | +namespace Azure.ResourceManager.SecurityInsights.Tests.Helpers |
| 18 | +{ |
| 19 | + public static class ResourceDataHelpers |
| 20 | + { |
| 21 | + public static IDictionary<string, string> ReplaceWith(this IDictionary<string, string> dest, IDictionary<string, string> src) |
| 22 | + { |
| 23 | + dest.Clear(); |
| 24 | + foreach (var kv in src) |
| 25 | + { |
| 26 | + dest.Add(kv); |
| 27 | + } |
| 28 | + |
| 29 | + return dest; |
| 30 | + } |
| 31 | + |
| 32 | + public static void AssertResource(ResourceData r1, ResourceData r2) |
| 33 | + { |
| 34 | + Assert.AreEqual(r1.Name, r2.Name); |
| 35 | + Assert.AreEqual(r1.Id, r2.Id); |
| 36 | + Assert.AreEqual(r1.ResourceType, r2.ResourceType); |
| 37 | + } |
| 38 | + |
| 39 | + #region SecurityInsightsAlertRuleData |
| 40 | + public static void AssertSecurityInsightsAlertRuleData(SecurityInsightsAlertRuleData data1, SecurityInsightsAlertRuleData data2) |
| 41 | + { |
| 42 | + AssertResource(data1, data2); |
| 43 | + Assert.AreEqual(data1.Kind, data2.Kind); |
| 44 | + } |
| 45 | + public static SecurityInsightsAlertRuleData GetSecurityInsightsAlertRuleData() |
| 46 | + { |
| 47 | + var data = new MicrosoftSecurityIncidentCreationAlertRule() |
| 48 | + { |
| 49 | + ProductFilter = "Microsoft Cloud App Security", |
| 50 | + IsEnabled = true, |
| 51 | + DisplayName = "SDKTest" |
| 52 | + }; |
| 53 | + return data; |
| 54 | + } |
| 55 | + #endregion |
| 56 | + |
| 57 | + #region AutomationRuleData |
| 58 | + public static void AssertAutomationRuleData(SecurityInsightsAutomationRuleData data1, SecurityInsightsAutomationRuleData data2) |
| 59 | + { |
| 60 | + AssertResource(data1, data2); |
| 61 | + Assert.AreEqual(data1.DisplayName, data2.DisplayName); |
| 62 | + Assert.AreEqual(data1.Order, data2.Order); |
| 63 | + } |
| 64 | + public static SecurityInsightsAutomationRuleData GetAutomationRuleData(string resourcegroup) |
| 65 | + { |
| 66 | + var trigger = new SecurityInsightsAutomationRuleTriggeringLogic(false, TriggersOn.Incidents, TriggersWhen.Created); |
| 67 | + IEnumerable<AutomationRuleModifyPropertiesAction> action = new List<AutomationRuleModifyPropertiesAction>() |
| 68 | + { |
| 69 | + new AutomationRuleModifyPropertiesAction(1) |
| 70 | + { |
| 71 | + ActionConfiguration = new SecurityInsightsIncidentActionConfiguration() |
| 72 | + { |
| 73 | + Labels = |
| 74 | + { |
| 75 | + new SecurityInsightsIncidentLabel("testlabel1") |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + }; |
| 80 | + var data = new SecurityInsightsAutomationRuleData("SDK Test", 1, trigger, action) |
| 81 | + { |
| 82 | + }; |
| 83 | + return data; |
| 84 | + } |
| 85 | + #endregion |
| 86 | + #region BookmarkData |
| 87 | + public static void AssertBookmarkData(SecurityInsightsBookmarkData data1, SecurityInsightsBookmarkData data2) |
| 88 | + { |
| 89 | + AssertResource(data1, data2); |
| 90 | + Assert.AreEqual(data1.DisplayName, data2.DisplayName); |
| 91 | + Assert.AreEqual(data1.Notes, data2.Notes); |
| 92 | + Assert.AreEqual(data1.Query, data2.Query); |
| 93 | + Assert.AreEqual(data1.QueryResult, data2.QueryResult); |
| 94 | + } |
| 95 | + public static SecurityInsightsBookmarkData GetBookmarkData() |
| 96 | + { |
| 97 | + var data = new SecurityInsightsBookmarkData() |
| 98 | + { |
| 99 | + DisplayName = "SDKTestBookmark", |
| 100 | + Query = "SecurityEvent | take 10", |
| 101 | + }; |
| 102 | + return data; |
| 103 | + } |
| 104 | + #endregion |
| 105 | + |
| 106 | + #region IncidentData |
| 107 | + public static void AssertIncidentData(SecurityInsightsIncidentData data1, SecurityInsightsIncidentData data2) |
| 108 | + { |
| 109 | + AssertResource(data1, data2); |
| 110 | + Assert.AreEqual(data1.Title, data2.Title); |
| 111 | + Assert.AreEqual(data1.Classification, data2.Classification); |
| 112 | + Assert.AreEqual(data1.Description, data2.Description); |
| 113 | + Assert.AreEqual(data1.ClassificationComment, data2.ClassificationComment); |
| 114 | + } |
| 115 | + public static SecurityInsightsIncidentData GetIncidentData() |
| 116 | + { |
| 117 | + var data = new SecurityInsightsIncidentData() |
| 118 | + { |
| 119 | + Title = "SDKCreateIncidentTest", |
| 120 | + Status = "Active", |
| 121 | + Severity = "Low" |
| 122 | + }; |
| 123 | + return data; |
| 124 | + } |
| 125 | + #endregion |
| 126 | + |
| 127 | + #region DataConnectorData |
| 128 | + public static void AssertDataConnectorData(SecurityInsightsDataConnectorData data1, SecurityInsightsDataConnectorData data2) |
| 129 | + { |
| 130 | + AssertResource(data1, data2); |
| 131 | + Assert.AreEqual(data1.Kind, data2.Kind); |
| 132 | + } |
| 133 | + public static SecurityInsightsDataConnectorData GetDataConnectorData() |
| 134 | + { |
| 135 | + var data = new SecurityInsightsAscDataConnector() |
| 136 | + { |
| 137 | + SubscriptionId = "db1ab6f0-4769-4b27-930e-01e2ef9c123c", |
| 138 | + DataTypes = new SecurityInsightsAlertsDataTypeOfDataConnector(new DataConnectorDataTypeCommon() |
| 139 | + { |
| 140 | + State = SecurityInsightsDataTypeConnectionState.Enabled |
| 141 | + }) |
| 142 | + }; |
| 143 | + return data; |
| 144 | + } |
| 145 | + #endregion |
| 146 | + |
| 147 | + #region ThreatIntelligenceIndicatorData |
| 148 | + public static void AssertThreatIntelligenceIndicatorData(SecurityInsightsThreatIntelligenceIndicatorBaseData data1, SecurityInsightsThreatIntelligenceIndicatorBaseData data2) |
| 149 | + { |
| 150 | + AssertResource(data1, data2); |
| 151 | + } |
| 152 | + public static SecurityInsightsThreatIntelligenceIndicatorData GetThreatIntelligenceIndicatorData() |
| 153 | + { |
| 154 | + var data = new SecurityInsightsThreatIntelligenceIndicatorData() |
| 155 | + { |
| 156 | + DisplayName = "SDK Test", |
| 157 | + PatternType = "ipv4-addr", |
| 158 | + Pattern = "[ipv4-addr:value = '1.1.1.2']", |
| 159 | + ThreatTypes = |
| 160 | + { |
| 161 | + "unknown" |
| 162 | + }, |
| 163 | + ValidFrom = DateTime.Now, |
| 164 | + Source = "Azure Sentinel" |
| 165 | + }; |
| 166 | + return data; |
| 167 | + } |
| 168 | + #endregion |
| 169 | + #region WatchlistItemData |
| 170 | + public static void AssertWatchlistItemData(SecurityInsightsWatchlistItemData data1, SecurityInsightsWatchlistItemData data2) |
| 171 | + { |
| 172 | + AssertResource(data1, data2); |
| 173 | + Assert.AreEqual(data1.IsDeleted, data2.IsDeleted); |
| 174 | + Assert.AreEqual(data1.WatchlistItemId, data2.WatchlistItemId); |
| 175 | + Assert.AreEqual(data1.TenantId, data2.TenantId); |
| 176 | + Assert.AreEqual(data1.WatchlistItemType, data2.WatchlistItemType); |
| 177 | + } |
| 178 | + public static SecurityInsightsWatchlistItemData GetWatchlistItemData() |
| 179 | + { |
| 180 | + return new SecurityInsightsWatchlistItemData() |
| 181 | + { |
| 182 | + ItemsKeyValue = BinaryData.FromString("{\"ipaddress\":\"1.1.1.2\"}") |
| 183 | + }; |
| 184 | + } |
| 185 | + #endregion |
| 186 | + |
| 187 | + #region WatchlistData |
| 188 | + public static void AssertWatchlistData(SecurityInsightsWatchlistData data1, SecurityInsightsWatchlistData data2) |
| 189 | + { |
| 190 | + AssertResource(data1, data2); |
| 191 | + Assert.AreEqual(data1.IsDeleted, data2.IsDeleted); |
| 192 | + Assert.AreEqual(data1.Source, data2.Source); |
| 193 | + Assert.AreEqual(data1.TenantId, data2.TenantId); |
| 194 | + Assert.AreEqual(data1.Provider, data2.Provider); |
| 195 | + } |
| 196 | + public static SecurityInsightsWatchlistData GetWatchlistData() |
| 197 | + { |
| 198 | + var data = new SecurityInsightsWatchlistData() |
| 199 | + { |
| 200 | + DisplayName = "SDK Test", |
| 201 | + Provider = "SDK Test", |
| 202 | + Source = "sdktest", |
| 203 | + ItemsSearchKey = "ipaddress" |
| 204 | + }; |
| 205 | + return data; |
| 206 | + } |
| 207 | + #endregion |
| 208 | + |
| 209 | + #region SentinelOnboardingStateData |
| 210 | + public static void AssertSentinelOnboardingStateData(SecurityInsightsSentinelOnboardingStateData data1, SecurityInsightsSentinelOnboardingStateData data2) |
| 211 | + { |
| 212 | + AssertResource(data1, data2); |
| 213 | + Assert.AreEqual(data1.IsCustomerManagedKeySet, data2.IsCustomerManagedKeySet); |
| 214 | + } |
| 215 | + public static SecurityInsightsSentinelOnboardingStateData GetSentinelOnboardingStateData() |
| 216 | + { |
| 217 | + return new SecurityInsightsSentinelOnboardingStateData() |
| 218 | + { |
| 219 | + IsCustomerManagedKeySet = false, |
| 220 | + }; |
| 221 | + } |
| 222 | + #endregion |
| 223 | + } |
| 224 | +} |
0 commit comments