Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions src/Weaviate.Client.Tests/Integration/TestAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ namespace Weaviate.Client.Tests.Integration;

public class TestAuth : IntegrationTests
{
const int OKTA_PORT_CC = 8082;
const int OKTA_PORT_USERS = 8083;

private static async Task<(
bool IsSuccessStatusCode,
string? TokenEndpoint,
Expand Down Expand Up @@ -71,11 +68,11 @@ private static async Task<bool> IsAuthEnabled(string url)
[Fact]
public async Task TestNoAuthProvided()
{
Assert.True(await IsAuthEnabled($"localhost:{OKTA_PORT_CC}"));
Assert.True(await IsAuthEnabled($"{OidcHost}:{OidcOktaCcPort}"));

await Assert.ThrowsAnyAsync<WeaviateServerException>(async () =>
{
await Connect.Local(hostname: "localhost", restPort: OKTA_PORT_CC);
await Connect.Local(hostname: OidcHost, restPort: OidcOktaCcPort);
});
}

Expand All @@ -88,11 +85,11 @@ public async Task TestAuthenticationClientCredentials_Okta()
Assert.Skip("OKTA_CLIENT_SECRET is not set");
}

Assert.True(await IsAuthEnabled($"localhost:{OKTA_PORT_CC}"));
Assert.True(await IsAuthEnabled($"{OidcHost}:{OidcOktaCcPort}"));

var client = await Connect.Local(
hostname: "localhost",
restPort: OKTA_PORT_CC,
hostname: OidcHost,
restPort: OidcOktaCcPort,
credentials: Auth.ClientCredentials(clientSecret, "some_scope"),
httpMessageHandler: _httpMessageHandler
);
Expand All @@ -111,11 +108,11 @@ public async Task TestAuthenticationUserPw_Okta()
Assert.Skip("OKTA_DUMMY_CI_PW is not set");
}

Assert.True(await IsAuthEnabled($"localhost:{OKTA_PORT_USERS}"));
Assert.True(await IsAuthEnabled($"{OidcHost}:{OidcOktaUsersPort}"));

