|
| 1 | +const chai = require('chai'); |
| 2 | +const processor = require('../src/proxy/processors/push-action/checkUserPushPermission'); |
| 3 | +const { Action } = require('../src/proxy/actions/Action'); |
| 4 | +const { expect } = chai; |
| 5 | +const db = require('../src/db'); |
| 6 | +chai.should(); |
| 7 | + |
| 8 | +const TEST_ORG = 'finos'; |
| 9 | +const TEST_REPO = 'test'; |
| 10 | +const TEST_URL = 'https://github.com/finos/user-push-perms-test.git'; |
| 11 | +const TEST_USERNAME_1 = 'push-perms-test'; |
| 12 | +const TEST_EMAIL_1 = '[email protected]'; |
| 13 | +const TEST_USERNAME_2 = 'push-perms-test-2'; |
| 14 | +const TEST_EMAIL_2 = '[email protected]'; |
| 15 | +const TEST_EMAIL_3 = '[email protected]'; |
| 16 | + |
| 17 | +describe('CheckUserPushPermissions...', async () => { |
| 18 | + before(async function () { |
| 19 | + await db.deleteRepo(TEST_REPO); |
| 20 | + await db.deleteUser(TEST_USERNAME_1); |
| 21 | + |
| 22 | + await db.createRepo({ |
| 23 | + project: TEST_ORG, |
| 24 | + name: TEST_REPO, |
| 25 | + url: TEST_URL, |
| 26 | + }); |
| 27 | + await db.createUser(TEST_USERNAME_1, 'abc', TEST_EMAIL_1, TEST_USERNAME_1, false); |
| 28 | + await db.addUserCanPush(TEST_REPO, TEST_USERNAME_1); |
| 29 | + |
| 30 | + await db.createUser(TEST_USERNAME_2, 'abc', TEST_EMAIL_2, TEST_USERNAME_2, false); |
| 31 | + }); |
| 32 | + |
| 33 | + after(async function () { |
| 34 | + await db.deleteRepo(TEST_REPO); |
| 35 | + await db.deleteUser(TEST_USERNAME_1); |
| 36 | + await db.deleteUser(TEST_USERNAME_2); |
| 37 | + }); |
| 38 | + |
| 39 | + it('A committer that is approved should be allowed to push...', async () => { |
| 40 | + const action = new Action('1', 'type', 'method', 1, TEST_ORG + '/' + TEST_REPO); |
| 41 | + action.userEmail = TEST_EMAIL_1; |
| 42 | + const { error } = await processor.exec(null, action); |
| 43 | + expect(error).to.be.false; |
| 44 | + }); |
| 45 | + |
| 46 | + it('A committer that is NOT approved should NOT be allowed to push...', async () => { |
| 47 | + const action = new Action('1', 'type', 'method', 1, TEST_ORG + '/' + TEST_REPO); |
| 48 | + action.userEmail = TEST_EMAIL_2; |
| 49 | + const { error, errorMessage } = await processor.exec(null, action); |
| 50 | + expect(error).to.be.true; |
| 51 | + expect(errorMessage).to.contains('Your push has been blocked'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('An unknown committer should NOT be allowed to push...', async () => { |
| 55 | + const action = new Action('1', 'type', 'method', 1, TEST_ORG + '/' + TEST_REPO); |
| 56 | + action.userEmail = TEST_EMAIL_3; |
| 57 | + const { error, errorMessage } = await processor.exec(null, action); |
| 58 | + expect(error).to.be.true; |
| 59 | + expect(errorMessage).to.contains('Your push has been blocked'); |
| 60 | + }); |
| 61 | +}); |
0 commit comments