예제 #1
0
        public async void CoreAuthenticationErrorShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var errors = new List <string>
            {
                "ACCOUNT_ID_REQUIRED",
                "ACCOUNT_ID_UNKNOWN",
                "AUTHORIZATION_INVALID",
                "LICENSE_KEY_REQUIRED",
                "USER_ID_REQUIRED",
                "USER_ID_UNKNOWN"
            };

            foreach (var error in errors)
            {
                var msg    = "Appropriate user-readable error message";
                var client = CreateClientCore(type, status: HttpStatusCode.Unauthorized,
                                              content:
                                              ErrorJson(error, msg));

                var exception = await Record.ExceptionAsync(async() => await cr(client));

                Assert.NotNull(exception);
                Assert.IsType <AuthenticationException>(exception);
                Assert.Contains(msg, exception.Message);
            }
        }
예제 #2
0
        public override async Task RunClient(IAsyncStreamReader <ClientArgs> requestStream, IServerStreamWriter <ClientStatus> responseStream, ServerCallContext context)
        {
            if (!await requestStream.MoveNext())
            {
                throw new InvalidOperationException();
            }
            var clientConfig = requestStream.Current.Setup;
            var clientRunner = ClientRunner.Start(_loggerFactory, clientConfig);

            try
            {
                await responseStream.WriteAsync(new ClientStatus
                {
                    Stats = clientRunner.GetStats(false)
                });

                while (await requestStream.MoveNext())
                {
                    var reset = requestStream.Current.Mark.Reset;
                    await responseStream.WriteAsync(new ClientStatus
                    {
                        Stats = clientRunner.GetStats(reset)
                    });
                }
            }
            finally
            {
                _logger.LogInformation("Exiting RunClient.");
                await clientRunner.StopAsync();
            }
        }
예제 #3
0
        public void SurprisingStatusShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.MultipleChoices);

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <HttpException>()
                        .And.Message.Contains("Received an unexpected response for"));
        }
예제 #4
0
파일: Program.cs 프로젝트: zoakes/Gain_Base
        static void Main()
        {
            var runner = ClientRunner.OnWorkerThread();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm(runner.WithClient(GFApi.CreateClient())));
        }
예제 #5
0
        public void NoErrorBodyShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.Forbidden);

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <HttpException>()
                        .And.Message.Contains("with no body"));
        }
        public async Task AddressNotFoundShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var ip = "1.2.3.16";
            var client = CreateClient(type, ip, HttpStatusCode.NotFound,
                content: ErrorJson("IP_ADDRESS_NOT_FOUND", "The value 1.2.3.16 is not in the database."));

            await cr(client, ip);
        }
예제 #7
0
        public void EmptyBodyShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type);

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <HttpException>()
                        .And.Message.Contains("message body"));
        }
예제 #8
0
        public void BadContentTypeShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.OK,
                                      content: CountryJson, contentType: "bad/content-type");

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <GeoIP2Exception>()
                        .And.Message.Contains("but it does not appear to be JSON"));
        }
예제 #9
0
        public void WeirdErrorBodyShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.Forbidden,
                                      content: "{\"weird\": 42}");

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <HttpException>()
                        .And.Message.Contains("does not specify code or error keys"));
        }
예제 #10
0
        public async void CoreSurprisingStatusShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client    = CreateClientCore(type, status: HttpStatusCode.MultipleChoices);
            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <HttpException>(exception);
            Assert.Contains("Received an unexpected response for", exception.Message);
        }
예제 #11
0
        public void UndeserializableJsonShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.OK,
                                      content: "{\"invalid\":yes}");

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <GeoIP2Exception>()
                        .And.Message.Contains("Received a 200 response but not decode it as JSON"));
        }
예제 #12
0
        public void UnexpectedErrorBodyShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.Forbidden,
                                      content: "{\"invalid\": }");

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <HttpException>()
                        .And.Message.Contains("it did not include the expected JSON body"));
        }
예제 #13
0
        public void InternalServerErrorShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.InternalServerError,
                                      content: "Internal Server Error");

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <HttpException>()
                        .And.Message.Contains("Received a server (500) error"));
        }
예제 #14
0
        public void WebServiceErrorShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.Forbidden,
                                      content: ErrorJson("IP_ADDRESS_INVALID",
                                                         "The value 1.2.3 is not a valid IP address"));

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <InvalidRequestException>()
                        .And.Message.Contains("not a valid IP address"));
        }
예제 #15
0
        public async void CoreNoErrorBodyShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClientCore(type, status: HttpStatusCode.Forbidden);

            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <HttpException>(exception);
            Assert.Contains("with no body", exception.Message);
        }
