|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const Config = require('../lib/Config'); |
| 4 | +const { CheckState } = require('../lib/Security/Check'); |
| 5 | +const CheckGroupServerConfig = require('../lib/Security/CheckGroups/CheckGroupServerConfig'); |
| 6 | +const CheckGroupDatabase = require('../lib/Security/CheckGroups/CheckGroupDatabase'); |
| 7 | + |
| 8 | +describe('Security Check Groups', () => { |
| 9 | + let config; |
| 10 | + |
| 11 | + beforeEach(async () => { |
| 12 | + config = { |
| 13 | + appId: 'test', |
| 14 | + appName: 'ExampleAppName', |
| 15 | + publicServerURL: 'http://localhost:8378/1', |
| 16 | + security: { |
| 17 | + enableCheck: true, |
| 18 | + enableCheckLog: false, |
| 19 | + }, |
| 20 | + }; |
| 21 | + await reconfigureServer(config); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('CheckGroupServerConfig', () => { |
| 25 | + it('is subclassed correctly', async () => { |
| 26 | + const group = new CheckGroupServerConfig(); |
| 27 | + expect(group.name()).toBeDefined(); |
| 28 | + expect(group.checks().length).toBeGreaterThan(0); |
| 29 | + }); |
| 30 | + |
| 31 | + it('checks succeed correctly', async () => { |
| 32 | + config.masterKey = 'aMoreSecur3Passwor7!'; |
| 33 | + config.security.enableCheckLog = false; |
| 34 | + config.allowClientClassCreation = false; |
| 35 | + await reconfigureServer(config); |
| 36 | + |
| 37 | + const group = new CheckGroupServerConfig(); |
| 38 | + await group.run(); |
| 39 | + expect(group.checks()[0].checkState()).toBe(CheckState.success); |
| 40 | + expect(group.checks()[1].checkState()).toBe(CheckState.success); |
| 41 | + expect(group.checks()[2].checkState()).toBe(CheckState.success); |
| 42 | + }); |
| 43 | + |
| 44 | + it('checks fail correctly', async () => { |
| 45 | + config.masterKey = 'insecure'; |
| 46 | + config.security.enableCheckLog = true; |
| 47 | + config.allowClientClassCreation = true; |
| 48 | + await reconfigureServer(config); |
| 49 | + |
| 50 | + const group = new CheckGroupServerConfig(); |
| 51 | + await group.run(); |
| 52 | + expect(group.checks()[0].checkState()).toBe(CheckState.fail); |
| 53 | + expect(group.checks()[1].checkState()).toBe(CheckState.fail); |
| 54 | + expect(group.checks()[2].checkState()).toBe(CheckState.fail); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe('CheckGroupDatabase', () => { |
| 59 | + it('is subclassed correctly', async () => { |
| 60 | + const group = new CheckGroupDatabase(); |
| 61 | + expect(group.name()).toBeDefined(); |
| 62 | + expect(group.checks().length).toBeGreaterThan(0); |
| 63 | + }); |
| 64 | + |
| 65 | + it('checks succeed correctly', async () => { |
| 66 | + const config = Config.get(Parse.applicationId); |
| 67 | + config.database.adapter._uri = 'protocol://user:aMoreSecur3Passwor7!@example.com'; |
| 68 | + const group = new CheckGroupDatabase(); |
| 69 | + await group.run(); |
| 70 | + expect(group.checks()[0].checkState()).toBe(CheckState.success); |
| 71 | + }); |
| 72 | + |
| 73 | + it('checks fail correctly', async () => { |
| 74 | + const config = Config.get(Parse.applicationId); |
| 75 | + config.database.adapter._uri = 'protocol://user:insecure@example.com'; |
| 76 | + const group = new CheckGroupDatabase(); |
| 77 | + await group.run(); |
| 78 | + expect(group.checks()[0].checkState()).toBe(CheckState.fail); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments