Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1/controllers/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import DB from '../../../lib/db.mjs'
*/
export async function generatePassword (req, res, next) {
const pwd = generator.generate({
length: Config.get().generated_password_length || 20,
length: req.query.length || Config.get().generated_password_length || 15,
numbers: true,
symbols: req?.query?.symbols !== 'false',
lowercase: true,
Expand Down
2 changes: 1 addition & 1 deletion config-skel.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
},
"readonly": false,
"enable_metrics": true,
"generated_password_length": 20
"generated_password_length": 15
}
11 changes: 11 additions & 0 deletions docs/apidoc/parameters/util.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ symbols:
required: false
schema:
type: string

length:
name: length
in: query
description: The length of the generated password
required: false
schema:
type: integer
minimum: 1
maximum: 50
default: 15
1 change: 1 addition & 0 deletions docs/apidoc/paths/utilgeneratepassword.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ get:
- bearerAuth: []
parameters:
- $ref: '..\parameters\util.yaml#/symbols'
- $ref: '..\parameters\util.yaml#/length'
responses:
"200":
$ref: '..\responsebodies\util.yaml#/generatepasswordsuccess'
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ Copy `config-skel.json` to `config.json` and adjust the options (all options are
- `max_hours`: Max one-time secrets duration, expressed in hours
- `readonly`: true or false; if true, no write operation is allowed both for admins and non-admins (logging is still operational)
- `enable_metrics`: true or false, enables Prometheus-formatted metrics
- `generated_password_length`: length of random generated password, default is 20
- `generated_password_length`: default length of random generated password (default is 15)

## 5. Prepare the database

Expand Down
6 changes: 4 additions & 2 deletions test/generator.spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ require('./common.cjs')
describe('Generator', function () {
it('Generate password with symbols', async () => {
const res1 = await agent
.get(`${global.host}/api/v1/util/generatepassword`)
.get(`${global.host}/api/v1/util/generatepassword?length=25`)
.set('Authorization', `Bearer ${global.userJWT}`)
.catch(v => v)

assert.strictEqual(res1.status, 200)
assert.strictEqual(res1.body.data.password.length, 25)
})

it('Generate password without symbols', async () => {
const res1 = await agent
.get(`${global.host}/api/v1/util/generatepassword?symbols=false`)
.get(`${global.host}/api/v1/util/generatepassword?length=25&symbols=false`)
.set('Authorization', `Bearer ${global.userJWT}`)
.catch(v => v)

assert.strictEqual(res1.status, 200)
assert.strictEqual(res1.body.data.password.length, 25)
})
})