var client = await Connect.Local(
hostname: "localhost",
restPort: OKTA_PORT_USERS,
hostname: OidcHost,
restPort: OidcOktaUsersPort,
credentials: Auth.ClientPassword(
username: "test@test.de",
password: pw,
Expand All @@ -132,10 +129,10 @@ await client
[Fact]
public async Task TestClientWithAuthenticationWithAnonWeaviate()
{
Assert.False(await IsAuthEnabled($"localhost:{RestPort}"));
Assert.False(await IsAuthEnabled($"{RestHost}:{RestPort}"));

var client = await Connect.Local(
hostname: "localhost",
hostname: RestHost,
restPort: RestPort,
grpcPort: GrpcPort,
credentials: Auth.ClientPassword(
Expand All @@ -152,7 +149,7 @@ public async Task TestClientWithAuthenticationWithAnonWeaviate()
[Fact]
public async Task TestAuthenticationWithBearerToken_Okta()
{
string url = $"localhost:{OKTA_PORT_USERS}";
string url = $"{OidcHost}:{OidcOktaUsersPort}";
Assert.True(await IsAuthEnabled(url));
string pw = Environment.GetEnvironmentVariable("OKTA_DUMMY_CI_PW")!;
if (string.IsNullOrEmpty(pw))
Expand All @@ -168,8 +165,8 @@ public async Task TestAuthenticationWithBearerToken_Okta()
);

var client = await Connect.Local(
hostname: "localhost",
restPort: OKTA_PORT_USERS,
hostname: OidcHost,
restPort: OidcOktaUsersPort,
credentials: auth,
httpMessageHandler: _httpMessageHandler
);
Expand All @@ -180,7 +177,7 @@ public async Task TestAuthenticationWithBearerToken_Okta()
[Fact]
public async Task TestAuthenticationWithBearerTokenNoRefresh()
{
string url = $"localhost:{OKTA_PORT_USERS}";
string url = $"{OidcHost}:{OidcOktaUsersPort}";
Assert.True(await IsAuthEnabled(url));
string pw = Environment.GetEnvironmentVariable("OKTA_DUMMY_CI_PW")!;
if (string.IsNullOrEmpty(pw))
Expand All @@ -196,8 +193,8 @@ public async Task TestAuthenticationWithBearerTokenNoRefresh()
);

var client = await Connect.Local(
hostname: "localhost",
restPort: OKTA_PORT_USERS,
hostname: OidcHost,
restPort: OidcOktaUsersPort,
credentials: auth,
httpMessageHandler: _httpMessageHandler
);
Expand All @@ -213,13 +210,13 @@ await client
public async Task TestAuthenticationFailure()
{
string clientSecret = "invalid-secret";
Assert.True(await IsAuthEnabled($"localhost:{OKTA_PORT_CC}"));
Assert.True(await IsAuthEnabled($"{OidcHost}:{OidcOktaCcPort}"));

await Assert.ThrowsAsync<WeaviateAuthenticationException>(async () =>
{
await Connect.Local(
hostname: "localhost",
restPort: OKTA_PORT_CC,
hostname: OidcHost,
restPort: OidcOktaCcPort,
credentials: Auth.ClientCredentials(clientSecret, "some_scope"),
httpMessageHandler: _httpMessageHandler
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ await _weaviate.Users.Db.AssignRoles(

// Create a new client with the user's API key
var userClient = await new WeaviateClientBuilder()
.WithRestEndpoint("localhost")
.WithRestEndpoint(RestHost)
.WithRestPort(RestPort)
.WithGrpcEndpoint("localhost")
.WithGrpcEndpoint(RestHost)
.WithGrpcPort(GrpcPort)
.WithCredentials(Auth.ApiKey(apiKey))
.BuildAsync();
Expand Down
12 changes: 6 additions & 6 deletions src/Weaviate.Client.Tests/Integration/TestRbacUsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task Test_CreateUserAndGet()

// Verify we can connect with the new user's API key
var newUserClient = await Connect.Local(
hostname: "localhost",
hostname: RestHost,
restPort: RestPort,
grpcPort: GrpcPort,
credentials: Auth.ApiKey(apiKey),
Expand Down Expand Up @@ -146,7 +146,7 @@ public async Task Test_RotateUserKey()

// Verify old key works
var oldKeyClient = await Connect.Local(
hostname: "localhost",
hostname: RestHost,
restPort: RestPort,
grpcPort: GrpcPort,
credentials: Auth.ApiKey(apiKeyOld),
Expand All @@ -167,7 +167,7 @@ public async Task Test_RotateUserKey()

// Verify new key works
var newKeyClient = await Connect.Local(
hostname: "localhost",
hostname: RestHost,
restPort: RestPort,
grpcPort: GrpcPort,
credentials: Auth.ApiKey(apiKeyNew),
Expand Down Expand Up @@ -281,7 +281,7 @@ await _weaviate.Users.Db.Deactivate(
await Assert.ThrowsAnyAsync<WeaviateException>(async () =>
{
var oldKeyClient = await Connect.Local(
hostname: "localhost",
hostname: RestHost,
restPort: RestPort,
grpcPort: GrpcPort,
credentials: Auth.ApiKey(apiKeyOld),
Expand All @@ -300,7 +300,7 @@ await _weaviate.Users.Db.Activate(
await Assert.ThrowsAnyAsync<WeaviateException>(async () =>
{
var oldKeyClient = await Connect.Local(
hostname: "localhost",
hostname: RestHost,
restPort: RestPort,
grpcPort: GrpcPort,
credentials: Auth.ApiKey(apiKeyOld),
Expand All @@ -317,7 +317,7 @@ await Assert.ThrowsAnyAsync<WeaviateException>(async () =>

// New key should work
var newKeyClient = await Connect.Local(
hostname: "localhost",
hostname: RestHost,
restPort: RestPort,
grpcPort: GrpcPort,
credentials: Auth.ApiKey(apiKeyNew ?? string.Empty),
Expand Down
14 changes: 11 additions & 3 deletions src/Weaviate.Client.Tests/Integration/TestReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Weaviate.Client.Tests.Integration;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Weaviate.Client;
using Weaviate.Client.Models;
using Xunit;
Expand All @@ -16,16 +17,23 @@ namespace Weaviate.Client.Tests.Integration;
[CollectionDefinition("TestReplication", DisableParallelization = true)]
public class TestReplication : IntegrationTests
{
// Use dedicated ports for replication test suite to avoid clashes with other running instances
// Use the dedicated cluster instance to avoid clashes with other running instances.
// Configurable via WV_TEST_CLUSTER_HOST, WV_TEST_CLUSTER_REST_PORT, WV_TEST_CLUSTER_GRPC_PORT.
/// <inheritdoc />
public override string RestHost =>
_configuration.GetValue<string>("WV_TEST_CLUSTER_HOST") ?? "localhost";

/// <summary>
/// Gets the value of the rest port
/// </summary>
public override ushort RestPort => 8087;
public override ushort RestPort =>
_configuration.GetValue<ushort>("WV_TEST_CLUSTER_REST_PORT", 8087);

/// <summary>
/// Gets the value of the grpc port
/// </summary>
public override ushort GrpcPort => 50058;
public override ushort GrpcPort =>
_configuration.GetValue<ushort>("WV_TEST_CLUSTER_GRPC_PORT", 50058);

/// <summary>
/// Initializes this instance
Expand Down
30 changes: 28 additions & 2 deletions src/Weaviate.Client.Tests/Integration/_Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,41 @@ public IntegrationTests()
/// </summary>
public virtual ICredentials? Credentials => null;

/// <summary>
/// Gets the value of the rest host
/// </summary>
public virtual string RestHost =>
_configuration.GetValue<string>("WV_TEST_HOST") ?? "localhost";

/// <summary>
/// Gets the value of the rest port
/// </summary>
public virtual ushort RestPort => _configuration.GetValue<ushort>("WV_HTTP_PORT", 8080);
public virtual ushort RestPort => _configuration.GetValue<ushort>("WV_TEST_REST_PORT", 8080);

/// <summary>
/// Gets the value of the grpc port
/// </summary>
public virtual ushort GrpcPort => _configuration.GetValue<ushort>("WV_GRPC_PORT", 50051);
public virtual ushort GrpcPort => _configuration.GetValue<ushort>("WV_TEST_GRPC_PORT", 50051);

/// <summary>
/// Gets the value of the OIDC host. Override via WV_TEST_OIDC_HOST (default: localhost).
/// </summary>
public virtual string OidcHost =>
_configuration.GetValue<string>("WV_TEST_OIDC_HOST") ?? "localhost";

/// <summary>
/// Gets the value of the OIDC Okta client-credentials REST port.
/// Override via WV_TEST_OIDC_OKTA_CC_PORT (default: 8082).
/// </summary>
public virtual ushort OidcOktaCcPort =>
_configuration.GetValue<ushort>("WV_TEST_OIDC_OKTA_CC_PORT", 8082);

/// <summary>
/// Gets the value of the OIDC Okta users REST port.
/// Override via WV_TEST_OIDC_OKTA_USERS_PORT (default: 8083).
/// </summary>
public virtual ushort OidcOktaUsersPort =>
_configuration.GetValue<ushort>("WV_TEST_OIDC_OKTA_USERS_PORT", 8083);

/// <summary>
/// Disposes this instance
Expand Down
17 changes: 11 additions & 6 deletions src/Weaviate.Client.Tests/Integration/_RbacIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ namespace Weaviate.Client.Tests.Integration;
using Weaviate.Client;

/// <summary>
/// Base class for RBAC integration tests. Connects to the RBAC-enabled Weaviate instance
/// whose ports are controlled by WV_RBAC_HTTP_PORT / WV_RBAC_GRPC_PORT environment variables
/// (defaulting to 8092 / 50063 to match the local docker-compose RBAC service).
/// Use WV_RBAC_HTTP_PORT / WV_RBAC_GRPC_PORT to point these tests at the proxy RBAC endpoint.
/// Base class for RBAC integration tests. Connects to the RBAC-enabled Weaviate instance.
/// Configurable via WV_TEST_RBAC_HOST, WV_TEST_RBAC_REST_PORT, WV_TEST_RBAC_GRPC_PORT
/// (defaulting to localhost:8092 / 50063).
/// </summary>
public abstract class RbacIntegrationTests : IntegrationTests
{
/// <summary>The API key for the built-in admin user on the RBAC server.</summary>
protected const string ADMIN_API_KEY = "admin-key";

/// <inheritdoc />
public override ushort RestPort => _configuration.GetValue<ushort>("WV_RBAC_HTTP_PORT", 8092);
public override string RestHost =>
_configuration.GetValue<string>("WV_TEST_RBAC_HOST") ?? "localhost";

/// <inheritdoc />
public override ushort GrpcPort => _configuration.GetValue<ushort>("WV_RBAC_GRPC_PORT", 50063);
public override ushort RestPort =>
_configuration.GetValue<ushort>("WV_TEST_RBAC_REST_PORT", 8092);

/// <inheritdoc />
public override ushort GrpcPort =>
_configuration.GetValue<ushort>("WV_TEST_RBAC_GRPC_PORT", 50063);

/// <inheritdoc />
public override ICredentials? Credentials => Auth.ApiKey(ADMIN_API_KEY);
Expand Down
Loading