Ejemplo n.º 1
0
        public async Task ProcessReceivedPayload_TargetNotFound()
        {
            var tcsPr = new TaskCompletionSource <PingRequest>();

            tcsPr.SetResult(new PingRequest
            {
                SourceHasLink = true,
                ContainsHtml  = false
            });

            var tcsPt = new TaskCompletionSource <(Guid Id, string Title)>();

            tcsPt.SetResult((Guid.Empty, string.Empty));

            _pingSourceInspectorMock
            .Setup(p => p.ExamineSourceAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(tcsPr.Task);
            _pingTargetFinderMock.Setup(p => p.GetPostIdTitle(It.IsAny <string>(), It.IsAny <IDbConnection>())).Returns(tcsPt.Task);

            var pingbackService = new PingbackService(
                _loggerMock.Object,
                _dbConnectionMock.Object,
                _pingSourceInspectorMock.Object,
                _pingTargetFinderMock.Object);

            var result = await pingbackService.ReceivePingAsync(_fakePingRequest, "10.0.0.1", null);

            Assert.AreEqual(result, PingbackResponse.Error32TargetUriNotExist);
        }
Ejemplo n.º 2
0
        public async Task ProcessReceivedPayload_NoMethod()
        {
            var pingbackService = new PingbackService(
                _loggerMock.Object,
                _dbConnectionMock.Object,
                _pingSourceInspectorMock.Object,
                _pingTargetFinderMock.Object);

            var result = await pingbackService.ReceivePingAsync("<hello></hello>", "10.0.0.1", null);

            Assert.AreEqual(result, PingbackResponse.InvalidPingRequest);
        }
Ejemplo n.º 3
0
        public async Task <PingbackResponse> ProcessReceivedPayload_EmptyRequest(string requestBody)
        {
            var pingbackService = new PingbackService(
                _loggerMock.Object,
                _dbConnectionMock.Object,
                _pingSourceInspectorMock.Object,
                _pingTargetFinderMock.Object);

            var result = await pingbackService.ReceivePingAsync(requestBody, "10.0.0.1", null);

            return(result);
        }
Ejemplo n.º 4
0
        public async Task ProcessReceivedPayload_InvalidRequest()
        {
            var tcs = new TaskCompletionSource <PingRequest>();

            tcs.SetResult(null);

            _pingSourceInspectorMock
            .Setup(p => p.ExamineSourceAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(tcs.Task);

            var pingbackService = new PingbackService(
                _loggerMock.Object,
                _dbConnectionMock.Object,
                _pingSourceInspectorMock.Object,
                _pingTargetFinderMock.Object);

            var result = await pingbackService.ReceivePingAsync(_fakePingRequest, "10.0.0.1", null);

            Assert.AreEqual(result, PingbackResponse.InvalidPingRequest);
        }
Ejemplo n.º 5
0
        public async Task TestProcessReceivedPayloadAsyncError17()
        {
            var tcs = new TaskCompletionSource <PingRequest>();

            tcs.SetResult(new PingRequest
            {
                SourceHasLink = false
            });

            _pingSourceInspectorMock
            .Setup(p => p.ExamineSourceAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(tcs.Task);

            var pingbackService = new PingbackService(
                _loggerMock.Object,
                _configurationMock.Object,
                _pingSourceInspectorMock.Object,
                _pingTargetFinderMock.Object);

            var result = await pingbackService.ReceivePingAsync(_fakePingRequest, "10.0.0.1", null);

            Assert.AreEqual(result, PingbackResponse.Error17SourceNotContainTargetUri);
        }
Ejemplo n.º 6
0
        public async Task ProcessReceivedPayload_Spam()
        {
            var tcs = new TaskCompletionSource <PingRequest>();

            tcs.SetResult(new PingRequest
            {
                SourceHasLink = true,
                ContainsHtml  = true
            });

            _pingSourceInspectorMock
            .Setup(p => p.ExamineSourceAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(tcs.Task);

            var pingbackService = new PingbackService(
                _loggerMock.Object,
                _dbConnectionMock.Object,
                _pingSourceInspectorMock.Object,
                _pingTargetFinderMock.Object);

            var result = await pingbackService.ReceivePingAsync(_fakePingRequest, "10.0.0.1", null);

            Assert.AreEqual(result, PingbackResponse.SpamDetectedFakeNotFound);
        }
Ejemplo n.º 7
0
        public async Task ProcessReceivedPayload_AlreadyPinged()
        {
            var tcsPr = new TaskCompletionSource <PingRequest>();

            tcsPr.SetResult(new PingRequest
            {
                SourceHasLink = true,
                ContainsHtml  = false
            });

            _pingSourceInspectorMock
            .Setup(p => p.ExamineSourceAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(tcsPr.Task);

            var tcsPt = new TaskCompletionSource <(Guid Id, string Title)>();

            tcsPt.SetResult((Guid.NewGuid(), "Pingback Unit Test"));
            _pingTargetFinderMock.Setup(p => p.GetPostIdTitle(It.IsAny <string>(), It.IsAny <IDbConnection>())).Returns(tcsPt.Task);

            var tcsAp = new TaskCompletionSource <bool>();

            tcsAp.SetResult(true);
            _pingTargetFinderMock.Setup(p => p.HasAlreadyBeenPinged(
                                            It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IDbConnection>()))
            .Returns(tcsAp.Task);

            var pingbackService = new PingbackService(
                _loggerMock.Object,
                _dbConnectionMock.Object,
                _pingSourceInspectorMock.Object,
                _pingTargetFinderMock.Object);

            var result = await pingbackService.ReceivePingAsync(_fakePingRequest, "10.0.0.1", null);

            Assert.AreEqual(result, PingbackResponse.Error48PingbackAlreadyRegistered);
        }