Skip to content

Commit

Permalink
fix(server): handle PasswordConflict explicitly to avoid a 500 (Jig…
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens authored Apr 17, 2024
1 parent 5bd4647 commit be0d3b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/shadowbox/server/manager_service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,16 @@ describe('ShadowsocksManagerService', () => {
done();
});
});

it('rejects a password that is already in use', async (done) => {
const PASSWORD = 'foobar';
await repo.createNewAccessKey({password: PASSWORD});
const res = {send: SEND_NOTHING};
await serviceMethod({params: {id: accessKeyId, password: PASSWORD}}, res, (error) => {
expect(error.statusCode).toEqual(409);
responseProcessed = true; // required for afterEach to pass.
done();
});
});
it('uses the default port for new keys when no port is provided', async (done) => {
const res = {
send: (httpCode, data) => {
Expand Down
5 changes: 4 additions & 1 deletion src/shadowbox/server/manager_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ export class ShadowsocksManagerService {
logging.error(error);
if (error instanceof errors.InvalidCipher || error instanceof errors.InvalidPortNumber) {
throw new restifyErrors.InvalidArgumentError({statusCode: 400}, error.message);
} else if (error instanceof errors.PortUnavailable) {
} else if (
error instanceof errors.PortUnavailable ||
error instanceof errors.PasswordConflict
) {
throw new restifyErrors.ConflictError(error.message);
}
throw error;
Expand Down

0 comments on commit be0d3b3

Please sign in to comment.