-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bump to 1.0.1, add exec, merge user config
- add "bin" to package.json to support running git-proxy as an executable. Largely taken from #184 and fixes #183 - refactor config to read in `user-settings.json` from local directory to support custom user settings outside the repo. - load default settings from a module instead of explicit file path - add test for default & user setting merging - bump @finos/git-proxy to 1.0.1
- Loading branch information
1 parent
a7929cc
commit fd7bc16
Showing
4 changed files
with
140 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env node | ||
const proxy = require('./src/proxy'); | ||
const service = require('./src/service'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* eslint-disable max-len */ | ||
const chai = require('chai'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const defaultSettings = require('../resources/config.json'); | ||
|
||
chai.should(); | ||
const expect = chai.expect; | ||
|
||
describe('default configuration', function () { | ||
it('should use default values if no user-settings.json file exists', function () { | ||
const config = require('../src/config'); | ||
|
||
expect(config.getAuthentication()).to.be.eql( | ||
defaultSettings.authentication[0], | ||
); | ||
expect(config.getDatabase()).to.be.eql(defaultSettings.sink[0]); | ||
expect(config.getTempPasswordConfig()).to.be.eql( | ||
defaultSettings.tempPassword, | ||
); | ||
expect(config.getAuthorisedList()).to.be.eql( | ||
defaultSettings.authorisedList, | ||
); | ||
}); | ||
after(function () { | ||
delete require.cache[require.resolve('../src/config')]; | ||
}); | ||
}); | ||
|
||
describe('user configuration', function () { | ||
let tempDir; | ||
let tempUserFile; | ||
let curDirUserFile; | ||
|
||
beforeEach(function () { | ||
tempDir = fs.mkdtempSync('gitproxy-test'); | ||
tempUserFile = path.join(tempDir, 'user-settings.json'); | ||
curDirUserFile = path.join(process.cwd(), 'user-settings.json'); | ||
fs.symlinkSync(tempUserFile, curDirUserFile); | ||
}); | ||
|
||
it('should override default settings for authorisedList', function () { | ||
const user = { | ||
authorisedList: [ | ||
{ | ||
project: 'foo', | ||
name: 'bar', | ||
url: 'https://github.com/foo/bar.git', | ||
}, | ||
], | ||
}; | ||
fs.writeFileSync(tempUserFile, JSON.stringify(user)); | ||
|
||
const config = require('../src/config'); | ||
|
||
expect(config.getAuthorisedList()).to.be.eql(user.authorisedList); | ||
expect(config.getAuthentication()).to.be.eql( | ||
defaultSettings.authentication[0], | ||
); | ||
expect(config.getDatabase()).to.be.eql(defaultSettings.sink[0]); | ||
expect(config.getTempPasswordConfig()).to.be.eql( | ||
defaultSettings.tempPassword, | ||
); | ||
}); | ||
|
||
it('should override default settings for authentication', function () { | ||
const user = { | ||
authentication: [ | ||
{ | ||
type: 'google', | ||
enabled: true, | ||
}, | ||
], | ||
}; | ||
fs.writeFileSync(tempUserFile, JSON.stringify(user)); | ||
|
||
const config = require('../src/config'); | ||
|
||
expect(config.getAuthentication()).to.be.eql(user.authentication[0]); | ||
expect(config.getAuthentication()).to.not.be.eql( | ||
defaultSettings.authentication[0], | ||
); | ||
expect(config.getDatabase()).to.be.eql(defaultSettings.sink[0]); | ||
expect(config.getTempPasswordConfig()).to.be.eql( | ||
defaultSettings.tempPassword, | ||
); | ||
}); | ||
|
||
it('should override default settings for database', function () { | ||
const user = { | ||
sink: [ | ||
{ | ||
type: 'postgres', | ||
enabled: true, | ||
}, | ||
], | ||
}; | ||
fs.writeFileSync(tempUserFile, JSON.stringify(user)); | ||
|
||
const config = require('../src/config'); | ||
|
||
expect(config.getDatabase()).to.be.eql(user.sink[0]); | ||
expect(config.getDatabase()).to.not.be.eql(defaultSettings.sink[0]); | ||
expect(config.getAuthentication()).to.be.eql( | ||
defaultSettings.authentication[0], | ||
); | ||
expect(config.getTempPasswordConfig()).to.be.eql( | ||
defaultSettings.tempPassword, | ||
); | ||
}); | ||
|
||
afterEach(function () { | ||
fs.unlinkSync(curDirUserFile); | ||
fs.rmSync(tempUserFile); | ||
fs.rmdirSync(tempDir); | ||
delete require.cache[require.resolve('../src/config')]; | ||
}); | ||
}); |