Skip to content

Commit 9d8680a

Browse files
authored
Merge pull request #4 from anusapan/DPS
Add IoTHub DPS cmdlets
2 parents 854173b + c0f018c commit 9d8680a

File tree

86 files changed

+21826
-2
lines changed

Some content is hidden

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

86 files changed

+21826
-2
lines changed

setup/azurecmdfiles.wxi

Lines changed: 4349 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
Please leave this section at the top of the change log.
3+
4+
Changes for the current release should go under the section titled "Current Release", and should adhere to the following format:
5+
6+
## Current Release
7+
* Overview of change #1
8+
- Additional information about change #1
9+
* Overview of change #2
10+
- Additional information about change #2
11+
- Additional information about change #2
12+
* Overview of change #3
13+
* Overview of change #4
14+
- Additional information about change #4
15+
16+
## YYYY.MM.DD - Version X.Y.Z (Previous Release)
17+
* Overview of change #1
18+
- Additional information about change #1
19+
-->
20+
## Current Release
21+
* Add IoTHub device provisioning service(DPS) support cmdlets
22+

src/ResourceManager/DeviceProvisioningServices/Commands.DeviceProvisioningServices.Test/Commands.DeviceProvisioningServices.Test.csproj

Lines changed: 260 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Commands.DeviceProvisioningServices.Test
16+
{
17+
using Microsoft.Azure.Commands.Common.Authentication;
18+
using Microsoft.Azure.Management.DeviceProvisioningServices;
19+
using Microsoft.Azure.Management.IotHub;
20+
using Microsoft.Azure.Management.Resources;
21+
using Microsoft.Azure.Test;
22+
using Microsoft.Azure.Test.HttpRecorder;
23+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
24+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
25+
using System;
26+
using System.Collections.Generic;
27+
using System.IO;
28+
using System.Linq;
29+
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
30+
using TestBase = Microsoft.Azure.Test.TestBase;
31+
using TestUtilities = Microsoft.Azure.Test.TestUtilities;
32+
33+
public sealed class IotDpsController
34+
{
35+
private CSMTestEnvironmentFactory csmTestFactory;
36+
private EnvironmentSetupHelper helper;
37+
38+
public ResourceManagementClient ResourceManagementClient { get; private set; }
39+
40+
public IotHubClient IotHubClient { get; private set; }
41+
42+
public IotDpsClient IotDpsClient { get; private set; }
43+
44+
public static IotDpsController NewInstance
45+
{
46+
get
47+
{
48+
return new IotDpsController();
49+
}
50+
}
51+
52+
public IotDpsController()
53+
{
54+
helper = new EnvironmentSetupHelper();
55+
}
56+
57+
public void RunPsTest(params string[] scripts)
58+
{
59+
var callingClassType = TestUtilities.GetCallingClass(2);
60+
var mockName = TestUtilities.GetCurrentMethodName(2);
61+
62+
RunPsTestWorkflow(
63+
() => scripts,
64+
null,
65+
null,
66+
callingClassType,
67+
mockName);
68+
}
69+
70+
71+
public void RunPsTestWorkflow(
72+
Func<string[]> scriptBuilder,
73+
Action<CSMTestEnvironmentFactory> initialize,
74+
Action cleanup,
75+
string callingClassType,
76+
string mockName)
77+
{
78+
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
79+
using (MockContext context = MockContext.Start(callingClassType, mockName))
80+
{
81+
this.csmTestFactory = new CSMTestEnvironmentFactory();
82+
if (initialize != null)
83+
{
84+
initialize(this.csmTestFactory);
85+
}
86+
SetupManagementClients(context);
87+
88+
helper.SetupEnvironment(AzureModule.AzureResourceManager);
89+
90+
var callingClassName = callingClassType
91+
.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
92+
.Last();
93+
helper.SetupModules(AzureModule.AzureResourceManager,
94+
"ScenarioTests\\" + callingClassName + ".ps1",
95+
helper.RMProfileModule,
96+
helper.RMResourceModule,
97+
helper.GetRMModulePath(@"AzureRM.DeviceProvisioningServices.psd1"),
98+
helper.GetRMModulePath(@"AzureRM.IotHub.psd1"),
99+
"AzureRM.Resources.ps1"
100+
);
101+
102+
try
103+
{
104+
if (scriptBuilder != null)
105+
{
106+
var psScripts = scriptBuilder();
107+
108+
if (psScripts != null)
109+
{
110+
helper.RunPowerShellTest(psScripts);
111+
}
112+
}
113+
}
114+
finally
115+
{
116+
if (cleanup != null)
117+
{
118+
cleanup();
119+
}
120+
}
121+
}
122+
}
123+
124+
private void SetupManagementClients(MockContext context)
125+
{
126+
ResourceManagementClient = GetResourceManagementClient();
127+
IotHubClient = GetIotHubClient(context);
128+
IotDpsClient = GetIotDpsClient(context);
129+
130+
helper.SetupManagementClients(
131+
ResourceManagementClient,
132+
IotHubClient,
133+
IotDpsClient
134+
);
135+
}
136+
137+
private ResourceManagementClient GetResourceManagementClient()
138+
{
139+
return TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
140+
}
141+
142+
private IotHubClient GetIotHubClient(MockContext context)
143+
{
144+
return context.GetServiceClient<IotHubClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
145+
}
146+
private IotDpsClient GetIotDpsClient(MockContext context)
147+
{
148+
return context.GetServiceClient<IotDpsClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
149+
}
150+
}
151+
}
152+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
using Xunit;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Commands.DeviceProvisioningServices.Test")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Commands.DeviceProvisioningServices.Test")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("4802bbf0-70f7-4fcb-81a6-381810234f14")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
37+
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
using Xunit.Abstractions;
20+
21+
namespace Commands.DeviceProvisioningServices.Test.ScenarioTests
22+
{
23+
public class IotDpsAccessPolicyTests : RMTestBase
24+
{
25+
public IotDpsAccessPolicyTests(ITestOutputHelper output)
26+
{
27+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
28+
}
29+
30+
[Fact]
31+
[Trait(Category.AcceptanceType, Category.CheckIn)]
32+
public void TestAzureIotDpsAccessPolicyLifeCycle()
33+
{
34+
IotDpsController.NewInstance.RunPsTest("Test-AzureIotDpsAccessPolicyLifeCycle");
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
16+
##########################################
17+
## Manage IotDps Access Policy Cmdlets ##
18+
##########################################
19+
20+
<#
21+
.SYNOPSIS
22+
Test Iot Hub Device Provisioning Service Access Policy cmdlets for CRUD operations
23+
#>
24+
25+
function Test-AzureIotDpsAccessPolicyLifeCycle
26+
{
27+
$Location = Get-Location "Microsoft.Devices" "Device Provisioning Service"
28+
$IotDpsName = getAssetName
29+
$ResourceGroupName = getAssetName
30+
31+
# Constant variable
32+
$AccessPolicyDefaultKeyName = "provisioningserviceowner"
33+
$AccessPolicyDefaultRights = "ServiceConfig, DeviceConnect, EnrollmentWrite"
34+
$NewAccessPolicyKeyName = "Access1"
35+
$NewAccessPolicyRights = "ServiceConfig, RegistrationStatusWrite"
36+
37+
# Create or Update Resource Group
38+
$resourceGroup = New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
39+
40+
# Create Iot Hub Device Provisioning Service
41+
$iotDps = New-AzureRmIoTDps -ResourceGroupName $ResourceGroupName -Name $IotDpsName -Location $Location
42+
Assert-True { $iotDps.Name -eq $IotDpsName }
43+
44+
# Get Iot Hub Device Provisioning Service Access Policy
45+
$iotDpsAccessPolicy1 = Get-AzureRmIoTDpsAccessPolicy -ResourceGroupName $ResourceGroupName -Name $IotDpsName
46+
Assert-True { $iotDpsAccessPolicy1.Count -eq 1 }
47+
Assert-True { $iotDpsAccessPolicy1.KeyName -eq $AccessPolicyDefaultKeyName }
48+
Assert-True { $iotDpsAccessPolicy1.Rights -eq $AccessPolicyDefaultRights }
49+
50+
# Add Iot Hub Device Provisioning Service Access Policy
51+
$iotDpsAccessPolicy2 = Add-AzureRmIoTDpsAccessPolicy -ResourceGroupName $ResourceGroupName -Name $IotDpsName -KeyName $NewAccessPolicyKeyName -Permissions $NewAccessPolicyRights
52+
Assert-True { $iotDpsAccessPolicy2.Count -eq 2 }
53+
Assert-True { $iotDpsAccessPolicy2[1].KeyName -eq $NewAccessPolicyKeyName }
54+
Assert-True { $iotDpsAccessPolicy2[1].Rights -eq $NewAccessPolicyRights }
55+
56+
# Delete Iot Hub Device Provisioning Service Access Policy
57+
$result = Remove-AzureRmIoTDpsAccessPolicy -ResourceGroupName $ResourceGroupName -Name $IotDpsName -KeyName $NewAccessPolicyKeyName -PassThru
58+
Assert-True { $result }
59+
60+
# Update Iot Hub Device Provisioning Service Access Policy
61+
$iotDpsAccessPolicy3 = Update-AzureRmIoTDpsAccessPolicy -ResourceGroupName $ResourceGroupName -Name $IotDpsName -KeyName $AccessPolicyDefaultKeyName -Permissions $NewAccessPolicyRights
62+
Assert-True { $iotDpsAccessPolicy3.Count -eq 1 }
63+
Assert-True { $iotDpsAccessPolicy3.KeyName -eq $AccessPolicyDefaultKeyName }
64+
Assert-True { $iotDpsAccessPolicy3.Rights -eq $NewAccessPolicyRights }
65+
66+
# Remove Iot Hub Device Provisioning Service
67+
$result = Remove-AzureRmIoTDps -ResourceGroupName $ResourceGroupName -Name $IotDpsName -PassThru
68+
Assert-True { $result }
69+
70+
# Remove Resource Group
71+
Remove-AzureRmResourceGroup -Name $ResourceGroupName -force
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
using Xunit.Abstractions;
20+
21+
namespace Commands.DeviceProvisioningServices.Test.ScenarioTests
22+
{
23+
public class IotDpsCertificateTests : RMTestBase
24+
{
25+
public IotDpsCertificateTests(ITestOutputHelper output)
26+
{
27+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
28+
}
29+
30+
[Fact]
31+
[Trait(Category.AcceptanceType, Category.CheckIn)]
32+
public void TestAzureIotDpsCertificateLifeCycle()
33+
{
34+
IotDpsController.NewInstance.RunPsTest("Test-AzureIotDpsCertificateLifeCycle");
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)