Example #1
0
        public async void TestCreateUpdateUsers()
        {
            // create users.
            PropertyBag bag      = new PropertyBag();
            string      password = "";
            List <User> list     = new List <User>();

            for (int n = 0; n < 10; ++n)
            {
                // generate using an easily reproducible safe-key.
                // the username, role and email help us identify these users later.
                bag["username"]   = $"{CardsavrSession.e2e_identifier}_{CardsavrSession.random.Next(1000)}_{n}";
                password          = $"{CardsavrSession.e2e_identifier}_{CardsavrSession.random.Next(1000)}_{n}";
                bag["password"]   = password;
                bag["role"]       = "customer_agent";
                bag["first_name"] = $"Otto_{n}";
                bag["last_name"]  = $"Matic_{n}";
                bag["email"]      = $"cardsavr_e2e_{CardsavrSession.random.Next(1000)}@gmail.com";
                CardSavrResponse <User> result = await this.session.http.CreateUserAsync(bag);
            }

            CardSavrResponse <List <User> > users = await this.session.http.GetUsersAsync(null, new Paging()
            {
                PageLength = 100
            });

            foreach (User user in users.Body)
            {
                if (!user.username.StartsWith(CardsavrSession.e2e_identifier))
                {
                    continue;
                }
                bag.Clear();
                bag["id"]    = user.id;
                bag["email"] = "new_" + user.email;
                CardSavrResponse <List <User> > updated_users = await this.session.http.UpdateUserAsync(user.id, bag);

                //log.Info(JsonConvert.SerializeObject(updated_users.Body[0], Formatting.Indented));
                Assert.Equal(bag["email"], updated_users.Body[0].email);
                list.Add(user);
            }

            Assert.Equal(10, list.Count);

            CardsavrHelper helper = new CardsavrHelper();

            CardsavrSession.InstanceConfig config = session.getConfig();
            helper.SetAppSettings(config.cardsavr_server, config.app_name, config.app_key, CardsavrSession.rejectUnauthorized);
            //use the latest user
            string testing_agent = list[list.Count - 1].username;
            await helper.LoginAndCreateSession(testing_agent, password);

            string new_password = await helper.RotateAgentPassword(testing_agent);

            await helper.CloseSession(testing_agent);

            ClientSession login = await helper.LoginAndCreateSession(testing_agent, new_password);

            Assert.NotNull(login);
        }
        public async void TestUpdateIntegrator()
        {
            string      last_key = IntegratorTests.integrator.current_key;
            string      new_key  = Aes256.GetRandomString(44, 32);
            PropertyBag body     = new PropertyBag();

            body["description"] = $"{CardsavrSession.e2e_identifier}_{CardsavrSession.e2e_identifier}";
            body["current_key"] = new_key;
            body["last_key"]    = last_key;

            CardSavrResponse <List <Integrator> > updated = await this.session.http.UpdateIntegratorsAsync(IntegratorTests.integrator.id, body);

            Assert.Single(updated.Body);

            IntegratorTests.integrator = updated.Body[0];
            Assert.Equal(new_key, IntegratorTests.integrator.current_key);
            Assert.Equal(last_key, IntegratorTests.integrator.last_key);
            log.Info($"updated integrator {IntegratorTests.integrator.name}");

            Assert.Equal(HttpStatusCode.Created, updated.StatusCode);

            CardsavrSession.InstanceConfig config = session.getConfig();
            CardsavrHelper helper = new CardsavrHelper();

            helper.SetAppSettings(config.cardsavr_server, IntegratorTests.integrator.name, last_key, CardsavrSession.rejectUnauthorized);
            ClientSession login = await helper.LoginAndCreateSession(config.app_username, config.app_password, "{\"key\": \"my_trace\"}");

            CardSavrResponse <List <Integrator> > integrator = await login.client.GetIntegratorsAsync(IntegratorTests.integrator.id);

            Assert.Equal(integrator.Body[0].id, IntegratorTests.integrator.id);

            string new_new_key = await helper.RotateIntegrator(config.app_username, IntegratorTests.integrator.name);

            log.Info($"rotated integrator {IntegratorTests.integrator.name} to {new_new_key} using 'old' integrator");

            helper.SetAppSettings(config.cardsavr_server, IntegratorTests.integrator.name, new_key, CardsavrSession.rejectUnauthorized);
            login = await helper.LoginAndCreateSession(config.app_username, config.app_password, "{\"key\": \"my_trace\"}");

            log.Info($"logged in successfully with 'old' 'new' integrator");

            helper.SetAppSettings(config.cardsavr_server, IntegratorTests.integrator.name, new_new_key, CardsavrSession.rejectUnauthorized);
            login = await helper.LoginAndCreateSession(config.app_username, config.app_password, "{\"key\": \"my_trace\"}");

            log.Info($"logged in successfully with 'new' 'new' integrator");

            helper.SetAppSettings(config.cardsavr_server, IntegratorTests.integrator.name, last_key, CardsavrSession.rejectUnauthorized);
            Exception ex = await Assert.ThrowsAsync <RequestException>(async() => {
                await helper.LoginAndCreateSession(config.app_username, config.app_password, "{\"key\": \"my_trace\"}");
            });

            Assert.True(ex.Message.IndexOf("Request Signature failed") >= 0);
        }
        public async void TestCreateHydratedCard()
        {
            CardsavrSession.InstanceConfig config = this.session.getConfig();
            CardsavrHelper helper = new CardsavrHelper();

            helper.SetAppSettings(config.cardsavr_server, config.app_name, config.app_key, CardsavrSession.rejectUnauthorized);
            await helper.LoginAndCreateSession(config.app_username, config.app_password, "{\"key\": \"my_trace\"}");

            PropertyBag cd = new PropertyBag()
            {
                { "my_fi", new PropertyBag()
                  {
                      { "token", "123" }
                  } }
            };
            string      cuid  = $"{CardsavrSession.e2e_identifier}_{CardsavrSession.random.Next(10000)}_0";
            ClientLogin login = await helper.CreateCard(config.app_username,
                                                        new Cardholder()
            {
                custom_data = cd, cuid = cuid
            },
                                                        new Card()
            {
                pan = "4111111111111111", cvv = "111", expiration_month = "01", expiration_year = "25"
            },
                                                        new Address()
            {
                first_name = "Strivve", last_name = "User", email = "*****@*****.**", is_primary = true, phone_number = "5555555555", address1 = "1234 1st ave", city = "Seattle", subnational = "WA", postal_code = "98006", country = "USA"
            }
                                                        );

            await helper.CloseSession(config.app_username);

            Assert.NotNull(login.cardholder.grant);
            Assert.Equal(login.cardholder.cuid, cuid);
            Assert.True(login.card.id > 0);
            log.Info("CARDSAVRHELPERTESTS cuid: " + login.cardholder.cuid + ", grant: " + login.grant + ", card_id: " + login.card.id);
            //login can now be used as a redirect to a url that can log in and process jobs
        }
