diff --git a/src/Weaviate.Client.Tests/Integration/TestAuth.cs b/src/Weaviate.Client.Tests/Integration/TestAuth.cs index 907892e3..ff7058dc 100644 --- a/src/Weaviate.Client.Tests/Integration/TestAuth.cs +++ b/src/Weaviate.Client.Tests/Integration/TestAuth.cs @@ -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, @@ -71,11 +68,11 @@ private static async Task 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(async () => { - await Connect.Local(hostname: "localhost", restPort: OKTA_PORT_CC); + await Connect.Local(hostname: OidcHost, restPort: OidcOktaCcPort); }); } @@ -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 ); @@ -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, @@ -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( @@ -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)) @@ -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 ); @@ -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)) @@ -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 ); @@ -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(async () => { await Connect.Local( - hostname: "localhost", - restPort: OKTA_PORT_CC, + hostname: OidcHost, + restPort: OidcOktaCcPort, credentials: Auth.ClientCredentials(clientSecret, "some_scope"), httpMessageHandler: _httpMessageHandler ); diff --git a/src/Weaviate.Client.Tests/Integration/TestRbacAuthorization.cs b/src/Weaviate.Client.Tests/Integration/TestRbacAuthorization.cs index 37c86f7d..fdb17fdf 100644 --- a/src/Weaviate.Client.Tests/Integration/TestRbacAuthorization.cs +++ b/src/Weaviate.Client.Tests/Integration/TestRbacAuthorization.cs @@ -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(); diff --git a/src/Weaviate.Client.Tests/Integration/TestRbacUsers.cs b/src/Weaviate.Client.Tests/Integration/TestRbacUsers.cs index 9314fcc5..90fdd9f0 100644 --- a/src/Weaviate.Client.Tests/Integration/TestRbacUsers.cs +++ b/src/Weaviate.Client.Tests/Integration/TestRbacUsers.cs @@ -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), @@ -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), @@ -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), @@ -281,7 +281,7 @@ await _weaviate.Users.Db.Deactivate( await Assert.ThrowsAnyAsync(async () => { var oldKeyClient = await Connect.Local( - hostname: "localhost", + hostname: RestHost, restPort: RestPort, grpcPort: GrpcPort, credentials: Auth.ApiKey(apiKeyOld), @@ -300,7 +300,7 @@ await _weaviate.Users.Db.Activate( await Assert.ThrowsAnyAsync(async () => { var oldKeyClient = await Connect.Local( - hostname: "localhost", + hostname: RestHost, restPort: RestPort, grpcPort: GrpcPort, credentials: Auth.ApiKey(apiKeyOld), @@ -317,7 +317,7 @@ await Assert.ThrowsAnyAsync(async () => // New key should work var newKeyClient = await Connect.Local( - hostname: "localhost", + hostname: RestHost, restPort: RestPort, grpcPort: GrpcPort, credentials: Auth.ApiKey(apiKeyNew ?? string.Empty), diff --git a/src/Weaviate.Client.Tests/Integration/TestReplication.cs b/src/Weaviate.Client.Tests/Integration/TestReplication.cs index c83957bb..6b421611 100644 --- a/src/Weaviate.Client.Tests/Integration/TestReplication.cs +++ b/src/Weaviate.Client.Tests/Integration/TestReplication.cs @@ -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; @@ -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. + /// + public override string RestHost => + _configuration.GetValue("WV_TEST_CLUSTER_HOST") ?? "localhost"; + /// /// Gets the value of the rest port /// - public override ushort RestPort => 8087; + public override ushort RestPort => + _configuration.GetValue("WV_TEST_CLUSTER_REST_PORT", 8087); /// /// Gets the value of the grpc port /// - public override ushort GrpcPort => 50058; + public override ushort GrpcPort => + _configuration.GetValue("WV_TEST_CLUSTER_GRPC_PORT", 50058); /// /// Initializes this instance diff --git a/src/Weaviate.Client.Tests/Integration/_Integration.cs b/src/Weaviate.Client.Tests/Integration/_Integration.cs index b4c2a868..600927fc 100644 --- a/src/Weaviate.Client.Tests/Integration/_Integration.cs +++ b/src/Weaviate.Client.Tests/Integration/_Integration.cs @@ -80,15 +80,41 @@ public IntegrationTests() /// public virtual ICredentials? Credentials => null; + /// + /// Gets the value of the rest host + /// + public virtual string RestHost => + _configuration.GetValue("WV_TEST_HOST") ?? "localhost"; + /// /// Gets the value of the rest port /// - public virtual ushort RestPort => _configuration.GetValue("WV_HTTP_PORT", 8080); + public virtual ushort RestPort => _configuration.GetValue("WV_TEST_REST_PORT", 8080); /// /// Gets the value of the grpc port /// - public virtual ushort GrpcPort => _configuration.GetValue("WV_GRPC_PORT", 50051); + public virtual ushort GrpcPort => _configuration.GetValue("WV_TEST_GRPC_PORT", 50051); + + /// + /// Gets the value of the OIDC host. Override via WV_TEST_OIDC_HOST (default: localhost). + /// + public virtual string OidcHost => + _configuration.GetValue("WV_TEST_OIDC_HOST") ?? "localhost"; + + /// + /// Gets the value of the OIDC Okta client-credentials REST port. + /// Override via WV_TEST_OIDC_OKTA_CC_PORT (default: 8082). + /// + public virtual ushort OidcOktaCcPort => + _configuration.GetValue("WV_TEST_OIDC_OKTA_CC_PORT", 8082); + + /// + /// Gets the value of the OIDC Okta users REST port. + /// Override via WV_TEST_OIDC_OKTA_USERS_PORT (default: 8083). + /// + public virtual ushort OidcOktaUsersPort => + _configuration.GetValue("WV_TEST_OIDC_OKTA_USERS_PORT", 8083); /// /// Disposes this instance diff --git a/src/Weaviate.Client.Tests/Integration/_RbacIntegration.cs b/src/Weaviate.Client.Tests/Integration/_RbacIntegration.cs index b06e4fe1..2258652f 100644 --- a/src/Weaviate.Client.Tests/Integration/_RbacIntegration.cs +++ b/src/Weaviate.Client.Tests/Integration/_RbacIntegration.cs @@ -4,10 +4,9 @@ namespace Weaviate.Client.Tests.Integration; using Weaviate.Client; /// -/// 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). /// public abstract class RbacIntegrationTests : IntegrationTests { @@ -15,10 +14,16 @@ public abstract class RbacIntegrationTests : IntegrationTests protected const string ADMIN_API_KEY = "admin-key"; /// - public override ushort RestPort => _configuration.GetValue("WV_RBAC_HTTP_PORT", 8092); + public override string RestHost => + _configuration.GetValue("WV_TEST_RBAC_HOST") ?? "localhost"; /// - public override ushort GrpcPort => _configuration.GetValue("WV_RBAC_GRPC_PORT", 50063); + public override ushort RestPort => + _configuration.GetValue("WV_TEST_RBAC_REST_PORT", 8092); + + /// + public override ushort GrpcPort => + _configuration.GetValue("WV_TEST_RBAC_GRPC_PORT", 50063); /// public override ICredentials? Credentials => Auth.ApiKey(ADMIN_API_KEY);