UNPKG

realm-object-server

Version:

Realm Object Server

44 lines 2.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const TokenValidator_1 = require("./TokenValidator"); const Token_1 = require("./Token"); const Logger_1 = require("./Logger"); const RealmFactory_1 = require("../RealmFactory"); const RealmDirectoryClient_1 = require("../service-clients/RealmDirectoryClient"); const SingleProcessDiscovery_1 = require("../discovery/SingleProcessDiscovery"); const chai_1 = require("chai"); const fs_1 = require("fs"); const path_1 = require("path"); const privateKey = fs_1.readFileSync(path_1.join(__dirname, "../../fixtures/keys/auth.key")).toString(); const publicKey = fs_1.readFileSync(path_1.join(__dirname, "../../fixtures/keys/auth.pub")).toString(); describe("TokenValidator", () => { it("parses an access token", () => { const adminToken = Token_1.generateAdminToken({ privateKey: privateKey, canSkipRevocationCheck: true }); const realmDirectoryClient = new RealmDirectoryClient_1.RealmDirectoryClient(null, adminToken, null, null); const realmFactory = new RealmFactory_1.RealmFactory({ adminToken, dataPath: "foo", discovery: new SingleProcessDiscovery_1.SingleProcessDiscovery(), logger: new Logger_1.MuteLogger(), realmDirectoryClient: realmDirectoryClient, ssl: null }); const tokenValidator = new TokenValidator_1.TokenValidator({ logger: new Logger_1.MuteLogger(), publicKey, realmFactory, disableRevocation: true }); const exampleJWT = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjVkYTY0NzI2NTM5NWM0ZmY0NzE2ZmE4NyIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZWFsbSIsImV4cCI6NDU3MTE3ODYzOSwiaWF0Ijo0NTcxMTc4Mjc5LCJpc3MiOiJyZWFsbSIsInN0aXRjaF9kYXRhIjp7InJlYWxtX2FjY2VzcyI6WyJkb3dubG9hZCIsInVwbG9hZCIsIm1hbmFnZSJdLCJyZWFsbV9wYXRoIjoiLzVkYTY0NzI3NTM5NWM0ZmY0NzE2ZmE5My9leGFtcGxlIiwicmVhbG1fc3luY19sYWJlbCI6ImRlZmF1bHQifSwic3RpdGNoX2RldklkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwic3RpdGNoX2RvbWFpbklkIjoiNWRhNjQ3MjY1Mzk1YzRmZjQ3MTZmYTg2Iiwic3ViIjoiNWRhNjQ3Mjc1Mzk1YzRmZjQ3MTZmYTkzIiwidHlwIjoiYWNjZXNzIiwidXNlcl9kYXRhIjpudWxsfQ.SQyB0XLTksSKrDK8gb6wBc6zT1zBKuHMx8lQtOwPpqChCwQfbR2f1A7PoyRAVIIVMqso7Um4zwCVZntv4-LA0tZRiycqqvo1xh_ZziZjyegm5zXhlcpPMrO5zHfmQptgG8vb83ezv0cY3E6yWgqQxDKgFTCozF3lI9HAM0ZNydzPMZd0bkhZUZGY4NYBbrOzpy2Fd4rBUCy4xg-mQL4_-iO-lpWuoc3zbFelohcFdO3ORC7oczhqI-fShnSMRwXCtk4IoNpS9F14WLsg_84k-HXIpMei9rwBLb-M9nkuHgoXVeKcCyau5rmaPylB1kd3uzv7AKqFbS1wRjDLGJSobQ"; const token = tokenValidator.parse(exampleJWT); chai_1.assert.instanceOf(token, Token_1.AccessToken); const accessToken = token; chai_1.assert.strictEqual(accessToken.path, "/5da647275395c4ff4716fa93/example"); chai_1.assert.deepEqual(accessToken.access, ["download", "upload", "manage"]); chai_1.assert.strictEqual(accessToken.syncLabel, "default"); }); }); //# sourceMappingURL=TokenValidator.spec.js.map