Ejemplo n.º 1
0
        /// <summary>
        /// Get async the uniq users that belong to a device.
        /// </summary>
        /// <param name="d">Device ID.</param>
        /// <returns>List of uniqs</returns>
        public async Task <UniquesInfo> GetUniquesAsync(string d)
        {
            if (string.IsNullOrEmpty(d))
            {
                throw new AccessException(AccessErrorType.INVALID_DATA, "Parameter \"d\" is required.");
            }

            using (WebClient client = new WebClient())
            {
                PrepareWebClient(client);
                this.LogRequest(UniquesEndpoint, deviceId: d);

                try
                {
                    var    endPoint = $"{UniquesEndpoint}?v={this._version}&d={d}";
                    string res      = await client.DownloadStringTaskAsync(endPoint);

                    UniquesInfo uniqInfo = JsonConvert.DeserializeObject <UniquesInfo>(res);

                    return(uniqInfo);
                }
                catch (WebException ex)
                {
                    HandleWebException(ex);
                }
                return(null);
            }
        }
Ejemplo n.º 2
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);
        }
        public void TestSdkInit()
        {
            ILoggerFactory factory = LogFactory.GetLoggerFactory();

            this.logger = factory.GetLogger(typeof(AccessSDKTestBase).ToString());

            deviceInfo        = new DeviceInfo();
            deviceInfo.Device = new Device {
                Country = ipGeo, Region = "ID", GeoLat = 43.37, GeoLong = -116.200, Id = fingerprint, IpAddress = ipAddress, IpGeo = ipGeo, Mobile = 1, Proxy = 0
            };
            deviceInfo.ResponseId = responseId;
            jsonDevInfo           = JsonConvert.SerializeObject(deviceInfo);

            velocityInfo                  = new VelocityInfo();
            velocityInfo.Device           = deviceInfo.Device;
            velocityInfo.ResponseId       = responseId;
            velocityInfo.Velocity         = new Velocity();
            velocityInfo.Velocity.Account = new SubAccount {
                dlh = 1, dlm = 1, iplh = 1, iplm = 1, plh = 1, plm = 1, ulh = 1, ulm = 1
            };
            velocityInfo.Velocity.Device = new SubDevice {
                alh = 1, alm = 1, iplh = 3, iplm = 3, plh = 2, plm = 2, ulh = 1, ulm = 1
            };
            velocityInfo.Velocity.IpAddress = new SubAddress {
                ulm = 3, ulh = 3, plm = 3, plh = 3, alh = 2, alm = 2, dlh = 1, dlm = 1
            };
            velocityInfo.Velocity.Password = new SubPassword {
                dlm = 2, dlh = 2, alm = 2, alh = 2, iplh = 1, iplm = 1, ulh = 3, ulm = 3
            };
            velocityInfo.Velocity.User = new SubUser {
                iplm = 3, iplh = 3, alh = 2, alm = 2, dlh = 2, dlm = 2, plh = 1, plm = 1
            };
            jsonVeloInfo = JsonConvert.SerializeObject(velocityInfo);

            decisionInfo            = new DecisionInfo();
            decisionInfo.Device     = deviceInfo.Device;
            decisionInfo.ResponseId = responseId;
            decisionInfo.Velocity   = velocityInfo.Velocity;
            decisionInfo.Decision   = new Decision
            {
                Errors = new List <string> {
                    "E1", "E2"
                },
                Warnings = new List <string> {
                    "W1", "W2"
                },
                Reply = new Reply
                {
                    RuleEvents = new RuleEvents
                    {
                        Decision = decision,
                        Total    = 10,
                        Events   = new List <string> {
                            "Event 1", "Event 2"
                        }
                    }
                }
            };

            jsonDeciInfo = JsonConvert.SerializeObject(decisionInfo);

            info            = new Info();
            info.Device     = deviceInfo.Device;
            info.Decision   = decisionInfo.Decision;
            info.Velocity   = velocityInfo.Velocity;
            info.ResponseId = responseId;
            info.Trusted    = new TrustState()
            {
                State = DeviceTrustState.Trusted
            };
            info.BehavioSec = new BehavioSec()
            {
                Confidence = 0,
                IsBot      = false,
                IsTrained  = false,
                PolicyId   = 4,
                Score      = 0
            };

            jsonInfo = JsonConvert.SerializeObject(info);

            devicesInfo            = new DevicesInfo();
            devicesInfo.ResponseId = responseId;
            devicesInfo.Devices    = new List <DeviceBasicInfo>()
            {
                new DeviceBasicInfo()
                {
                    DeviceId = "54569fcbd187483a8a1570a3c67d1113", FriendlyName = "Device A", TrustState = DeviceTrustState.Trusted, DateFirstSeen = DateTime.UtcNow.AddHours(-1)
                },
                new DeviceBasicInfo()
                {
                    DeviceId = "abcdef12345678910abcdef987654321", FriendlyName = "Device B", TrustState = DeviceTrustState.Banned, DateFirstSeen = DateTime.UtcNow.AddHours(-2)
                }
            };

            jsonDevicesInfo = JsonConvert.SerializeObject(devicesInfo);

            uniquesInfo            = new UniquesInfo();
            uniquesInfo.ResponseId = responseId;
            uniquesInfo.Uniques    = new List <Unique>()
            {
                new Unique()
                {
                    UniqueId = "55e9fbfda2ce489d83b4a99c84c6f3e1", DateLastSeen = DateTime.UtcNow.AddHours(-1), TrustState = DeviceTrustState.Trusted
                },
                new Unique()
                {
                    UniqueId = "55e9fbfda2ce489d83b4a99c84c6f3e2", DateLastSeen = DateTime.UtcNow.AddHours(-2), TrustState = DeviceTrustState.Banned
                }
            };

            jsonUniquesInfo = JsonConvert.SerializeObject(uniquesInfo);
        }