Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpRequestException: Response status code does not indicate success: 401 (Unauthorized). #3

Closed
icnocop opened this issue Jan 16, 2020 · 3 comments

Comments

@icnocop
Copy link
Owner

icnocop commented Jan 16, 2020

Hi Dave.

Thank you for AzurePipelines.TestLogger v1.0.3.

Since the built-in TfsPublisher logger is deprecated in Visual Studio 2017, I'm trying to use this logger to publish test results to TFS 2015 Update 4 (on-premise) as part of my build instead. 😊

Before I enabled the Allow Scripts to Access OAuth Token option in my build definition, I received the error message AzurePipelines.TestLogger: Not an Azure Pipelines test run, environment variable SYSTEM_ACCESSTOKEN not set.

However, after I enabled the Allow Scripts to Access OAuth Token option in my build definition, I receive the following error:

Error from AzurePipelines logger while sending POST to http://tfs2015:8080/tfs/DefaultCollection/MyTeamProject/_apis/test/runs?api-version=5.0
          Body:
          {"name":"MyTestAssembly (OS: Microsoft Windows 10.0.14393 , Job: Build, Agent: Agent-WIN-MACHINENAME)","build":{"id":"12345"},"startedDate":"2020-01-15T23:38:48.191Z","isAutomated":true}
          Exception:
          System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
             at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
             at AzurePipelines.TestLogger.ApiClient.<SendAsync>d__3.MoveNext()

Do you have any ideas on how I can troubleshoot and/or resolve this issue?

Is there another security setting that needs to be configured?

Is it possible to test this using the default logged in Windows credentials instead of the Basic authentication type?
For example, see https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.usedefaultcredentials.

The Visual Studio 2017 test agent (VsoAgent) is running in interactive mode.
The build definition is using the new build pipeline definition and isn't a XAML build definition.

Command line:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "c:\agent\_work\1\s\MyProject\bin\Release\MyTestAssembly.dll" /logger:"AzurePipelines" /TestAdapterPath:"c:\agent\_work\1\s\AzurePipelines.TestLogger\v1.0.3\netstandard1.5"

Thank you!

@daveaglick
Copy link
Collaborator

Interesting, never envisioned this being used for an on-prem TFS install and don't have one to test on, but happy to support it if we can figure it out.

In Azure Pipelines enabling access to the token isn't quite enough. You also have to pass SYSTEM_ACCESSTOKEN down to the script via the YAML definition:

env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)

I suspect given that you received a different error after turning on the token that it's being set as an environment variable now. You might be on to something with the basic vs. windows authentication though. Here's where it sets the auth header: https://github.com/daveaglick/AzurePipelines.TestLogger/blob/master/src/AzurePipelines.TestLogger/ApiClient.cs#L21-L22 - I could try adding a flag that uses default/windows credentials instead. Do you think that would help? Might at least give us a little more information...

@icnocop
Copy link
Owner Author

icnocop commented Feb 6, 2020

@daveaglick, I'm not sure if you had noticed my previous comment, so I'll just mention it in this issue - PR #6 is now ready for your review. :)

Thank you.

@icnocop
Copy link
Owner Author

icnocop commented Jun 18, 2020

Release v1.1.0 has added support for using default credentials instead of an access token for authentication.

@icnocop icnocop closed this as completed Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants