Mono<ServerResponse> createComment(ServerRequest request) {
        return request.bodyToMono(CommentRequest.class)
            .flatMap(commentRequest -> {
                Comment comment = commentRequest.toComment();
                comment.getSpec().setIpAddress(IpAddressUtils.getIpAddress(request));
                comment.getSpec().setUserAgent(HaloUtils.userAgentFrom(request));
                return commentService.create(comment);
            })
            .flatMap(comment -> ServerResponse.ok().bodyValue(comment))
            .transformDeferred(createIpBasedRateLimiter(request))
            .onErrorMap(RequestNotPermitted.class, RateLimitExceededException::new);
    }
@Test
    void createComment() {
        when(commentService.create(any())).thenReturn(Mono.empty());

        RateLimiterConfig config = RateLimiterConfig.custom()
            .limitForPeriod(10)
            .limitRefreshPeriod(Duration.ofSeconds(1))
            .timeoutDuration(Duration.ofSeconds(10))
            .build();
        RateLimiter rateLimiter = RateLimiter.of("comment-creation-from-ip-" + "0:0:0:0:0:0:0:0",
            config);
        when(rateLimiterRegistry.rateLimiter(anyString(), anyString())).thenReturn(rateLimiter);

        final CommentRequest commentRequest = new CommentRequest();
        Ref ref = new Ref();
        ref.setGroup("content.halo.run");
        ref.setVersion("v1alpha1");
        ref.setKind("Post");
        ref.setName("test-post");
        commentRequest.setSubjectRef(ref);
        commentRequest.setContent("content");
        commentRequest.setRaw("raw");
        commentRequest.setAllowNotification(false);
        webTestClient.post()
            .uri("/comments")
            .bodyValue(commentRequest)
            .exchange()
            .expectStatus()
            .isOk();

        ArgumentCaptor<Comment> captor = ArgumentCaptor.forClass(Comment.class);
        verify(commentService, times(1)).create(captor.capture());
        Comment value = captor.getValue();
        assertThat(value.getSpec().getIpAddress()).isNotNull();
        assertThat(value.getSpec().getUserAgent()).isNotNull();
        assertThat(value.getSpec().getSubjectRef()).isEqualTo(ref);
    }