Skip to content

Commit b82bbab

Browse files
georgendGeorge Ndungu
andauthored
Allow caller to Specify desired OutputType (#499)
* Introduce `-OutputType` parameter to allow user to specifiy `OutputType` as [PSObject | HashTable | Json | HttpResponseMessage ] * Add integration tests to confirm `-OutputType` usage scenarios. * Inform user of Non-Json Responses and possible resolutions. Co-authored-by: George Ndungu <gendungu@microsoft.com>
1 parent 61ec9b0 commit b82bbab

26 files changed

Lines changed: 813 additions & 235 deletions

.azure-pipelines/generate-auth-module-template.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
pwsh: true
4242
script: |
4343
Write-Host $(BUILDNUMBER)
44-
pwsh $(System.DefaultWorkingDirectory)/tools/GenerateAuthenticationModule.ps1 -ArtifactsLocation $(Build.ArtifactStagingDirectory) -Build -ModulePreviewNumber $(BUILDNUMBER)
44+
pwsh $(System.DefaultWorkingDirectory)/tools/GenerateAuthenticationModule.ps1 -ArtifactsLocation $(Build.ArtifactStagingDirectory) -Build -ModulePreviewNumber $(BUILDNUMBER) -Test
4545
4646
- task: DotNetCoreCLI@2
4747
displayName: 'Run: Enabled Tests'
@@ -190,6 +190,16 @@ jobs:
190190
packagesToPush: '$(Build.ArtifactStagingDirectory)\$(AUTH_MODULE_NAME)\Microsoft.Graph.$(AUTH_MODULE_NAME)*.nupkg'
191191
publishVstsFeed: '0985d294-5762-4bc2-a565-161ef349ca3e/edc337b9-e5ea-49dd-a2cb-e8d66668ca57'
192192
allowPackageConflicts: true
193+
194+
- task: PublishTestResults@2
195+
inputs:
196+
testResultsFormat: 'NUnit'
197+
testResultsFiles: '**/*-TestResults.xml'
198+
199+
- task: PublishCodeCoverageResults@1
200+
inputs:
201+
#codeCoverageTool: 'JaCoCo' # Options: cobertura, jaCoCo
202+
summaryFileLocation: "**/coverage.xml"
193203

194204
- task: PublishBuildArtifacts@1
195205
displayName: Publish Artifact Microsoft.Graph.Authentication.nupkg'

.azure-pipelines/integrated-pipeline.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ stages:
4747
Write-Host $(BUILDNUMBER)
4848
printenv
4949
50+
- stage: GetSecrets
51+
displayName: 'Get Secrets From Azure KeyVault'
52+
jobs:
53+
- job: GetSecrets
54+
steps:
55+
- task: AzureKeyVault@1
56+
inputs:
57+
azureSubscription: 'Microsoft Graph Build Agents'
58+
KeyVaultName: 'msgraph-build-vault'
59+
SecretsFilter: '*'
60+
RunAsPreJob: true
61+
62+
- task: PowerShell@2
63+
displayName: 'Install Test Certificate'
64+
inputs:
65+
targetType: 'inline'
66+
script: |
67+
$kvSecretBytes = [System.Convert]::FromBase64String('$(MsGraphPSSDKCertificate)')
68+
$certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
69+
$certCollection.Import($kvSecretBytes,$null,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
70+
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My", "CurrentUser")
71+
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
72+
$store.AddRange($certCollection)
73+
$store.Close()
74+
5075
- stage: SecurityPreChecks
5176
displayName: 'Security Pre Checks'
5277
jobs:

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,7 @@ MigrationBackup/
353353
.ionide/
354354

355355
# Visual Studio Code
356-
.vscode/
356+
.vscode/
357+
358+
#Custom Environment Files
359+
localenv.json

Nuget.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<configuration>
33
<packageSources>
44
<clear />
5+
<add key="Nuget" value="https://api.nuget.org/v3/index.json" />
56
<add key="PowerShellSDK_BuildFeed" value="https://pkgs.dev.azure.com/microsoftgraph/0985d294-5762-4bc2-a565-161ef349ca3e/_packaging/PowerShellSDK_BuildFeed/nuget/v3/index.json" />
67
<add key="LocalNugetFeed" value="https://pkgs.dev.azure.com/microsoftgraph/0985d294-5762-4bc2-a565-161ef349ca3e/_packaging/b395d603-5c77-4af9-a495-1e3cdbb49e1e/nuget/v2" />
78
</packageSources>
Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,55 @@
1-
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using System.Text;
1+
namespace Microsoft.Graph.Authentication.Test.Helpers
2+
{
53

6-
using Microsoft.Graph.PowerShell.Authentication.Helpers;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Management.Automation;
77

8-
using Xunit;
8+
using Microsoft.Graph.PowerShell.Authentication.Helpers;
9+
10+
using Xunit;
911

10-
namespace Microsoft.Graph.Authentication.Test.Helpers
11-
{
1212
public class StringUtilTests
1313
{
1414
private const string TestJsonArray = "{\"@odata.context\": \"https://graph.microsoft.com/v1.0/$metadata#users\"," + "\"value\": [{\"id\": \"6e7b768e-07e2-4810-8459-485f84f8f204\"},{\"id\": \"87d349ed-44d7-43e1-9a83-5f2406dee5bd\"}]}";
1515

1616
private const string TestJsonObject = "{\"@odata.context\": \"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\"businessPhones\": [\"+1 412 555 0109\"],\"displayName\": \"Megan Bowen\",\"givenName\": \"Megan\",\"jobTitle\": \"Auditor\",\"mail\": \"MeganB@M365x214355.onmicrosoft.com\", \"mobilePhone\": null, \"officeLocation\": \"12/1110\",\"preferredLanguage\": \"en-US\",\"surname\": \"Bowen\",\"userPrincipalName\": \"MeganB@M365x214355.onmicrosoft.com\",\"id\": \"48d31887-5fad-4d73-a9f5-3c356e68a038\"}";
17+
public static IEnumerable<object[]> TestJsonData =>
18+
new List<object[]>
19+
{
20+
new object[] { TestJsonArray},
21+
new object[] { TestJsonObject}
22+
};
1723

1824
[Theory]
1925
[MemberData(nameof(TestJsonData))]
2026
public void ShouldReturnCaseInsensitiveDictionaries(string jsonString)
2127
{
22-
Exception ex = null;
23-
var converted = jsonString.TryConvertToJson(out var jsonObj, ref ex);
28+
var hashTable = jsonString.ConvertFromJson(true, null, out _);
2429

25-
Assert.True(converted);
26-
Assert.IsType<Hashtable>(jsonObj);
27-
var jsonHashTable = (Hashtable)jsonObj;
30+
Assert.NotNull(hashTable);
31+
var jsonHashTable = (Hashtable)hashTable;
2832
Assert.Equal(jsonHashTable["Value"], jsonHashTable["value"]);
2933
}
30-
public static IEnumerable<object[]> TestJsonData =>
31-
new List<object[]>
32-
{
33-
new object[] { TestJsonArray},
34-
new object[] { TestJsonObject}
35-
};
34+
35+
[Theory]
36+
[MemberData(nameof(TestJsonData))]
37+
public void ShouldReturnPsObject(string jsonString)
38+
{
39+
var psObject = jsonString.ConvertFromJson(false, null, out _);
40+
41+
Assert.NotNull(psObject);
42+
Assert.IsType<PSObject>(psObject);
43+
}
44+
45+
[Theory]
46+
[MemberData(nameof(TestJsonData))]
47+
public void ShouldReturnHashTable(string jsonString)
48+
{
49+
var hashTable = jsonString.ConvertFromJson(true, null, out _);
50+
51+
Assert.NotNull(hashTable);
52+
Assert.IsType<Hashtable>(hashTable);
53+
}
3654
}
3755
}

src/Authentication/Authentication.Test/Microsoft.Graph.Authentication.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
14+
<!-- As described in this post https://devblogs.microsoft.com/powershell/depending-on-the-right-powershell-nuget-package-in-your-net-project, reference the SDK for dotnetcore-->
15+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.2.7" PrivateAssets="all" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
1416
<PackageReference Include="xunit" Version="2.4.0" />
1517
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
1618
<PackageReference Include="coverlet.collector" Version="1.0.1" />

0 commit comments

Comments
 (0)