{"record":{"id":"3ba1b8cd7c4f415e","repo":"quarkusio/quarkus","slug":"username-s-not-in-the-test-user-table","errorCode":null,"errorMessage":"Username '%s' not in the 'test_user' table","messagePattern":"Username '(.+?)' not in the 'test_user' table","errorType":"exception","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"integration-tests/elytron-security-jdbc/src/main/java/io/quarkus/elytron/security/jdbc/it/JdbcPermissionChecker.java","lineNumber":33,"sourceCode":"@ApplicationScoped\npublic class JdbcPermissionChecker {\n\n    @Inject\n    AgroalDataSource defaultDataSource;\n\n    @Transactional\n    @PermissionChecker(\"admin-role-in-db\")\n    boolean hasAdminRole(String usernameHeader) {\n        String username = switch (usernameHeader) {\n            case \"admin\" -> \"admin\";\n            case \"user\" -> \"user\";\n            default -> throw new IllegalArgumentException(\"Invalid username: \" + usernameHeader);\n        };\n        try (Connection connection = defaultDataSource.getConnection(); Statement stat = connection.createStatement()) {\n            try (ResultSet roleQuery = stat\n                    .executeQuery(\"select u.role from test_user u where u.username='\" + username + \"'\")) {\n                if (!roleQuery.first()) {\n                    throw new IllegalStateException(\"Username '%s' not in the 'test_user' table\".formatted(username));\n                }\n                var role = roleQuery.getString(1);\n                return \"admin\".equals(role);\n            }\n        } catch (SQLException e) {\n            throw new RuntimeException(e);\n        }\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":43,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/elytron-security-jdbc/src/main/java/io/quarkus/elytron/security/jdbc/it/JdbcPermissionChecker.java#L15-L43","documentation":"IllegalStateException thrown by JdbcPermissionChecker.hasAdminRole() when the SQL query \"select u.role from test_user u where u.username='...'\" returns no rows. The authenticated username is valid but not present in the test_user database table, so the role-based permission cannot be resolved.","triggerScenarios":"Permission check runs against a database whose test_user table lacks a row for the resolved username — empty/never-seeded DB, or a username whose lookup was just added to the switch but not seeded in the table.","commonSituations":"Dev/test database not initialized with seed data; schema created by a different migration; DB wiped between runs; inserting into a different datasource than defaultDataSource.","solutions":["Seed the test_user table with rows for the expected usernames (admin/user and their roles)","Verify the datasource defaultDataSource points to the database containing the seed data","Check schema/migration scripts run before the permission check executes","Confirm the username string written into the query matches the row exactly"],"exampleFix":"// before: empty table -> no rows\n// after (seed)\nINSERT INTO test_user (username, role) VALUES ('admin', 'admin');\nINSERT INTO test_user (username, role) VALUES ('user', 'user');","handlingStrategy":"validation","validationCode":"try (Connection c = defaultDataSource.getConnection();\n     PreparedStatement ps = c.prepareStatement(\"select count(*) from test_user where username=?\")) {\n    ps.setString(1, username);\n    try (ResultSet rs = ps.executeQuery()) {\n        if (!rs.next() || rs.getInt(1) == 0) {\n            throw new IllegalStateException(\"User not seeded: \" + username);\n        }\n    }\n}","typeGuard":"boolean userExists(String username) throws SQLException {\n    // query test_user for the row; return true only when present\n    return countByUsername(username) > 0;\n}","tryCatchPattern":"try {\n    return checkRole(username);\n} catch (SQLException e) {\n    throw new RuntimeException(\"DB access failed during permission check\", e);\n}","preventionTips":["Seed test_user with all usernames the permission checker can resolve","Use parameterized statements instead of string-concatenated SQL","Verify the datasource points at the seeded database before running tests","Add startup validation that required rows exist"],"tags":["security","jdbc","database","missing-data"],"backgroundTag":"user-not-found-in-database","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}