Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions test-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Test file for CodeBuddy AI review

// Issue 1: No error handling
function fetchUser(userId) {
return fetch(`https://api.example.com/users/${userId}`)
.then(response => response.json());
}

// Issue 2: SQL injection vulnerability
function getUser(username) {
const query = "SELECT * FROM users WHERE username = '" + username + "'";
return db.query(query);
}

// Issue 3: Inefficient nested loops (O(n²))
function findDuplicates(arr) {
let duplicates = [];
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j]) {
duplicates.push(arr[i]);
}
}
}
return duplicates;
}

// Issue 4: No input validation
function calculateTotal(items) {
let total = 0;
for (let i = 0; i < items.length; i++) {
total += items[i].price;
}
return total;
}

// Issue 5: Hardcoded credentials (SECURITY RISK!)
const config = {
apiKey: "sk-1234567890abcdef",
password: "admin123",
dbUrl: "mongodb://admin:password123@localhost:27017"
};

module.exports = { fetchUser, getUser, findDuplicates, calculateTotal, config };
// final test with gemini-2.0-flash-exp
// testing gemini-2.0-flash-lite