Skip to content

Commit

Permalink
rename auth interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
daliclovr committed Sep 25, 2023
1 parent f3234f8 commit 1ea46d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static void Main(string[] args)
var messageSize = 200 * 1024 * 1024; // 200 MB
options.MaxReceiveMessageSize = messageSize;
options.MaxSendMessageSize = messageSize;
options.Interceptors.Add<ServerAuthInterceptor>();
options.Interceptors.Add<GRPCAuthInterceptor>();
});
builder.WebHost.ConfigureKestrel(options =>
{
Expand Down
6 changes: 3 additions & 3 deletions src/Rpc/AuthInterceptor.cs → src/Rpc/GRPCAuthInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace NodeGuard.Rpc;

public class ServerAuthInterceptor : Interceptor
public class GRPCAuthInterceptor : Interceptor
{
private readonly IAPITokenRepository _apiTokenRepository;

public ServerAuthInterceptor(IAPITokenRepository apiTokenRepository)
public GRPCAuthInterceptor(IAPITokenRepository apiTokenRepository)
{
_apiTokenRepository = apiTokenRepository;
}
Expand All @@ -30,7 +30,7 @@ public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
{
throw new RpcException(new Status(StatusCode.Unauthenticated, "Invalid token"));
}

return await continuation(request, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public async Task AuthInterceptor_NoTokenProvided()
// Arrange
var context = TestServerCallContext.Create();
var mockedApiTokenRepository = new Mock<IAPITokenRepository>();
var interceptor = new ServerAuthInterceptor(mockedApiTokenRepository.Object);
var interceptor = new GRPCAuthInterceptor(mockedApiTokenRepository.Object);
var continuation = new UnaryServerMethod<string, string>(async (request, context) => { return "response"; });

var expectedMessage = "No token provided";
Expand All @@ -30,7 +30,7 @@ public async Task AuthInterceptor_NonExistingToken()
// Arrange
var context = TestServerCallContext.Create(new Metadata{{"auth-token", "iamastupidtoken"}});
var mockedApiTokenRepository = new Mock<IAPITokenRepository>();
var interceptor = new ServerAuthInterceptor(mockedApiTokenRepository.Object);
var interceptor = new GRPCAuthInterceptor(mockedApiTokenRepository.Object);
var continuation = new UnaryServerMethod<string, string>(async (request, context) => { return "response"; });

var expectedMessage = "Invalid token";
Expand All @@ -52,7 +52,7 @@ public async Task AuthInterceptor_ExistingTokenValid()
.ReturnsAsync(apiTokenFixture);

var context = TestServerCallContext.Create(new Metadata{{"auth-token", validToken}});
var interceptor = new ServerAuthInterceptor(mockedApiTokenRepository.Object);
var interceptor = new GRPCAuthInterceptor(mockedApiTokenRepository.Object);
var mockContinuation = new Mock<UnaryServerMethod<string, string>>();
mockContinuation.Setup(x => x.Invoke(
It.IsAny<string>(),
Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task AuthInterceptor_ExistingTokenInvalid()
.ReturnsAsync(apiTokenFixture);

var context = TestServerCallContext.Create(new Metadata{{"auth-token", validToken}});
var interceptor = new ServerAuthInterceptor(mockedApiTokenRepository.Object);
var interceptor = new GRPCAuthInterceptor(mockedApiTokenRepository.Object);
var continuation = new UnaryServerMethod<string, string>(async (request, context) => { return "response"; });

var expectedMessage = "Invalid token";
Expand Down

0 comments on commit 1ea46d2

Please sign in to comment.