Example #4
0
        public async Task <ClientLogin> TestCreateHydratedCard()
        {
            try {
                CardsavrHelper helper = new CardsavrHelper();
                helper.SetAppSettings("https://api.<SERVERR>.cardsavr.io/", "<INTEGRATOR NAME>", "<INTEGRATOR KEY>", false);
                ClientSession auth = await helper.LoginAndCreateSession("<USERNAME>", "<PASSWORD>", "{\"key\": \"my_trace\"}");

                PropertyBag cd = new PropertyBag()
                {
                    { "my_fi", new PropertyBag()
                      {
                          { "token", "123" }
                      } }
                };
                ClientLogin login = await helper.CreateCard("testing_user",
                                                            new Cardholder()
                {
                    email = "*****@*****.**", custom_data = cd, cuid = "12345"
                },
                                                            new Card()
                {
                    pan = "4111111111111111", cvv = "111", expiration_month = "01", expiration_year = "25"
                },
                                                            new Address()
                {
                    first_name = "Strivve", last_name = "User", is_primary = true, phone_number = "5555555555", address1 = "1234 1st ave", city = "Seattle", subnational = "WA", postal_code = "98006", country = "USA"
                }
                                                            );

                await helper.CloseSession("AdvAppUser");

                Console.WriteLine("CARDSAVRHELPERTESTS cuid: " + login.cardholder.cuid + ", grant: " + login.grant + ", card_id: " + login.card.id);

                return(login);
            } catch (Exception e) {
                Console.Write(e);
            }
            return(null);
        }