Ejemplo n.º 1
0
        public async Task TrafficShouldBeForwardedWhenUserLocationServiceReturns(string ip, string currentConnectedIP, bool expected)
        {
            // Arrange
            var response = ApiResponseResult <UserLocation> .Ok(new UserLocation
            {
                Ip = ip
            });

            _vpnConfig.BlackHoleIps.Returns(new List <string> {
                "62.112.9.168", "104.245.144.186"
            });
            _userLocationService.LocationAsync().Returns(response);
            var subject = new ForwardedTraffic(_userLocationService, _vpnConfig);
            await subject.OnVpnStateChanged(new VpnStateChangedEventArgs(
                                                VpnStatus.Connected,
                                                VpnError.None,
                                                GetConnectedServer(currentConnectedIP),
                                                false,
                                                VpnProtocol.Auto));

            // Act
            var result = await subject.Value();

            // Assert
            result.Forwarded.Should().Be(expected);
        }
Ejemplo n.º 2
0
        public async Task <ForwardedTrafficResult> Value()
        {
            var response = await _userLocationService.LocationAsync();

            return(response.Failure
                ? new ForwardedTrafficResult(false, false, string.Empty)
                : new ForwardedTrafficResult(true, _config.BlackHoleIps().Contains(response.Value.Ip),
                                             response.Value.Ip));
        }
Ejemplo n.º 3
0
        public async Task <ForwardedTrafficResult> Value()
        {
            var response = await _userLocationService.LocationAsync();

            if (response.Failure)
            {
                return(new ForwardedTrafficResult(false, false, string.Empty));
            }

            return(new ForwardedTrafficResult(true, IsForwarded(response.Value.Ip), response.Value.Ip));
        }
Ejemplo n.º 4
0
        public async Task Detected_ShouldBe_WhenUserLocationService_Returns(string ip, bool expected)
        {
            // Arrange
            var response = ApiResponseResult <UserLocation> .Ok(new UserLocation
            {
                Ip = ip
            });

            _vpnConfig.BlackHoleIps.Returns(new List <string> {
                "62.112.9.168", "104.245.144.186"
            });
            _userLocationService.LocationAsync().Returns(response);
            var subject = new ForwardedTraffic(_userLocationService, _vpnConfig);
            // Act
            var result = await subject.Value();

            // Assert
            result.Forwarded.Should().Be(expected);
        }