-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix internal authority in HTTP handler transactions #5978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| namespace Runtime.Tests; | ||
|
|
||
| using SpacetimeDB; | ||
|
|
||
| public class HandlerContextTests | ||
| { | ||
| private sealed class TestLocal : LocalBase { } | ||
|
|
||
| private sealed class TestTxContext(SpacetimeDB.Internal.TxContext inner) | ||
| : HandlerTxContextBase(inner) { } | ||
|
|
||
| private sealed class TestHandlerContext() : HandlerContextBase(new Random(0), new Timestamp(0)) | ||
| { | ||
| protected override LocalBase CreateLocal() => new TestLocal(); | ||
|
|
||
| protected override HandlerTxContextBase CreateTxContext(SpacetimeDB.Internal.TxContext inner) => | ||
| new TestTxContext(inner); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void HandlerTransactionsAreExternalWithoutJwt() | ||
| { | ||
| var handler = new TestHandlerContext(); | ||
| // EnterTxContext is the construction path used by WithTx and TryWithTx, | ||
| // including when a failed commit is retried with a new timestamp. | ||
| for (long timestamp = 0; timestamp < 3; timestamp++) | ||
| { | ||
| var auth = handler.EnterTxContext(timestamp).SenderAuth; | ||
| Assert.False(auth.IsInternal); | ||
| Assert.False(auth.HasJwt); | ||
| Assert.Null(auth.Jwt); | ||
| } | ||
| handler.ExitTxContext(); | ||
| Assert.False(handler.EnterTxContext(3).SenderAuth.IsInternal); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ private AuthCtx(bool isInternal, Func<JwtClaims?> jwtFactory) | |
| _jwtLazy = new Lazy<JwtClaims?>(() => jwtFactory?.Invoke()); | ||
| } | ||
|
|
||
| internal static AuthCtx Anonymous() => new(isInternal: false, jwtFactory: () => null); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make this a static readonly field just to avoid a few small unnecessary allocations: |
||
|
|
||
| /// <summary> | ||
| /// Create an AuthCtx for an internal call, with no JWT. | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ | |
| <ItemGroup> | ||
| <UpToDateCheckInput Include="bindings.c" /> | ||
| <UpToDateCheckInput Include="driver.h" /> | ||
| <InternalsVisibleTo Include="Runtime.Tests" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove this because we should not be using |
||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this project
Runtime.Testsbut it's not used: it's not part of the solution and it's not invoked in CI. So we should move this out of here.We should probably move it to be alongside the other C# tests inside of
http_routes.rs.