Skip to content

Commit 7f1b612

Browse files
mattia1208Giacomo117
authored andcommitted
test: failing test for PARSE_SERVER_AUTH_PROVIDERS env (string vs object)
1 parent f27b050 commit 7f1b612

3 files changed

Lines changed: 167 additions & 0 deletions

File tree

spec/AuthParserStandalone.spec.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Test standalone per verificare il parsing di PARSE_SERVER_AUTH_PROVIDERS
2+
// Questo test NON avvia Parse Server e testa solo la funzione parser
3+
4+
'use strict';
5+
6+
// Non importiamo helper.js per evitare di avviare il server
7+
const parsers = require('../lib/Options/parsers');
8+
const definitions = require('../lib/Options/Definitions');
9+
10+
describe('Auth Providers Parser (Standalone)', () => {
11+
12+
it('should parse auth providers JSON string to object with objectParser', () => {
13+
const authProvidersString = JSON.stringify({
14+
facebook: {
15+
appIds: ['test-facebook-app-id-1', 'test-facebook-app-id-2']
16+
},
17+
google: {
18+
clientId: 'test-google-client-id',
19+
clientSecret: 'test-google-client-secret'
20+
}
21+
});
22+
23+
const result = parsers.objectParser(authProvidersString);
24+
25+
expect(typeof result).toBe('object');
26+
expect(result).not.toBeNull();
27+
expect(result.facebook).toBeDefined();
28+
expect(result.facebook.appIds).toEqual(['test-facebook-app-id-1', 'test-facebook-app-id-2']);
29+
expect(result.google).toBeDefined();
30+
expect(result.google.clientId).toBe('test-google-client-id');
31+
expect(result.google.clientSecret).toBe('test-google-client-secret');
32+
});
33+
34+
it('should accept auth providers as object directly with objectParser', () => {
35+
const authProvidersObject = {
36+
facebook: {
37+
appIds: ['direct-facebook-app-id']
38+
},
39+
twitter: {
40+
consumerKey: 'test-consumer-key',
41+
consumerSecret: 'test-consumer-secret'
42+
}
43+
};
44+
45+
const result = parsers.objectParser(authProvidersObject);
46+
47+
expect(typeof result).toBe('object');
48+
expect(result.facebook).toBeDefined();
49+
expect(result.facebook.appIds).toEqual(['direct-facebook-app-id']);
50+
expect(result.twitter).toBeDefined();
51+
expect(result.twitter.consumerKey).toBe('test-consumer-key');
52+
});
53+
54+
it('should throw error for invalid JSON string', () => {
55+
expect(() => {
56+
parsers.objectParser('invalid-json-string-not-json');
57+
}).toThrow();
58+
59+
expect(() => {
60+
parsers.objectParser('just a plain string');
61+
}).toThrow();
62+
});
63+
64+
it('should verify auth definition in ParseServerOptions', () => {
65+
const authDefinition = definitions.ParseServerOptions.auth;
66+
67+
expect(authDefinition).toBeDefined();
68+
expect(authDefinition.env).toBe('PARSE_SERVER_AUTH_PROVIDERS');
69+
expect(authDefinition.help).toContain('authentication providers');
70+
});
71+
72+
it('CRITICAL TEST: auth definition should have objectParser action', () => {
73+
const authDefinition = definitions.ParseServerOptions.auth;
74+
75+
// Questo è il test più importante: verifica che ci sia l'action parser
76+
if (authDefinition.action) {
77+
// Se c'è l'action, testiamo che funzioni correttamente
78+
const testAuthString = JSON.stringify({
79+
facebook: { appIds: ['test'] },
80+
google: { clientId: 'test-client' }
81+
});
82+
const result = authDefinition.action(testAuthString);
83+
84+
expect(typeof result).toBe('object');
85+
expect(result.facebook).toBeDefined();
86+
expect(result.google).toBeDefined();
87+
88+
// Testa anche che accetti oggetti direttamente
89+
const testAuthObject = { facebook: { appIds: ['test2'] } };
90+
const result2 = authDefinition.action(testAuthObject);
91+
expect(result2.facebook.appIds).toEqual(['test2']);
92+
93+
} else {
94+
// Se non c'è l'action, questo test fallisce intenzionalmente
95+
// per evidenziare il problema
96+
fail('PROBLEMA TROVATO: auth definition manca di action parser! ' +
97+
'Quando PARSE_SERVER_AUTH_PROVIDERS viene passata come variabile d\'ambiente, ' +
98+
'verrà trattata come stringa invece che come oggetto. ' +
99+
'Aggiungi "action: parsers.objectParser" alla definizione di auth in Definitions.js');
100+
}
101+
});
102+
103+
it('should demonstrate the problem: environment variable stays as string without parser', () => {
104+
const authDefinition = definitions.ParseServerOptions.auth;
105+
106+
// Simula quello che succede quando viene passata una variabile d'ambiente
107+
const envValue = '{"facebook":{"appIds":["test"]}}';
108+
109+
if (!authDefinition.action) {
110+
// Senza action parser, la stringa rimane stringa
111+
expect(typeof envValue).toBe('string');
112+
console.log('⚠️ PROBLEMA: La variabile d\'ambiente PARSE_SERVER_AUTH_PROVIDERS ' +
113+
'viene passata come stringa e non viene parsata in oggetto!');
114+
} else {
115+
// Con action parser, viene convertita in oggetto
116+
const parsed = authDefinition.action(envValue);
117+
expect(typeof parsed).toBe('object');
118+
console.log('✓ OK: La variabile d\'ambiente viene correttamente parsata in oggetto');
119+
}
120+
});
121+
});

