From 3202f95e26ef30e989f5bab59e9632035521fc3a Mon Sep 17 00:00:00 2001 From: Dawid Libiszewski Date: Fri, 21 May 2021 17:44:53 +0200 Subject: [PATCH 1/2] CAS-6994 --- lib/Castle.php | 3 +++ lib/Castle/Castle.php | 37 ++++++++++++++++++++++++++++++++++++ lib/Castle/Models/Filter.php | 6 ++++++ lib/Castle/Models/Log.php | 6 ++++++ lib/Castle/Models/Risk.php | 6 ++++++ test/Castle.php | 3 +++ test/CastleTest.php | 32 +++++++++++++++++++++++++++++++ test/FilterTest.php | 17 +++++++++++++++++ test/LogTest.php | 17 +++++++++++++++++ test/RiskTest.php | 17 +++++++++++++++++ 10 files changed, 144 insertions(+) create mode 100644 lib/Castle/Models/Filter.php create mode 100644 lib/Castle/Models/Log.php create mode 100644 lib/Castle/Models/Risk.php create mode 100644 test/FilterTest.php create mode 100644 test/LogTest.php create mode 100644 test/RiskTest.php diff --git a/lib/Castle.php b/lib/Castle.php index 16bda88..2090406 100755 --- a/lib/Castle.php +++ b/lib/Castle.php @@ -22,6 +22,9 @@ function lcfirst( $str ) { require(dirname(__FILE__) . '/RestModel/Model.php'); require(dirname(__FILE__) . '/Castle/Models/Context.php'); require(dirname(__FILE__) . '/Castle/Models/Authenticate.php'); +require(dirname(__FILE__) . '/Castle/Models/Filter.php'); +require(dirname(__FILE__) . '/Castle/Models/Log.php'); +require(dirname(__FILE__) . '/Castle/Models/Risk.php'); require(dirname(__FILE__) . '/Castle/Models/Review.php'); require(dirname(__FILE__) . '/Castle/CurlTransport.php'); require(dirname(__FILE__) . '/Castle/RequestContext.php'); diff --git a/lib/Castle/Castle.php b/lib/Castle/Castle.php index 06e1476..08aeec8 100755 --- a/lib/Castle/Castle.php +++ b/lib/Castle/Castle.php @@ -161,4 +161,41 @@ public static function track(Array $attributes) $request = new Castle_Request(); $request->send('post', '/track', $attributes); } + + + /** + * Filter an action + * @param String $attributes 'name', and 'user' object with 'id' are required + * @return Castle_Log + */ + public static function filter(Array $attributes) + { + $filter = new Castle_Filter($attributes); + $filter->save(); + return $filter; + } + + /** + * Log events + * @param String $attributes 'name', 'status' and 'user' object with 'id' are required + * @return Castle_Log + */ + public static function log(Array $attributes) + { + $log = new Castle_Log($attributes); + $log->save(); + return $log; + } + + /** + * Risk + * @param String $attributes 'name', 'status' and 'user' object with 'id' are required + * @return Castle_Risk + */ + public static function risk(Array $attributes) + { + $risk = new Castle_Risk($attributes); + $risk->save(); + return $risk; + } } diff --git a/lib/Castle/Models/Filter.php b/lib/Castle/Models/Filter.php new file mode 100644 index 0000000..20c0a3d --- /dev/null +++ b/lib/Castle/Models/Filter.php @@ -0,0 +1,6 @@ +assertRequest('post', '/track'); } + public function testFilter() + { + Castle_RequestTransport::setResponse(204, ''); + Castle::filter(Array( + 'name' => '$registration', + 'user' => Array('id' => 'abc', 'email' => 'user@foobar.io') + )); + $this->assertRequest('post', '/filter'); + } + + public function testLog() + { + Castle_RequestTransport::setResponse(204, ''); + Castle::log(Array( + 'name' => '$login', + 'status' => '$failed', + 'user' => Array('id' => 'abc', 'email' => 'user@foobar.io') + )); + $this->assertRequest('post', '/log'); + } + + public function testRisk() + { + Castle_RequestTransport::setResponse(204, ''); + Castle::risk(Array( + 'name' => '$login', + 'status' => '$succeeded', + 'user' => Array('id' => 'abc', 'email' => 'user@foobar.io') + )); + $this->assertRequest('post', '/risk'); + } + public function testAuthenticate() { Castle_RequestTransport::setResponse(201, '{ "status": "approve" }'); diff --git a/test/FilterTest.php b/test/FilterTest.php new file mode 100644 index 0000000..5b149ad --- /dev/null +++ b/test/FilterTest.php @@ -0,0 +1,17 @@ +save(); + $this->assertRequest('post', '/filter'); + } +} diff --git a/test/LogTest.php b/test/LogTest.php new file mode 100644 index 0000000..9bab10c --- /dev/null +++ b/test/LogTest.php @@ -0,0 +1,17 @@ +save(); + $this->assertRequest('post', '/log'); + } +} diff --git a/test/RiskTest.php b/test/RiskTest.php new file mode 100644 index 0000000..a0829b8 --- /dev/null +++ b/test/RiskTest.php @@ -0,0 +1,17 @@ +save(); + $this->assertRequest('post', '/risk'); + } +} From f4c2f4d921eff32911791947058433704ebd6302 Mon Sep 17 00:00:00 2001 From: Dawid Libiszewski Date: Tue, 25 May 2021 19:24:32 +0200 Subject: [PATCH 2/2] missing attr adding --- test/CastleTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/CastleTest.php b/test/CastleTest.php index fd62fe8..d5c3948 100644 --- a/test/CastleTest.php +++ b/test/CastleTest.php @@ -30,6 +30,7 @@ public function testFilter() { Castle_RequestTransport::setResponse(204, ''); Castle::filter(Array( + 'request_token' => '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302', 'name' => '$registration', 'user' => Array('id' => 'abc', 'email' => 'user@foobar.io') )); @@ -40,6 +41,7 @@ public function testLog() { Castle_RequestTransport::setResponse(204, ''); Castle::log(Array( + 'request_token' => '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302', 'name' => '$login', 'status' => '$failed', 'user' => Array('id' => 'abc', 'email' => 'user@foobar.io') @@ -51,6 +53,7 @@ public function testRisk() { Castle_RequestTransport::setResponse(204, ''); Castle::risk(Array( + 'request_token' => '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302', 'name' => '$login', 'status' => '$succeeded', 'user' => Array('id' => 'abc', 'email' => 'user@foobar.io')