fix(tests): make Turnstile CAPTCHA optional for tests
- Turnstile validation only required when TURNSTILE_SECRET_KEY is set - Allows tests to run without CAPTCHA in test environment - Fixes matching-runs-audit test failures caused by missing turnstileToken - Update validators.js to conditionally require turnstileToken - Update auth.js controller to skip verification when not configured
This commit is contained in:
@@ -18,35 +18,37 @@ async function register(req, res, next) {
|
||||
try {
|
||||
const { username, email, password, firstName, lastName, wsdcId, turnstileToken } = req.body;
|
||||
|
||||
// Verify Turnstile token
|
||||
// Verify Turnstile token (only if TURNSTILE_SECRET_KEY is configured)
|
||||
const turnstileSecret = process.env.TURNSTILE_SECRET_KEY;
|
||||
const turnstileVerifyUrl = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
|
||||
if (turnstileSecret && turnstileToken) {
|
||||
const turnstileVerifyUrl = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
|
||||
|
||||
try {
|
||||
const turnstileResponse = await fetch(turnstileVerifyUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
secret: turnstileSecret,
|
||||
response: turnstileToken,
|
||||
remoteip: getClientIP(req),
|
||||
}),
|
||||
});
|
||||
try {
|
||||
const turnstileResponse = await fetch(turnstileVerifyUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
secret: turnstileSecret,
|
||||
response: turnstileToken,
|
||||
remoteip: getClientIP(req),
|
||||
}),
|
||||
});
|
||||
|
||||
const turnstileResult = await turnstileResponse.json();
|
||||
const turnstileResult = await turnstileResponse.json();
|
||||
|
||||
if (!turnstileResult.success) {
|
||||
return res.status(400).json({
|
||||
if (!turnstileResult.success) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: 'CAPTCHA verification failed. Please try again.',
|
||||
});
|
||||
}
|
||||
} catch (turnstileError) {
|
||||
console.error('Turnstile verification error:', turnstileError);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
error: 'CAPTCHA verification failed. Please try again.',
|
||||
});
|
||||
}
|
||||
} catch (turnstileError) {
|
||||
console.error('Turnstile verification error:', turnstileError);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
error: 'CAPTCHA verification failed. Please try again.',
|
||||
});
|
||||
}
|
||||
|
||||
// Check if user already exists
|
||||
|
||||
Reference in New Issue
Block a user