-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.mjs
57 lines (52 loc) · 1.59 KB
/
test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import Promise from "bluebird";
import { strictEqual } from "assert";
import { rejects } from "assert-exception";
import {
createIoServerAsync,
createIoClientAsync,
createSession
} from "./test-helpers";
import firebaseAdmin from "firebase-admin";
import createFirebaseAdminMiddlware from "./";
import credential from "./.credential";
let app, middleware, server, port;
it.before(async () => {
app = firebaseAdmin.initializeApp({
credential: firebaseAdmin.credential.cert(credential)
});
middleware = createFirebaseAdminMiddlware(app);
server = await createIoServerAsync(middleware);
port = server.address().port;
});
it.after(async () => {
app.delete();
server.destroy();
});
it("should deny unauthorized user using deny mode(default)", async () => {
const error = await rejects(createIoClientAsync(port));
const expectMessage = "Decoding Firebase session cookie failed";
strictEqual(error.message.slice(0, expectMessage.length), expectMessage);
});
it(
"should allow authorized user, and middleware have user claims cache(default)",
async () => {
const session = await createSession(
middleware,
"CUCPCuD50xgKeEfVggJ1fYQYNOj1"
);
server.io.on("connect", client => {
client.on("claims", resolve => {
resolve(middleware.getCache(client));
});
});
const client = await createIoClientAsync(port, { session });
await new Promise(async resolve => {
client.emit("claims", claims => {
strictEqual(claims.email, "[email protected]");
client.close();
resolve();
});
});
},
{ timeout: 3000 }
);