spec/CLI.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,25 @@ describe('execution', () => {
333333
handleStderr(childProcess, done);
334334
handleError(childProcess, done);
335335
});
336+
337+
it('should parse PARSE_SERVER_AUTH_PROVIDERS environment variable from JSON string to object', done => {
338+
const env = { ...process.env };
339+
env.NODE_OPTIONS = '--dns-result-order=ipv4first --trace-deprecation';
340+
env.PARSE_SERVER_AUTH_PROVIDERS = JSON.stringify({
341+
facebook: {
342+
appIds: ['test-facebook-app-id']
343+
},
344+
google: {
345+
clientId: 'test-google-client-id'
346+
}
347+
});
348+
env.PARSE_SERVER_APPLICATION_ID = 'testAppId';
349+
env.PARSE_SERVER_MASTER_KEY = 'testMasterKey';
350+
env.PARSE_SERVER_DATABASE_URI = databaseURI;
351+
352+
childProcess = spawn(binPath, [], { env });
353+
handleStdout(childProcess, done, aggregatedData, ['parse-server running on']);
354+
handleStderr(childProcess, done);
355+
handleError(childProcess, done);
356+
});
336357
});

spec/parsers.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,29 @@ describe('parsers', () => {
8080
expect(parser(1)).toEqual(1);
8181
expect(parser('blabla')).toEqual('blabla');
8282
});
83+
84+
it('parses auth providers JSON string with objectParser', () => {
85+
const parser = objectParser;
86+
const authProvidersString = JSON.stringify({
87+
facebook: {
88+
appIds: ['test-app-id-1', 'test-app-id-2']
89+
},
90+
google: {
91+
clientId: 'test-client-id',
92+
clientSecret: 'test-client-secret'
93+
}
94+
});
95+
const expectedObject = {
96+
facebook: {
97+
appIds: ['test-app-id-1', 'test-app-id-2']
98+
},
99+
google: {
100+
clientId: 'test-client-id',
101+
clientSecret: 'test-client-secret'
102+
}
103+
};
104+
105+
expect(parser(authProvidersString)).toEqual(expectedObject);
106+
expect(parser(expectedObject)).toEqual(expectedObject);
107+
});
83108
});

0 commit comments

Comments
 (0)