Skip to content

Commit dc5e0bb

Browse files
committed
Shield on CoreFX broken
- BasicAuthentication only listened to the authentication set on the request, not connectionsettings. - HttpConnection-CoreFX did not take RunAs into account - Maximum runtime for integration tests is now 30minutes, we are well under that luckily though :)
1 parent 58d213a commit dc5e0bb

File tree

3 files changed

+54
-48
lines changed

3 files changed

+54
-48
lines changed

Diff for: build/scripts/Paths.fsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,16 @@ module Tooling =
288288
match (runtime, hasClr, hasCoreClr) with
289289
| (Core, _, Some c) ->
290290
let proc = c.Process exe
291-
execProcess proc arguments
291+
execProcessWithTimeout proc arguments (TimeSpan.FromMinutes 30.)
292292
| (Desktop, Some d, _) ->
293293
let proc = d.Process exe
294-
execProcess proc arguments
294+
execProcessWithTimeout proc arguments (TimeSpan.FromMinutes 30.)
295295
| (Both, Some d, Some c) ->
296296
let proc = d.Process exe
297297
let result = execProcess proc arguments
298298
if result <> 0 then failwith (sprintf "Failed to run dnx tooling for %s args: %A" proc arguments)
299299
let proc = c.Process exe
300-
execProcess proc arguments
300+
execProcessWithTimeout proc arguments (TimeSpan.FromMinutes 30.)
301301
| _ -> failwith "Tried to run dnx tooling in unknown state"
302302
|> ignore
303303

Diff for: paket.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
NUGET
2-
remote: http://api.nuget.org/v3/index.json
2+
remote: https://www.nuget.org/api/v2
33
specs:
44
AsciiDocNet (1.0.0-alpha3)
5+
RazorMachine (2.6.1)
6+
remote: http://api.nuget.org/v3/index.json
7+
specs:
58
Bogus (3.0.5-beta-2)
69
Newtonsoft.Json (>= 8.0.2) - framework: >= net40, dnx451, dnxcore50
710
System.ComponentModel (>= 4.0.1-beta-23516) - framework: dnxcore50
@@ -348,9 +351,6 @@ NUGET
348351
System.Threading.Tasks (>= 4.0) - framework: dnxcore50
349352
xunit.abstractions (>= 2.0) - framework: dnxcore50
350353
xunit.extensibility.core (2.1) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.0, wpav8.1
351-
remote: https://www.nuget.org/api/v2
352-
specs:
353-
RazorMachine (2.6.1)
354354

355355
GROUP build
356356
NUGET

Diff for: src/Elasticsearch.Net/Connection/HttpConnection-CoreFx.cs

+47-41
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,46 @@ public class HttpConnection : IConnection
3030
private readonly object _lock = new object();
3131
private readonly ConcurrentDictionary<int, HttpClient> _clients = new ConcurrentDictionary<int, HttpClient>();
3232

33-
private string DefaultContentType => "application/json";
33+
private string DefaultContentType => "application/json";
3434

