-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modular: each streaming store decides what usernames are valid
- Loading branch information
1 parent
3475290
commit 94db9bd
Showing
4 changed files
with
51 additions
and
23 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
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,8 @@ | ||
/** each streaming store decides what user names are valid, and may use its own password validation if desired. */ | ||
|
||
module.exports = { | ||
EMAIL_PATTERN: /[\p{L}\p{N}]@[a-zA-Z0-9][a-zA-Z0-9.]/u, | ||
EMAIL_ERROR: 'Email must contain an alphanumeric, followed by an @-sign, followed by two ASCII alphanumerics', | ||
PASSWORD_PATTERN: /\S{8,}/, | ||
PASSWORD_ERROR: 'Password must contain at least 8 non-space 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 |
---|---|---|
|
@@ -8,37 +8,37 @@ chai.use(require('chai-as-promised')); | |
module.exports.shouldCreateDeleteAndReadAccounts = function () { | ||
describe('createUser', function () { | ||
before(function () { | ||
this.username1 = 'automated-test-' + Math.round(Math.random() * Number.MAX_SAFE_INTEGER); | ||
this.username = 'automated-test-' + Math.round(Math.random() * Number.MAX_SAFE_INTEGER); | ||
}); | ||
|
||
after(async function () { | ||
await this.store.deleteUser(this.username1); | ||
await this.store.deleteUser(this.username); | ||
}); | ||
|
||
it('rejects a user with too short a name', async function () { | ||
const params = { username: 'a', email: '[email protected]', password: 'swordfish' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, 'Username must be at least 2 characters'); | ||
const params = { username: 'aa', email: '[email protected]', password: 'swordfish' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, /user\s?name/i); | ||
}); | ||
|
||
it('rejects creating a user with illegal characters in username', async function () { | ||
const params = { username: 'a+a', email: '[email protected]', password: 'swordfish' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, 'only contain lowercase letters, numbers, dots, dashes and underscores'); | ||
const params = { username: this.username + '\\q', email: '[email protected]', password: 'swordfish' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, /user\s?name/i); | ||
}); | ||
|
||
it('rejects creating a user with bad email', async function () { | ||
const params = { username: 'a1a', email: 'a@b', password: 'swordfish' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, 'Email is not valid'); | ||
const params = { username: this.username + 'j', email: 'a@b', password: 'swordfish' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, /email/i); | ||
}); | ||
|
||
it('rejects creating a user without password', async function () { | ||
const params = { username: 'a2a', email: '[email protected]', password: '' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, 'Password must not be blank'); | ||
const params = { username: this.username + 'h', email: '[email protected]', password: '' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, /password/i); | ||
}); | ||
|
||
it('creates a user & rejects creating a new user with an existing name', async function () { | ||
const params1 = { username: this.username1, email: '[email protected]', password: 'swordfish' }; | ||
await expect(this.store.createUser(params1)).to.eventually.eql(this.username1); | ||
const params2 = { username: this.username1, email: '[email protected]', password: 'iloveyou' }; | ||
const params1 = { username: this.username, email: '[email protected]', password: 'swordfish' }; | ||
await expect(this.store.createUser(params1)).to.eventually.eql(this.username + this.USER_NAME_SUFFIX); | ||
const params2 = { username: this.username, email: '[email protected]', password: 'iloveyou' }; | ||
await expect(this.store.createUser(params2)).to.be.rejectedWith(Error, 'is already taken'); | ||
}); | ||
}); | ||
|
@@ -54,7 +54,7 @@ module.exports.shouldCreateDeleteAndReadAccounts = function () { | |
|
||
it('deletes a user', async function () { | ||
const params = { username: this.username2, email: '[email protected]', password: 'swordfish' }; | ||
await expect(this.store.createUser(params)).to.eventually.eql(this.username2); | ||
await expect(this.store.createUser(params)).to.eventually.eql(this.username2 + this.USER_NAME_SUFFIX); | ||
const result = await this.store.deleteUser(this.username2); | ||
await expect(result?.[0]).to.be.greaterThanOrEqual(2); | ||
await expect(result?.[1]).to.equal(0); | ||
|
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
/* eslint-env mocha, chai, node */ | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const s3handler = require('../../lib/routes/S3Handler'); | ||
const { shouldStoreStream } = require('../streaming_handler.spec'); | ||
const { configureLogger } = require('../../lib/logger'); | ||
|
@@ -10,12 +12,20 @@ const { shouldCreateDeleteAndReadAccounts } = require('../account.spec'); | |
describe('S3 streaming handler', function () { | ||
before(function () { | ||
configureLogger({ stdout: [], log_dir: './test-log', log_files: ['debug'] }); | ||
this.USER_NAME_SUFFIX = '-java.extraordinary.org'; | ||
// If the environment variables aren't set, tests are run using a shared public account on play.min.io | ||
this.handler = s3handler(process.env.S3_ENDPOINT, process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY); | ||
this.handler = s3handler(process.env.S3_ENDPOINT, process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY, undefined, this.USER_NAME_SUFFIX); | ||
this.store = this.handler; | ||
}); | ||
|
||
shouldCreateDeleteAndReadAccounts(); | ||
|
||
describe('createUser (S3-specific)', function () { | ||
it('rejects a user with too long a name for the user name suffix', async function () { | ||
const params = { username: 'a-------10--------20--------30--------40-', email: '[email protected]', password: 'swordfish' }; | ||
await expect(this.store.createUser(params)).to.be.rejectedWith(Error, '3–40 characters long'); | ||
}); | ||
}); | ||
|
||
shouldStoreStream(); | ||
}); |