Skip to content

Commit 68794f8

Browse files
authored
Merge pull request #193 from weaviate/feat/missing-exceptions
2 parents f39e552 + 87a2f88 commit 68794f8

20 files changed

+1957
-124
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ jobs:
152152
name: Test on Weaviate v${{ matrix.version }}
153153
permissions:
154154
contents: read
155+
checks: write
155156
needs: [unit-tests, setup]
156157
strategy:
157158
fail-fast: false

.github/workflows/test-on-weaviate-version.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
name: Quick Integration Tests - v${{ inputs.weaviate-version }}
2727
permissions:
2828
contents: read
29+
checks: write
2930
uses: ./.github/workflows/integration-test.yml
3031
secrets: inherit
3132
with:
@@ -38,6 +39,7 @@ jobs:
3839
name: Slow Integration Tests - v${{ inputs.weaviate-version }}
3940
permissions:
4041
contents: read
42+
checks: write
4143
needs: [integration-rbac]
4244
if: ${{ inputs.run-slow-tests }}
4345
uses: ./.github/workflows/integration-test.yml
@@ -52,6 +54,7 @@ jobs:
5254
name: RBAC Integration Tests - v${{ inputs.weaviate-version }}
5355
permissions:
5456
contents: read
57+
checks: write
5558
needs: [integration-quick]
5659
if: ${{ inputs.run-slow-tests }}
5760
uses: ./.github/workflows/integration-test.yml

src/Weaviate.Client.Tests/Integration/TestAuth.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace Weaviate.Client.Tests.Integration;
22

3-
using System;
43
using System.Net.Http;
54
using System.Threading.Tasks;
65
using Weaviate.Client;
7-
using Xunit;
86

97
public class TestAuth : IntegrationTests
108
{
@@ -208,4 +206,21 @@ await client
208206

209207
// TODO Needs a finalized way to inject a logger and check that no warnings were logged
210208
}
209+
210+
[Fact]
211+
public async Task TestAuthenticationFailure()
212+
{
213+
string clientSecret = "invalid-secret";
214+
Assert.True(await IsAuthEnabled($"localhost:{OKTA_PORT_CC}"));
215+
216+
await Assert.ThrowsAsync<WeaviateAuthenticationException>(async () =>
217+
{
218+
await Connect.Local(
219+
hostname: "localhost",
220+
restPort: OKTA_PORT_CC,
221+
credentials: Auth.ClientCredentials(clientSecret, "some_scope"),
222+
httpMessageHandler: _httpMessageHandler
223+
);
224+
});
225+
}
211226
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
namespace Weaviate.Client.Tests.Integration;
2+
3+
using System.Linq;
4+
using Weaviate.Client;
5+
using Weaviate.Client.Models;
6+
using Xunit;
7+
8+
/// <summary>
9+
/// RBAC Groups integration tests (Rest:8092 gRPC:50063). Authorization checks for various operations.
10+
/// </summary>
11+
public class TestRbacAuthorization : IntegrationTests
12+
{
13+
public override ushort RestPort => 8092;
14+
public override ushort GrpcPort => 50063;
15+
private const string ADMIN_API_KEY = "admin-key";
16+
17+
public override async ValueTask InitializeAsync()
18+
{
19+
await base.InitializeAsync();
20+
21+
RequireVersion("1.32.0");
22+
}
23+
24+
public override ICredentials? Credentials => Auth.ApiKey(ADMIN_API_KEY);
25+
26+
[Fact, Trait("Category", "RBAC")]
27+
public async Task TestAuthorizationFailure()
28+
{
29+
// Generate random names for collection and user
30+
var collectionName = $"AuthorizationTest";
31+
var userId = Helpers.GenerateUniqueIdentifier("user");
32+
33+
// Create collection
34+
var collectionConfig = new CollectionConfig
35+
{
36+
Name = collectionName,
37+
Properties = new[]
38+
{
39+
new Property { Name = "name", DataType = new[] { "string" } },
40+
},
41+
};
42+
43+
var client = await CollectionFactory<object>(collectionConfig);
44+
45+
// Create a role with only read permission for this collection
46+
var readOnlyRole = await _weaviate.Roles.Create(
47+
"read-only-role",
48+
[
49+
new Permissions.Collections(collectionName) { Read = true },
50+
new Permissions.Data(collectionName, null, null) { Read = true },
51+
],
52+
TestContext.Current.CancellationToken
53+
);
54+
55+
// Create a user and assign the read-only role
56+
var apiKey = await _weaviate.Users.Db.Create(
57+
userId,
58+
cancellationToken: TestContext.Current.CancellationToken
59+
);
60+
await _weaviate.Users.Db.AssignRoles(
61+
userId,
62+
new[] { readOnlyRole.Name },
63+
cancellationToken: TestContext.Current.CancellationToken
64+
);
65+
66+
// Create a new client with the user's API key
67+
var userClient = await new WeaviateClientBuilder()
68+
.WithRestEndpoint("localhost")
69+
.WithRestPort(RestPort)
70+
.WithGrpcEndpoint("localhost")
71+
.WithGrpcPort(GrpcPort)
72+
.WithCredentials(Auth.ApiKey(apiKey))
73+
.BuildAsync();
74+
75+
var userCollection = userClient.Collections.Use(collectionName);
76+
77+
// Try to insert data and assert that authorization exception is thrown
78+
await Assert.ThrowsAsync<WeaviateAuthorizationException>(async () =>
79+
{
80+
await userCollection.Data.Insert(
81+
new { name = "should fail" },
82+
cancellationToken: TestContext.Current.CancellationToken
83+
);
84+
});
85+
}
86+
}

0 commit comments

Comments
 (0)