diff --git a/app/classes/agent.php b/app/classes/agent.php index 5ae1b15..ffd8291 100644 --- a/app/classes/agent.php +++ b/app/classes/agent.php @@ -43,11 +43,11 @@ class Agent { jat.endpoint AS agent_endpoint, h.platform_id FROM - jilo_agents ja + jilo_agent ja JOIN - jilo_agent_types jat ON ja.agent_type_id = jat.id + jilo_agent_type jat ON ja.agent_type_id = jat.id JOIN - hosts h ON ja.host_id = h.id + host h ON ja.host_id = h.id WHERE ja.host_id = :host_id'; @@ -87,11 +87,11 @@ class Agent { jat.endpoint AS agent_endpoint, h.platform_id FROM - jilo_agents ja + jilo_agent ja JOIN - jilo_agent_types jat ON ja.agent_type_id = jat.id + jilo_agent_type jat ON ja.agent_type_id = jat.id JOIN - hosts h ON ja.host_id = h.id + host h ON ja.host_id = h.id WHERE ja.id = :agent_id'; @@ -110,7 +110,7 @@ class Agent { */ public function getAgentTypes() { $sql = 'SELECT * - FROM jilo_agent_types + FROM jilo_agent_type ORDER BY id'; $query = $this->db->prepare($sql); $query->execute(); @@ -131,7 +131,7 @@ class Agent { id, agent_type_id FROM - jilo_agents + jilo_agent WHERE host_id = :host_id'; $query = $this->db->prepare($sql); @@ -152,7 +152,7 @@ class Agent { */ public function addAgent($host_id, $newAgent) { try { - $sql = 'INSERT INTO jilo_agents + $sql = 'INSERT INTO jilo_agent (host_id, agent_type_id, url, secret_key, check_period) VALUES (:host_id, :agent_type_id, :url, :secret_key, :check_period)'; @@ -184,7 +184,7 @@ class Agent { */ public function editAgent($agent_id, $updatedAgent) { try { - $sql = 'UPDATE jilo_agents + $sql = 'UPDATE jilo_agent SET agent_type_id = :agent_type_id, url = :url, @@ -222,7 +222,7 @@ class Agent { */ public function deleteAgent($agent_id) { try { - $sql = 'DELETE FROM jilo_agents + $sql = 'DELETE FROM jilo_agent WHERE id = :agent_id'; @@ -420,13 +420,13 @@ class Agent { jac.agent_id, jat.description FROM - jilo_agent_checks jac + jilo_agent_check jac JOIN - jilo_agents ja ON jac.agent_id = ja.id + jilo_agent ja ON jac.agent_id = ja.id JOIN - jilo_agent_types jat ON ja.agent_type_id = jat.id + jilo_agent_type jat ON ja.agent_type_id = jat.id JOIN - hosts h ON ja.host_id = h.id + host h ON ja.host_id = h.id WHERE h.id = :host_id AND jat.description = :agent_type @@ -520,13 +520,13 @@ class Agent { jac.response_content, COUNT(*) as checks_count FROM - jilo_agent_checks jac + jilo_agent_check jac JOIN - jilo_agents ja ON jac.agent_id = ja.id + jilo_agent ja ON jac.agent_id = ja.id JOIN - jilo_agent_types jat ON ja.agent_type_id = jat.id + jilo_agent_type jat ON ja.agent_type_id = jat.id JOIN - hosts h ON ja.host_id = h.id + host h ON ja.host_id = h.id WHERE h.id = :host_id AND jat.description = :agent_type @@ -591,13 +591,13 @@ class Agent { jac.timestamp, jac.response_content FROM - jilo_agent_checks jac + jilo_agent_check jac JOIN - jilo_agents ja ON jac.agent_id = ja.id + jilo_agent ja ON jac.agent_id = ja.id JOIN - jilo_agent_types jat ON ja.agent_type_id = jat.id + jilo_agent_type jat ON ja.agent_type_id = jat.id JOIN - hosts h ON ja.host_id = h.id + host h ON ja.host_id = h.id WHERE h.id = :host_id AND jat.description = :agent_type diff --git a/app/classes/host.php b/app/classes/host.php index f299e9c..3bf0f5f 100644 --- a/app/classes/host.php +++ b/app/classes/host.php @@ -37,7 +37,7 @@ class Host { platform_id, name FROM - hosts'; + host'; if ($platform_id !== '' && $host_id !== '') { $sql .= ' WHERE platform_id = :platform_id AND id = :host_id'; @@ -71,7 +71,7 @@ class Host { */ public function addHost($newHost) { try { - $sql = 'INSERT INTO hosts + $sql = 'INSERT INTO host (address, platform_id, name) VALUES (:address, :platform_id, :name)'; @@ -101,7 +101,7 @@ class Host { */ public function editHost($platform_id, $updatedHost) { try { - $sql = 'UPDATE hosts SET + $sql = 'UPDATE host SET address = :address, name = :name WHERE @@ -140,13 +140,13 @@ class Host { $this->db->beginTransaction(); // First delete all agents associated with this host - $sql = 'DELETE FROM jilo_agents WHERE host_id = :host_id'; + $sql = 'DELETE FROM jilo_agent WHERE host_id = :host_id'; $query = $this->db->prepare($sql); $query->bindParam(':host_id', $host_id); $query->execute(); // Then delete the host - $sql = 'DELETE FROM hosts WHERE id = :host_id'; + $sql = 'DELETE FROM host WHERE id = :host_id'; $query = $this->db->prepare($sql); $query->bindParam(':host_id', $host_id); $query->execute(); diff --git a/app/classes/passwordReset.php b/app/classes/passwordReset.php index 8b7c4fb..338b61a 100644 --- a/app/classes/passwordReset.php +++ b/app/classes/passwordReset.php @@ -26,8 +26,8 @@ class PasswordReset { // Check if email exists $query = $this->db->prepare(" SELECT u.id, um.email - FROM users u - JOIN users_meta um ON u.id = um.user_id + FROM user u + JOIN user_meta um ON u.id = um.user_id WHERE um.email = :email" ); $query->bindParam(':email', $email); diff --git a/app/classes/platform.php b/app/classes/platform.php index 02bad67..f7577d0 100644 --- a/app/classes/platform.php +++ b/app/classes/platform.php @@ -30,7 +30,7 @@ class Platform { * @return array An associative array containing platform details. */ public function getPlatformDetails($platform_id = '') { - $sql = 'SELECT * FROM platforms'; + $sql = 'SELECT * FROM platform'; if ($platform_id !== '') { $sql .= ' WHERE id = :platform_id'; $query = $this->db->prepare($sql); @@ -57,7 +57,7 @@ class Platform { */ public function addPlatform($newPlatform) { try { - $sql = 'INSERT INTO platforms + $sql = 'INSERT INTO platform (name, jitsi_url, jilo_database) VALUES (:name, :jitsi_url, :jilo_database)'; @@ -90,7 +90,7 @@ class Platform { */ public function editPlatform($platform_id, $updatedPlatform) { try { - $sql = 'UPDATE platforms SET + $sql = 'UPDATE platform SET name = :name, jitsi_url = :jitsi_url, jilo_database = :jilo_database @@ -125,7 +125,7 @@ class Platform { $this->db->beginTransaction(); // First, get all hosts in this platform - $sql = 'SELECT id FROM hosts WHERE platform_id = :platform_id'; + $sql = 'SELECT id FROM host WHERE platform_id = :platform_id'; $query = $this->db->prepare($sql); $query->bindParam(':platform_id', $platform_id); $query->execute(); @@ -133,20 +133,20 @@ class Platform { // Delete all agents for each host foreach ($hosts as $host) { - $sql = 'DELETE FROM jilo_agents WHERE host_id = :host_id'; + $sql = 'DELETE FROM jilo_agent WHERE host_id = :host_id'; $query = $this->db->prepare($sql); $query->bindParam(':host_id', $host['id']); $query->execute(); } // Delete all hosts in this platform - $sql = 'DELETE FROM hosts WHERE platform_id = :platform_id'; + $sql = 'DELETE FROM host WHERE platform_id = :platform_id'; $query = $this->db->prepare($sql); $query->bindParam(':platform_id', $platform_id); $query->execute(); // Finally, delete the platform - $sql = 'DELETE FROM platforms WHERE id = :platform_id'; + $sql = 'DELETE FROM platform WHERE id = :platform_id'; $query = $this->db->prepare($sql); $query->bindParam(':platform_id', $platform_id); $query->execute(); diff --git a/app/classes/user.php b/app/classes/user.php index bc03b9d..849a687 100644 --- a/app/classes/user.php +++ b/app/classes/user.php @@ -3,7 +3,7 @@ /** * class User * - * Handles user-related functionalities such as registration, login, rights management, and profile updates. + * Handles user-related functionalities such as login, rights management, and profile updates. */ class User { /** @@ -36,9 +36,9 @@ class User { /** * Logs in a user by verifying credentials. * - * @param string $username The username of the user. - * @param string $password The password of the user. - * @param string $twoFactorCode Optional. The 2FA code if 2FA is enabled. + * @param string $username The username of the user. + * @param string $password The password of the user. + * @param string $twoFactorCode Optional. The 2FA code if 2FA is enabled. * * @return array Login result with status and any necessary data */ @@ -53,7 +53,7 @@ class User { } // Then check credentials - $query = $this->db->prepare("SELECT * FROM users WHERE username = :username"); + $query = $this->db->prepare("SELECT * FROM user WHERE username = :username"); $query->bindParam(':username', $username); $query->execute(); @@ -92,7 +92,10 @@ class User { // Get remaining attempts AFTER this failed attempt $remainingAttempts = $this->rateLimiter->getRemainingAttempts($username, $ipAddress); - throw new Exception("Invalid credentials. {$remainingAttempts} attempts remaining."); + return [ + 'status' => 'failed', + 'message' => "Invalid credentials. {$remainingAttempts} attempts remaining." + ]; } @@ -105,7 +108,7 @@ class User { */ // FIXME not used now? public function getUserId($username) { - $sql = 'SELECT id FROM users WHERE username = :username'; + $sql = 'SELECT id FROM user WHERE username = :username'; $query = $this->db->prepare($sql); $query->bindParam(':username', $username); @@ -128,8 +131,8 @@ class User { um.*, u.username FROM - users_meta um - LEFT JOIN users u + user_meta um + LEFT JOIN user u ON um.user_id = u.id WHERE u.id = :user_id'; @@ -153,7 +156,7 @@ class User { * @return void */ public function addUserRight($userId, $right_id) { - $sql = 'INSERT INTO users_rights + $sql = 'INSERT INTO user_right (user_id, right_id) VALUES (:user_id, :right_id)'; @@ -174,7 +177,7 @@ class User { * @return void */ public function removeUserRight($userId, $right_id) { - $sql = 'DELETE FROM users_rights + $sql = 'DELETE FROM user_right WHERE user_id = :user_id AND @@ -196,7 +199,7 @@ class User { $sql = 'SELECT id AS right_id, name AS right_name - FROM rights + FROM `right` ORDER BY id ASC'; $query = $this->db->prepare($sql); $query->execute(); @@ -219,10 +222,10 @@ class User { r.id AS right_id, r.name AS right_name FROM - users u - LEFT JOIN users_rights ur + `user` u + LEFT JOIN `user_right` ur ON u.id = ur.user_id - LEFT JOIN rights r + LEFT JOIN `right` r ON ur.right_id = r.id WHERE u.id = :user_id'; @@ -312,7 +315,7 @@ class User { */ public function editUser($userId, $updatedUser) { try { - $sql = 'UPDATE users_meta SET + $sql = 'UPDATE user_meta SET name = :name, email = :email, timezone = :timezone, @@ -347,7 +350,7 @@ class User { public function removeAvatar($userId, $old_avatar = '') { try { // remove from database - $sql = 'UPDATE users_meta SET + $sql = 'UPDATE user_meta SET avatar = NULL WHERE user_id = :user_id'; $query = $this->db->prepare($sql); @@ -396,7 +399,7 @@ class User { if (move_uploaded_file($fileTmpPath, $dest_path)) { try { // update user's avatar path in DB - $sql = 'UPDATE users_meta SET + $sql = 'UPDATE user_meta SET avatar = :avatar WHERE user_id = :user_id'; $query = $this->db->prepare($sql); @@ -432,7 +435,7 @@ class User { */ public function getUsers() { $sql = "SELECT id, username - FROM users + FROM `user` ORDER BY username ASC"; $stmt = $this->db->prepare($sql); @@ -495,7 +498,7 @@ class User { public function changePassword($userId, $currentPassword, $newPassword) { try { // First verify the current password - $sql = "SELECT password FROM users WHERE id = :user_id"; + $sql = "SELECT password FROM user WHERE id = :user_id"; $query = $this->db->prepare($sql); $query->execute([':user_id' => $userId]); $user = $query->fetch(PDO::FETCH_ASSOC); @@ -508,7 +511,7 @@ class User { $hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT); // Update the password - $sql = "UPDATE users SET password = :password WHERE id = :user_id"; + $sql = "UPDATE user SET password = :password WHERE id = :user_id"; $query = $this->db->prepare($sql); return $query->execute([ ':password' => $hashedPassword, diff --git a/doc/database/main.sql b/doc/database/main.sql index 155feab..bcd3bf5 100644 --- a/doc/database/main.sql +++ b/doc/database/main.sql @@ -11,7 +11,7 @@ SET NAMES utf8mb4; -- -- -------------------------------------------------------- -CREATE TABLE `users` ( +CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `password` varchar(100) NOT NULL, @@ -19,12 +19,12 @@ CREATE TABLE `users` ( UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -INSERT INTO `users` (`id`, `username`, `password`) VALUES +INSERT INTO `user` (`id`, `username`, `password`) VALUES (1,'demo','$2y$12$AtIKs3eVxD4wTT1IWwJujuuHyGhhmfBJYqSfIrPFFPMDfKu3Rcsx6'), (2,'demo1','$2y$12$ELwYyhQ8XDkVvX9Xsb0mlORqeQHNFaBOvaBuPQym4n4IomA/DgvLC'); -- -------------------------------------------------------- -CREATE TABLE `users_meta` ( +CREATE TABLE `user_meta` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `name` varchar(255) DEFAULT NULL, @@ -34,22 +34,22 @@ CREATE TABLE `users_meta` ( `bio` text DEFAULT NULL, PRIMARY KEY (`id`,`user_id`) USING BTREE, KEY `user_id` (`user_id`), - CONSTRAINT `user_meta_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `user_meta_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -INSERT INTO `users_meta` (`id`, `user_id`, `name`, `email`, `timezone`, `avatar`, `bio`) VALUES +INSERT INTO `user_meta` (`id`, `user_id`, `name`, `email`, `timezone`, `avatar`, `bio`) VALUES (1,1,'demo admin user','admin@example.com',NULL,NULL,'This is a demo user of the demo install of Jilo Web'), (2,2,'demo user','demo@example.com',NULL,NULL,'This is a demo user of the demo install of Jilo Web'); -- -------------------------------------------------------- -CREATE TABLE `rights` ( +CREATE TABLE `right` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -INSERT INTO `rights` (`id`, `name`) VALUES +INSERT INTO `right` (`id`, `name`) VALUES (1, 'superuser'), (2, 'edit users'), (3, 'view config file'), @@ -67,13 +67,13 @@ INSERT INTO `rights` (`id`, `name`) VALUES (15,'view jilo config'); -- -------------------------------------------------------- -CREATE TABLE `users_rights` ( +CREATE TABLE `user_right` ( `user_id` int(11) NOT NULL, `right_id` int(11) NOT NULL, PRIMARY KEY (`user_id`,`right_id`), KEY `fk_right_id` (`right_id`), - CONSTRAINT `fk_right_id` FOREIGN KEY (`right_id`) REFERENCES `rights` (`id`), - CONSTRAINT `fk_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `fk_right_id` FOREIGN KEY (`right_id`) REFERENCES `right` (`id`), + CONSTRAINT `fk_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- -------------------------------------------------------- @@ -85,7 +85,7 @@ CREATE TABLE `user_2fa` ( `created_at` datetime NOT NULL, `last_used` datetime DEFAULT NULL, PRIMARY KEY (`user_id`), - CONSTRAINT `fk_user_2fa_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `fk_user_2fa_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- -------------------------------------------------------- @@ -95,7 +95,7 @@ CREATE TABLE `user_2fa_temp` ( `created_at` datetime NOT NULL, `expires_at` datetime NOT NULL, PRIMARY KEY (`user_id`, `code`), - CONSTRAINT `fk_user_2fa_temp_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `fk_user_2fa_temp_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- -------------------------------------------------------- @@ -106,7 +106,7 @@ CREATE TABLE `user_password_reset` ( `expires` int(11) NOT NULL, `used` TINYINT(1) NOT NULL DEFAULT 0, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT `fk_user_password_reset` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`), + CONSTRAINT `fk_user_password_reset` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`), UNIQUE KEY `token_idx` (`token`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; @@ -115,7 +115,7 @@ CREATE TABLE `user_password_reset` ( -- -- -------------------------------------------------------- -CREATE TABLE `login_attempts` ( +CREATE TABLE `security_rate_auth` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ip_address` varchar(45) NOT NULL, `username` varchar(255) NOT NULL, @@ -125,7 +125,7 @@ CREATE TABLE `login_attempts` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- -------------------------------------------------------- -CREATE TABLE `pages_rate_limits` ( +CREATE TABLE `security_rate_page` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ip_address` varchar(45) NOT NULL, `endpoint` varchar(255) NOT NULL, @@ -136,7 +136,7 @@ CREATE TABLE `pages_rate_limits` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- -------------------------------------------------------- -CREATE TABLE `ip_blacklist` ( +CREATE TABLE `security_ip_blacklist` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ip_address` varchar(45) NOT NULL, `is_network` tinyint(1) DEFAULT 0, @@ -148,7 +148,7 @@ CREATE TABLE `ip_blacklist` ( UNIQUE KEY `unique_ip` (`ip_address`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -INSERT INTO `ip_blacklist` (`id`, `ip_address`, `is_network`, `reason`, `expiry_time`, `created_at`, `created_by`) VALUES +INSERT INTO `security_ip_blacklist` (`id`, `ip_address`, `is_network`, `reason`, `expiry_time`, `created_at`, `created_by`) VALUES (1, '0.0.0.0/8', 1, 'Reserved address space - RFC 1122', NULL, '2025-01-03 16:40:15', 'system'), (2, '100.64.0.0/10', 1, 'Carrier-grade NAT space - RFC 6598', NULL, '2025-01-03 16:40:15', 'system'), (3, '192.0.2.0/24', 1, 'TEST-NET-1 Documentation space - RFC 5737', NULL, '2025-01-03 16:40:15', 'system'), @@ -156,7 +156,7 @@ INSERT INTO `ip_blacklist` (`id`, `ip_address`, `is_network`, `reason`, `expiry_ (5, '203.0.113.0/24', 1, 'TEST-NET-3 Documentation space - RFC 5737', NULL, '2025-01-03 16:40:15', 'system'); -- -------------------------------------------------------- -CREATE TABLE `ip_whitelist` ( +CREATE TABLE `security_ip_whitelist` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ip_address` varchar(45) NOT NULL, `is_network` tinyint(1) DEFAULT 0, @@ -167,7 +167,7 @@ CREATE TABLE `ip_whitelist` ( UNIQUE KEY `unique_ip` (`ip_address`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -INSERT INTO `ip_whitelist` (`id`, `ip_address`, `is_network`, `description`, `created_at`, `created_by`) VALUES +INSERT INTO `security_ip_whitelist` (`id`, `ip_address`, `is_network`, `description`, `created_at`, `created_by`) VALUES (1, '127.0.0.1', 0, 'localhost IPv4', '2025-01-03 16:40:15', 'system'), (2, '::1', 0, 'localhost IPv6', '2025-01-03 16:40:15', 'system'), (3, '10.0.0.0/8', 1, 'Private network (Class A)', '2025-01-03 16:40:15', 'system'), @@ -179,7 +179,7 @@ INSERT INTO `ip_whitelist` (`id`, `ip_address`, `is_network`, `description`, `cr -- -- -------------------------------------------------------- -CREATE TABLE `logs` ( +CREATE TABLE `log` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `time` datetime NOT NULL DEFAULT current_timestamp(), @@ -187,7 +187,7 @@ CREATE TABLE `logs` ( `message` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), - CONSTRAINT `log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- @@ -195,13 +195,13 @@ CREATE TABLE `logs` ( -- -- -------------------------------------------------------- -CREATE TABLE `jilo_agent_types` ( +CREATE TABLE `jilo_agent_type` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(255), `endpoint` varchar(255), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -INSERT INTO `jilo_agent_types` (`id`, `description`, `endpoint`) VALUES +INSERT INTO `jilo_agent_type` (`id`, `description`, `endpoint`) VALUES (1,'jvb','/jvb'), (2,'jicofo','/jicofo'), (3,'prosody','/prosody'), @@ -209,7 +209,7 @@ INSERT INTO `jilo_agent_types` (`id`, `description`, `endpoint`) VALUES (5,'jibri','/jibri'); -- -------------------------------------------------------- -CREATE TABLE `platforms` ( +CREATE TABLE `platform` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `jitsi_url` varchar(255) NOT NULL, @@ -221,17 +221,17 @@ INSERT INTO `platforms` (`id`, `name`, `jitsi_url`, `jilo_database`) VALUES (1,'example.com','https://meet.example.com','../../jilo/jilo.db'); -- -------------------------------------------------------- -CREATE TABLE `hosts` ( +CREATE TABLE `host` ( `id` int(11) NOT NULL AUTO_INCREMENT, `address` varchar(255) NOT NULL, `platform_id` int(11) NOT NULL, `name` varchar(255), PRIMARY KEY (`id`), - CONSTRAINT `hosts_ibfk_1` FOREIGN KEY (`platform_id`) REFERENCES `platforms` (`id`) + CONSTRAINT `host_ibfk_1` FOREIGN KEY (`platform_id`) REFERENCES `platform` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- -------------------------------------------------------- -CREATE TABLE `jilo_agents` ( +CREATE TABLE `jilo_agent` ( `id` int(11) NOT NULL AUTO_INCREMENT, `host_id` int(11) NOT NULL, `agent_type_id` int(11) NOT NULL, @@ -239,12 +239,12 @@ CREATE TABLE `jilo_agents` ( `secret_key` varchar(255), `check_period` int(11) DEFAULT 0, PRIMARY KEY (`id`), - CONSTRAINT `jilo_agents_ibfk_1` FOREIGN KEY (`agent_type_id`) REFERENCES `jilo_agent_types` (`id`), - CONSTRAINT `jilo_agents_ibfk_2` FOREIGN KEY (`host_id`) REFERENCES `hosts` (`id`) + CONSTRAINT `jilo_agent_ibfk_1` FOREIGN KEY (`agent_type_id`) REFERENCES `jilo_agent_type` (`id`), + CONSTRAINT `jilo_agent_ibfk_2` FOREIGN KEY (`host_id`) REFERENCES `host` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- -------------------------------------------------------- -CREATE TABLE jilo_agent_checks ( +CREATE TABLE `jilo_agent_check` ( `id` int(11) NOT NULL AUTO_INCREMENT, `agent_id` int(11), `timestamp` datetime DEFAULT current_timestamp(), @@ -252,9 +252,8 @@ CREATE TABLE jilo_agent_checks ( `response_time_ms` int(11), `response_content` varchar(255), PRIMARY KEY (`id`), - CONSTRAINT `jilo_agent_checks_ibfk_1` FOREIGN KEY (`agent_id`) REFERENCES `jilo_agents` (`id`) + CONSTRAINT `jilo_agent_check_ibfk_1` FOREIGN KEY (`agent_id`) REFERENCES `jilo_agent` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; - COMMIT; diff --git a/plugins/logs/models/Log.php b/plugins/logs/models/Log.php index 43bc527..8da9daa 100644 --- a/plugins/logs/models/Log.php +++ b/plugins/logs/models/Log.php @@ -32,7 +32,7 @@ class Log { */ public function insertLog($userId, $message, $scope = 'user') { try { - $sql = 'INSERT INTO logs + $sql = 'INSERT INTO log (user_id, scope, message) VALUES (:user_id, :scope, :message)'; @@ -68,8 +68,8 @@ class Log { // Base query with user join $base_sql = 'SELECT l.*, u.username - FROM logs l - LEFT JOIN users u ON l.user_id = u.id'; + FROM log l + LEFT JOIN user u ON l.user_id = u.id'; // Add scope condition if ($scope === 'user') { diff --git a/plugins/register/models/register.php b/plugins/register/models/register.php index a8108a0..93a48db 100644 --- a/plugins/register/models/register.php +++ b/plugins/register/models/register.php @@ -49,9 +49,9 @@ class Register { // hash the password, don't store it plain $hashedPassword = password_hash($password, PASSWORD_DEFAULT); - // insert into users table + // insert into user table $sql = 'INSERT - INTO users (username, password) + INTO user (username, password) VALUES (:username, :password)'; $query = $this->db->prepare($sql); $query->bindValue(':username', $username); @@ -64,9 +64,9 @@ class Register { return false; } - // insert the last user id into users_meta table + // insert the last user id into user_meta table $sql2 = 'INSERT - INTO users_meta (user_id) + INTO user_meta (user_id) VALUES (:user_id)'; $query2 = $this->db->prepare($sql2); $query2->bindValue(':user_id', $this->db->lastInsertId()); diff --git a/tests/Unit/Classes/AgentTest.php b/tests/Unit/Classes/AgentTest.php index cc0f3e9..0024703 100644 --- a/tests/Unit/Classes/AgentTest.php +++ b/tests/Unit/Classes/AgentTest.php @@ -24,9 +24,9 @@ class AgentTest extends TestCase 'dbFile' => ':memory:' ]); - // Create jilo_agents table + // Create jilo_agent table $this->db->getConnection()->exec(" - CREATE TABLE jilo_agents ( + CREATE TABLE jilo_agent ( id INTEGER PRIMARY KEY AUTOINCREMENT, host_id INTEGER NOT NULL, agent_type_id INTEGER NOT NULL, @@ -38,18 +38,18 @@ class AgentTest extends TestCase ) "); - // Create jilo_agent_types table + // Create jilo_agent_type table $this->db->getConnection()->exec(" - CREATE TABLE jilo_agent_types ( + CREATE TABLE jilo_agent_type ( id INTEGER PRIMARY KEY AUTOINCREMENT, description TEXT NOT NULL, endpoint TEXT NOT NULL ) "); - // Create hosts table + // Create host table $this->db->getConnection()->exec(" - CREATE TABLE hosts ( + CREATE TABLE host ( id INTEGER PRIMARY KEY AUTOINCREMENT, platform_id INTEGER NOT NULL, name TEXT NOT NULL @@ -58,12 +58,12 @@ class AgentTest extends TestCase // Insert test host $this->db->getConnection()->exec(" - INSERT INTO hosts (id, platform_id, name) VALUES (1, 1, 'Test Host') + INSERT INTO host (id, platform_id, name) VALUES (1, 1, 'Test Host') "); // Insert test agent type $this->db->getConnection()->exec(" - INSERT INTO jilo_agent_types (id, description, endpoint) + INSERT INTO jilo_agent_type (id, description, endpoint) VALUES (1, 'Test Agent Type', '/api/test') "); @@ -85,7 +85,7 @@ class AgentTest extends TestCase $this->assertTrue($result); // Verify agent was created - $stmt = $this->db->getConnection()->prepare('SELECT * FROM jilo_agents WHERE host_id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT * FROM jilo_agent WHERE host_id = ?'); $stmt->execute([$hostId]); $agent = $stmt->fetch(PDO::FETCH_ASSOC); @@ -131,7 +131,7 @@ class AgentTest extends TestCase $this->agent->addAgent($hostId, $data); // Get agent ID - $stmt = $this->db->getConnection()->prepare('SELECT id FROM jilo_agents WHERE host_id = ? LIMIT 1'); + $stmt = $this->db->getConnection()->prepare('SELECT id FROM jilo_agent WHERE host_id = ? LIMIT 1'); $stmt->execute([$hostId]); $agentId = $stmt->fetch(PDO::FETCH_COLUMN); @@ -148,7 +148,7 @@ class AgentTest extends TestCase $this->assertTrue($result); // Verify update - $stmt = $this->db->getConnection()->prepare('SELECT * FROM jilo_agents WHERE id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT * FROM jilo_agent WHERE id = ?'); $stmt->execute([$agentId]); $agent = $stmt->fetch(PDO::FETCH_ASSOC); @@ -171,7 +171,7 @@ class AgentTest extends TestCase $this->agent->addAgent($hostId, $data); // Get agent ID - $stmt = $this->db->getConnection()->prepare('SELECT id FROM jilo_agents WHERE host_id = ? LIMIT 1'); + $stmt = $this->db->getConnection()->prepare('SELECT id FROM jilo_agent WHERE host_id = ? LIMIT 1'); $stmt->execute([$hostId]); $agentId = $stmt->fetch(PDO::FETCH_COLUMN); @@ -180,7 +180,7 @@ class AgentTest extends TestCase $this->assertTrue($result); // Verify deletion - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) FROM jilo_agents WHERE id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) FROM jilo_agent WHERE id = ?'); $stmt->execute([$agentId]); $count = $stmt->fetch(PDO::FETCH_COLUMN); @@ -201,7 +201,7 @@ class AgentTest extends TestCase $this->agent->addAgent($hostId, $data); // Get agent ID - $stmt = $this->db->getConnection()->prepare('SELECT id FROM jilo_agents WHERE host_id = ? LIMIT 1'); + $stmt = $this->db->getConnection()->prepare('SELECT id FROM jilo_agent WHERE host_id = ? LIMIT 1'); $stmt->execute([$hostId]); $agentId = $stmt->fetch(PDO::FETCH_COLUMN); diff --git a/tests/Unit/Classes/HostTest.php b/tests/Unit/Classes/HostTest.php index 8e1e08b..22e996f 100644 --- a/tests/Unit/Classes/HostTest.php +++ b/tests/Unit/Classes/HostTest.php @@ -23,9 +23,9 @@ class HostTest extends TestCase 'dbFile' => ':memory:' ]); - // Create hosts table + // Create host table $this->db->getConnection()->exec(" - CREATE TABLE hosts ( + CREATE TABLE host ( id INTEGER PRIMARY KEY AUTOINCREMENT, platform_id INTEGER NOT NULL, name TEXT NOT NULL, @@ -33,9 +33,9 @@ class HostTest extends TestCase ) "); - // Create jilo_agents table for relationship testing + // Create jilo_agent table for relationship testing $this->db->getConnection()->exec(" - CREATE TABLE jilo_agents ( + CREATE TABLE jilo_agent ( id INTEGER PRIMARY KEY AUTOINCREMENT, host_id INTEGER NOT NULL, agent_type_id INTEGER NOT NULL, @@ -60,7 +60,7 @@ class HostTest extends TestCase $this->assertTrue($result); // Verify host was created - $stmt = $this->db->getConnection()->prepare('SELECT * FROM hosts WHERE platform_id = ? AND name = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT * FROM host WHERE platform_id = ? AND name = ?'); $stmt->execute([$data['platform_id'], $data['name']]); $host = $stmt->fetch(\PDO::FETCH_ASSOC); @@ -107,7 +107,7 @@ class HostTest extends TestCase $this->host->addHost($data); // Get host ID - $stmt = $this->db->getConnection()->prepare('SELECT id FROM hosts WHERE platform_id = ? AND name = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT id FROM host WHERE platform_id = ? AND name = ?'); $stmt->execute([$data['platform_id'], $data['name']]); $hostId = $stmt->fetch(\PDO::FETCH_COLUMN); @@ -122,7 +122,7 @@ class HostTest extends TestCase $this->assertTrue($result); // Verify update - $stmt = $this->db->getConnection()->prepare('SELECT * FROM hosts WHERE id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT * FROM host WHERE id = ?'); $stmt->execute([$hostId]); $host = $stmt->fetch(\PDO::FETCH_ASSOC); @@ -141,13 +141,13 @@ class HostTest extends TestCase $this->host->addHost($data); // Get host ID - $stmt = $this->db->getConnection()->prepare('SELECT id FROM hosts WHERE platform_id = ? AND name = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT id FROM host WHERE platform_id = ? AND name = ?'); $stmt->execute([$data['platform_id'], $data['name']]); $hostId = $stmt->fetch(\PDO::FETCH_COLUMN); // Add test agent to the host $this->db->getConnection()->exec(" - INSERT INTO jilo_agents (host_id, agent_type_id, url, secret_key) + INSERT INTO jilo_agent (host_id, agent_type_id, url, secret_key) VALUES ($hostId, 1, 'http://test:8080', 'secret') "); @@ -156,13 +156,13 @@ class HostTest extends TestCase $this->assertTrue($result); // Verify host deletion - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) FROM hosts WHERE id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) FROM host WHERE id = ?'); $stmt->execute([$hostId]); $hostCount = $stmt->fetch(\PDO::FETCH_COLUMN); $this->assertEquals(0, $hostCount); // Verify agent deletion - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) FROM jilo_agents WHERE host_id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) FROM jilo_agent WHERE host_id = ?'); $stmt->execute([$hostId]); $agentCount = $stmt->fetch(\PDO::FETCH_COLUMN); $this->assertEquals(0, $agentCount); diff --git a/tests/Unit/Classes/LogTest.php b/tests/Unit/Classes/LogTest.php index 22bac6e..b490a59 100644 --- a/tests/Unit/Classes/LogTest.php +++ b/tests/Unit/Classes/LogTest.php @@ -20,9 +20,9 @@ class LogTest extends TestCase 'dbFile' => ':memory:' ]); - // Create users table + // Create user table $this->db->getConnection()->exec(" - CREATE TABLE users ( + CREATE TABLE user ( id INTEGER PRIMARY KEY, username TEXT NOT NULL ) @@ -30,18 +30,18 @@ class LogTest extends TestCase // Create test user $this->db->getConnection()->exec(" - INSERT INTO users (id, username) VALUES (1, 'testuser'), (2, 'testuser2') + INSERT INTO user (id, username) VALUES (1, 'testuser'), (2, 'testuser2') "); - // Create logs table + // Create log table $this->db->getConnection()->exec(" - CREATE TABLE logs ( + CREATE TABLE log ( id INTEGER PRIMARY KEY, user_id INTEGER, scope TEXT NOT NULL, message TEXT NOT NULL, time DATETIME DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES users(id) + FOREIGN KEY (user_id) REFERENCES user(id) ) "); @@ -53,7 +53,7 @@ class LogTest extends TestCase $result = $this->log->insertLog(1, 'Test message', 'test'); $this->assertTrue($result); - $stmt = $this->db->getConnection()->prepare("SELECT * FROM logs WHERE scope = ?"); + $stmt = $this->db->getConnection()->prepare("SELECT * FROM log WHERE scope = ?"); $stmt->execute(['test']); $log = $stmt->fetch(PDO::FETCH_ASSOC); diff --git a/tests/Unit/Classes/PlatformTest.php b/tests/Unit/Classes/PlatformTest.php index e3f2aa9..539a942 100644 --- a/tests/Unit/Classes/PlatformTest.php +++ b/tests/Unit/Classes/PlatformTest.php @@ -20,26 +20,26 @@ class PlatformTest extends TestCase 'dbFile' => ':memory:' ]); - // Create hosts table + // Create host table $this->db->getConnection()->exec(" - CREATE TABLE hosts ( + CREATE TABLE host ( id INTEGER PRIMARY KEY AUTOINCREMENT, platform_id INTEGER NOT NULL, name TEXT NOT NULL ) "); - // Create jilo_agents table + // Create jilo_agent table $this->db->getConnection()->exec(" - CREATE TABLE jilo_agents ( + CREATE TABLE jilo_agent ( id INTEGER PRIMARY KEY AUTOINCREMENT, host_id INTEGER NOT NULL ) "); - // Create platforms table + // Create platform table $this->db->getConnection()->exec(" - CREATE TABLE platforms ( + CREATE TABLE platform ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, jitsi_url TEXT NOT NULL, @@ -64,7 +64,7 @@ class PlatformTest extends TestCase $this->assertTrue($result); // Verify platform was created - $stmt = $this->db->getConnection()->prepare('SELECT * FROM platforms WHERE name = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT * FROM platform WHERE name = ?'); $stmt->execute([$data['name']]); $platform = $stmt->fetch(PDO::FETCH_ASSOC); @@ -77,7 +77,7 @@ class PlatformTest extends TestCase public function testGetPlatformDetails() { // Create test platform - $stmt = $this->db->getConnection()->prepare('INSERT INTO platforms (name, jitsi_url, jilo_database) VALUES (?, ?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO platform (name, jitsi_url, jilo_database) VALUES (?, ?, ?)'); $stmt->execute(['Test platform', 'https://jitsi.example.com', '/path/to/jilo.db']); $platformId = $this->db->getConnection()->lastInsertId(); @@ -95,7 +95,7 @@ class PlatformTest extends TestCase public function testEditPlatform() { // Create test platform - $stmt = $this->db->getConnection()->prepare('INSERT INTO platforms (name, jitsi_url, jilo_database) VALUES (?, ?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO platform (name, jitsi_url, jilo_database) VALUES (?, ?, ?)'); $stmt->execute(['Test platform', 'https://jitsi.example.com', '/path/to/jilo.db']); $platformId = $this->db->getConnection()->lastInsertId(); @@ -109,7 +109,7 @@ class PlatformTest extends TestCase $this->assertTrue($result); // Verify update - $stmt = $this->db->getConnection()->prepare('SELECT * FROM platforms WHERE id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT * FROM platform WHERE id = ?'); $stmt->execute([$platformId]); $platform = $stmt->fetch(PDO::FETCH_ASSOC); @@ -120,36 +120,36 @@ class PlatformTest extends TestCase public function testDeletePlatform() { // Create test platform - $stmt = $this->db->getConnection()->prepare('INSERT INTO platforms (name, jitsi_url, jilo_database) VALUES (?, ?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO platform (name, jitsi_url, jilo_database) VALUES (?, ?, ?)'); $stmt->execute(['Test platform', 'https://jitsi.example.com', '/path/to/jilo.db']); $platformId = $this->db->getConnection()->lastInsertId(); // Create test host - $stmt = $this->db->getConnection()->prepare('INSERT INTO hosts (platform_id, name) VALUES (?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO host (platform_id, name) VALUES (?, ?)'); $stmt->execute([$platformId, 'Test host']); $hostId = $this->db->getConnection()->lastInsertId(); // Create test agent - $stmt = $this->db->getConnection()->prepare('INSERT INTO jilo_agents (host_id) VALUES (?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO jilo_agent (host_id) VALUES (?)'); $stmt->execute([$hostId]); $result = $this->platform->deletePlatform($platformId); $this->assertTrue($result); // Verify platform deletion - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM platforms WHERE id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM platform WHERE id = ?'); $stmt->execute([$platformId]); $result = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(0, $result['count']); // Verify host deletion - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM hosts WHERE platform_id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM host WHERE platform_id = ?'); $stmt->execute([$platformId]); $result = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(0, $result['count']); // Verify agent deletion - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM jilo_agents WHERE host_id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM jilo_agent WHERE host_id = ?'); $stmt->execute([$hostId]); $result = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(0, $result['count']); @@ -167,7 +167,7 @@ class PlatformTest extends TestCase $this->assertTrue($result); // Verify platform was created - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM platforms WHERE name = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM platform WHERE name = ?'); $stmt->execute([$validData['name']]); $result = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(1, $result['count']); @@ -182,7 +182,7 @@ class PlatformTest extends TestCase $this->assertIsString($result); // Should return error message // Verify platform was not created - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM platforms WHERE name = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM platform WHERE name = ?'); $stmt->execute([$invalidData['name']]); $result = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(0, $result['count']); @@ -205,7 +205,7 @@ class PlatformTest extends TestCase $this->assertTrue($result); // Verify platform was created - $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM platforms WHERE jilo_database = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT COUNT(*) as count FROM platform WHERE jilo_database = ?'); $stmt->execute([$tempDb]); $result = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(1, $result['count']); diff --git a/tests/Unit/Classes/UserRegisterTest.php b/tests/Unit/Classes/UserRegisterTest.php index 9dbf8c2..64d9d90 100644 --- a/tests/Unit/Classes/UserRegisterTest.php +++ b/tests/Unit/Classes/UserRegisterTest.php @@ -23,18 +23,18 @@ class UserRegisterTest extends TestCase 'dbFile' => ':memory:' ]); - // Create users table + // Create user table $this->db->getConnection()->exec(" - CREATE TABLE users ( + CREATE TABLE user ( id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE, password TEXT NOT NULL ) "); - // Create users_meta table + // Create user_meta table $this->db->getConnection()->exec(" - CREATE TABLE users_meta ( + CREATE TABLE user_meta ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, name TEXT, @@ -42,7 +42,7 @@ class UserRegisterTest extends TestCase timezone TEXT, bio TEXT, avatar TEXT, - FOREIGN KEY (user_id) REFERENCES users(id) + FOREIGN KEY (user_id) REFERENCES user(id) ) "); @@ -55,7 +55,7 @@ class UserRegisterTest extends TestCase backup_codes TEXT, enabled TINYINT(1) NOT NULL DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE ) "); @@ -102,7 +102,7 @@ class UserRegisterTest extends TestCase $this->assertTrue($result); // Verify user was created - $stmt = $this->db->getConnection()->prepare('SELECT * FROM users WHERE username = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT * FROM user WHERE username = ?'); $stmt->execute(['testuser']); $user = $stmt->fetch(\PDO::FETCH_ASSOC); @@ -110,7 +110,7 @@ class UserRegisterTest extends TestCase $this->assertTrue(password_verify('password123', $user['password'])); // Verify user_meta was created - $stmt = $this->db->getConnection()->prepare('SELECT * FROM users_meta WHERE user_id = ?'); + $stmt = $this->db->getConnection()->prepare('SELECT * FROM user_meta WHERE user_id = ?'); $stmt->execute([$user['id']]); $meta = $stmt->fetch(\PDO::FETCH_ASSOC); @@ -123,7 +123,7 @@ class UserRegisterTest extends TestCase $password = 'password123'; $hashedPassword = password_hash($password, PASSWORD_DEFAULT); - $stmt = $this->db->getConnection()->prepare('INSERT INTO users (username, password) VALUES (?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO user (username, password) VALUES (?, ?)'); $stmt->execute(['testuser', $hashedPassword]); // Mock $_SERVER['REMOTE_ADDR'] for rate limiter @@ -163,12 +163,12 @@ class UserRegisterTest extends TestCase public function testGetUserDetails() { // Create a test user - $stmt = $this->db->getConnection()->prepare('INSERT INTO users (username, password) VALUES (?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO user (username, password) VALUES (?, ?)'); $stmt->execute(['testuser', 'hashedpassword']); $userId = $this->db->getConnection()->lastInsertId(); // Create user meta with some data - $stmt = $this->db->getConnection()->prepare('INSERT INTO users_meta (user_id, name, email) VALUES (?, ?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO user_meta (user_id, name, email) VALUES (?, ?, ?)'); $stmt->execute([$userId, 'Test User', 'test@example.com']); $userDetails = $this->user->getUserDetails($userId); diff --git a/tests/Unit/Classes/UserTest.php b/tests/Unit/Classes/UserTest.php index 5a96497..a47cac7 100644 --- a/tests/Unit/Classes/UserTest.php +++ b/tests/Unit/Classes/UserTest.php @@ -21,18 +21,18 @@ class UserTest extends TestCase 'dbFile' => ':memory:' ]); - // Create users table + // Create user table $this->db->getConnection()->exec(" - CREATE TABLE users ( + CREATE TABLE user ( id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE, password TEXT NOT NULL ) "); - // Create users_meta table + // Create user_meta table $this->db->getConnection()->exec(" - CREATE TABLE users_meta ( + CREATE TABLE user_meta ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, name TEXT, @@ -40,7 +40,7 @@ class UserTest extends TestCase timezone TEXT, bio TEXT, avatar TEXT, - FOREIGN KEY (user_id) REFERENCES users(id) + FOREIGN KEY (user_id) REFERENCES user(id) ) "); @@ -53,7 +53,7 @@ class UserTest extends TestCase backup_codes TEXT, enabled TINYINT(1) NOT NULL DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE ) "); @@ -99,7 +99,7 @@ class UserTest extends TestCase $password = 'password123'; $hashedPassword = password_hash($password, PASSWORD_DEFAULT); - $stmt = $this->db->getConnection()->prepare('INSERT INTO users (username, password) VALUES (?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO user (username, password) VALUES (?, ?)'); $stmt->execute(['testuser', $hashedPassword]); // Mock $_SERVER['REMOTE_ADDR'] for rate limiter @@ -139,12 +139,12 @@ class UserTest extends TestCase public function testGetUserDetails() { // Create a test user - $stmt = $this->db->getConnection()->prepare('INSERT INTO users (username, password) VALUES (?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO user (username, password) VALUES (?, ?)'); $stmt->execute(['testuser', 'hashedpassword']); $userId = $this->db->getConnection()->lastInsertId(); // Create user meta with some data - $stmt = $this->db->getConnection()->prepare('INSERT INTO users_meta (user_id, name, email) VALUES (?, ?, ?)'); + $stmt = $this->db->getConnection()->prepare('INSERT INTO user_meta (user_id, name, email) VALUES (?, ?, ?)'); $stmt->execute([$userId, 'Test User', 'test@example.com']); $userDetails = $this->user->getUserDetails($userId);