Skip to content
File

Blob: fuzzilli/analytics-mock.js

javascript53 lines
1function shouldChaos() {
2 return Math.random() < 0.1; // 10% chaos for Analytics
3}
4 
5function getChaoticAnalyticsResponse() {
6 const chaos = Math.random();
7 if (chaos < 0.3) {
8 // Data ingestion limit exceeded
9 return new Response('Daily quota exceeded', { status: 429 });
10 } else if (chaos < 0.5) {
11 // Invalid data format
12 return new Response('Invalid analytics data format', { status: 400 });
13 } else if (chaos < 0.7) {
14 // Service temporarily down
15 return new Response('Analytics service temporarily unavailable', {
16 status: 503,
17 });
18 } else if (chaos < 0.9) {
19 // Success but with warning
20 return new Response('Data accepted with warnings', { status: 202 });
21 } else {
22 // Unexpected server behavior
23 return new Response('<html><body>Maintenance page</body></html>', {
24 status: 200,
25 headers: { 'Content-Type': 'text/html' },
26 });
27 }
28}
29 
30export default {
31 async fetch(request, env, ctx) {
32 // Random chaos injection
33 if (shouldChaos()) {
34 return getChaoticAnalyticsResponse();
35 }
36 
37 // Analytics Engine accepts data points via HTTP POST
38 if (request.method === 'POST') {
39 const body = await request.text();
40 console.log('Analytics data received:', body.slice(0, 100));
41 
42 // Sometimes simulate processing delay or partial acceptance
43 if (Math.random() < 0.05) {
44 return new Response('Partial data accepted', { status: 206 });
45 }
46 
47 return new Response('', { status: 200 });
48 }
49 
50 return new Response('Analytics mock ready', { status: 200 });
51 },
52};