forked from redis/NRedisStack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthenticationTests.cs
53 lines (43 loc) · 2.01 KB
/
AuthenticationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Xunit;
using StackExchange.Redis;
using Azure.Identity;
using NRedisStack.RedisStackCommands;
using NRedisStack.Search;
namespace NRedisStack.Tests.TokenBasedAuthentication
{
public class AuthenticationTests : AbstractNRedisStackTest
{
static readonly string key = "myKey";
static readonly string value = "myValue";
static readonly string index = "myIndex";
static readonly string field = "myField";
static readonly string alias = "myAlias";
public AuthenticationTests(RedisFixture redisFixture) : base(redisFixture) { }
[TargetEnvironment("standalone-entraid-acl")]
public void TestTokenBasedAuthentication()
{
var configurationOptions = new ConfigurationOptions().ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()).Result!;
configurationOptions.Ssl = false;
configurationOptions.AbortOnConnectFail = true; // Fail fast for the purposes of this sample. In production code, this should remain false to retry connections on startup
ConnectionMultiplexer? connectionMultiplexer = redisFixture.GetConnectionById(configurationOptions, "standalone-entraid-acl");
IDatabase db = connectionMultiplexer.GetDatabase();
db.KeyDelete(key);
try
{
db.FT().DropIndex(index);
}
catch { }
db.StringSet(key, value);
string result = db.StringGet(key);
Assert.Equal(value, result);
var ft = db.FT();
Schema sc = new Schema().AddTextField(field);
Assert.True(ft.Create(index, FTCreateParams.CreateParams(), sc));
db.HashSet(index, new HashEntry[] { new HashEntry(field, value) });
Assert.True(ft.AliasAdd(alias, index));
SearchResult res1 = ft.Search(alias, new Query("*").ReturnFields(field));
Assert.Equal(1, res1.TotalResults);
Assert.Equal(value, res1.Documents[0][field]);
}
}
}