3535
public HttpConnection() { }
36-
36+
3737
private HttpClient GetClient(RequestData requestData)
3838
{
3939
var hashCode = requestData.GetHashCode();
4040
HttpClient client;
4141
if (this._clients.TryGetValue(hashCode, out client)) return client;
42-
lock(_lock)
42+
lock (_lock)
4343
{
4444
if (this._clients.TryGetValue(hashCode, out client)) return client;
4545

46-
var handler = new HttpClientHandler
47-
{
48-
AutomaticDecompression = requestData.HttpCompression ? GZip | Deflate : None
49-
};
50-
51-
if (!requestData.ProxyAddress.IsNullOrEmpty())
52-
{
53-
var uri = new Uri(requestData.ProxyAddress);
54-
var proxy = new WebProxy(uri);
55-
var credentials = new NetworkCredential(requestData.ProxyUsername, requestData.ProxyPassword);
56-
proxy.Credentials = credentials;
57-
handler.Proxy = proxy;
58-
}
59-
60-
if (requestData.DisableAutomaticProxyDetection)
61-
handler.Proxy = null;
62-
63-
client = new HttpClient(handler, false)
64-
{
65-
Timeout = requestData.RequestTimeout
66-
};
67-
68-
client.DefaultRequestHeaders.ExpectContinue = false;
69-
70-
//TODO add headers
71-
//client.DefaultRequestHeaders =
72-
this._clients.TryAdd(hashCode, client);
46+
var handler = new HttpClientHandler
47+
{
48+
AutomaticDecompression = requestData.HttpCompression ? GZip | Deflate : None
49+
};
50+
51+
if (!requestData.ProxyAddress.IsNullOrEmpty())
52+
{
53+
var uri = new Uri(requestData.ProxyAddress);
54+
var proxy = new WebProxy(uri);
55+
var credentials = new NetworkCredential(requestData.ProxyUsername, requestData.ProxyPassword);
56+
proxy.Credentials = credentials;
57+
handler.Proxy = proxy;
58+
}
59+
60+
if (requestData.DisableAutomaticProxyDetection)
61+
handler.Proxy = null;
62+
63+
client = new HttpClient(handler, false)
64+
{
65+
Timeout = requestData.RequestTimeout
66+
};
67+
68+
client.DefaultRequestHeaders.ExpectContinue = false;
69+
70+
//TODO add headers
71+
//client.DefaultRequestHeaders =
72+
this._clients.TryAdd(hashCode, client);
7373
return client;
7474
}
7575

@@ -122,13 +122,27 @@ private static HttpRequestMessage CreateHttpRequestMessage(RequestData requestDa
122122
var method = ConvertHttpMethod(requestData.Method);
123123
var requestMessage = new HttpRequestMessage(method, requestData.Uri);
124124

125-
foreach(string key in requestData.Headers)
125+
foreach (string key in requestData.Headers)
126126
{
127127
requestMessage.Headers.TryAddWithoutValidation(key, requestData.Headers.GetValues(key));
128128
}
129129

130130
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(requestData.ContentType));
131131

132+
if (!requestData.RunAs.IsNullOrEmpty())
133+
requestMessage.Headers.Add("es-shield-runas-user", requestData.RunAs);
134+
135+
string userInfo = null;
136+
if (!requestData.Uri.UserInfo.IsNullOrEmpty())
137+
userInfo = Uri.UnescapeDataString(requestData.Uri.UserInfo);
138+
else if (requestData.BasicAuthorizationCredentials != null)
139+
userInfo = requestData.BasicAuthorizationCredentials.ToString();
140+
if (!userInfo.IsNullOrEmpty())
141+
{
142+
var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(userInfo));
143+
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);
144+
}
145+
132146
var data = requestData.PostData;
133147

134148
if (data != null)
@@ -153,18 +167,10 @@ private static HttpRequestMessage CreateHttpRequestMessage(RequestData requestDa
153167
else
154168
{
155169
// Set content in order to set a Content-Type header.
156-
// Content gets diposed so can't be shared instance
170+
// Content gets diposed so can't be shared instance
157171
requestMessage.Content = new ByteArrayContent(new byte[0]);
158172
}
159-
160173
requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(requestData.ContentType);
161-
162-
if (!string.IsNullOrWhiteSpace(requestData.Uri.UserInfo))
163-
{
164-
var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(requestMessage.RequestUri.UserInfo));
165-
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);
166-
}
167-
168174
return requestMessage;
169175
}
170176

@@ -186,7 +192,7 @@ private static System.Net.Http.HttpMethod ConvertHttpMethod(HttpMethod httpMetho
186192

187193
protected virtual void DisposeManagedResources()
188194
{
189-
foreach(var c in _clients)
195+
foreach (var c in _clients)
190196
c.Value.Dispose();
191197
}
192198
}

0 commit comments

Comments
 (0)