Skip to content

Commit 813987e

Browse files
committed
XPack security usernames now must start with an alpha character or _ added a way for crud tests to sanitize the call distinct string value they get passed
1 parent db92f95 commit 813987e

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/Tests/Framework/EndpointTests/CrudTestBase.cs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public abstract class CrudTestBase<TCluster, TCreateResponse, TReadResponse, TUp
3939
where TUpdateResponse : class, IResponse
4040
where TDeleteResponse : class, IResponse
4141
{
42-
private LazyResponses _createResponse;
43-
private LazyResponses _createGetResponse;
44-
private LazyResponses _updateResponse;
45-
private LazyResponses _updateGetResponse;
46-
private LazyResponses _deleteResponse;
47-
private LazyResponses _deleteGetResponse;
42+
private readonly LazyResponses _createResponse;
43+
private readonly LazyResponses _createGetResponse;
44+
private readonly LazyResponses _updateResponse;
45+
private readonly LazyResponses _updateGetResponse;
46+
private readonly LazyResponses _deleteResponse;
47+
private readonly LazyResponses _deleteGetResponse;
4848

49-
readonly ClusterBase _cluster;
49+
private readonly ClusterBase _cluster;
5050

5151
[SuppressMessage("Potential Code Quality Issues", "RECS0021:Warns about calls to virtual member functions occuring in the constructor", Justification = "Expected behaviour")]
5252
protected CrudTestBase(ClusterBase cluster, EndpointUsage usage)
@@ -65,10 +65,10 @@ protected CrudTestBase(ClusterBase cluster, EndpointUsage usage)
6565
protected abstract LazyResponses Update();
6666
protected virtual LazyResponses Delete() => LazyResponses.Empty;
6767

68-
protected static string RandomFluent { get; } = RandomString();
69-
protected static string RandomFluentAsync { get; } = RandomString();
70-
protected static string RandomInitializer { get; } = RandomString();
71-
protected static string RandomInitializerAsync { get; } = RandomString();
68+
private static string RandomFluent { get; } = RandomString();
69+
private static string RandomFluentAsync { get; } = RandomString();
70+
private static string RandomInitializer { get; } = RandomString();
71+
private static string RandomInitializerAsync { get; } = RandomString();
7272

7373
protected virtual bool SupportsDeletes => true;
7474

@@ -89,14 +89,25 @@ Func<string, IElasticClient, TInitializer, Task<TResponse>> requestAsync
8989
return new LazyResponses(async () =>
9090
{
9191
var dict = new Dictionary<ClientMethod, IResponse>();
92-
dict.Add(Integration.ClientMethod.Fluent, fluent(RandomFluent, client, f => fluentBody(RandomFluent, f)));
93-
dict.Add(Integration.ClientMethod.FluentAsync, await fluentAsync(RandomFluentAsync, client, f => fluentBody(RandomFluentAsync, f)));
94-
dict.Add(Integration.ClientMethod.Initializer, request(RandomInitializer, client, initializerBody(RandomInitializer)));
95-
dict.Add(Integration.ClientMethod.InitializerAsync, await requestAsync(RandomInitializerAsync, client, initializerBody(RandomInitializerAsync)));
92+
93+
var sf = Sanitize(RandomFluent);
94+
dict.Add(Integration.ClientMethod.Fluent, fluent(sf, client, f => fluentBody(sf, f)));
95+
96+
var sfa = Sanitize(RandomFluentAsync);
97+
dict.Add(Integration.ClientMethod.FluentAsync, await fluentAsync(sfa, client, f => fluentBody(sfa, f)));
98+
99+
var si = Sanitize(RandomInitializer);
100+
dict.Add(Integration.ClientMethod.Initializer, request(si, client, initializerBody(si)));
101+
102+
var sia = Sanitize(RandomInitializerAsync);
103+
dict.Add(Integration.ClientMethod.InitializerAsync, await requestAsync(sia, client, initializerBody(sia)));
96104
return dict;
97105
});
98106
}
99107
protected static string RandomString() => Guid.NewGuid().ToString("N").Substring(0, 8);
108+
109+
protected virtual string Sanitize(string randomString) => randomString;
110+
100111
protected int IntegrationPort { get; set; } = 9200;
101112
protected virtual IElasticClient Client => this._cluster.Client;
102113

src/Tests/XPack/Security/User/UserCrudTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class UserCrudTests
1414
private string[] _roles = { "user" };
1515
public UserCrudTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1616

17+
//Since we basically take the first 8 characters of a guid we have no way
18+
//to guarantee it starts with a-zA-Z which is mandatory since 5.1
19+
protected override string Sanitize(string callDistinctValue) => "u" + callDistinctValue;
20+
1721
protected override LazyResponses Create() => Calls<PutUserDescriptor, PutUserRequest, IPutUserRequest, IPutUserResponse>(
1822
CreateInitializer,
1923
CreateFluent,

0 commit comments

Comments
 (0)