예제 #16
0
        public void MissingUserIdShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.Unauthorized,
                                      content:
                                      ErrorJson("USER_ID_REQUIRED", "You have not supplied a MaxMind user ID in the Authorization header."));

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <AuthenticationException>()
                        .And.Message.Contains("You have not supplied a MaxMind user ID in the Authorization header."));
        }
예제 #17
0
        public async void CoreEmptyBodyShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClientCore(type);

            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <HttpException>(exception);
            Assert.Contains("message body", exception.Message);
        }
예제 #18
0
        public void AddressReservedShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var ip     = "1.2.3.17";
            var client = CreateClient(type, ip, HttpStatusCode.Forbidden,
                                      content: ErrorJson("IP_ADDRESS_RESERVED", "The value 1.2.3.17 belongs to a reserved or private range."));

            Assert.That(async() => await cr(client, ip),
                        Throws.TypeOf <AddressNotFoundException>()
                        .And.Message.Contains("The value 1.2.3.17 belongs to a reserved or private range"));
        }
예제 #19
0
        public void BadCharsetRequirementShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.NotAcceptable,
                                      content: "Cannot satisfy your Accept-Charset requirements",
                                      contentType: "text/plain");

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <HttpException>()
                        .And.Message.Contains("Cannot satisfy your Accept-Charset requirements"));
        }
예제 #20
0
        public async void CoreWeirdErrorBodyShouldThrowExceptionAsync(string type, ClientRunner cr, Type t)
        {
            var client = CreateClientCore(type, status: HttpStatusCode.Forbidden,
                                          content: "{\"weird\": 42}");
            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <HttpException>(exception);
            Assert.Contains("does not specify code or error keys", exception.Message);
        }
예제 #21
0
        public void UnknownUserIdShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var msg    = "You have supplied an invalid MaxMind user ID and/or license key in the Authorization header.";
            var client = CreateClient(type, status: HttpStatusCode.Unauthorized,
                                      content:
                                      ErrorJson("USER_ID_UNKNOWN", msg));

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <AuthenticationException>()
                        .And.Message.Contains(msg));
        }
예제 #22
0
        public void PermissionRequiredShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var msg    = "You do not have permission to use this web service.";
            var client = CreateClient(type, status: HttpStatusCode.Forbidden,
                                      content:
                                      ErrorJson("PERMISSION_REQUIRED", msg));

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <PermissionRequiredException>()
                        .And.Message.Contains(msg));
        }
예제 #23
0
        public async void CoreUndeserializableJsonShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClientCore(type, status: HttpStatusCode.OK,
                                          content: "{\"invalid\":yes}");

            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <GeoIP2Exception>(exception);
            Assert.Contains("Received a 200 response but not decode it as JSON", exception.Message);
        }
예제 #24
0
        /*
         * helper: If you dont like duplicationg code. Use this
         */
        private static (ServerRunner serverRunner, Player playerInit, ClientRunner clientRunner) InitiateServer()
        {
            var server = new ServerRunner();

            server.Start();
            var client = new ClientRunner("127.0.0.1", 32123);

            client.Start();
            client.JoinServer("player");
            return(server, server.GetPlayer("player"), client);
        }
예제 #25
0
        public async void CoreAddressNotFoundShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClientCore(type, status: HttpStatusCode.NotFound,
                                          content: ErrorJson("IP_ADDRESS_NOT_FOUND", "The value 1.2.3.16 is not in the database."));

            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <AddressNotFoundException>(exception);
            Assert.Contains("The value 1.2.3.16 is not in the database", exception.Message);
        }
예제 #26
0
        public async void UnexpectedErrorBodyShouldThrowExceptionAsync(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.Forbidden,
                                      content: "{\"invalid\": }");

            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <HttpException>(exception);
            Assert.Contains("it did not include the expected JSON body", exception.Message);
        }
예제 #27
0
        public void OutOfQueriesShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.PaymentRequired,
                                      content:
                                      ErrorJson("OUT_OF_QUERIES",
                                                "The license key you have provided is out of queries. Please purchase more queries to use this service."));

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <OutOfQueriesException>()
                        .And.Message.Contains("The license key you have provided is out of queries"));
        }
예제 #28
0
        public async void CoreBadContentTypeShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClientCore(type, status: HttpStatusCode.OK,
                                          content: CountryJson, contentType: "bad/content-type");

            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <GeoIP2Exception>(exception);
            Assert.Contains("but it does not appear to be JSON", exception.Message);
        }
예제 #29
0
        public async void CoreInternalServerErrorShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClientCore(type, status: HttpStatusCode.InternalServerError,
                                          content: "Internal Server Error");

            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <HttpException>(exception);
            Assert.Contains("Received a server (500) error", exception.Message);
        }
