public void TestCallBuildWithAllDataSetsIncludedAndDuplications_ShouldReturnThirtyOne() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithInfo() .WithInfo() .WithInfo() .WithInfo() .WithVelocity() .WithVelocity() .WithVelocity() .WithVelocity() .WithDecision() .WithTrusted() .WithTrusted() .WithTrusted() .WithTrusted() .Build(); // Assert Assert.AreEqual(31, dataSetNumber); }
public void TestCallWithBuildOnly_DefaultValueIsZero() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements.Build(); // Assert Assert.AreEqual(0, dataSetNumber); }
public void TestCallBuildWithBehavioSec_ShouldReturnSixteen() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithBehavioSec() .Build(); // Assert Assert.AreEqual(16, dataSetNumber); }
public void TestCallBuildWithDeviceInfo_ShouldReturnOne() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithInfo() .Build(); // Assert Assert.AreEqual(1, dataSetNumber); }
public void TestCallBuildWithVelocity_ShouldReturnTwo() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithVelocity() .Build(); // Assert Assert.AreEqual(2, dataSetNumber); }
public void TestCallBuildWithDecision_ShouldReturnFour() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithDecision() .Build(); // Assert Assert.AreEqual(4, dataSetNumber); }
public void TestCallBuildWithTrustedDeviceInfo_ShouldReturnEight() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithTrusted() .Build(); // Assert Assert.AreEqual(8, dataSetNumber); }
public void TestCallBuildWithVelocityAndDecision_ShouldReturnSix() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithVelocity() .WithDecision() .Build(); // Assert Assert.AreEqual(6, dataSetNumber); }
public void TestCallBuildWithTrustedDeviceInfoAndBehavioSec_ShouldReturnTwentyFour() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithTrusted() .WithBehavioSec() .Build(); // Assert Assert.AreEqual(24, dataSetNumber); }
[TestCase(7)] // WithInfo, WithVelocity and WithDecision public void TestGetInfoWithoutUniq_ShouldPassValidation(int dataSetNumber) { DataSetElements dataSets = GetDataSetElementsFromExpectedValueAfterBuild(dataSetNumber); // Arrange MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonInfo); AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory); var emptyUniq = ""; // Act Info infoResp = sdk.GetInfo(session, user, password, emptyUniq, dataSets); // Assert Assert.IsNotNull(infoResp); }
public void TestGetInfoWithoutPassword_ShouldThrowException(int dataSetNumber) { DataSetElements dataSets = GetDataSetElementsFromExpectedValueAfterBuild(dataSetNumber); // Arrange MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonInfo); AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory); var emptyPassword = ""; // Act ActualValueDelegate <object> testDelegate = () => sdk.GetInfo(session, user, emptyPassword, uniq, dataSets); // Assert Assert.That(testDelegate, Throws.TypeOf <AccessException>()); }
public void TestCallBuildWithDecisionAndTrustedDeviceInfo_ShouldReturnTwelve() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithDecision() .WithTrusted() .Build(); // Assert Assert.AreEqual(12, dataSetNumber); }
public void TestCallBuildWithDeviceInfoAndVelocity_ShouldReturnThree() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithInfo() .WithVelocity() .Build(); // Assert Assert.AreEqual(3, dataSetNumber); }
public void TestCallBuildWith_Decision_TrustedDeviceInfo_BehavioSec_ShouldReturnTwentyfour() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithDecision() .WithTrusted() .Build(); // Assert Assert.AreEqual(28, dataSetNumber); }
public void TestCallBuildWithDeviceInfo_Velocity_Decision_ShouldReturnSeven() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithInfo() .WithVelocity() .WithDecision() .Build(); // Assert Assert.AreEqual(7, dataSetNumber); }
public void TestCallBuildWithVelocity_Decision_TrustedDeviceInfo_ShouldReturnFourteen() { // Arrange var dataSetElements = new DataSetElements(); // Act var dataSetNumber = dataSetElements .WithVelocity() .WithDecision() .WithTrusted() .Build(); // Assert Assert.AreEqual(14, dataSetNumber); }
private static void ValidateGetInfo(string sessionId, string username, string password, string uniq, int i) { ValidateSession(sessionId); var trusted = new DataSetElements().WithTrusted().Build(); var velocity = new DataSetElements().WithVelocity().Build(); var decision = new DataSetElements().WithDecision().Build(); // username and password are required if velocity or decision data is requested if ((((i & velocity) == velocity || (i & decision) == decision)) && (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))) { throw new AccessException(AccessErrorType.INVALID_DATA, "Parameters \"username\" and \"password\" are both required."); } }
public void TestGetInfoWithoutSession_ShouldThrowException() { // Arrange MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonInfo); AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory); var dataSets = new DataSetElements() .WithInfo(); var emptySessionId = ""; // Act ActualValueDelegate <object> testDelegate = () => sdk.GetInfo(emptySessionId, user, password, uniq, dataSets); // Assert Assert.That(testDelegate, Throws.TypeOf <AccessException>()); }
private DataSetElements GetDataSetElementsFromExpectedValueAfterBuild(int expectedValue) { var dse = new DataSetElements(); var info = new DataSetElements().WithInfo().Build(); if ((expectedValue & info) == info) { dse.WithInfo(); } var velocity = new DataSetElements().WithVelocity().Build(); if ((expectedValue & velocity) == velocity) { dse.WithVelocity(); } var decision = new DataSetElements().WithDecision().Build(); if ((expectedValue & decision) == decision) { dse.WithDecision(); } var trusted = new DataSetElements().WithTrusted().Build(); if ((expectedValue & trusted) == trusted) { dse.WithTrusted(); } var behavioSec = new DataSetElements().WithBehavioSec().Build(); if ((expectedValue & behavioSec) == behavioSec) { dse.WithBehavioSec(); } if (expectedValue != dse.Build()) { throw new AccessException(AccessErrorType.INVALID_DATA, "Expected value and DataSetElements.Build() value are different."); } return(dse); }
public void TestGetInfo() { // Arrange MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonInfo); AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory); var allDataSets = new DataSetElements() .WithInfo() .WithVelocity() .WithDecision() .WithTrusted(); // Act Info infoResp = sdk.GetInfo(session, user, password, uniq, allDataSets); this.logger.Debug(JsonConvert.SerializeObject(info)); // Assert Assert.IsNotNull(info); Assert.AreEqual(info.ResponseId, infoResp.ResponseId); Assert.AreEqual(info.Device.Id, infoResp.Device.Id); Assert.IsTrue(info.Velocity.Password.Equals(infoResp.Velocity.Password)); }
/// <summary> /// Simple Example within the Constructor. /// </summary> public KountAccessExample() { try { // Create the SDK. If any of these values are invalid, an com.kount.kountaccess.AccessException will be // thrown along with a message detailing why. AccessSdk sdk = new AccessSdk(host, merchantId, apiKey); // If you want the device information for a particular user's session, just pass in the sessionId. This // contains the id (fingerprint), IP address, IP Geo Location (country), whether the user was using a proxy // (and it was bypassed), and ... DeviceInfo deviceInfo = sdk.GetDevice(this.session); this.PrintDeviceInfo(deviceInfo.Device); // ... if you want to see the velocity information in relation to the users session and their account // information, you can make an access (velocity) request. Usernames and passwords will be hashed prior to // transmission to Kount within the SDK. You may optionally hash prior to passing them in as long as the // hashing method is consistent for the same value. String username = "******"; String password = "******"; VelocityInfo accessInfo = sdk.GetVelocity(session, username, password); // Let's see the response Console.WriteLine("Response: " + accessInfo); // Each Access Request has its own uniqueID Console.WriteLine("This is our access response_id: " + accessInfo.ResponseId); // The device is included in an access request: this.PrintDeviceInfo(accessInfo.Device); // you can get the device information from the accessInfo object Device device = accessInfo.Device; string jsonVeloInfo = JsonConvert.SerializeObject(accessInfo); Console.WriteLine(jsonVeloInfo); this.PrintVelocityInfo(accessInfo.Velocity); // Or you can access specific Metrics directly. Let's say we want the // number of unique user accounts used by the current sessions device // within the last hour int numUsersForDevice = accessInfo.Velocity.Device.ulh; Console.WriteLine( "The number of unique user access request(s) this hour for this device is:" + numUsersForDevice); // Decision Information is stored in a JSONObject, by entity type DecisionInfo decisionInfo = sdk.GetDecision(session, username, password); Decision decision = decisionInfo.Decision; // Let's look at the data this.PrintDecisionInfo(decision); // Get Kount Access data for session based on what was requested in the info flag String uniq = "uniq(customer identifier)"; DataSetElements dataSet = new DataSetElements() .WithInfo() .WithVelocity() .WithDecision() .WithTrusted() .WithBehavioSec(); Info info = sdk.GetInfo(session, username, password, uniq, dataSet); this.PrintDeviceInfo(info.Device); this.PrintDecisionInfo(info.Decision); this.PrintVelocityInfo(info.Velocity); this.PrintFields(info.Trusted); this.PrintFields(info.BehavioSec); // Get devices that belong to a uniq user. DevicesInfo devices = sdk.GetDevices(uniq); foreach (var d in devices.Devices) { this.PrintFields(d); } // Get the uniq users that belong to a device. string deviceId = "DEVICE_ID"; var uniques = sdk.GetUniques(deviceId); foreach (var u in uniques.Uniques) { this.PrintFields(u); } // Update device trust referenced by session ID sdk.SetDeviceTrustBySession(session, uniq, DeviceTrustState.Banned); // Update device trust referenced by device ID sdk.SetDeviceTrustByDevice(uniq, deviceId, DeviceTrustState.Trusted); // Update behavior data. string timing = "timing data"; // BehavioHost and BehavioEnvironment can be set via AccessSdk constructor too. // sdk.BehavioHost = "https://api.behavio.kaptcha.com"; //sdk.BehavioEnvironment = "sandbox"; //sdk.SetBehavioSec(session, uniq, timing); } catch (AccessException ae) { // These can be thrown if there were any issues making the request. // See the AccessException class for more information. Console.WriteLine("ERROR Type: " + ae.ErrorType); Console.WriteLine("ERROR: " + ae.Message); } }
/// <summary> /// Get set of data elements async for the session's username, password and uniq. /// The set of data elements depends of "i" param. /// </summary> /// <param name="sessionId">The Session ID returned from the JavaScript data collector.</param> /// <param name="username">The username of the user.</param> /// <param name="password">Customer identifier.</param> /// <param name="uniq">The password of the user.</param> /// <param name="dse">The requested set of data elements expected in response.</param> /// <returns>Set of data elements</returns> public async Task <Info> GetInfoAsync(string sessionId, string username, string password, string uniq, DataSetElements dse) { int i = dse.Build(); ValidateGetInfo(sessionId, username, password, uniq, i); using (WebClient client = new WebClient()) { PrepareWebClient((WebClient)client, true); NameValueCollection reqparm = GetRequestedParams(sessionId, username, password, uniq, i); this.LogRequest(InfoEndpoint, username: username, password: password, session: sessionId, uniq: uniq, i: i); try { byte[] responsebytes = await client.UploadValuesTaskAsync(InfoEndpoint, "POST", reqparm); string responsebody = Encoding.UTF8.GetString(responsebytes); Info info = JsonConvert.DeserializeObject <Info>(responsebody); return(info); } catch (WebException ex) { HandleWebException(ex); } return(null); } }