public void TestGetDevice()
        {
            try
            {
                MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevInfo);

                AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

                DeviceInfo dInfo = sdk.GetDevice(session);

                Assert.IsNotNull(dInfo);
                this.logger.Debug(JsonConvert.SerializeObject(dInfo));

                Assert.AreEqual(fingerprint, dInfo.Device.Id);
                Assert.AreEqual(ipAddress, dInfo.Device.IpAddress);
                Assert.AreEqual(ipGeo, dInfo.Device.IpGeo);
                Assert.AreEqual(1, dInfo.Device.Mobile);
                Assert.AreEqual(0, dInfo.Device.Proxy);
                Assert.AreEqual(responseId, dInfo.ResponseId);
            }
            catch (AccessException ae)
            {
                Assert.Fail($"Bad exception {ae.ErrorType}:{ae.Message}");
            }
        }
        public void TestGetDecision()
        {
            try
            {
                MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDeciInfo);

                AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

                DecisionInfo decisionInfo = sdk.GetDecision(session, user, password);

                Assert.IsNotNull(decisionInfo);

                this.logger.Debug(JsonConvert.SerializeObject(decisionInfo));


                Assert.AreEqual(decision, decisionInfo.Decision.Reply.RuleEvents.Decision);

                Assert.AreEqual(deviceInfo.Device.Id, decisionInfo.Device.Id);
                Assert.IsTrue(velocityInfo.Velocity.Password.Equals(decisionInfo.Velocity.Password));
            }
            catch (AccessException ae)
            {
                Assert.Fail($"Bad exception {ae.ErrorType}:{ae.Message}");
            }
        }
예제 #3
0
        public void TestDeviceTrustBySession_ShouldNotThrowException()
        {
            // Arrange
            MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonUniquesInfo);
            AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

            // Act
            sdk.SetDeviceTrustBySession(session, uniq, DeviceTrustState.Trusted);

            // Assert
        }
예제 #4
0
        public void TestDeviceTrustByDevice_ShouldNotThrowException()
        {
            // Arrange
            MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonUniquesInfo);
            AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

            // Act
            sdk.SetDeviceTrustByDevice(uniq, "abcdef12345678910abcdef987654321", DeviceTrustState.Trusted);

            // Assert
        }
 public void TestConstructorAccessSDKMissingHost()
 {
     try
     {
         AccessSdk sdk = new AccessSdk(null, merchantId, apiKey);
         Assert.Fail("Should have failed host");
     }
     catch (AccessException ae)
     {
         Assert.AreEqual(AccessErrorType.INVALID_DATA, ae.ErrorType);
     }
 }
예제 #6
0
        public void TestDeviceTrustBySessionWithoutSessionId_ShouldThrowException()
        {
            // Arrange
            MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevicesInfo);
            AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

            var emptySession = "";

            // Act
            // Assert
            Assert.That(() => sdk.SetDeviceTrustBySession(emptySession, uniq, DeviceTrustState.Trusted), Throws.TypeOf <AccessException>());
        }
 public void TestConstructorAccessSDKBlankApiKey()
 {
     try
     {
         AccessSdk sdk = new AccessSdk(host, merchantId, "    ");
         Assert.Fail("Should have failed apiKey");
     }
     catch (AccessException ae)
     {
         Assert.AreEqual(AccessErrorType.INVALID_DATA, ae.ErrorType);
     }
 }
예제 #8
0
        public void TestDeviceTrustByDeviceWithoutUniq_ShouldThrowException()
        {
            // Arrange
            MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevicesInfo);
            AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

            var emptyUniq = "";

            // Act
            // Assert
            Assert.That(() => sdk.SetDeviceTrustByDevice(emptyUniq, "abcdef12345678910abcdef987654321", DeviceTrustState.Trusted), Throws.TypeOf <AccessException>());
        }
예제 #9
0
        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>());
        }
예제 #10
0
        [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);
        }
예제 #11
0
        public void TestGetUniquesWithoutDeviceId_ShouldThrowException()
        {
            // Arrange
            MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevicesInfo);
            AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

            var emptyDeviceId = "";

            // Act
            ActualValueDelegate <object> testDelegate = () => sdk.GetUniques(emptyDeviceId);

            // Assert
            Assert.That(testDelegate, Throws.TypeOf <AccessException>());
        }
