Skip to content

Commit

Permalink
Merge pull request #157 from mbland/downcase-users-domains
Browse files Browse the repository at this point in the history
config: Convert users and domains to lowercase
  • Loading branch information
mbland committed Oct 25, 2017
2 parents 9b0bc10 + b02093b commit c2cd6a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ following required fields:
You must also provide at least one of the following fields:

* **users**: A list of specific user account names (usually email addresses)
that are authorized to access the server.
that are authorized to access the server. (Case insensitive)
* **domains**: A list of user domains (i.e. email address domains) that are
authorized to access the server.
authorized to access the server. (Case insensitive)

You may define both of these fields if you wish.

Expand Down
12 changes: 12 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@ function Config(configData) {
REDIS_PORT: true
}


applyEnvUpdates(configData)
validateConfig(configData)
setItemsToLowerCase(configData, ['users', 'domains'])

Object.keys(configData).forEach(key => {
var value = configData[key]
config[key] = numericValues[key] ? parseInt(value) : value
})
}

function setItemsToLowerCase(configData, properties) {
properties.forEach(prop => {
var items = configData[prop]

if (items !== undefined) {
configData[prop] = items.map(item => item.toLowerCase())
}
})
}

Config.fromFile = (configPath, logger) => {
var errorPrefix

Expand Down
11 changes: 11 additions & 0 deletions tests/server/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ describe('config', function() {
expect(JSON.stringify(config)).to.equal(JSON.stringify(configData))
})

it('converts users and domains to lowercase', function() {
var configData = helpers.baseConfig(),
config

configData.users = ['MBland@acm.org']
configData.domains = ['ACM.org']
config = new Config(configData)
expect(config.users).to.eql(['mbland@acm.org'])
expect(config.domains).to.eql(['acm.org'])
})

it('raises errors for missing fields', function() {
var errors = [
'missing PORT',
Expand Down

0 comments on commit c2cd6a2

Please sign in to comment.