Skip to content

Commit f9984fa

Browse files
authored
SecurityInsights(22-11) (Azure#33287)
* move * test * part1 * delete * finished
1 parent a7d840b commit f9984fa

File tree

68 files changed

+34695
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+34695
-6
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
<PackageReference Update="Azure.Messaging.ServiceBus" Version="7.11.1" />
187187
<PackageReference Update="Azure.ResourceManager.Compute" Version="1.0.0" />
188188
<PackageReference Update="Azure.ResourceManager.Network" Version="1.1.0" />
189+
<PackageReference Update="Azure.ResourceManager.OperationalInsights" Version="1.0.0" />
189190
<PackageReference Update="Azure.ResourceManager.Resources" Version="1.3.1" />
190191
<PackageReference Update="Azure.ResourceManager.Storage" Version="1.1.0" />
191192
<PackageReference Update="Azure.Search.Documents" Version="11.2.0" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<ItemGroup>
3+
<Compile Remove="TestCase\ActionResponseCollectionTests.cs" />
4+
<Compile Remove="TestCase\ActionResponseResourceTests.cs" />
5+
</ItemGroup>
26
<ItemGroup>
37
<ProjectReference Include="..\src\Azure.ResourceManager.SecurityInsights.csproj" />
48
</ItemGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Azure.ResourceManager.OperationalInsights" />
12+
</ItemGroup>
513
</Project>
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
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+
}

sdk/securityinsights/Azure.ResourceManager.SecurityInsights/tests/SecurityInsightsManagementTestBase.cs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,82 @@
55
using Azure.Core.TestFramework;
66
using Azure.ResourceManager.Resources;
77
using Azure.ResourceManager.TestFramework;
8+
using Azure.ResourceManager.OperationalInsights;
89
using NUnit.Framework;
910
using System.Threading.Tasks;
11+
using System;
12+
using Azure.ResourceManager.OperationalInsights.Models;
1013

1114
namespace Azure.ResourceManager.SecurityInsights.Tests
1215
{
1316
public class SecurityInsightsManagementTestBase : ManagementRecordedTestBase<SecurityInsightsManagementTestEnvironment>
1417
{
1518
protected ArmClient Client { get; private set; }
19+
protected AzureLocation DefaultLocation => AzureLocation.EastUS;
20+
protected string groupName;
21+
protected SubscriptionResource DefaultSubscription { get; private set; }
1622

1723
protected SecurityInsightsManagementTestBase(bool isAsync, RecordedTestMode mode)
1824
: base(isAsync, mode)
1925
{
2026
}
2127

28+
public ResourceIdentifier CreateResourceIdentifier(string subscriptionId, string resourceGroupName, string workspaceName)
29+
{
30+
var resourceId = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}";
31+
return new ResourceIdentifier(resourceId);
32+
}
33+
2234
protected SecurityInsightsManagementTestBase(bool isAsync)
2335
: base(isAsync)
2436
{
2537
}
2638

2739
[SetUp]
28-
public void CreateCommonClient()
40+
public async Task CreateCommonClient()
2941
{
3042
Client = GetArmClient();
43+
DefaultSubscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false);
3144
}
3245

33-
protected async Task<ResourceGroupResource> CreateResourceGroup(SubscriptionResource subscription, string rgNamePrefix, AzureLocation location)
46+
protected async Task<ResourceGroupResource> CreateResourceGroupAsync()
47+
{
48+
var resourceGroupName = Recording.GenerateAssetName("testRG-");
49+
var rgOp = await DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(
50+
WaitUntil.Completed,
51+
resourceGroupName,
52+
new ResourceGroupData(DefaultLocation)
53+
{
54+
Tags =
55+
{
56+
{ "test", "env" }
57+
}
58+
});
59+
if (Mode == RecordedTestMode.Playback)
60+
{
61+
groupName = resourceGroupName;
62+
}
63+
else
64+
{
65+
using (Recording.DisableRecording())
66+
{
67+
groupName = rgOp.Value.Data.Name;
68+
}
69+
}
70+
return rgOp.Value;
71+
}
72+
#region workspace
73+
public static OperationalInsightsWorkspaceData GetWorkspaceData()
3474
{
35-
string rgName = Recording.GenerateAssetName(rgNamePrefix);
36-
ResourceGroupData input = new ResourceGroupData(location);
37-
var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input);
38-
return lro.Value;
75+
var data = new OperationalInsightsWorkspaceData(AzureLocation.WestUS)
76+
{
77+
RetentionInDays = 30,
78+
Sku = new OperationalInsightsWorkspaceSku(OperationalInsightsWorkspaceSkuName.PerNode),
79+
PublicNetworkAccessForIngestion = OperationalInsightsPublicNetworkAccessType.Enabled,
80+
PublicNetworkAccessForQuery = OperationalInsightsPublicNetworkAccessType.Enabled,
81+
};
82+
return data;
3983
}
84+
#endregion
4085
}
4186
}

0 commit comments

Comments
 (0)