Beispiel #1
0
        /// <inheritdoc />
        public virtual void FieldResolutionSecurityChallengeResult(GraphFieldAuthorizationContext context)
        {
            var logLevel = context.Result.Status == FieldAuthorizationStatus.Unauthorized
                ? LogLevel.Warning
                : LogLevel.Trace;

            if (!this.IsEnabled(logLevel))
            {
                return;
            }

            var entry = new FieldAuthorizationCompletedLogEntry(context);

            this.LogEvent(logLevel, entry);
        }
Beispiel #2
0
        public void FieldSecurityChallengeCompletedLogEntry()
        {
            var builder = new TestServerBuilder()
                          .AddGraphType <LogTestController>();

            builder.User.SetUsername("bobSmith");
            var server = builder.Build();

            var package      = server.CreateFieldContextBuilder <LogTestController>(nameof(LogTestController.ExecuteField2));
            var fieldRequest = package.FieldRequest;
            var authContext  = package.CreateAuthorizationContext();

            authContext.Result = FieldAuthorizationResult.Fail("test message 1");
            var entry = new FieldAuthorizationCompletedLogEntry(authContext);

            Assert.AreEqual(LogEventIds.FieldAuthorizationCompleted.Id, entry.EventId);
            Assert.AreEqual(fieldRequest.Id, entry.PipelineRequestId);
            Assert.AreEqual(fieldRequest.Field.Route.Path, entry.FieldPath);
            Assert.AreEqual(authContext.User?.RetrieveUsername(), entry.Username);
            Assert.AreEqual(authContext.Result.Status.ToString(), entry.AuthorizationStatus);
            Assert.IsNotNull(entry.ToString());
            Assert.AreEqual(authContext.Result.LogMessage, entry.LogMessage);
        }