Skip to content

Commit bef3b6f

Browse files
committed
Bypass windows auth on whitespace for VSTS client
1 parent 4ffc8f3 commit bef3b6f

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

RutaHttpModule/SonarAuthPassthroughModule.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,20 @@ private void HandleAuthenticateRequestRequestInternal(ISonarAuthPassthroughHttpC
100100
// This is most efficent.
101101
if (context.HasTokenHeader)
102102
{
103+
traceSource.TraceEvent(TraceEventType.Information, 0, "Found token.");
103104
AssignPassThruUser(context);
105+
return;
104106
}
105107

106108
// If we have no agent, or the agent does not match any of our pass thrus
107109
string userAgent = context.UserAgent;
108-
if (string.IsNullOrWhiteSpace(userAgent) || !this.settings.PassThruUserAgents.Any(userAgent.StartsWith))
110+
traceSource.TraceEvent(TraceEventType.Information, 0, $"UserAgent: '{userAgent}'");
111+
112+
if (string.IsNullOrWhiteSpace(userAgent) || this.settings.PassThruUserAgents.Any(userAgent.StartsWith))
109113
{
114+
AssignPassThruUser(context);
110115
return;
111-
}
112-
113-
AssignPassThruUser(context);
116+
}
114117
}
115118

116119
private void AssignPassThruUser(ISonarAuthPassthroughHttpContext context)

RutaHttpModuleTest/SonarAuthPassthroughModuleTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ public void SetWhenUserAgentMatchesTest()
6767
Assert.IsTrue(this.httpContext.Object.User.Identity.IsAuthenticated);
6868
}
6969

70+
[TestMethod]
71+
public void SetWhenUserAgentOnWhitespaceTest()
72+
{
73+
this.httpContext.SetupProperty(x => x.User);
74+
string agentName = string.Empty;
75+
76+
this.httpContext.SetupGet(x => x.UserAgent).Returns(agentName);
77+
this.settings.SetupGet(x => x.PassThruUserAgents).Returns(new string[0]);
78+
79+
this.sonarAuthPassthroughModule.HandleAuthenticateRequest(httpContext.Object);
80+
81+
this.httpContext.VerifySet(x => x.SkipAuthorization = true, Times.Once());
82+
Assert.IsTrue(this.httpContext.Object.User.Identity.IsAuthenticated);
83+
}
84+
7085
[TestMethod]
7186
public void DontSetWhenUserAgentMatchesTest()
7287
{

0 commit comments

Comments
 (0)