MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
445 stars 155 forks source link

Update-VSTeamRelease WARNING: VS402865: An empty body in the POST request is not allowed. #326

Closed speedmind closed 4 years ago

speedmind commented 4 years ago

This issue is similar (if not identical) to #239 & #221 but is still present in the current release 6.4.8. Please note that no modifications are being made to the release, so it's effectively been submitted as it arrives.

This occurs whenever the JSON request contains special characters and in our case I've identified a user with a special character in his name in the request under artifacts/definitionReference/requestedFor/id, but it could have been anywhere...

I've tried on Windows locally, but it also fails consistently on a Linux hosted agent (ubuntu-18.04) on AzD.

I've also captured the whole communication using fiddler and can provide it upon request.

Steps to reproduce

These are essentially the steps provided in the Update-VSTeamRelease reference documentation here: https://github.com/DarqueWarrior/vsteam/blob/master/.docs/Update-VSTeamRelease.md

Set-VSTeamAccount -Account myAccount -PersonalAccessToken <redacted>
$r = Get-VSTeamRelease -ProjectName myProject -Id 999 -Raw
Update-VSTeamRelease -ProjectName myProject -Id 999 -release $r

Expected behavior By modifying the Update-VSTeamRelease function locally I get the behavior below

Should return $r without any error similar to the one below

id                         : 999
name                       : Release-343
status                     : active
createdOn                  : 2020-05-25 14:08:18
modifiedOn                 : 2020-05-25 20:23:17
modifiedBy                 : @{…}
createdBy                  : @{…}
createdFor                 : @{…}
environments               : {@{…}…}
variables                  : @{…}
variableGroups             : {}
artifacts                  : {@{…}}
releaseDefinition          : @{…}
releaseDefinitionRevision  : 301
description                : Triggered by Repository:
                             Microsoft.VisualStudio.Services.ReleaseManagement.Server.Plugins.Model.GitRepository,
                             Branch: refs/heads/development, Commit Id: 2070.
reason                     : continuousIntegration
releaseNameFormat          : Release-$(rev:r)
keepForever                : False
definitionSnapshotRevision : 17
logsContainerUrl           : …
url                        : …
_links                     : @{self=; web=}
tags                       : {}
triggeringArtifactAlias    :
projectReference           : @{…}
properties                 :

Actual behavior

WARNING: VS402865: An empty body in the POST request is not allowed.
Invoke-RestMethod: C:\Users\vas\Documents\PowerShell\Modules\VSTeam\6.4.8\vsteam.functions.ps1:268
Line |
 268 |           $resp = Invoke-RestMethod @params
     |                   ~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"$id":"1","innerException":null,"message":"VS402865: An empty body in the POST request is not
     | allowed.","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}

Environment data

OS

Server

> Get-VSTeamAPIVersion
Name                           Value
----                           -----
Release                        5.1-preview
Tfvc                           5.0
Packaging                      5.1-preview
TaskGroups                     5.1-preview.1
Policy                         5.1
VariableGroups                 5.0-preview.1
ExtensionsManagement           5.1-preview
Version                        AzD
Git                            5.1-preview
Build                          5.1-preview
ServiceFabricEndpoint          5.0-preview
Core                           5.0
MemberEntitlementManagement    5.1-preview
DistributedTask                5.0-preview
Graph                          5.1-preview
> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.0.1
PSEdition                      Core
GitCommitId                    7.0.1
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
SebastianSchuetze commented 4 years ago

Thanks for reporting. We will check this.

SebastianSchuetze commented 4 years ago

@speedmind could you provide the fiddle request? That would help a lot. Do you have sensitive data in the fiddler request?

speedmind commented 4 years ago

It does, but I'll invalidate my PAT... Please delete once downloaded. update: remove the download link

DarqueWarrior commented 4 years ago

What was the special character in the users name? I want to setup a test environment to duplicate.

speedmind commented 4 years ago

What was the special character in the users name? I want to setup a test environment to duplicate.

Hi Donovan, It's kind of strange. The character causing the issue is an unknown character \xEF\xBF\xBD (�) but the correct character should have been \xC3\xA1 (á)

If you have access to the fiddler session I uploaded, you'll see that the requests No. 11, 20, 23, 50 & 56 submit the wrong (�) character but the responses No. 8, 23 & 56 return the correct character (á).

You can find the offending character by looking at either the request or the response using xPath: $.artifacts[1].definitionReference.requestedFor.id

Either way, when the request is submitted with charset=utf-8 (it was added manually by me in fiddler) in the Content-Type (see requests No. 23 & 56) the server seems to be happy (as opposed to requests No. 20 & 60 which fail without it).

Hope this clarifies the situation and I appreciate you looking into this, Vas.

DarqueWarrior commented 4 years ago

I have a copy of the Fiddler log. I will find time to review. Thanks.

SebastianSchuetze commented 4 years ago

I took a look and I can confirm that it is an encoding problem. Gonna fix it now.

SebastianSchuetze commented 4 years ago

fixing took a bit longer since I also implemented integration tests for this cmdlet. But PR is checked now and should go through.

DarqueWarrior commented 4 years ago

Fix will be in 6.5.1