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 TestDeleteIntegrator() { CardSavrResponse <List <Integrator> > deleted = await this.session.http.DeleteIntegratorAsync(IntegratorTests.integrator.id); Assert.Single(deleted.Body); IntegratorTests.integrator = deleted.Body[0]; Assert.Single(deleted.Body); Assert.Equal(HttpStatusCode.OK, deleted.StatusCode); }
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 TestCreateIntegrator() { PropertyBag body = new PropertyBag(); body["name"] = CardsavrSession.e2e_identifier + $"_{CardsavrSession.random.Next(1000, 2000)}"; string integrator_name = (string)body["name"]; body["description"] = CardsavrSession.e2e_identifier; body["integrator_type"] = "cust_internal"; CardSavrResponse <Integrator> result = await this.session.http.CreateIntegratorAsync(body); log.Info($"created integrator: {result.Body.id}"); IntegratorTests.integrator = result.Body; Assert.Equal(HttpStatusCode.Created, result.StatusCode); Assert.True(integrator.id > 0); }
public async void TestUpdatePassword() { CardSavrResponse <List <User> > users = await this.session.http.GetUsersAsync(null); foreach (User user in users.Body) { if (user.username.StartsWith(CardsavrSession.e2e_identifier)) { log.Info($"updating password for user \"{user.username}\" ({user.id})"); string pwBase = "foobar"; string newPassword = pwBase.PadRight(44 - pwBase.Length); PropertyBag bag = new PropertyBag(); bag["username"] = user.username; bag["old_password"] = CardsavrSession.GenerateBogus32BitPassword(CardsavrSession.e2e_identifier); bag["password"] = CardsavrSession.GenerateBogus32BitPassword(user.username + CardsavrSession.e2e_identifier); bag["password_copy"] = bag["password"]; CardSavrResponse <PropertyBag> result = await this.session.http.UpdateUserPasswordAsync((int)user.id, bag); log.Info($"password update successful for user \"{user.username}\" ({user.id})"); Assert.Equal(HttpStatusCode.Created, result.StatusCode); break; } } List <int> list = new List <int>(); users = await this.session.http.GetUsersAsync(null, new Paging() { PageLength = 100 }); foreach (User u in users.Body) { if (!u.username.StartsWith(CardsavrSession.e2e_identifier)) { continue; } list.Add((int)u.id); } CardSavrResponse <List <User> > deleted_users = await this.session.http.DeleteUserAsync(list); Assert.Equal(10, deleted_users.Body.Count); }
public async void TestSelectMerchants() { Paging paging = new Paging() { PageLength = 10, Sort = "name" }; CardSavrResponse <List <MerchantSite> > merchants = await this.session.http.GetMerchantSitesAsync(null, paging); Assert.Equal(10, merchants.Body.Count); foreach (MerchantSite merch in merchants.Body) { log.Info($"Loaded merchant site: {merch.name}: {merch.host}"); } merchants = await this.session.http.GetMerchantSitesAsync( new NameValueCollection() { { "top_hosts", "amazon.com,apple.com" }, { "exclude_hosts", "petco.com,safeway.com" } } ); Assert.Equal("amazon.com", merchants.Body[0].host); }
public async void TestCreateCardholders() { List <Cardholder> cardholders = new List <Cardholder>(); // create cardholders. PropertyBag bag = new PropertyBag(); int count = 10; for (int n = 0; n < count; ++n) { // generate using an easily reproducible safe-key. bag["cuid"] = $"{CardsavrSession.e2e_identifier}_cardholder_tests_{CardsavrSession.random.Next(10000)}_{n}"; bag["first_name"] = $"Otto_{n}_cardholder"; bag["last_name"] = $"Matic_{n}_cardholder"; bag["email"] = $"cardsavr_e2e_{CardsavrSession.random.Next(10000)}@gmail.com"; string safeKey = count % 2 == 0 ? null : CardsavrSession.GenerateBogus32BitPassword(bag.GetString("cuid")); CardSavrResponse <Cardholder> result = await this.session.http.CreateCardholderAsync(bag, safeKey); cardholders.Add(result.Body); } Assert.Equal(cardholders.Count, count); CardSavrResponse <List <Cardholder> > cardholderResponse = await this.session.http.GetCardholdersAsync(null); foreach (Cardholder c in cardholderResponse.Body) { if (c.cuid.StartsWith($"{CardsavrSession.e2e_identifier}_cardholder_tests")) { await this.session.http.DeleteCardholderAsync(c.id); count--; } } Assert.Equal(0, count); }
public async void TestCreateJob() { List <Cardholder> cardholders = new List <Cardholder>(); // create cardholders. PropertyBag bag = new PropertyBag(); int count = 2; string[] safeKeys = new string[count]; for (int n = 0; n < count; ++n) { // generate using an easily reproducible safe-key. bag["cuid"] = $"{CardsavrSession.e2e_identifier}_job_tests_{CardsavrSession.random.Next(10000)}_{n}"; bag["first_name"] = $"Otto_{n}_cardholder"; bag["last_name"] = $"Matic_{n}_cardholder"; bag["email"] = $"cardsavr_e2e_{CardsavrSession.random.Next(10000)}@gmail.com"; safeKeys[n] = n % 2 == 0 ? null : CardsavrSession.GenerateBogus32BitPassword(bag.GetString("cuid")); CardSavrResponse <Cardholder> result = await this.session.http.CreateCardholderAsync(bag, safeKeys[n]); cardholders.Add(result.Body); } Assert.Equal(cardholders.Count, count); for (int n = 0; n < count; ++n) { bag.Clear(); bag["cardholder_id"] = cardholders[n].id; bag["merchant_site_id"] = 1; bag["username"] = "******"; bag["password"] = ""; CardSavrResponse <Account> account = await this.session.http.CreateAccountAsync(bag, safeKeys[n]); Assert.Equal(HttpStatusCode.Created, account.StatusCode); bag.Clear(); bag = new PropertyBag() { { "cardholder_id", cardholders[n].id }, { "requesting_brand", "mbudos" }, { "status", "INITIATED" }, { "account_id", account.Body.id } }; CardSavrResponse <SingleSiteJob> job = await this.session.http.CreateSingleSiteJobAsync(bag, safeKeys[n]); Assert.Equal(HttpStatusCode.Created, job.StatusCode); CardSavrResponse <List <SingleSiteJob> > singleJobs = await this.session.http.GetSingleSiteJobsAsync( new NameValueCollection() { { "ids", job.Body.id.ToString() } } ); log.Info($"retrieved {singleJobs.Body.Count} single-site jobs."); foreach (SingleSiteJob sj in singleJobs.Body) { Assert.Equal(job.Body.id, sj.id); } bag.Clear(); bag["status"] = "CANCEL_REQUESTED"; // NOT BACKWARD COMPATIBLE - Only using agent now job = await this.session.http.UpdateSingleSiteJobAsync(job.Body.id, bag, null); log.Info($"{job.Body.id}: {job.Body.status}"); Assert.Equal(job.Body.status, bag["status"]); } CardSavrResponse <List <Cardholder> > cardholderResponse = await this.session.http.GetCardholdersAsync(null); foreach (Cardholder c in cardholderResponse.Body) { if (c.cuid.StartsWith($"{CardsavrSession.e2e_identifier}_job_tests")) { await this.session.http.DeleteCardholderAsync(c.id); count--; } } Assert.Equal(0, count); }
public async void TestCreateAccounts() { List <Cardholder> cardholders = new List <Cardholder>(); // create cardholders. PropertyBag bag = new PropertyBag(); int count = 10; string[] safeKeys = new string[count]; for (int n = 0; n < count; ++n) { // generate using an easily reproducible safe-key. bag["cuid"] = $"{CardsavrSession.e2e_identifier}_account_tests_{CardsavrSession.random.Next(10000)}_{n}"; bag["first_name"] = $"Otto_{n}_cardholder"; bag["last_name"] = $"Matic_{n}_cardholder"; bag["email"] = $"cardsavr_e2e_{CardsavrSession.random.Next(10000)}@gmail.com"; safeKeys[n] = n % 2 == 0 ? null : CardsavrSession.GenerateBogus32BitPassword(bag.GetString("cuid")); CardSavrResponse <Cardholder> result = await this.session.http.CreateCardholderAsync(bag, safeKeys[n]); cardholders.Add(result.Body); } Assert.Equal(cardholders.Count, count); //MerchantSite site = ctx.GetSyntheticSite(); CardSavrResponse <List <MerchantSite> > sites = await this.session.http.GetMerchantSitesAsync(new NameValueCollection() { { "host", "dynamic-synthetic.herokuapp.com/index.html" } }); for (int n = 0; n < count; ++n) { // create an account. bag.Clear(); bag["cardholder_id"] = cardholders[n].id; bag["merchant_site_id"] = sites.Body[0].id; bag["username"] = "******"; bag["password"] = ""; CardSavrResponse <Account> result = await this.session.http.CreateAccountAsync(bag, safeKeys[n]); Assert.Equal(HttpStatusCode.Created, result.StatusCode); log.Info($"created account {result.Body.id} for cardholder-id={cardholders[n].id} ({cardholders[n].cuid})"); // update it. bag.Clear(); bag["password"] = $"{CardsavrSession.e2e_identifier}-{CardsavrSession.e2e_identifier}"; result = await this.session.http.UpdateAccountAsync(result.Body.id, bag, null, safeKeys[n]); Assert.Equal(HttpStatusCode.Created, result.StatusCode); log.Info($"updated account-id={result.Body.id}"); if (safeKeys[n] != null) { Exception ex = await Assert.ThrowsAsync <RequestException>(async() => { result = await this.session.http.UpdateAccountAsync(result.Body.id, bag, null, null); }); Assert.True(ex.Message.IndexOf("No safe_key for this cardholder_id") >= 0); } } CardSavrResponse <List <Cardholder> > cardholderResponse = await this.session.http.GetCardholdersAsync(null); foreach (Cardholder c in cardholderResponse.Body) { if (c.cuid.StartsWith($"{CardsavrSession.e2e_identifier}_account_tests")) { await this.session.http.DeleteCardholderAsync(c.id); count--; } } Assert.Equal(0, count); }
public async void TestCreateCards() { List <Cardholder> cardholders = new List <Cardholder>(); // create cardholders. PropertyBag bag = new PropertyBag(); int count = 2; string[] safeKeys = new string[count]; for (int n = 0; n < count; ++n) { // generate using an easily reproducible safe-key. bag["cuid"] = $"{CardsavrSession.e2e_identifier}_account_tests_{CardsavrSession.random.Next(10000)}_{n}"; bag["first_name"] = $"Otto_{n}_cardholder"; bag["last_name"] = $"Matic_{n}_cardholder"; bag["email"] = $"cardsavr_e2e_{CardsavrSession.random.Next(10000)}@gmail.com"; safeKeys[n] = n % 2 == 0 ? null : CardsavrSession.GenerateBogus32BitPassword(bag.GetString("cuid")); CardSavrResponse <Cardholder> result = await this.session.http.CreateCardholderAsync(bag, safeKeys[n]); cardholders.Add(result.Body); } Assert.Equal(cardholders.Count, count); for (int n = 0; n < count; ++n) { bag.Clear(); // create an address. bag["cardholder_id"] = cardholders[n].id; bag["is_primary"] = true; bag["address1"] = $"{CardsavrSession.random.Next(1000, 9000)} SDK Ave NE"; bag["address2"] = CardsavrSession.e2e_identifier; bag["city"] = "Seattle"; bag["subnational"] = "Washington"; bag["country"] = "USA"; bag["postal_code"] = "98119"; Address addr = (await this.session.http.CreateAddressAsync(bag)).Body; Assert.Equal(addr.address1, bag["address1"]); log.Info($"created primary address {addr.id} for cardholder: {cardholders[n].first_name} {cardholders[n].last_name} ({cardholders[n].id})"); // update it. bag.Clear(); bag["address1"] = $"{CardsavrSession.random.Next(1000, 9000)} CSharp-SDK Ave NE"; addr = (await this.session.http.UpdateAddressAsync(addr.id, bag)).Body[0]; Assert.Equal(addr.address1, bag["address1"]); log.Info($"updated primary address {addr.id} for cardholder: {cardholders[n].first_name} {cardholders[n].last_name} ({cardholders[n].id})"); // the card we create uses our (possibly truncated) special identifier as the color // so we can identify it later if needed. DateTime expire = DateTime.Now.AddYears(1); string expYear = (expire.Year % 2000).ToString(); string expMonth = expire.Month.ToString(); string pan = "4111111111111111"; PropertyBag body = new PropertyBag() { { "cardholder_id", cardholders[n].id }, { "address_id", addr.id }, { "pan", pan }, { "cvv", "345" }, { "par", ApiUtil.GenerateRandomPAR(pan, expMonth, expYear, cardholders[n].cuid) }, { "first_name", cardholders[n].first_name }, { "last_name", cardholders[n].last_name }, { "name_on_card", "BOGUS CARD" }, { "expiration_month", expMonth }, { "expiration_year", expYear } }; // our test cardholders sometimes have a known safe-key. // NOT BACKWARD COMPATIBLE - client is now always the agent CardSavrResponse <Card> card = await this.session.http.CreateCardAsync(body, safeKeys[n]); log.Info($"created card-id={card.Body.id}"); // update it: just change the address. body.Clear(); body.Add("id", card.Body.id); body.Add("name_on_card", "REALLY BOGUS CARD"); CardSavrResponse <List <Card> > upd = await this.session.http.UpdateCardAsync(null, body); Assert.Equal(upd.Body[0].name_on_card, body["name_on_card"]); log.Info($"update card for cardholder \"{cardholders[n].cuid}\""); } CardSavrResponse <List <Cardholder> > cardholderResponse = await this.session.http.GetCardholdersAsync(null); foreach (Cardholder c in cardholderResponse.Body) { if (c.cuid.StartsWith($"{CardsavrSession.e2e_identifier}_account_tests")) { await this.session.http.DeleteCardholderAsync(c.id); count--; } } Assert.Equal(0, count); }