예제 #30
0
        public void InvalidAuthShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.Unauthorized,
                                      content:
                                      ErrorJson("AUTHORIZATION_INVALID",
                                                "You have supplied an invalid MaxMind user ID and/or license key in the Authorization header."));

            Assert.That(async() => await cr(client),
                        Throws.TypeOf <AuthenticationException>()
                        .And.Message.Contains("You have supplied an invalid MaxMind user ID and/or license key"));
        }
예제 #31
0
        public async void CoreWebServiceErrorShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClientCore(type, status: HttpStatusCode.Forbidden,
                                          content: ErrorJson("IP_ADDRESS_INVALID",
                                                             "The value 1.2.3 is not a valid IP address"));
            var exception = await Record.ExceptionAsync(async() => await cr(client));

            Assert.NotNull(exception);
            Assert.IsType <InvalidRequestException>(exception);
            Assert.Contains("not a valid IP address", exception.Message);
        }
        public override void Run()
        {
            var json = DataFileLoader.Load(File);
            var config = JsonConvert.DeserializeObject<FileRunnerConfig>(json, new ClaimConverter());

            if (config.Clients != null)
            {
                var r = new ClientRunner(this);
                r.Run(config.Clients);
            }

            if (config.Scopes != null)
            {
                var r = new ScopeRunner(this);
                r.Run(config.Scopes);
            }
        }
 public async Task IncorrectlyFormattedIPAddressShouldThrowException(string type, ClientRunner cr, Type t)
 {
     await cr(CreateClient(type), "foo");
 }
 public async Task InternalServerErrorShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.InternalServerError,
         content: "Internal Server Error");
     await cr(client);
 }
 public async Task InvalidAuthShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.Unauthorized,
         content:
             ErrorJson("AUTHORIZATION_INVALID",
                 "You have supplied an invalid MaxMind user ID and/or license key in the Authorization header."));
     await cr(client);
 }
        public async Task CorrectlyFormattedResponseShouldDeserializeIntoResponseObject(string type, ClientRunner cr,
            Type t)
        {
            var client = CreateClient(type, content: CountryJson);
            var result = await cr(client);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.GetType(), Is.EqualTo(t));
        }
        public async Task WebServiceErrorShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.Forbidden,
                content: ErrorJson("IP_ADDRESS_INVALID",
                    "The value 1.2.3 is not a valid IP address"));

            await cr(client);
        }
 public async Task WeirdErrorBodyShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.Forbidden,
         content: "{\"weird\": 42}");
     await cr(client);
 }
 public async Task MissingLicenseShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.Unauthorized,
         content:
             ErrorJson("LICENSE_KEY_REQUIRED",
                 "You have not supplied a MaxMind license key in the Authorization header."));
     await cr(client);
 }
        public async Task UndeserializableJsonShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.OK,
                content: "{\"invalid\":yes}");

            await cr(client);
        }
 public async Task MissingUserIdShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.Unauthorized,
         content:
             ErrorJson("USER_ID_REQUIRED", "You have not supplied a MaxMind user ID in the Authorization header."));
     await cr(client);
 }
 public async Task SurprisingStatusShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.MultipleChoices);
     await cr(client);
 }
 public async Task EmptyBodyShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type);
     await cr(client);
 }
 public async Task NoErrorBodyShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.Forbidden);
     await cr(client);
 }
 public async Task OutOfQueriesShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.PaymentRequired,
         content:
             ErrorJson("OUT_OF_QUERIES",
                 "The license key you have provided is out of queries. Please purchase more queries to use this service."));
     await cr(client);
 }
        public async Task MeEndpointIsCalledCorrectly(string type, ClientRunner cr,
    Type t)
        {
            var client = CreateClient(type, "me", content: CountryJson);
            var result = await cr(client, null);

            Assert.That(result, Is.Not.Null);
        }
 public async Task BadContentTypeShouldThrowException(string type, ClientRunner cr, Type t)
 {
     var client = CreateClient(type, status: HttpStatusCode.OK,
         content: CountryJson, contentType: "bad/content-type");
     await cr(client);
 }
        public async Task BadCharsetRequirementShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var client = CreateClient(type, status: HttpStatusCode.NotAcceptable,
                content: "Cannot satisfy your Accept-Charset requirements",
                contentType: "text/plain");

            await cr(client);
        }
        public async Task AddressReservedShouldThrowException(string type, ClientRunner cr, Type t)
        {
            var ip = "1.2.3.17";
            var client = CreateClient(type, ip, HttpStatusCode.Forbidden,
                content: ErrorJson("IP_ADDRESS_RESERVED", "The value 1.2.3.17 belongs to a reserved or private range."));

            await cr(client, ip);
        }