Fixes tests
parent
4a43d8cfc7
commit
6fdf123f9f
|
@ -29,8 +29,8 @@ class RateLimitMiddlewareTest extends TestCase
|
||||||
'type' => 'mariadb',
|
'type' => 'mariadb',
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
'port' => '3306',
|
'port' => '3306',
|
||||||
'dbname' => 'totalmeet_test',
|
'dbname' => 'jilo_test',
|
||||||
'user' => 'test_totalmeet',
|
'user' => 'test_jilo',
|
||||||
'password' => $password
|
'password' => $password
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -11,47 +11,47 @@ use PHPUnit\Framework\TestCase;
|
||||||
*/
|
*/
|
||||||
class TestLogger {
|
class TestLogger {
|
||||||
private $db;
|
private $db;
|
||||||
|
|
||||||
public function __construct($database) {
|
public function __construct($database) {
|
||||||
$this->db = $database->getConnection();
|
$this->db = $database->getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insertLog($userId, $message, $scope = 'user') {
|
public function insertLog($userId, $message, $scope = 'user') {
|
||||||
try {
|
try {
|
||||||
$sql = 'INSERT INTO log
|
$sql = 'INSERT INTO log
|
||||||
(user_id, scope, message)
|
(user_id, scope, message)
|
||||||
VALUES
|
VALUES
|
||||||
(:user_id, :scope, :message)';
|
(:user_id, :scope, :message)';
|
||||||
|
|
||||||
$query = $this->db->prepare($sql);
|
$query = $this->db->prepare($sql);
|
||||||
$query->execute([
|
$query->execute([
|
||||||
':user_id' => $userId,
|
':user_id' => $userId,
|
||||||
':scope' => $scope,
|
':scope' => $scope,
|
||||||
':message' => $message,
|
':message' => $message,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function readLog($userId, $scope, $offset = 0, $items_per_page = '', $filters = []) {
|
public function readLog($userId, $scope, $offset = 0, $items_per_page = '', $filters = []) {
|
||||||
$params = [];
|
$params = [];
|
||||||
$where_clauses = [];
|
$where_clauses = [];
|
||||||
|
|
||||||
// Base query with user join
|
// Base query with user join
|
||||||
$base_sql = 'SELECT l.*, u.username
|
$base_sql = 'SELECT l.*, u.username
|
||||||
FROM log l
|
FROM log l
|
||||||
LEFT JOIN user u ON l.user_id = u.id';
|
LEFT JOIN user u ON l.user_id = u.id';
|
||||||
|
|
||||||
// Add scope condition
|
// Add scope condition
|
||||||
if ($scope === 'user') {
|
if ($scope === 'user') {
|
||||||
$where_clauses[] = 'l.user_id = :user_id';
|
$where_clauses[] = 'l.user_id = :user_id';
|
||||||
$params[':user_id'] = $userId;
|
$params[':user_id'] = $userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add time range filters if specified
|
// Add time range filters if specified
|
||||||
if (!empty($filters['from_time'])) {
|
if (!empty($filters['from_time'])) {
|
||||||
$where_clauses[] = 'l.time >= :from_time';
|
$where_clauses[] = 'l.time >= :from_time';
|
||||||
|
@ -61,37 +61,37 @@ class TestLogger {
|
||||||
$where_clauses[] = 'l.time <= :until_time';
|
$where_clauses[] = 'l.time <= :until_time';
|
||||||
$params[':until_time'] = $filters['until_time'] . ' 23:59:59';
|
$params[':until_time'] = $filters['until_time'] . ' 23:59:59';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add message search if specified
|
// Add message search if specified
|
||||||
if (!empty($filters['message'])) {
|
if (!empty($filters['message'])) {
|
||||||
$where_clauses[] = 'l.message LIKE :message';
|
$where_clauses[] = 'l.message LIKE :message';
|
||||||
$params[':message'] = '%' . $filters['message'] . '%';
|
$params[':message'] = '%' . $filters['message'] . '%';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add user ID search if specified
|
// Add user ID search if specified
|
||||||
if (!empty($filters['id'])) {
|
if (!empty($filters['id'])) {
|
||||||
$where_clauses[] = 'l.user_id = :search_user_id';
|
$where_clauses[] = 'l.user_id = :search_user_id';
|
||||||
$params[':search_user_id'] = $filters['id'];
|
$params[':search_user_id'] = $filters['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine WHERE clauses
|
// Combine WHERE clauses
|
||||||
$sql = $base_sql;
|
$sql = $base_sql;
|
||||||
if (!empty($where_clauses)) {
|
if (!empty($where_clauses)) {
|
||||||
$sql .= ' WHERE ' . implode(' AND ', $where_clauses);
|
$sql .= ' WHERE ' . implode(' AND ', $where_clauses);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ordering
|
// Add ordering
|
||||||
$sql .= ' ORDER BY l.time DESC';
|
$sql .= ' ORDER BY l.time DESC';
|
||||||
|
|
||||||
// Add pagination
|
// Add pagination
|
||||||
if ($items_per_page) {
|
if ($items_per_page) {
|
||||||
$items_per_page = (int)$items_per_page;
|
$items_per_page = (int)$items_per_page;
|
||||||
$sql .= ' LIMIT ' . $offset . ',' . $items_per_page;
|
$sql .= ' LIMIT ' . $offset . ',' . $items_per_page;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->db->prepare($sql);
|
$query = $this->db->prepare($sql);
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
|
|
||||||
return $query->fetchAll(PDO::FETCH_ASSOC);
|
return $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,8 +115,8 @@ class LogTest extends TestCase
|
||||||
'type' => 'mariadb',
|
'type' => 'mariadb',
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
'port' => '3306',
|
'port' => '3306',
|
||||||
'dbname' => 'totalmeet_test',
|
'dbname' => 'jilo_test',
|
||||||
'user' => 'test_totalmeet',
|
'user' => 'test_jilo',
|
||||||
'password' => $password
|
'password' => $password
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ class RateLimiterTest extends TestCase
|
||||||
'type' => 'mariadb',
|
'type' => 'mariadb',
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
'port' => '3306',
|
'port' => '3306',
|
||||||
'dbname' => 'totalmeet_test',
|
'dbname' => 'jilo_test',
|
||||||
'user' => 'test_totalmeet',
|
'user' => 'test_jilo',
|
||||||
'password' => $password
|
'password' => $password
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ class UserRegisterTest extends TestCase
|
||||||
'type' => 'mariadb',
|
'type' => 'mariadb',
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
'port' => '3306',
|
'port' => '3306',
|
||||||
'dbname' => 'totalmeet_test',
|
'dbname' => 'jilo_test',
|
||||||
'user' => 'test_totalmeet',
|
'user' => 'test_jilo',
|
||||||
'password' => $password
|
'password' => $password
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ class UserTest extends TestCase
|
||||||
'type' => 'mariadb',
|
'type' => 'mariadb',
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
'port' => '3306',
|
'port' => '3306',
|
||||||
'dbname' => 'totalmeet_test',
|
'dbname' => 'jilo_test',
|
||||||
'user' => 'test_totalmeet',
|
'user' => 'test_jilo',
|
||||||
'password' => $password
|
'password' => $password
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,11 @@
|
||||||
</coverage>
|
</coverage>
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
<env name="DB_CONNECTION" value="sqlite"/>
|
<env name="DB_TYPE" value="mariadb"/>
|
||||||
<env name="DB_DATABASE" value=":memory:"/>
|
<env name="DB_HOST" value="localhost"/>
|
||||||
|
<env name="DB_PORT" value="3306"/>
|
||||||
|
<env name="DB_DATABASE" value="jilo_test"/>
|
||||||
|
<env name="DB_USERNAME" value="root"/>
|
||||||
|
<env name="DB_PASSWORD" value=""/>
|
||||||
</php>
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
-- Create test database if not exists
|
||||||
|
CREATE DATABASE IF NOT EXISTS jilo_test;
|
||||||
|
USE jilo_test;
|
||||||
|
|
||||||
|
-- Create rate limiter table if not exists
|
||||||
|
CREATE TABLE IF NOT EXISTS security_rate_page (
|
||||||
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
ip_address VARCHAR(45) NOT NULL,
|
||||||
|
endpoint VARCHAR(255) NOT NULL,
|
||||||
|
request_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create security_ip_whitelist table if not exists
|
||||||
|
CREATE TABLE IF NOT EXISTS security_ip_whitelist (
|
||||||
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
ip_address VARCHAR(45) NOT NULL UNIQUE,
|
||||||
|
is_network BOOLEAN DEFAULT 0,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
created_by VARCHAR(255)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create security_ip_blacklist table if not exists
|
||||||
|
CREATE TABLE IF NOT EXISTS security_ip_blacklist (
|
||||||
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
ip_address VARCHAR(45) NOT NULL UNIQUE,
|
||||||
|
is_network BOOLEAN DEFAULT 0,
|
||||||
|
reason TEXT,
|
||||||
|
expiry_time TIMESTAMP NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
created_by VARCHAR(255)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Grant permissions to root user
|
||||||
|
GRANT ALL PRIVILEGES ON jilo_test.* TO 'root'@'localhost';
|
Loading…
Reference in New Issue