-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
223 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Test CI | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
test: | ||
uses: ./.github/workflows/base.yml | ||
with: | ||
docker-tag: 24.2.0-jammy | ||
docker-registry: docker.eventstore.com/eventstore-ee/eventstoredb-commercial | ||
test-matrix: '["Plugins"]' | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace EventStore.Client { | ||
/// <summary> | ||
/// Represents the user certificates used to authenticate and authorize operations on the EventStoreDB. | ||
/// </summary> | ||
public class UserCertificate { | ||
/// <summary> | ||
/// The user certificate | ||
/// </summary> | ||
public X509Certificate2? Certificate { get; } | ||
|
||
/// <summary> | ||
/// Constructs a new <see cref="UserCredentials"/>. | ||
/// </summary> | ||
public UserCertificate(X509Certificate2 userCertificate) { | ||
Certificate = userCertificate; | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new <see cref="UserCredentials"/>. | ||
/// </summary> | ||
public UserCertificate(string certificatePath, string privateKeyPath) { | ||
Certificate = CertificateUtils.LoadFromFile( | ||
certificatePath, | ||
privateKeyPath | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
test/EventStore.Client.Plugins.Tests/EventStore.Client.Plugins.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<ProjectReference Include="..\EventStore.Client.Tests.Common\EventStore.Client.Tests.Common.csproj"/> | ||
</ItemGroup> | ||
</Project> |
95 changes: 95 additions & 0 deletions
95
test/EventStore.Client.Plugins.Tests/UserCertificateTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Grpc.Core; | ||
|
||
namespace EventStore.Client.Plugins.Tests { | ||
[Trait("Category", "Certificates")] | ||
public class UserCertificateTests(ITestOutputHelper output, EventStoreFixture fixture) : EventStoreTests<EventStoreFixture>(output, fixture) { | ||
[Fact] | ||
public async Task user_credentials_takes_precedence_over_user_certificates() | ||
{ | ||
var certPath = Path.Combine("certs", "user-admin", "user-admin.crt"); | ||
var certKeyPath = Path.Combine("certs", "user-admin", "user-admin.key"); | ||
|
||
var connectionString = | ||
$"esdb://localhost:2113/?tls=true&tlsVerifyCert=true&certPath={certPath}&certKeyPath={certKeyPath}"; | ||
|
||
var stream = Fixture.GetStreamName(); | ||
|
||
var settings = EventStoreClientSettings.Create(connectionString); | ||
|
||
var client = new EventStoreClient(settings); | ||
|
||
await Assert.ThrowsAsync<NotAuthenticatedException>( | ||
() => client.AppendToStreamAsync( | ||
stream, | ||
StreamState.Any, | ||
Enumerable.Empty<EventData>(), | ||
userCredentials: TestCredentials.TestBadUser | ||
) | ||
); | ||
} | ||
|
||
[Fact] | ||
public Task does_not_accept_certificates_with_invalid_path() | ||
{ | ||
var certPath = Path.Combine("certs", "invalid", "invalid.crt"); | ||
var certKeyPath = Path.Combine("certs", "invalid", "invalid.key"); | ||
|
||
var connectionString = | ||
$"esdb://admin:changeit@localhost:2113/?tls=true&tlsVerifyCert=true&certPath={certPath}&certKeyPath={certKeyPath}"; | ||
|
||
Assert.Throws<InvalidSettingException>(() => EventStoreClientSettings.Create(connectionString) ); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
[Fact] | ||
public async Task append_should_be_successful_with_user_certificates() | ||
{ | ||
var certPath = Path.Combine(Environment.CurrentDirectory, "certs", "user-admin", "user-admin.crt"); | ||
var certKeyPath = Path.Combine(Environment.CurrentDirectory, "certs", "user-admin", "user-admin.key"); | ||
|
||
Assert.True(File.Exists(certPath)); | ||
Assert.True(File.Exists(certKeyPath)); | ||
|
||
var connectionString = | ||
$"esdb://localhost:2113/?tls=true&tlsVerifyCert=true&certPath={certPath}&certKeyPath={certKeyPath}"; | ||
|
||
Fixture.Log.Information("connectionString: {connectionString}", connectionString); | ||
|
||
var stream = Fixture.GetStreamName(); | ||
|
||
var settings = EventStoreClientSettings.Create(connectionString); | ||
|
||
var client = new EventStoreClient(settings); | ||
|
||
var result = await client.AppendToStreamAsync( | ||
stream, | ||
StreamState.Any, | ||
Enumerable.Empty<EventData>() | ||
); | ||
|
||
Assert.NotNull(result); | ||
} | ||
|
||
[Fact] | ||
public async Task append_with_overriden_user_certificates_should_pass() | ||
{ | ||
var connectionString = "esdb://admin:changeit@localhost:2113/?tls=true&tlsVerifyCert=true"; | ||
|
||
var stream = Fixture.GetStreamName(); | ||
|
||
var settings = EventStoreClientSettings.Create(connectionString); | ||
|
||
var client = new EventStoreClient(settings); | ||
|
||
var result = await client.AppendToStreamAsync( | ||
stream, | ||
StreamState.Any, | ||
Enumerable.Empty<EventData>(), | ||
userCredentials: TestCredentials.UserAdminCertificate | ||
); | ||
|
||
Assert.NotNull(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.