Skip to content

Commit acda705

Browse files
committed
FirebaseServerApp unit tests
1 parent 9e3fe1b commit acda705

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

packages/app/src/firebaseServerApp.test.ts

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ import { expect } from 'chai';
1919
import '../test/setup';
2020
import { ComponentContainer } from '@firebase/component';
2121
import { FirebaseServerAppImpl } from './firebaseServerApp';
22-
import { FirebaseServerAppSettings } from './public-types';
22+
import { FirebaseApp, FirebaseServerAppSettings } from './public-types';
23+
24+
const VALID_INSTATLLATIONS_AUTH_TOKEN_SECONDPART: string =
25+
'foo.eyJhcHBJZCI6IjE6MDAwMDAwMDAwMDAwOndlYjowMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwiZXhwIjoiMDAwMDAwMD' +
26+
'AwMCIsImZpZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJwcm9qZWN0TnVtYmVyIjoiMDAwMDAwMDAwMDAwIn0.foo';
27+
28+
const INVALID_INSTATLLATIONS_AUTH_TOKEN: string =
29+
'foo.eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9eyJhcHBJZCI6IjE6MDAwMDAwMDAwMDAwOndlYjowMDAwMDAwMDAwMD' +
30+
'AwMDAwMDAwMDAwIiwiZXhwIjowMDAwMDAwMDAwLCJwcm9qZWN0TnVtYmVyIjowMDAwMDAwMDAwMDB9.foo';
31+
32+
const INVALID_INSTATLLATIONS_AUTH_TOKEN_ONE_PART: string =
33+
'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9eyJhcHBJZCI6IjE6MDAwMDAwMDAwMDAwOndlYjowMDAwMDAwMDAwMD' +
34+
'AwMDAwMDAwMDAwIiwiZXhwIjowMDAwMDAwMDAwLCJwcm9qZWN0TnVtYmVyIjowMDAwMDAwMDAwMDB9';
2335

2436
describe('FirebaseServerApp', () => {
2537
it('has various accessors', () => {
@@ -155,4 +167,74 @@ describe('FirebaseServerApp', () => {
155167

156168
expect(JSON.stringify(app)).to.eql(undefined);
157169
});
170+
171+
it('parses valid installationsAuthToken', () => {
172+
const options = {
173+
apiKey: 'APIKEY'
174+
};
175+
176+
const serverAppSettings: FirebaseServerAppSettings = {
177+
automaticDataCollectionEnabled: false,
178+
installationsAuthToken: VALID_INSTATLLATIONS_AUTH_TOKEN_SECONDPART
179+
};
180+
181+
let app: FirebaseApp | null = null;
182+
try {
183+
app = new FirebaseServerAppImpl(
184+
options,
185+
serverAppSettings,
186+
'testName',
187+
new ComponentContainer('test')
188+
);
189+
} catch (e) {}
190+
expect(app).to.not.be.null;
191+
});
192+
193+
it('invalid installationsAuthToken throws', () => {
194+
const options = {
195+
apiKey: 'APIKEY'
196+
};
197+
198+
const serverAppSettings: FirebaseServerAppSettings = {
199+
automaticDataCollectionEnabled: false,
200+
installationsAuthToken: INVALID_INSTATLLATIONS_AUTH_TOKEN
201+
};
202+
203+
let failed = false;
204+
try {
205+
new FirebaseServerAppImpl(
206+
options,
207+
serverAppSettings,
208+
'testName',
209+
new ComponentContainer('test')
210+
);
211+
} catch (e) {
212+
failed = true;
213+
}
214+
expect(failed).to.be.true;
215+
});
216+
217+
it('invalid single part installationsAuthToken throws', () => {
218+
const options = {
219+
apiKey: 'APIKEY'
220+
};
221+
222+
const serverAppSettings: FirebaseServerAppSettings = {
223+
automaticDataCollectionEnabled: false,
224+
installationsAuthToken: INVALID_INSTATLLATIONS_AUTH_TOKEN_ONE_PART
225+
};
226+
227+
let failed = false;
228+
try {
229+
new FirebaseServerAppImpl(
230+
options,
231+
serverAppSettings,
232+
'testName',
233+
new ComponentContainer('test')
234+
);
235+
} catch (e) {
236+
failed = true;
237+
}
238+
expect(failed).to.be.true;
239+
});
158240
});

packages/app/src/firebaseServerApp.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ export class FirebaseServerAppImpl
8181
} catch (e) {
8282
console.warn(e);
8383
}
84-
if (!this._installationsId) {
85-
console.error('INVALID SERVER APP INSTALLATIONS AUTH TOKEN!');
84+
if (this._installationsId === null) {
85+
throw ERROR_FACTORY.create(
86+
AppError.INVALID_SERVER_APP_INSTALLATIONS_AUTH_TOKEN
87+
);
8688
}
8789
}
8890

0 commit comments

Comments
 (0)