0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

fix(config): respect the changePassword configuration flag (#3849)

This commit is contained in:
George Kalpakas 2023-06-02 19:52:41 +03:00 committed by GitHub
parent a13f1b3626
commit 679c19c1b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 1 deletions

View file

@ -0,0 +1,8 @@
---
'@verdaccio/config': patch
---
Respect the `changePassword` configuration flag to enable changing the password through the web API.
> **Note**
> This feature is still experimental and not fully supported in the default web application.

View file

@ -84,6 +84,7 @@ class Config implements AppConfig {
this.serverSettings = serverSettings;
this.flags = {
searchRemote: config.flags?.searchRemote ?? true,
changePassword: config.flags?.changePassword ?? false,
};
this.user_agent = config.user_agent;

View file

@ -13,6 +13,7 @@ export const HEADER_TYPE = {
CONTENT_TYPE: 'content-type',
CONTENT_LENGTH: 'content-length',
ACCEPT_ENCODING: 'accept-encoding',
AUTHORIZATION: 'authorization',
};
export const CHARACTER_ENCODING = {

View file

@ -79,6 +79,63 @@ describe('test web server', () => {
.expect(HTTP_STATUS.CANNOT_HANDLE, JSON.stringify({ error: 'cannot handle this' }));
});
test('should not change password if flag is disabled', async () => {
const oldPass = 'test';
const newPass = 'new-pass';
const api = supertest(await initializeServer('change-password-disabled.yaml'));
// Login with the old password.
const loginRes = await api
.post('/-/verdaccio/sec/login')
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify({
username: 'test',
password: oldPass,
})
)
.expect(HTTP_STATUS.OK);
// Try changing the password.
await api
.put('/-/verdaccio/sec/reset_password')
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.set(HEADER_TYPE.AUTHORIZATION, `Bearer ${loginRes.body.token}`)
.send(
JSON.stringify({
password: {
old: oldPass,
new: newPass,
},
})
)
.expect(HTTP_STATUS.CANNOT_HANDLE);
// Verify that you cannot login with the new (rejected) password.
await api
.post('/-/verdaccio/sec/login')
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify({
username: 'test',
password: newPass,
})
)
.expect(HTTP_STATUS.UNAUTHORIZED);
// Verify that you can still login with the old password.
await api
.post('/-/verdaccio/sec/login')
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify({
username: 'test',
password: oldPass,
})
)
.expect(HTTP_STATUS.OK);
});
test.todo('should change password');
test.todo('should not change password if flag is disabled');
});

View file

@ -0,0 +1,28 @@
auth:
auth-memory:
users:
test:
name: test
password: test
web:
title: verdaccio
publish:
allow_offline: false
uplinks:
log: { type: stdout, format: pretty, level: trace }
packages:
'@*/*':
access: $anonymous
publish: $anonymous
'**':
access: $anonymous
publish: $anonymous
_debug: true
flags:
changePassword: false