예제 #12
0
        public void TestHashValue()
        {
            try
            {
                var hash = AccessSdk.HashValue("admin");
                Assert.AreEqual("8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918", hash);

                var pass = AccessSdk.HashValue("password");
                Assert.AreEqual("5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", pass);
            }
            catch (AccessException ae)
            {
                Assert.Fail($"Bad exception {ae.ErrorType}:{ae.Message}");
            }
        }
        public void TestConstructorAccessSDKHappyPath()
        {
            // Create the SDK.  If any of these values are invalid, an
            // AccessException will be thrown along with a
            // message detailing why.
            try
            {
                AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey);

                Assert.IsNotNull(sdk);
            }
            catch (AccessException ae)
            {
                Assert.Fail($"Bad exception {ae.ErrorType}:{ae.Message}");
            }
        }
예제 #14
0
        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>());
        }
        public void TestGetDevices()
        {
            // Arrange
            MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevicesInfo);
            AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

            // Act
            DevicesInfo devicesResp = sdk.GetDevices(uniq);

            this.logger.Debug(JsonConvert.SerializeObject(devicesResp));

            // Assert
            Assert.IsNotNull(devicesResp);
            Assert.AreEqual(this.devicesInfo.ResponseId, devicesResp.ResponseId);

            Assert.AreEqual(this.devicesInfo.Devices.Count, devicesResp.Devices.Count);
        }
예제 #16
0
        public void TestGetUniques()
        {
            // Arrange
            MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonUniquesInfo);
            AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

            // Act
            UniquesInfo uniquesResp = sdk.GetUniques("54569fcbd187483a8a1570a3c67d1113");

            this.logger.Debug(JsonConvert.SerializeObject(uniquesResp));

            // Assert
            Assert.IsNotNull(uniquesResp);
            Assert.AreEqual(this.uniquesInfo.ResponseId, uniquesResp.ResponseId);

            Assert.AreEqual(this.uniquesInfo.Uniques.Count, uniquesResp.Uniques.Count);
        }
예제 #17
0
        public void TestGetDeviceConnectionClosed()
        {
            try
            {
                MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevInfo);

                AccessSdk sdk = new AccessSdk("gty://bad.host.com", merchantId, apiKey, DEFAULT_VERSION, mockFactory);

                DeviceInfo dInfo = sdk.GetDevice(session);

                Assert.Fail($"AccessException Not thrown");
            }
            catch (AccessException ae)
            {
                Assert.AreEqual(ae.ErrorType, AccessErrorType.NETWORK_ERROR);
            }
        }
예제 #18
0
        public void TestGetVelocityWebExceptionWithResponse()
        {
            try
            {
                MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonVeloInfo);

                AccessSdk sdk = new AccessSdk("gty://bad.host.com", merchantId, apiKey, DEFAULT_VERSION, mockFactory);

                VelocityInfo vInfo = sdk.GetVelocity(session, user, password);

                Assert.Fail($"AccessException Not thrown");
            }
            catch (AccessException ae)
            {
                Assert.AreEqual(ae.ErrorType, AccessErrorType.NETWORK_ERROR);
                Assert.IsTrue("BAD RESPONSE(OK):OK. UNKNOWN NETWORK ISSUE.".Equals(ae.Message.Trim()));
            }
        }
예제 #19
0
        public void TestGetVelocity()
        {
            try
            {
                MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonVeloInfo);

                AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

                VelocityInfo vInfo = sdk.GetVelocity(session, user, password);

                Assert.IsNotNull(vInfo);

                this.logger.Debug(JsonConvert.SerializeObject(vInfo));

                Assert.IsTrue(velocityInfo.Velocity.Password.Equals(vInfo.Velocity.Password));
                Assert.AreEqual(vInfo.ResponseId, responseId);
            }
            catch (AccessException ae)
            {
                Assert.Fail($"Bad exception {ae.ErrorType}:{ae.Message}");
            }
        }
예제 #20
0
        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));
        }
예제 #21
0
        /// <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);
            }
        }