Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Authentication/Authentication/ErrorConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal static class Codes
internal static class Message
{
internal const string InvalidJWT = "Invalid JWT access token.";
internal const string MissingAuthContext = "Authentication needed, call Connect-Graph.";
internal const string MissingAuthContext = "Authentication needed, call Connect-MgGraph.";
internal const string NullOrEmptyParameter = "Parameter '{0}' cannot be null or empty.";
internal const string MacKeyChainFailed = "{0} failed with result code {1}.";
internal const string DeviceCodeTimeout = "Device code terminal timed-out after {0} seconds. Please try again.";
Expand Down
11 changes: 11 additions & 0 deletions src/Identity.SignIns/Identity.SignIns/test/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ClientId": "56db239f-b87c-4dc0-9d9b-2ec0318e4ad9",
"TenantId": "61fcf17f-000c-4ab8-a4dc-9e92405fc737",
"Users": [
{
"Id": "85d17c69-6789-47c7-bf10-ad08ab4cd8da",
"DisplayName": "John Doe",
"Mail": "johndoe@testtenant.onmicrosoft.com"
}
]
}
8 changes: 6 additions & 2 deletions src/Identity.SignIns/Identity.SignIns/test/loadEnv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ if (Test-Path -Path (Join-Path $PSScriptRoot $envFile)) {
}
$env = @{}
if (Test-Path -Path $envFilePath) {
$env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json
$PSDefaultParameterValues=@{"*:SubscriptionId"=$env.SubscriptionId; "*:Tenant"=$env.Tenant}
# Load dummy configuration.
$env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json -AsHashTable
[Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance.AuthContext = New-Object Microsoft.Graph.PowerShell.Authentication.AuthContext -Property @{
ClientId = $env.ClientId
TenantId = $env.TenantId
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"New-MgInvitation+[NoContext]+ShouldCreateInvite+$POST+https://graph.microsoft.com/beta/invitations+1": {
"Request": {
"Method": "POST",
"RequestUri": "https://graph.microsoft.com/beta/invitations",
"Content": "{\r\n \"inviteRedirectUrl\": \"https://myapp.contoso.com\",\r\n \"invitedUserDisplayName\": \"John Doe\",\r\n \"invitedUserEmailAddress\": \"johndoe@testtenant.onmicrosoft.com\"\r\n}",
"Headers": {
},
"ContentHeaders": {
"Content-Type": [ "application/json" ],
"Content-Length": [ "165" ]
}
},
"Response": {
"StatusCode": 201,
"Headers": {
"Date": [ "Wed, 17 Feb 2021 23:05:50 GMT" ],
"Cache-Control": [ "no-store, must-revalidate, no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Location": [ "https://graph.microsoft.com/" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "7927b734-7f49-4704-8be9-2a802aeb76f8" ],
"client-request-id": [ "7927b734-7f49-4704-8be9-2a802aeb76f8" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00032E05\"}}" ],
"OData-Version": [ "4.0" ]
},
"ContentHeaders": {
},
"Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#invitations/$entity\",\"id\":\"0c9899a1-2e79-4b05-8285-7df46eda1e75\",\"inviteRedeemUrl\":\"https://login.microsoftonline.com/redeem?rd=NotValid\",\"invitedUserDisplayName\":\"John Doe\",\"invitedUserType\":\"Guest\",\"invitedUserEmailAddress\":\"johndoe@testtenant.onmicrosoft.com\",\"sendInvitationMessage\":false,\"resetRedemption\":false,\"inviteRedirectUrl\":\"https://myapp.contoso.com/\",\"status\":\"PendingAcceptance\",\"invitedUserMessageInfo\":{\"messageLanguage\":null,\"customizedMessageBody\":null,\"ccRecipients\":[{\"emailAddress\":{\"name\":null,\"address\":null}}]},\"invitedUser\":{\"id\":\"ebb12722-9cb6-4c90-ab39-bf1bb658bae7\"}}"
}
},
"New-MgInvitation+[NoContext]+ShouldThrowInvalidEmailError+$POST+https://graph.microsoft.com/beta/invitations+1": {
"Request": {
"Method": "POST",
"RequestUri": "https://graph.microsoft.com/beta/invitations",
"Content": "{\r\n \"invitedUser\": {\r\n \"id\": \"\",\r\n \"displayName\": \"John Doe\",\r\n \"mail\": \"johndoe@testtenant.onmicrosoft.com\",\r\n \"userPrincipalName\": \"johndoe@testtenant.onmicrosoft.com\"\r\n }\r\n}",
"Headers": {
},
"ContentHeaders": {
"Content-Type": [ "application/json" ],
"Content-Length": [ "190" ]
}
},
"Response": {
"StatusCode": 400,
"Headers": {
"Date": [ "Wed, 17 Feb 2021 23:05:50 GMT" ],
"Cache-Control": [ "no-store, must-revalidate, no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "e71de23d-cfb6-416a-b03e-416e493ba6ea" ],
"client-request-id": [ "e71de23d-cfb6-416a-b03e-416e493ba6ea" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00033720\"}}" ]
},
"ContentHeaders": {
},
"Content": "{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n \"message\": \"Invalid Email Address\",\r\n \"innerError\": {\r\n \"request-id\": \"e71de23d-cfb6-416a-b03e-416e493ba6ea\",\r\n \"date\": \"2021-02-17T23:05:51\",\r\n \"client-request-id\": \"e71de23d-cfb6-416a-b03e-416e493ba6ea\"\r\n }\r\n }\r\n}"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,80 @@
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgInvitation.Recording.json'
$currentPath = $PSScriptRoot
while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
BeforeAll {
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
# Set test mode to playback.
$TestMode = 'playback'
$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgInvitation.Recording.json'
$currentPath = $PSScriptRoot
while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
}
. ($mockingPath | Select-Object -First 1).FullName
# Switch to beta profile.
Select-MgProfile beta
}
. ($mockingPath | Select-Object -First 1).FullName

Describe 'New-MgInvitation' {
It 'CreateExpanded1' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
BeforeAll {
$Mock.PushDescription('New-MgInvitation')
}

Context 'CreateExpanded1' {
It 'ShouldCreateInvite' {
$Mock.PushScenario('ShouldCreateInvite')
$Params = @{
InvitedUserDisplayName = $env.Users[0].DisplayName
InvitedUserEmailAddress = $env.Users[0].Mail
InviteRedirectUrl = 'https://myapp.contoso.com'
}
$Invitation = New-MgInvitation @Params
$Invitation | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation1'
$Invitation | Should -HaveCount 1
$Invitation.InvitedUserDisplayName | Should -Be $env.Users[0].DisplayName
$Invitation.Status | Should -Be 'PendingAcceptance'
$Invitation.AdditionalProperties | Should -HaveCount 1
}

It 'ShouldThrowInvalidEmailError' {
$Mock.PushScenario('ShouldThrowInvalidEmailError')
$MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser1]@{
Id = $env.Users[0].UserId
DisplayName = $env.Users[0].DisplayName
Mail = $env.Users[0].Mail
UserPrincipalName = $env.Users[0].Mail
}
{ New-MgInvitation -InvitedUser $MyUser -ErrorAction Stop } | Should -Throw -ErrorId 'BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgInvitation_CreateExpanded1' -ExpectedMessage 'Invalid Email Address' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException<Microsoft.Graph.PowerShell.Models.IOdataError>'
}
}

It 'Create1' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
Context 'Create1' {
It 'ShouldCreateInvite' {
$Mock.PushScenario('ShouldCreateInvite')
$Params = @{
InvitedUserDisplayName = $env.Users[0].DisplayName
InvitedUserEmailAddress = $env.Users[0].Mail
InviteRedirectUrl = 'https://myapp.contoso.com'
}
$Invitation = New-MgInvitation -BodyParameter $Params
$Invitation | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation1'
$Invitation | Should -HaveCount 1
$Invitation.InvitedUserDisplayName | Should -Be $env.Users[0].DisplayName
$Invitation.Status | Should -Be 'PendingAcceptance'
$Invitation.AdditionalProperties | Should -HaveCount 1
}

It 'ShouldThrowInvalidEmailError' {
$Mock.PushScenario('ShouldThrowInvalidEmailError')
$MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser1]@{
Id = $env.Users[0].UserId
DisplayName = $env.Users[0].DisplayName
Mail = $env.Users[0].Mail
UserPrincipalName = $env.Users[0].Mail
}
{ New-MgInvitation -BodyParameter @{ InvitedUser = $MyUser } -ErrorAction Stop } | Should -Throw -ErrorId 'BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgInvitation_Create1' -ExpectedMessage 'Invalid Email Address' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException<Microsoft.Graph.PowerShell.Models.IOdataError>'
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"New-MgInvitation+[NoContext]+ShouldCreateInvite+$POST+https://graph.microsoft.com/v1.0/invitations+1": {
"Request": {
"Method": "POST",
"RequestUri": "https://graph.microsoft.com/v1.0/invitations",
"Content": "{\r\n \"inviteRedirectUrl\": \"https://myapp.contoso.com\",\r\n \"invitedUserDisplayName\": \"John Doe\",\r\n \"invitedUserEmailAddress\": \"johndoe@testtenant.onmicrosoft.com\"\r\n}",
"Headers": {
},
"ContentHeaders": {
"Content-Type": [ "application/json" ],
"Content-Length": [ "165" ]
}
},
"Response": {
"StatusCode": 201,
"Headers": {
"Date": [ "Wed, 17 Feb 2021 21:57:41 GMT" ],
"Cache-Control": [ "no-store, must-revalidate, no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Location": [ "https://graph.microsoft.com/" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "f4cd9413-56cc-4ab5-affa-e17d488a6eb2" ],
"client-request-id": [ "f4cd9413-56cc-4ab5-affa-e17d488a6eb2" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00032D50\"}}" ],
"OData-Version": [ "4.0" ]
},
"ContentHeaders": {
},
"Content": "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#invitations/$entity\",\"id\":\"0c9899a1-2e79-4b05-8285-7df46eda1e75\",\"inviteRedeemUrl\":\"https://login.microsoftonline.com/redeem?rd=NotValid\",\"invitedUserDisplayName\":\"John Doe\",\"invitedUserType\":\"Guest\",\"invitedUserEmailAddress\":\"johndoe@testtenant.onmicrosoft.com\",\"sendInvitationMessage\":false,\"inviteRedirectUrl\":\"https://myapp.contoso.com/\",\"status\":\"PendingAcceptance\",\"invitedUserMessageInfo\":{\"messageLanguage\":null,\"customizedMessageBody\":null,\"ccRecipients\":[{\"emailAddress\":{\"name\":null,\"address\":null}}]},\"invitedUser\":{\"id\":\"ebb12722-9cb6-4c90-ab39-bf1bb658bae7\"}}"
}
},
"New-MgInvitation+[NoContext]+ShouldThrowInvalidEmailError+$POST+https://graph.microsoft.com/v1.0/invitations+1": {
"Request": {
"Method": "POST",
"RequestUri": "https://graph.microsoft.com/v1.0/invitations",
"Content": "{\r\n \"invitedUser\": {\r\n \"id\": \"\",\r\n \"displayName\": \"John Doe\",\r\n \"mail\": \"johndoe@testtenant.onmicrosoft.com\",\r\n \"userPrincipalName\": \"johndoe@testtenant.onmicrosoft.com\"\r\n }\r\n}",
"Headers": {
},
"ContentHeaders": {
"Content-Type": [ "application/json" ],
"Content-Length": [ "190" ]
}
},
"Response": {
"StatusCode": 400,
"Headers": {
"Date": [ "Wed, 17 Feb 2021 21:57:39 GMT" ],
"Cache-Control": [ "no-store, must-revalidate, no-cache" ],
"Transfer-Encoding": [ "chunked" ],
"Vary": [ "Accept-Encoding" ],
"Strict-Transport-Security": [ "max-age=31536000" ],
"request-id": [ "90b8bf35-b7d7-4278-8582-07ad4f34bce3" ],
"client-request-id": [ "90b8bf35-b7d7-4278-8582-07ad4f34bce3" ],
"x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00032D57\"}}" ]
},
"ContentHeaders": {
},
"Content": "{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n \"message\": \"Invalid Email Address\",\r\n \"innerError\": {\r\n \"request-id\": \"90b8bf35-b7d7-4278-8582-07ad4f34bce3\",\r\n \"date\": \"2021-02-17T21:57:39\",\r\n \"client-request-id\": \"90b8bf35-b7d7-4278-8582-07ad4f34bce3\"\r\n }\r\n }\r\n}"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,80 @@
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgInvitation.Recording.json'
$currentPath = $PSScriptRoot
while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
BeforeAll {
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
# Set test mode to playback.
$TestMode = 'playback'
$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgInvitation.Recording.json'
$currentPath = $PSScriptRoot
while (-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
}
. ($mockingPath | Select-Object -First 1).FullName

Select-MgProfile 'v1.0'
}
. ($mockingPath | Select-Object -First 1).FullName

Describe 'New-MgInvitation' {
It 'CreateExpanded' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
BeforeAll {
$Mock.PushDescription('New-MgInvitation')
}

It 'Create' -skip {
{ throw [System.NotImplementedException] } | Should -Not -Throw
Context 'CreateExpanded' {
It 'ShouldCreateInvite' {
$Mock.PushScenario('ShouldCreateInvite')
$Params = @{
InvitedUserDisplayName = $env.Users[0].DisplayName
InvitedUserEmailAddress = $env.Users[0].Mail
InviteRedirectUrl = 'https://myapp.contoso.com'
}
$Invitation = New-MgInvitation @Params
$Invitation | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation'
$Invitation | Should -HaveCount 1
$Invitation.InvitedUserDisplayName | Should -Be $env.Users[0].DisplayName
$Invitation.Status | Should -Be 'PendingAcceptance'
$Invitation.AdditionalProperties | Should -HaveCount 1
}

It 'ShouldThrowInvalidEmailError' {
$Mock.PushScenario('ShouldThrowInvalidEmailError')
$MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser]@{
Id = $env.Users[0].UserId
DisplayName = $env.Users[0].DisplayName
Mail = $env.Users[0].Mail
UserPrincipalName = $env.Users[0].Mail
}
{ New-MgInvitation -InvitedUser $MyUser -ErrorAction Stop } | Should -Throw -ErrorId 'BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgInvitation_CreateExpanded' -ExpectedMessage 'Invalid Email Address' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException<Microsoft.Graph.PowerShell.Models.IOdataError>'
}
}

Context 'Create' {
It 'ShouldCreateInvite' {
$Mock.PushScenario('ShouldCreateInvite')
$Params = @{
InvitedUserDisplayName = $env.Users[0].DisplayName
InvitedUserEmailAddress = $env.Users[0].Mail
InviteRedirectUrl = 'https://myapp.contoso.com'
}
$Invitation = New-MgInvitation -BodyParameter $Params
$Invitation | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation'
$Invitation | Should -HaveCount 1
$Invitation.InvitedUserDisplayName | Should -Be $env.Users[0].DisplayName
$Invitation.Status | Should -Be 'PendingAcceptance'
$Invitation.AdditionalProperties | Should -HaveCount 1
}

It 'ShouldThrowInvalidEmailError' {
$Mock.PushScenario('ShouldThrowInvalidEmailError')
$MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser]@{
Id = $env.Users[0].UserId
DisplayName = $env.Users[0].DisplayName
Mail = $env.Users[0].Mail
UserPrincipalName = $env.Users[0].Mail
}
{ New-MgInvitation -BodyParameter @{ InvitedUser = $MyUser } -ErrorAction Stop } | Should -Throw -ErrorId 'BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgInvitation_Create' -ExpectedMessage 'Invalid Email Address' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException<Microsoft.Graph.PowerShell.Models.IOdataError>'
}
}
}
14 changes: 0 additions & 14 deletions src/readme.graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,20 +501,6 @@ directive:
$ = $.replace(additionalPropertiesRegex, '$1$2 new $3');
}

let regexPattern = /^\s*public\s*partial\s*class\s*MicrosoftGraph(?<EntityName>.*):$/gm;
let regexArray;
while ((regexArray = regexPattern.exec($)) !== null) {
if (regexArray['groups'] != null)
{
let EntityName = regexArray['groups'].EntityName.trim();
let newEntityId = EntityName + 'Id';
let newEntityIdPropRegex = new RegExp("^\\s*public\\s*string\\s*"+newEntityId+"\\.*","gm");
let existingIdPropRegex = /(^\s*)(public\s*string\s*Id\s.*)/gm;
if ((!$.match(newEntityIdPropRegex)) && $.match(existingIdPropRegex) && (newEntityId != "EntityId") && (newEntityId != "BaseItemId")) {
$ = $.replace(existingIdPropRegex, '$1$2\n\n$1partial void AfterToJson(ref Microsoft.Graph.PowerShell.Runtime.Json.JsonObject container, Microsoft.Graph.PowerShell.Runtime.SerializationMode serializationMode)\n$1{\n$1\tif (serializationMode == Microsoft.Graph.PowerShell.Runtime.SerializationMode.IncludeAll) {\n$1\t\tAddIf(null != this.Id ? (Microsoft.Graph.PowerShell.Runtime.Json.JsonNode)new Microsoft.Graph.PowerShell.Runtime.Json.JsonString(this.Id) : null, "'+ EntityName.toLowerCase() +'-id", container.Add);\n$1\t}\n$1}');
}
}
}
return $;
}
# Modify generated .cs cmdlets.
Expand Down